Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing problem with saving birthday #274

Merged
merged 20 commits into from May 4, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 14 additions & 11 deletions app/controllers/Profiles.java
Expand Up @@ -19,6 +19,7 @@
import org.apache.ivy.util.cli.ParseException; import org.apache.ivy.util.cli.ParseException;


import play.data.validation.Error; import play.data.validation.Error;
import play.data.validation.Match;


public class Profiles extends OBController { public class Profiles extends OBController {


Expand All @@ -40,11 +41,15 @@ public static void updateInformation(String birthday, String relationshipStatus,
User user = user(); User user = user();
Profile profile = Profile.find("owner = ?", user).first(); Profile profile = Profile.find("owner = ?", user).first();
profile.religion = religion; profile.religion = religion;
profile.relationshipStatus = Profile.Relationship.fromString(relationshipStatus);
DateFormat birthday_formatting = new SimpleDateFormat("MM/dd/yyyy"); DateFormat birthday_formatting = new SimpleDateFormat("MM/dd/yyyy");
try{ if(birthday != null){
profile.birthday = (Date) birthday_formatting.parse(birthday); try{
} catch (java.text.ParseException e) { profile.birthday = (Date) birthday_formatting.parse(birthday);
e.printStackTrace(); } 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; profile.gender = gender;
Expand All @@ -54,10 +59,11 @@ public static void updateInformation(String birthday, String relationshipStatus,
try { try {
profile.anniversary = (Date) anniversary_formatting.parse(anniversary); profile.anniversary = (Date) anniversary_formatting.parse(anniversary);
} catch (java.text.ParseException e) { } 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(); Language lang = Language.find("name = ?", language).first();
UserLanguage userlang = new UserLanguage(profile, lang); UserLanguage userlang = new UserLanguage(profile, lang);
Expand All @@ -74,18 +80,15 @@ public static void updateInformation(String birthday, String relationshipStatus,
public static void updateContactInfo(String phone, String address){ public static void updateContactInfo(String phone, String address){
User user = user(); User user = user();
Profile profile = Profile.find("owner = ?", user).first(); Profile profile = Profile.find("owner = ?", user).first();

String previousPhone = profile.phone;
if(!phone.equals("Add A Phone Number")){ if(!phone.equals("Add A Phone Number")){
profile.phone = phone; profile.phone = phone;
} }
else else
profile.phone = ""; profile.phone = "";
validation.phone(profile.phone); validation.phone(profile.phone);
if(validation.hasErrors()) { if(validation.hasErrors()) {
for(Error error: validation.errors()){ profile.phone = previousPhone;
System.out.println("\n\n\n\n" + error.message() + "\n\n\n\n");
}
profile.phone = "Add A Phone Number";
} }


if(!address.equals("Add Current Address")) if(!address.equals("Add Current Address"))
Expand Down
27 changes: 15 additions & 12 deletions app/models/Profile.java
Expand Up @@ -9,7 +9,7 @@
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;


import play.data.validation.Phone; import play.data.validation.*;


import utils.Bootstrap; import utils.Bootstrap;


Expand All @@ -27,6 +27,7 @@ public class Profile extends Model {


@OneToOne @OneToOne
public User significantOther; // The user's significant other 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 Date anniversary; // date of anniversary


public String bio; // The user's biography public String bio; // The user's biography
Expand All @@ -37,7 +38,8 @@ public class Profile extends Model {
@OneToOne @OneToOne
public Photo gravatarPhoto; 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 @ManyToOne
public Location location; // The user's current city public Location location; // The user's current city
Expand All @@ -53,16 +55,16 @@ public class Profile extends Model {
public String quotes; // The user's favorite quotes public String quotes; // The user's favorite quotes


public enum Relationship { public enum Relationship {
SINGLE ("single"), SINGLE ("Single"),
ENGAGED ("engaged"), ENGAGED ("Engaged"),
MARRIED ("married"), MARRIED ("Married"),
ITSCOMPLICATED ("it's complicated"), ITSCOMPLICATED ("It's complicated"),
OPEN ("open"), OPEN ("Open relationship"),
WIDOWED ("widowed"), WIDOWED ("Widowed"),
SEPERATED ("seperated"), SEPERATED ("Seperated"),
DIVORCED ("divorced"), DIVORCED ("Divorced"),
CIVILUNION ("civil union"), CIVILUNION ("Civil union"),
DOMESTIC ("domestic partnership"); DOMESTIC ("Domestic partnership");


private final String text; private final String text;
Relationship(String text) { Relationship(String text) {
Expand Down Expand Up @@ -149,5 +151,6 @@ public Profile(User owner, String bio, String gender, String quotes, String phon
this.phone = phone; this.phone = phone;
this.quotes = quotes; this.quotes = quotes;
this.website = website; this.website = website;
this.profilePhoto = Photo.findById(Bootstrap.defaultProfilePhotoID);
} }
} }
69 changes: 37 additions & 32 deletions app/views/Users/profile.html
Expand Up @@ -5,8 +5,13 @@
<script type="text/javascript" src="/public/javascripts/profile.js"></script> <script type="text/javascript" src="/public/javascripts/profile.js"></script>


<div class="globalContentAbout"> <div class="globalContentAbout">
<div class="LeftColumnAbout"> <div class="LeftColumnAbout">
<div class="Panel"> <div class="Panel">
#{ifErrors}
#{errors}
<li><b><font color="red"> ${error}</font></b></li>
#{/errors}
#{/ifErrors}
<span class="PanelTitle">&{'profile.about.you'}</span> <span class="PanelTitle">&{'profile.about.you'}</span>
<button class="EditButton" id="AboutMeEditButton">Edit<img src="@{'public/images/edit_icon.gif'}" /> <button class="EditButton" id="AboutMeEditButton">Edit<img src="@{'public/images/edit_icon.gif'}" />
</button><br/> </button><br/>
Expand Down Expand Up @@ -49,8 +54,13 @@
<td><label><b>&{'profile.birthday'}: </b></br> </label> <td><label><b>&{'profile.birthday'}: </b></br> </label>
</td> </td>
<td> <td>
<input type="text" id="datepicker" name="birthday" #{if profile.birthday != null}
value=""/> <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> </td>
</tr> </tr>
<tr> <tr>
Expand All @@ -63,9 +73,9 @@
</tr> </tr>


<tr> <tr>
<td><label><b>&{'profile.interested.in'}:</b></label></td> <td><label><b>&{'profile.interested.in'}: </b></label></td>
<td> <td>
#{select 'gender', value:profile.interestedIn} #{select 'interestedIn', value:profile.interestedIn}
#{option ''}#{/option} #{option ''}#{/option}
#{option 'Men'}Men#{/option} #{option 'Men'}Men#{/option}
#{option 'Women'}Women#{/option} #{option 'Women'}Women#{/option}
Expand All @@ -78,7 +88,8 @@
<tr> <tr>
<td><label><b>&{'profile.relationship.status'}: </b></label></td> <td><label><b>&{'profile.relationship.status'}: </b></label></td>
<td> <td>
#{select 'status', value:profile.relationshipStatus} #{select 'relationshipStatus', value:profile.relationshipStatus}
#{option ''}#{/option}
#{option 'Single'}Single#{/option} #{option 'Single'}Single#{/option}
#{option 'In a relationship'}In a relationship#{/option} #{option 'In a relationship'}In a relationship#{/option}
#{option 'Engaged'}Engaged#{/option} #{option 'Engaged'}Engaged#{/option}
Expand All @@ -96,7 +107,7 @@
#{if profile.hasAnniversary()} #{if profile.hasAnniversary()}
<tr> <tr>
<td><label><b>&{'profile.anniversary'}: </b></br></label></td> <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> </tr>
#{/if} #{/if}


Expand All @@ -121,44 +132,45 @@
</tr> </tr>
</table> </table>
<input type="submit" value="Save" id="updateInformation" /> <input type="submit" value="Save" id="updateInformation" />
<input type="reset" value="Cancel">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will the Cancel do? Have you tested it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

#{/form} #{/form}
</div> </div>
<div class="Data" id="InformationData" style="display:block;"> <div class="Data" id="InformationData" style="display:block;">
<table> <table>
#{if profile.birthday} #{if profile.birthday != null}
<tr> <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> <td class="data">${profile.birthday.format("MM/dd/yyyy")}</td>
</tr> </tr>
#{/if} #{/if}
#{if profile.gender} #{if profile.gender}
<tr> <tr>
<td><label><b>Sex:</b></label></td> <td><label><b>&{'profile.sex'}:</b></label></td>
<td class="data">${profile.gender}</td> <td class="data">${profile.gender}</td>
</tr> </tr>
#{/if} #{/if}
#{if profile.interestedIn} #{if profile.interestedIn}
<tr> <tr>
<td><label><b>Interested in:</b></label></td> <td><label><b>&{'profile.interested.in'}:</b></label></td>
<td class="data">${profile.interestedIn}</td> <td class="data">${profile.interestedIn}</td>
</tr> </tr>
#{/if} #{/if}
#{if profile.relationshipStatus} #{if profile.relationshipStatus}
<tr> <tr>
<td><label><b>Relationship Status: </b></label></td> <td><label><b>&{'profile.relationship.status'}: </b></label></td>
<td class="data">${profile.relationshipStatus} <td class="data">${profile.relationshipStatus.toString()}
</td> </td>
</tr> </tr>
#{/if} #{/if}
#{if profile.hasAnniversary()} #{if profile.anniversary != null}
<tr> <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> <td class="data">${profile.anniversary.format("MM/dd/yyyy")}</td>
</tr> </tr>
#{/if} #{/if}
#{if profile.languages.size() > 0} #{if profile.languages.size() > 0}
<tr> <tr>
<td><label>Languages: </label></td> <td><label>&{'profile.languages'}: </label></td>
<td> <td>
#{list items:profile.languages, as:'lang'} #{list items:profile.languages, as:'lang'}
${lang.toString()} ${lang.toString()}
Expand All @@ -169,13 +181,13 @@
#{/if} #{/if}
#{if profile.religion} #{if profile.religion}
<tr> <tr>
<td><label><b>Religious views: </b></label></td> <td><label><b>&{'profile.religious.views'}: </b></label></td>
<td> ${profile.religion}</td> <td> ${profile.religion}</td>
</tr> </tr>
#{/if} #{/if}
#{if profile.political} #{if profile.political}
<tr> <tr>
<td><label><b>Political Views: </b></label></td> <td><label><b>&{'profile.political.views'}: </b></label></td>
<td>${profile.political}</td> <td>${profile.political}</td>
</tr> </tr>
#{/if} #{/if}
Expand Down Expand Up @@ -205,27 +217,20 @@
</tr> </tr>
</table> </table>
<input type="submit" value="Save" id="updateContactInfo" /> <input type="submit" value="Save" id="updateContactInfo" />
<input type="reset" value="Cancel"> <input type="reset" value="Cancel">
#{/form} #{/form}
</div> </div>
<div class="Data" id="ContactInfoData" style="display:block;"> <div class="Data" id="ContactInfoData" style="display:block;">
<table> <table>
#{if profile.phone} #{if profile.phone}
<tr> <tr>
<td><label><b>Phone: </b></label></td> <td><label><b>&{'profile.phone'}: </b></label></td>
#{ifErrors} <td>${profile.phone}</td>
#{errors}
<li><b>Please enter a phone number</b></li>
#{/errors}
#{/ifErrors}
#{else}
<td>${profile.phone}</td>
#{/else}
</tr> </tr>
#{/if} #{/if}
#{if profile.address} #{if profile.address}
<tr> <tr>
<td><label><b>Address: </b></label></td> <td><label><b>&{'profile.address'}: </b></label></td>
<td>${profile.address}</td> <td>${profile.address}</td>
</tr> </tr>
#{/if} #{/if}
Expand Down Expand Up @@ -261,6 +266,7 @@
</tr> </tr>
</table> </table>
<input type="submit" value="Save" id="updateWorkEdu" /> <input type="submit" value="Save" id="updateWorkEdu" />
<input type="reset" value="Cancel">
#{/form} #{/form}
</div> </div>
<div class="Data" id="WorkEduData" style="display:block;"> <div class="Data" id="WorkEduData" style="display:block;">
Expand Down Expand Up @@ -299,7 +305,8 @@
</td> </td>
</tr> </tr>
</table> </table>
<input type="submit" value="Save" id="updateLiving" /> <input type="submit" value="Save" id="updateLiving" />
<input type="reset" value="Cancel">
#{/form} #{/form}
</div> </div>
<div class="Data" id="LivingData" style="display:block;"> <div class="Data" id="LivingData" style="display:block;">
Expand Down Expand Up @@ -343,6 +350,4 @@
</div> </div>
</div> </div>
</div> </div>
<div class="demo">
</div>
</div> </div>
2 changes: 2 additions & 0 deletions conf/initial-data.yml
Expand Up @@ -58,9 +58,11 @@ Profile(bobProfile):


Profile(jeffProfile): Profile(jeffProfile):
owner: jeff owner: jeff
birthday: 1992-05-05


Profile(aliceProfile): Profile(aliceProfile):
owner: alice owner: alice
birthday: 1991-05-10


Profile(gparkerProfile): Profile(gparkerProfile):
owner: gparker owner: gparker
Expand Down
2 changes: 2 additions & 0 deletions conf/messages
Expand Up @@ -47,6 +47,8 @@ profile.living=Living
profile.hometown=Hometown profile.hometown=Hometown
profile.favorite.quotations=Favorite Quotations profile.favorite.quotations=Favorite Quotations
profile.quote=Quotes profile.quote=Quotes
validation.phone=Please enter a phone number
validation.match=Please enter a valid date format (MM/dd/yyyy)


# Skin # Skin
skin.editMsg=Edit My Skin skin.editMsg=Edit My Skin
Expand Down