Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixing problem with saving birthday #274

Merged
merged 20 commits into from

2 participants

@fism88
Collaborator

Should be able to save birthdays for different users. #163

Added cancel button to each of the sections in the edit profile page. #165

Added default birthday values to upcoming dates for Alice and Jeff in initial data #273

Able to save Interested in field now #163

Added more internationalisation (i18n) to profile html file #147

Able to save relationship status now #163

app/controllers/Profiles.java
@@ -41,10 +41,12 @@ public static void updateInformation(String birthday, String relationshipStatus,
Profile profile = Profile.find("owner = ?", user).first();
profile.religion = religion;
DateFormat birthday_formatting = new SimpleDateFormat("MM/dd/yyyy");
- try{
- profile.birthday = (Date) birthday_formatting.parse(birthday);
- } catch (java.text.ParseException e) {
- e.printStackTrace();
+ if(birthday != null){
+ try{
+ profile.birthday = (Date) birthday_formatting.parse(birthday);
+ } catch (java.text.ParseException e) {
+ e.printStackTrace();
@amshali Collaborator
amshali added a note

you need to do something proper on the exception. It is very important to handle it well. We don't want to show the user the exception trace. Handle it, show a proper message to the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
app/controllers/Profiles.java
@@ -57,6 +59,8 @@ public static void updateInformation(String birthday, String relationshipStatus,
e.printStackTrace();
}
}
+// if(profile.relationshipStatus != null)
@amshali Collaborator
amshali added a note

remove the comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@amshali amshali commented on the diff
app/views/Users/profile.html
@@ -121,11 +126,12 @@
</tr>
</table>
<input type="submit" value="Save" id="updateInformation" />
+ <input type="reset" value="Cancel">
@amshali Collaborator
amshali added a note

What will the Cancel do? Have you tested it?

@fism88 Collaborator
fism88 added a note

Yes I tested it and it reverts back to the previous state for all the fields associated with it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@amshali
Collaborator

What's up?

@fism88
Collaborator

Does this now look better for the error messages?

@amshali
Collaborator

No. Look how errors are handled here:
http://www.playframework.org/documentation/1.2.4/guide4

@amshali
Collaborator

Also look at the signup page and how errors are handled there,

@fism88
Collaborator

Right, the validation. I'm still working on the regex and testing because I am using validation.match to handle user input errors for calendar related fields.

@amshali
Collaborator

As soon as you send an update I will review and merge it. Make sure you pull first.

@fism88
Collaborator

Okay I moved the error messages to display all of them at the top of the left panel in red and tested to see if saving still works.

@fism88
Collaborator

Just a heads up, I fixed some other things as well

@amshali
Collaborator

let me test it

@amshali amshali merged commit 9de6b17 into w7cook:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 2, 2012
  1. @fism88
  2. @fism88
  3. @fism88

    Added Cancel buttons

    fism88 authored
Commits on May 3, 2012
  1. @fism88
  2. @fism88

    Fixing anniversary issue

    fism88 authored
  3. @fism88
  4. @fism88
  5. @fism88
  6. @fism88
  7. @fism88
  8. @fism88

    Setting default skin

    fism88 authored
  9. @fism88
  10. @fism88
  11. @fism88
  12. @fism88
  13. @fism88

    removing .orig files

    fism88 authored
  14. @fism88

    Removing unused else statement

    fism88 authored
  15. @fism88

    Fixed interested in field

    fism88 authored
Commits on May 4, 2012
  1. @fism88

    i18n to more fields

    fism88 authored
  2. @fism88

    Saves relationship status

    fism88 authored
This page is out of date. Refresh to see the latest.
View
25 app/controllers/Profiles.java
@@ -19,6 +19,7 @@
import org.apache.ivy.util.cli.ParseException;
import play.data.validation.Error;
+import play.data.validation.Match;
public class Profiles extends OBController {
@@ -40,11 +41,15 @@ public static void updateInformation(String birthday, String relationshipStatus,
User user = user();
Profile profile = Profile.find("owner = ?", user).first();
profile.religion = religion;
+ profile.relationshipStatus = Profile.Relationship.fromString(relationshipStatus);
DateFormat birthday_formatting = new SimpleDateFormat("MM/dd/yyyy");
- try{
- profile.birthday = (Date) birthday_formatting.parse(birthday);
- } catch (java.text.ParseException e) {
- e.printStackTrace();
+ if(birthday != null){
+ try{
+ profile.birthday = (Date) birthday_formatting.parse(birthday);
+ } catch (java.text.ParseException e) {
+ Logger.error("Birthday should be in format: MM/dd/yyyy", e);
+ validation.match(birthday, ("\\^\\(0\\[1-9\\]\\|1\\[012\\]\\)\\[-/.\\]\\(0\\[1-9\\]\\|\\[12\\]\\[0-9\\]\\|3\\[01\\]\\)\\[-/.\\]\\(19\\|20\\)\\d\\d\\$"));
+ }
}
profile.gender = gender;
@@ -54,10 +59,11 @@ public static void updateInformation(String birthday, String relationshipStatus,
try {
profile.anniversary = (Date) anniversary_formatting.parse(anniversary);
} catch (java.text.ParseException e) {
- e.printStackTrace();
+ Logger.error("Anniversary should be in format: MM/dd/yyyy", e);
+ validation.match(anniversary, ("\\^\\(0\\[1-9\\]\\|1\\[012\\]\\)\\[-/.\\]\\(0\\[1-9\\]\\|\\[12\\]\\[0-9\\]\\|3\\[01\\]\\)\\[-/.\\]\\(19\\|20\\)\\d\\d\\$"));
}
+
}
- // profile.relationshipStatus = relationshipStatus;
Language lang = Language.find("name = ?", language).first();
UserLanguage userlang = new UserLanguage(profile, lang);
@@ -74,7 +80,7 @@ public static void updateInformation(String birthday, String relationshipStatus,
public static void updateContactInfo(String phone, String address){
User user = user();
Profile profile = Profile.find("owner = ?", user).first();
-
+ String previousPhone = profile.phone;
if(!phone.equals("Add A Phone Number")){
profile.phone = phone;
}
@@ -82,10 +88,7 @@ public static void updateContactInfo(String phone, String address){
profile.phone = "";
validation.phone(profile.phone);
if(validation.hasErrors()) {
- for(Error error: validation.errors()){
- System.out.println("\n\n\n\n" + error.message() + "\n\n\n\n");
- }
- profile.phone = "Add A Phone Number";
+ profile.phone = previousPhone;
}
if(!address.equals("Add Current Address"))
View
27 app/models/Profile.java
@@ -9,7 +9,7 @@
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
-import play.data.validation.Phone;
+import play.data.validation.*;
import utils.Bootstrap;
@@ -27,6 +27,7 @@
@OneToOne
public User significantOther; // The user's significant other
+ @Match("\\^\\(0\\[1-9\\]\\|1\\[012\\]\\)\\[-/.\\]\\(0\\[1-9\\]\\|\\[12\\]\\[0-9\\]\\|3\\[01\\]\\)\\[-/.\\]\\(19\\|20\\)\\d\\d\\$")
public Date anniversary; // date of anniversary
public String bio; // The user's biography
@@ -37,7 +38,8 @@
@OneToOne
public Photo gravatarPhoto;
- public Date birthday; // The user's birthday, uses jJQuery UI
+ @Match("\\^\\(0\\[1-9\\]\\|1\\[012\\]\\)\\[-/.\\]\\(0\\[1-9\\]\\|\\[12\\]\\[0-9\\]\\|3\\[01\\]\\)\\[-/.\\]\\(19\\|20\\)\\d\\d\\$")
+ public Date birthday; // The user's birthday, uses JQuery UI
@ManyToOne
public Location location; // The user's current city
@@ -53,16 +55,16 @@
public String quotes; // The user's favorite quotes
public enum Relationship {
- SINGLE ("single"),
- ENGAGED ("engaged"),
- MARRIED ("married"),
- ITSCOMPLICATED ("it's complicated"),
- OPEN ("open"),
- WIDOWED ("widowed"),
- SEPERATED ("seperated"),
- DIVORCED ("divorced"),
- CIVILUNION ("civil union"),
- DOMESTIC ("domestic partnership");
+ SINGLE ("Single"),
+ ENGAGED ("Engaged"),
+ MARRIED ("Married"),
+ ITSCOMPLICATED ("It's complicated"),
+ OPEN ("Open relationship"),
+ WIDOWED ("Widowed"),
+ SEPERATED ("Seperated"),
+ DIVORCED ("Divorced"),
+ CIVILUNION ("Civil union"),
+ DOMESTIC ("Domestic partnership");
private final String text;
Relationship(String text) {
@@ -149,5 +151,6 @@ public Profile(User owner, String bio, String gender, String quotes, String phon
this.phone = phone;
this.quotes = quotes;
this.website = website;
+ this.profilePhoto = Photo.findById(Bootstrap.defaultProfilePhotoID);
}
}
View
69 app/views/Users/profile.html
@@ -5,8 +5,13 @@
<script type="text/javascript" src="/public/javascripts/profile.js"></script>
<div class="globalContentAbout">
- <div class="LeftColumnAbout">
+ <div class="LeftColumnAbout">
<div class="Panel">
+ #{ifErrors}
+ #{errors}
+ <li><b><font color="red"> ${error}</font></b></li>
+ #{/errors}
+ #{/ifErrors}
<span class="PanelTitle">&{'profile.about.you'}</span>
<button class="EditButton" id="AboutMeEditButton">Edit<img src="@{'public/images/edit_icon.gif'}" />
</button><br/>
@@ -49,8 +54,13 @@
<td><label><b>&{'profile.birthday'}: </b></br> </label>
</td>
<td>
- <input type="text" id="datepicker" name="birthday"
- value=""/>
+ #{if profile.birthday != null}
+ <input type="text" id="datepicker" name="birthday"
+ value="${profile.birthday.format("MM/dd/yyyy")}"/>
+ #{/if}
+ #{else}
+ <input type="text" id="datepicker" name="birthday" value="Add birthday" />
+ #{/else}
</td>
</tr>
<tr>
@@ -63,9 +73,9 @@
</tr>
<tr>
- <td><label><b>&{'profile.interested.in'}:</b></label></td>
+ <td><label><b>&{'profile.interested.in'}: </b></label></td>
<td>
- #{select 'gender', value:profile.interestedIn}
+ #{select 'interestedIn', value:profile.interestedIn}
#{option ''}#{/option}
#{option 'Men'}Men#{/option}
#{option 'Women'}Women#{/option}
@@ -78,7 +88,8 @@
<tr>
<td><label><b>&{'profile.relationship.status'}: </b></label></td>
<td>
- #{select 'status', value:profile.relationshipStatus}
+ #{select 'relationshipStatus', value:profile.relationshipStatus}
+ #{option ''}#{/option}
#{option 'Single'}Single#{/option}
#{option 'In a relationship'}In a relationship#{/option}
#{option 'Engaged'}Engaged#{/option}
@@ -96,7 +107,7 @@
#{if profile.hasAnniversary()}
<tr>
<td><label><b>&{'profile.anniversary'}: </b></br></label></td>
- <td><input type="text" id="datepicker" name="anniversary" value=""/></td>
+ <td><input type="text" id="datepicker" name="anniversary" /></td>
</tr>
#{/if}
@@ -121,44 +132,45 @@
</tr>
</table>
<input type="submit" value="Save" id="updateInformation" />
+ <input type="reset" value="Cancel">
@amshali Collaborator
amshali added a note

What will the Cancel do? Have you tested it?

@fism88 Collaborator
fism88 added a note

Yes I tested it and it reverts back to the previous state for all the fields associated with it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
#{/form}
</div>
<div class="Data" id="InformationData" style="display:block;">
<table>
- #{if profile.birthday}
+ #{if profile.birthday != null}
<tr>
- <td><label><b>Birthday:</b></label></td>
+ <td><label><b>&{'profile.birthday'}:</b></label></td>
<td class="data">${profile.birthday.format("MM/dd/yyyy")}</td>
</tr>
#{/if}
#{if profile.gender}
<tr>
- <td><label><b>Sex:</b></label></td>
+ <td><label><b>&{'profile.sex'}:</b></label></td>
<td class="data">${profile.gender}</td>
</tr>
#{/if}
#{if profile.interestedIn}
<tr>
- <td><label><b>Interested in:</b></label></td>
+ <td><label><b>&{'profile.interested.in'}:</b></label></td>
<td class="data">${profile.interestedIn}</td>
</tr>
#{/if}
#{if profile.relationshipStatus}
<tr>
- <td><label><b>Relationship Status: </b></label></td>
- <td class="data">${profile.relationshipStatus}
+ <td><label><b>&{'profile.relationship.status'}: </b></label></td>
+ <td class="data">${profile.relationshipStatus.toString()}
</td>
</tr>
#{/if}
- #{if profile.hasAnniversary()}
+ #{if profile.anniversary != null}
<tr>
- <td><label><b>Anniversary: </b></br></label></td>
+ <td><label><b>&{'profile.anniversary'}: </b></br></label></td>
<td class="data">${profile.anniversary.format("MM/dd/yyyy")}</td>
</tr>
#{/if}
#{if profile.languages.size() > 0}
<tr>
- <td><label>Languages: </label></td>
+ <td><label>&{'profile.languages'}: </label></td>
<td>
#{list items:profile.languages, as:'lang'}
${lang.toString()}
@@ -169,13 +181,13 @@
#{/if}
#{if profile.religion}
<tr>
- <td><label><b>Religious views: </b></label></td>
+ <td><label><b>&{'profile.religious.views'}: </b></label></td>
<td> ${profile.religion}</td>
</tr>
#{/if}
#{if profile.political}
<tr>
- <td><label><b>Political Views: </b></label></td>
+ <td><label><b>&{'profile.political.views'}: </b></label></td>
<td>${profile.political}</td>
</tr>
#{/if}
@@ -205,27 +217,20 @@
</tr>
</table>
<input type="submit" value="Save" id="updateContactInfo" />
- <input type="reset" value="Cancel">
+ <input type="reset" value="Cancel">
#{/form}
</div>
<div class="Data" id="ContactInfoData" style="display:block;">
<table>
#{if profile.phone}
<tr>
- <td><label><b>Phone: </b></label></td>
- #{ifErrors}
- #{errors}
- <li><b>Please enter a phone number</b></li>
- #{/errors}
- #{/ifErrors}
- #{else}
- <td>${profile.phone}</td>
- #{/else}
+ <td><label><b>&{'profile.phone'}: </b></label></td>
+ <td>${profile.phone}</td>
</tr>
#{/if}
#{if profile.address}
<tr>
- <td><label><b>Address: </b></label></td>
+ <td><label><b>&{'profile.address'}: </b></label></td>
<td>${profile.address}</td>
</tr>
#{/if}
@@ -261,6 +266,7 @@
</tr>
</table>
<input type="submit" value="Save" id="updateWorkEdu" />
+ <input type="reset" value="Cancel">
#{/form}
</div>
<div class="Data" id="WorkEduData" style="display:block;">
@@ -299,7 +305,8 @@
</td>
</tr>
</table>
- <input type="submit" value="Save" id="updateLiving" />
+ <input type="submit" value="Save" id="updateLiving" />
+ <input type="reset" value="Cancel">
#{/form}
</div>
<div class="Data" id="LivingData" style="display:block;">
@@ -343,6 +350,4 @@
</div>
</div>
</div>
- <div class="demo">
- </div>
</div>
View
2  conf/initial-data.yml
@@ -58,9 +58,11 @@ Profile(bobProfile):
Profile(jeffProfile):
owner: jeff
+ birthday: 1992-05-05
Profile(aliceProfile):
owner: alice
+ birthday: 1991-05-10
Profile(gparkerProfile):
owner: gparker
View
2  conf/messages
@@ -47,6 +47,8 @@ profile.living=Living
profile.hometown=Hometown
profile.favorite.quotations=Favorite Quotations
profile.quote=Quotes
+validation.phone=Please enter a phone number
+validation.match=Please enter a valid date format (MM/dd/yyyy)
# Skin
skin.editMsg=Edit My Skin
Something went wrong with that request. Please try again.