+ protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
+ super.processTemplate(request, dataProvider);
+ ToadletContext toadletContenxt = request.getToadletContext();
+ Sone currentSone = getCurrentSone(toadletContenxt);
+ Profile profile = currentSone.getProfile();
+ String firstName = profile.getFirstName();
+ String middleName = profile.getMiddleName();
+ String lastName = profile.getLastName();
+ Integer birthDay = profile.getBirthDay();
+ Integer birthMonth = profile.getBirthMonth();
+ Integer birthYear = profile.getBirthYear();
+ Map<String, String> fields = profile.getFields();
+ if (request.getMethod() == Method.POST) {
+ if (request.getHttpRequest().getPartAsStringFailsafe("save-profile", 4).equals("true")) {
+ firstName = request.getHttpRequest().getPartAsStringFailsafe("first-name", 256).trim();
+ middleName = request.getHttpRequest().getPartAsStringFailsafe("middle-name", 256).trim();
+ lastName = request.getHttpRequest().getPartAsStringFailsafe("last-name", 256).trim();
+ birthDay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-day", 256).trim());
+ birthMonth = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-month", 256).trim());
+ birthYear = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-year", 256).trim());
+ profile.setFirstName(firstName.length() > 0 ? firstName : null);
+ profile.setMiddleName(middleName.length() > 0 ? middleName : null);
+ profile.setLastName(lastName.length() > 0 ? lastName : null);
+ profile.setBirthDay(birthDay).setBirthMonth(birthMonth).setBirthYear(birthYear);
+ for (int fieldIndex = 0; fieldIndex < profile.getFieldNames().size(); ++fieldIndex) {
+ String value = request.getHttpRequest().getPartAsStringFailsafe("field-" + fieldIndex, 400);
+ profile.setField(fieldIndex, value);
+ }
+ currentSone.setProfile(profile);
+ webInterface.getCore().saveSone(currentSone);
+ throw new RedirectException("index.html");
+ } else if (request.getHttpRequest().getPartAsStringFailsafe("add-field", 4).equals("true")) {
+ String fieldName = request.getHttpRequest().getPartAsStringFailsafe("field-name", 256).trim();
+ try {
+ profile.addField(fieldName);
+ currentSone.setProfile(profile);
+ fields = profile.getFields();
+ webInterface.getCore().saveSone(currentSone);
+ } catch (IllegalArgumentException iae1) {
+ dataProvider.set("fieldName", fieldName);
+ dataProvider.set("duplicateFieldName", true);
+ }
+ } else {
+ int deleteFieldIndex = getFieldIndex(request, "delete-field-");
+ if (deleteFieldIndex > -1) {
+ throw new RedirectException("deleteProfileField.html?field=" + deleteFieldIndex);
+ }
+ int moveUpFieldIndex = getFieldIndex(request, "move-up-field-");
+ if (moveUpFieldIndex > -1) {
+ profile.moveFieldUp(moveUpFieldIndex);
+ currentSone.setProfile(profile);
+ throw new RedirectException("editProfile.html#profile-fields");
+ }
+ int moveDownFieldIndex = getFieldIndex(request, "move-down-field-");
+ if (moveDownFieldIndex > -1) {
+ profile.moveFieldDown(moveDownFieldIndex);
+ currentSone.setProfile(profile);
+ throw new RedirectException("editProfile.html#profile-fields");
+ }
+ int editFieldIndex = getFieldIndex(request, "edit-field-");
+ if (editFieldIndex > -1) {
+ throw new RedirectException("editProfileField.html?field=" + editFieldIndex);
+ }
+ }
+ }
+ dataProvider.set("firstName", firstName);
+ dataProvider.set("middleName", middleName);
+ dataProvider.set("lastName", lastName);
+ dataProvider.set("birthDay", birthDay);
+ dataProvider.set("birthMonth", birthMonth);
+ dataProvider.set("birthYear", birthYear);
+ dataProvider.set("fields", fields);