Browse files

Personal summary model refactorized

  • Loading branch information...
1 parent c0a079f commit 9e793af54db1fef347d9f0056ef6d36a2dccefc0 @marpiec committed Apr 24, 2012
View
9 ...n/scala/pl/marpiec/socnet/web/page/editUserProfilePage/model/JobExperienceFormModel.scala
@@ -3,7 +3,6 @@ package pl.marpiec.socnet.web.page.editUserProfilePage.model
import pl.marpiec.socnet.service.userprofile.input.JobExperienceParam
import pl.marpiec.socnet.web.wicket.SecureFormModel
import pl.marpiec.util.UID
-import org.joda.time.LocalDate
import pl.marpiec.socnet.model.userprofile.JobExperience
/**
@@ -38,22 +37,22 @@ class JobExperienceFormModel extends SecureFormModel {
object JobExperienceFormModel {
def apply(param:JobExperience) = {
+ val model = new JobExperienceFormModel
copy(new JobExperienceFormModel, param)
+ model
}
- def copy(to:JobExperienceFormModel, from:JobExperience):JobExperienceFormModel = {
+ def copy(to:JobExperienceFormModel, from:JobExperience) {
to.id = from.id
to.companyName = from.companyName
to.position = from.position
to.description = from.description
- to
}
- def copy(to:JobExperience, from:JobExperienceFormModel):JobExperience = {
+ def copy(to:JobExperience, from:JobExperienceFormModel) {
to.id = from.id
to.companyName = from.companyName
to.position = from.position
to.description = from.description
- to
}
}
View
46 ...scala/pl/marpiec/socnet/web/page/editUserProfilePage/model/PersonalSummaryFormModel.scala
@@ -2,11 +2,55 @@ package pl.marpiec.socnet.web.page.editUserProfilePage.model
import pl.marpiec.socnet.service.userprofile.input.PersonalSummary
import pl.marpiec.socnet.web.wicket.SecureFormModel
+import pl.marpiec.socnet.model.UserProfile
/**
* @author Marcin Pieciukiewicz
*/
-class PersonalSummaryFormModel extends PersonalSummary with SecureFormModel {
+class PersonalSummaryFormModel extends SecureFormModel {
+ var professionalTitle: String = _
+ var city: String = _
+ var province: String = _
+ var wwwPage: String = _
+ var blogPage: String = _
+ var summary: String = _
+ def createPersonalSummary():PersonalSummary = {
+ val summary = new PersonalSummary
+ summary.professionalTitle = this.professionalTitle
+ summary.city = this.city
+ summary.province = this.province
+ summary.wwwPage = this.wwwPage
+ summary.blogPage = this.blogPage
+ summary.summary = this.summary
+ summary
+ }
+}
+
+object PersonalSummaryFormModel {
+
+ def apply(from: UserProfile):PersonalSummaryFormModel = {
+ val model = new PersonalSummaryFormModel
+ copy(model, from)
+ model
+ }
+
+ def copy(to: PersonalSummaryFormModel, from: UserProfile) {
+ to.professionalTitle = from.professionalTitle
+ to.city = from.city
+ to.province = from.province
+ to.wwwPage = from.wwwPage
+ to.blogPage = from.blogPage
+ to.summary = from.summary
+ }
+
+ def copy(to: UserProfile, from: PersonalSummaryFormModel) {
+ to.professionalTitle = from.professionalTitle
+ to.city = from.city
+ to.province = from.province
+ to.wwwPage = from.wwwPage
+ to.blogPage = from.blogPage
+ to.summary = from.summary
+ }
}
View
44 ...rpiec/socnet/web/page/editUserProfilePage/personalSummaryPanel/PersonalSummaryPanel.scala
@@ -9,11 +9,10 @@ import org.apache.wicket.ajax.markup.html.form.AjaxButton
import pl.marpiec.socnet.model.{User, UserProfile}
import pl.marpiec.socnet.di.Factory
import pl.marpiec.socnet.service.userprofile.UserProfileCommand
-import pl.marpiec.socnet.service.userprofile.input.PersonalSummary
-import org.apache.wicket.markup.html.form.{TextArea, TextField, Form}
import org.apache.wicket.model.{PropertyModel, CompoundPropertyModel}
import pl.marpiec.socnet.web.wicket.{SecureAjaxButton, SecureForm}
import pl.marpiec.socnet.web.page.editUserProfilePage.model.PersonalSummaryFormModel
+import org.apache.wicket.markup.html.form.{TextField, TextArea, Form}
/**
* ...
@@ -22,12 +21,14 @@ import pl.marpiec.socnet.web.page.editUserProfilePage.model.PersonalSummaryFormM
class PersonalSummaryPanel(id: String, val user: User, val userProfile: UserProfile) extends Panel(id) {
+ //dependencies
val userProfileCommand: UserProfileCommand = Factory.userProfileCommand
+ //initialization
var edit = false
-
setOutputMarkupId(true)
+ //schema
add(new WebMarkupContainer("personalSummaryPreview") {
add(new Label("professionalTitle", new PropertyModel(userProfile, "professionalTitle")))
@@ -52,7 +53,7 @@ class PersonalSummaryPanel(id: String, val user: User, val userProfile: UserProf
add(new SecureForm[PersonalSummaryFormModel]("personalSummaryForm") {
- val model = copyModelFromUserProfile(new PersonalSummaryFormModel)
+ val model = PersonalSummaryFormModel(userProfile)
setModel(new CompoundPropertyModel[PersonalSummaryFormModel](model))
@@ -67,8 +68,8 @@ class PersonalSummaryPanel(id: String, val user: User, val userProfile: UserProf
add(new AjaxButton("cancelButton") {
def onSubmit(target: AjaxRequestTarget, form: Form[_]) {
- val personalSummaryFormModel = form.getModel.asInstanceOf[CompoundPropertyModel[PersonalSummaryFormModel]].getObject
- copyModelFromUserProfile(personalSummaryFormModel)
+ val formModel = form.getModel.asInstanceOf[CompoundPropertyModel[PersonalSummaryFormModel]].getObject
+ PersonalSummaryFormModel.copy(formModel, userProfile)
edit = false
target.add(PersonalSummaryPanel.this)
}
@@ -80,10 +81,12 @@ class PersonalSummaryPanel(id: String, val user: User, val userProfile: UserProf
add(new SecureAjaxButton("submitButton") {
override def onSecureSubmit(target: AjaxRequestTarget, form: Form[_]) {
- val personalSummaryFormModel = form.getModel.asInstanceOf[CompoundPropertyModel[PersonalSummaryFormModel]].getObject
+ val formModel = form.getModel.asInstanceOf[CompoundPropertyModel[PersonalSummaryFormModel]].getObject
+
+ saveChangesToUserProfile(formModel)
+ copyFormDataIntoUserProfile(formModel)
- saveChangesToUserProfile(personalSummaryFormModel)
- copyFormDataIntoUserProfile(personalSummaryFormModel)
+ userProfile.incrementVersion
edit = false
target.add(PersonalSummaryPanel.this)
}
@@ -94,27 +97,12 @@ class PersonalSummaryPanel(id: String, val user: User, val userProfile: UserProf
}
})
- def copyModelFromUserProfile(model: PersonalSummaryFormModel): PersonalSummaryFormModel = {
- model.blogPage = userProfile.blogPage
- model.wwwPage = userProfile.wwwPage
- model.professionalTitle = userProfile.professionalTitle
- model.city = userProfile.city
- model.province = userProfile.province
- model.summary = userProfile.summary
- model
- }
-
- def copyFormDataIntoUserProfile(form: PersonalSummary) {
- userProfile.professionalTitle = form.professionalTitle
- userProfile.city = form.city
- userProfile.province = form.province
- userProfile.wwwPage = form.wwwPage
- userProfile.blogPage = form.blogPage
- userProfile.summary = form.summary
+ def copyFormDataIntoUserProfile(form: PersonalSummaryFormModel) {
+ PersonalSummaryFormModel.copy(userProfile, form)
userProfile.version = userProfile.version + 1
}
- def saveChangesToUserProfile(personalSummary: PersonalSummary) {
- userProfileCommand.updatePersonalSummary(user.id, userProfile.id, userProfile.version, personalSummary)
+ def saveChangesToUserProfile(personalSummary: PersonalSummaryFormModel) {
+ userProfileCommand.updatePersonalSummary(user.id, userProfile.id, userProfile.version, personalSummary.createPersonalSummary)
}
}

0 comments on commit 9e793af

Please sign in to comment.