From 90c85f39570270b879e2d3020fe95231410f57c6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 24 Oct 2010 18:24:44 +0200 Subject: [PATCH] Add birth date to profile. --- .../java/net/pterodactylus/sone/core/Core.java | 7 ++ .../pterodactylus/sone/core/SoneDownloader.java | 5 ++ .../java/net/pterodactylus/sone/data/Profile.java | 78 ++++++++++++++++++++++ .../pterodactylus/sone/web/EditProfilePage.java | 11 +++ src/main/resources/i18n/sone.en.properties | 7 ++ src/main/resources/static/css/sone.css | 10 +++ src/main/resources/templates/editProfile.html | 20 ++++++ src/main/resources/templates/insert/sone.xml | 3 + 8 files changed, 141 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 56e60d4..1c282d8 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -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++; diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index a611bae..a01c296 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -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"); diff --git a/src/main/java/net/pterodactylus/sone/data/Profile.java b/src/main/java/net/pterodactylus/sone/data/Profile.java index 7662eda..72901b3 100644 --- a/src/main/java/net/pterodactylus/sone/data/Profile.java +++ b/src/main/java/net/pterodactylus/sone/data/Profile.java @@ -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; + } + } diff --git a/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java b/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java index 181c454..372562b 100644 --- a/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java +++ b/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java @@ -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); } // diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 43996a1..f093d44 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -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! diff --git a/src/main/resources/static/css/sone.css b/src/main/resources/static/css/sone.css index 5908c82..5c83091 100644 --- a/src/main/resources/static/css/sone.css +++ b/src/main/resources/static/css/sone.css @@ -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; diff --git a/src/main/resources/templates/editProfile.html b/src/main/resources/templates/editProfile.html index 601188f..0760525 100644 --- a/src/main/resources/templates/editProfile.html +++ b/src/main/resources/templates/editProfile.html @@ -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(); @@ -38,6 +41,23 @@ +

<%= Page.EditProfile.Birthday.Title|l10n|html>

+ +
+ + +
+ +
+ + +
+ +
+ + +
+
diff --git a/src/main/resources/templates/insert/sone.xml b/src/main/resources/templates/insert/sone.xml index 229ac42..782eccd 100644 --- a/src/main/resources/templates/insert/sone.xml +++ b/src/main/resources/templates/insert/sone.xml @@ -9,6 +9,9 @@ <% currentSone.profile.firstName|xml> <% currentSone.profile.middleName|xml> <% currentSone.profile.lastName|xml> + <% currentSone.profile.birthDay|xml> + <% currentSone.profile.birthMonth|xml> + <% currentSone.profile.birthYear|xml> -- 2.7.4