Add birth date to profile.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 24 Oct 2010 16:24:44 +0000 (18:24 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 24 Oct 2010 16:24:44 +0000 (18:24 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/SoneDownloader.java
src/main/java/net/pterodactylus/sone/data/Profile.java
src/main/java/net/pterodactylus/sone/web/EditProfilePage.java
src/main/resources/i18n/sone.en.properties
src/main/resources/static/css/sone.css
src/main/resources/templates/editProfile.html
src/main/resources/templates/insert/sone.xml

index 56e60d4..1c282d8 100644 (file)
@@ -620,11 +620,15 @@ public class Core extends AbstractService {
                        String firstName = configuration.getStringValue(sonePrefix + "/Profile/FirstName").getValue(null);
                        String middleName = configuration.getStringValue(sonePrefix + "/Profile/MiddleName").getValue(null);
                        String lastName = configuration.getStringValue(sonePrefix + "/Profile/LastName").getValue(null);
+                       Integer birthDay = configuration.getIntValue(sonePrefix + "/Profile/BirthDay").getValue(null);
+                       Integer birthMonth = configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").getValue(null);
+                       Integer birthYear = configuration.getIntValue(sonePrefix + "/Profile/BirthYear").getValue(null);
                        try {
                                Profile profile = new Profile();
                                profile.setFirstName(firstName);
                                profile.setMiddleName(middleName);
                                profile.setLastName(lastName);
+                               profile.setBirthDay(birthDay).setBirthMonth(birthMonth).setBirthYear(birthYear);
                                Sone sone = getSone(id).setName(name).setTime(time).setRequestUri(new FreenetURI(requestUri)).setInsertUri(new FreenetURI(insertUri));
                                sone.setProfile(profile);
                                int postId = 0;
@@ -755,6 +759,9 @@ public class Core extends AbstractService {
                                configuration.getStringValue(sonePrefix + "/Profile/FirstName").setValue(profile.getFirstName());
                                configuration.getStringValue(sonePrefix + "/Profile/MiddleName").setValue(profile.getMiddleName());
                                configuration.getStringValue(sonePrefix + "/Profile/LastName").setValue(profile.getLastName());
+                               configuration.getIntValue(sonePrefix + "/Profile/BirthDay").setValue(profile.getBirthDay());
+                               configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").setValue(profile.getBirthMonth());
+                               configuration.getIntValue(sonePrefix + "/Profile/BirthYear").setValue(profile.getBirthYear());
                                int postId = 0;
                                for (Post post : sone.getPosts()) {
                                        String postPrefix = sonePrefix + "/Post." + postId++;
index a611bae..a01c296 100644 (file)
@@ -32,6 +32,7 @@ import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.util.io.Closer;
 import net.pterodactylus.util.logging.Logging;
+import net.pterodactylus.util.number.Numbers;
 import net.pterodactylus.util.service.AbstractService;
 import net.pterodactylus.util.xml.SimpleXML;
 import net.pterodactylus.util.xml.XML;
@@ -219,7 +220,11 @@ public class SoneDownloader extends AbstractService {
                        String profileFirstName = profileXml.getValue("first-name", null);
                        String profileMiddleName = profileXml.getValue("middle-name", null);
                        String profileLastName = profileXml.getValue("last-name", null);
+                       Integer profileBirthDay = Numbers.safeParseInteger(profileXml.getValue("birth-day", null));
+                       Integer profileBirthMonth = Numbers.safeParseInteger(profileXml.getValue("birth-month", null));
+                       Integer profileBirthYear = Numbers.safeParseInteger(profileXml.getValue("birth-year", null));
                        Profile profile = new Profile().setFirstName(profileFirstName).setMiddleName(profileMiddleName).setLastName(profileLastName);
+                       profile.setBirthDay(profileBirthDay).setBirthMonth(profileBirthMonth).setBirthYear(profileBirthYear);
 
                        /* parse posts. */
                        SimpleXML postsXml = soneXml.getNode("posts");
index 7662eda..72901b3 100644 (file)
@@ -37,6 +37,15 @@ public class Profile {
        /** The last name. */
        private String lastName;
 
+       /** The day of the birth date. */
+       private Integer birthDay;
+
+       /** The month of the birth date. */
+       private Integer birthMonth;
+
+       /** The year of the birth date. */
+       private Integer birthYear;
+
        /**
         * Creates a new empty profile.
         */
@@ -57,6 +66,9 @@ public class Profile {
                this.firstName = profile.firstName;
                this.middleName = profile.middleName;
                this.lastName = profile.lastName;
+               this.birthDay = profile.birthDay;
+               this.birthMonth = profile.birthMonth;
+               this.birthYear = profile.birthYear;
        }
 
        //
@@ -141,4 +153,70 @@ public class Profile {
                return this;
        }
 
+       /**
+        * Returns the day of the birth date.
+        *
+        * @return The day of the birth date (from 1 to 31)
+        */
+       public Integer getBirthDay() {
+               return birthDay;
+       }
+
+       /**
+        * Sets the day of the birth date.
+        *
+        * @param birthDay
+        *            The day of the birth date (from 1 to 31)
+        * @return This profile (for method chaining)
+        */
+       public Profile setBirthDay(Integer birthDay) {
+               modified |= ((birthDay != null) && (!birthDay.equals(this.birthDay))) || (this.birthDay != null);
+               this.birthDay = birthDay;
+               return this;
+       }
+
+       /**
+        * Returns the month of the birth date.
+        *
+        * @return The month of the birth date (from 1 to 12)
+        */
+       public Integer getBirthMonth() {
+               return birthMonth;
+       }
+
+       /**
+        * Sets the month of the birth date.
+        *
+        * @param birthMonth
+        *            The month of the birth date (from 1 to 12)
+        * @return This profile (for method chaining)
+        */
+       public Profile setBirthMonth(Integer birthMonth) {
+               modified |= ((birthMonth != null) && (!birthMonth.equals(this.birthMonth))) || (this.birthMonth != null);
+               this.birthMonth = birthMonth;
+               return this;
+       }
+
+       /**
+        * Returns the year of the birth date.
+        *
+        * @return The year of the birth date
+        */
+       public Integer getBirthYear() {
+               return birthYear;
+       }
+
+       /**
+        * Sets the year of the birth date.
+        *
+        * @param birthYear
+        *            The year of the birth date
+        * @return This profile (for method chaining)
+        */
+       public Profile setBirthYear(Integer birthYear) {
+               modified |= ((birthYear != null) && (!birthYear.equals(this.birthYear))) || (this.birthYear != null);
+               this.birthYear = birthYear;
+               return this;
+       }
+
 }
index 181c454..372562b 100644 (file)
@@ -20,6 +20,7 @@ package net.pterodactylus.sone.web;
 import net.pterodactylus.sone.data.Profile;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.page.Page.Request.Method;
+import net.pterodactylus.util.number.Numbers;
 import net.pterodactylus.util.template.Template;
 import freenet.clients.http.ToadletContext;
 
@@ -58,13 +59,20 @@ public class EditProfilePage extends SoneTemplatePage {
                String firstName = profile.getFirstName();
                String middleName = profile.getMiddleName();
                String lastName = profile.getLastName();
+               Integer birthDay = profile.getBirthDay();
+               Integer birthMonth = profile.getBirthMonth();
+               Integer birthYear = profile.getBirthYear();
                if (request.getMethod() == Method.POST) {
                        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);
                        if (profile.isModified()) {
                                currentSone.setProfile(profile);
                        }
@@ -73,6 +81,9 @@ public class EditProfilePage extends SoneTemplatePage {
                template.set("firstName", firstName);
                template.set("middleName", middleName);
                template.set("lastName", lastName);
+               template.set("birthDay", birthDay);
+               template.set("birthMonth", birthMonth);
+               template.set("birthYear", birthYear);
        }
 
        //
index 43996a1..f093d44 100644 (file)
@@ -78,6 +78,10 @@ Page.EditProfile.Page.Hint.Optionality=And remember, every single field of this
 Page.EditProfile.Label.FirstName=First name:
 Page.EditProfile.Label.MiddleName=Middle name(s):
 Page.EditProfile.Label.LastName=Last name:
+Page.EditProfile.Birthday.Title=Birthday
+Page.EditProfile.Birthday.Label.Day=Day:
+Page.EditProfile.Birthday.Label.Month=Month:
+Page.EditProfile.Birthday.Label.Year=Year:
 Page.EditProfile.Page.Status.Changed=Your changes have been saved and will be inserted shortly.
 Page.EditProfile.Button.Save=Save Profile
 Page.EditProfile.Keys.Title=Sone Keys
@@ -178,5 +182,8 @@ WebInterface.DefaultText.SoneRequestURI=Sone Request Key
 WebInterface.DefaultText.FirstName=First name
 WebInterface.DefaultText.MiddleName=Middle name(s)
 WebInterface.DefaultText.LastName=Last name
+WebInterface.DefaultText.BirthDay=Day
+WebInterface.DefaultText.BirthMonth=Month
+WebInterface.DefaultText.BirthYear=Year
 WebInterface.Confirmation.DeletePostButton=Yes, delete!
 WebInterface.Confirmation.DeleteReplyButton=Yes, delete!
index 5908c82..5c83091 100644 (file)
@@ -111,6 +111,16 @@ textarea {
        padding: 1em;
 }
 
+#sone #edit-profile #birth-day, #sone #edit-profile #birth-month, #sone #edit-profile #birth-year {
+       display: inline;
+       width: 15em;
+}
+
+#sone #edit-profile #birth-day input, #sone #edit-profile #birth-month input, #sone #edit-profile #birth-year input {
+       width: 4em;
+       text-align: right;
+}
+
 #sone .post {
        padding: 1ex 0px;
        border-bottom: solid 1px #ccc;
index 601188f..0760525 100644 (file)
@@ -5,6 +5,9 @@
                        registerInputTextareaSwap("#sone #edit-profile input[name=first-name]", "WebInterface.DefaultText.FirstName", "first-name", true, true);
                        registerInputTextareaSwap("#sone #edit-profile input[name=middle-name]", "WebInterface.DefaultText.MiddleName", "middle-name", true, true);
                        registerInputTextareaSwap("#sone #edit-profile input[name=last-name]", "WebInterface.DefaultText.LastName", "last-name", true, true);
+                       registerInputTextareaSwap("#sone #edit-profile input[name=birth-day]", "WebInterface.DefaultText.BirthDay", "birth-day", true, true);
+                       registerInputTextareaSwap("#sone #edit-profile input[name=birth-month]", "WebInterface.DefaultText.BirthMonth", "birth-month", true, true);
+                       registerInputTextareaSwap("#sone #edit-profile input[name=birth-year]", "WebInterface.DefaultText.BirthYear", "birth-year", true, true);
 
                        /* hide all the labels. */
                        $("#sone #edit-profile label").hide();
                        <input type="text" name="last-name" value="<% lastName|html>" />
                </div>
 
+               <h1><%= Page.EditProfile.Birthday.Title|l10n|html></h1>
+
+               <div id="birth-day">
+                       <label for="birth-day"><%= Page.EditProfile.Birthday.Label.Day|l10n|html></label>
+                       <input type="text" name="birth-day" value="<% birthDay|html>" />
+               </div>
+
+               <div id="birth-month">
+                       <label for="birth-month"><%= Page.EditProfile.Birthday.Label.Month|l10n|html></label>
+                       <input type="text" name="birth-month" value="<% birthMonth|html>" />
+               </div>
+
+               <div id="birth-year">
+                       <label for="birth-year"><%= Page.EditProfile.Birthday.Label.Year|l10n|html></label>
+                       <input type="text" name="birth-year" value="<% birthYear|html>" />
+               </div>
+
                <div>
                        <button type="submit"><%= Page.EditProfile.Button.Save|l10n|html></button>
                </div>
index 229ac42..782eccd 100644 (file)
@@ -9,6 +9,9 @@
                <first-name><% currentSone.profile.firstName|xml></first-name>
                <middle-name><% currentSone.profile.middleName|xml></middle-name>
                <last-name><% currentSone.profile.lastName|xml></last-name>
+               <birth-day><% currentSone.profile.birthDay|xml></birth-day>
+               <birth-month><% currentSone.profile.birthMonth|xml></birth-month>
+               <birth-year><% currentSone.profile.birthYear|xml></birth-year>
        </profile>
 
        <posts>