- Timestamp:
- Jan 4, 2010, 8:13:03 AM (15 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 1 added
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/AssignedPersonDetailedController.groovy
r249 r255 12 12 // the delete, save and update actions only accept POST requests 13 13 static allowedMethods = [delete:'POST', save:'POST', update:'POST'] 14 15 def list = {16 def result = assignedPersonService.list(params)17 if(!result.error) {18 return [ assignedPersonInstanceList: result.assignedPersonInstanceList,19 assignedPersonInstanceTotal: result.assignedPersonInstanceTotal ]20 }21 22 flash.message = g.message(code: result.error.code, args: result.error.args)23 redirect( controller: "appCore", action: "start" )24 }25 26 def show = {27 def result = assignedPersonService.show(params)28 29 if(!result.error)30 return [ assignedPersonInstance: result.assignedPersonInstance ]31 32 flash.message = g.message(code: result.error.code, args: result.error.args)33 34 if(params.task?.id)35 redirect(controller:"taskDetailed", action:"show", id: params.task.id)36 37 redirect(controller:"taskDetailed", action:"search")38 }39 14 40 15 def delete = { … … 60 35 def result = assignedPersonService.edit(params) 61 36 62 if(!result.error) 63 return [ assignedPersonInstance : result.assignedPersonInstance ] 37 if(!result.error) { 38 return [assignedPersonInstance: result.assignedPersonInstance, 39 person: result.person, 40 groupsForPerson: result.groupsForPerson] 41 } 64 42 65 43 flash.message = g.message(code: result.error.code, args: result.error.args) … … 74 52 if(!result.error) { 75 53 flash.message = g.message(code: "default.update.success", args: ["AssignedPerson", params.id]) 76 redirect( action:show, id: params.id)54 redirect(controller:"taskDetailed", action:"show", id: result.assignedPersonInstance.task.id) 77 55 return 78 56 } … … 84 62 } 85 63 86 render(view:'edit', model:[assignedPersonInstance: result.assignedPersonInstance.attach()]) 64 if(result.error.code == "person.not.found") { 65 flash.message = g.message(code: result.error.code, args: result.error.args) 66 redirect(action:"edit", id: params.id) 67 return 68 } 69 70 render(view:'edit', model:[assignedPersonInstance: result.assignedPersonInstance.attach(), 71 person: result.person.attach(), 72 groupsForPerson: result.groupsForPerson]) 87 73 } 88 74 … … 90 76 def result = assignedPersonService.create(params) 91 77 92 if(!result.error) 93 return [assignedPersonInstance: result.assignedPersonInstance] 78 if(!result.error) { 79 return [assignedPersonInstance: result.assignedPersonInstance, 80 person: result.person, 81 groupsForPerson: result.groupsForPerson] 82 } 94 83 95 84 if(result.error.code == "assignedPerson.task.not.found") { … … 112 101 } 113 102 114 render(view:'edit', model:[assignedPersonInstance: result.assignedPersonInstance]) 103 if(result.error.code == "person.not.found") { 104 flash.message = g.message(code: result.error.code, args: result.error.args) 105 redirect(action:"create", params:["task.id": params.task?.id]) 106 return 107 } 108 109 render(view:'create', model:[assignedPersonInstance: result.assignedPersonInstance, 110 person: result.person.attach(), 111 groupsForPerson: result.groupsForPerson]) 112 } 113 114 def groupsForPerson = { 115 def result = assignedPersonService.groupsForPerson(params) 116 117 if(!result.error) { 118 render ( template:"groupsForPerson", 119 model: [person: result.person, groupsForPerson: result.groupsForPerson] ) 120 return 121 } 122 123 render { 124 div(id:"groupsForPerson", g.message(code: result.error.code, args: result.error.args) ) 125 } 126 115 127 } 116 128 -
trunk/grails-app/i18n/messages.properties
r254 r255 53 53 taskRecurringSchedule.notFound=Could not complete operation, recurring schedule not found. 54 54 personGroup.not.found=Person Group not found, it may have been deleted. 55 person.not.found=Person record not found, it may have been deleted. 55 56 56 57 task.assignedGroups=Assigned Groups -
trunk/grails-app/services/AssignedPersonService.groovy
r251 r255 4 4 5 5 def personService 6 7 def list(params) {8 def result = [:]9 def fail = { Map m ->10 result.error = [ code: m.code, args: ["AssignedPerson"] ]11 return result12 }13 14 params.max = Math.min( params.max ? params.max.toInteger() : 10, 100)15 result.assignedPersonInstanceList = AssignedPerson.list(params)16 result.assignedPersonInstanceTotal = AssignedPerson.count()17 18 if(!result.assignedPersonInstanceList || !result.assignedPersonInstanceTotal)19 return fail(code:"default.list.failure")20 21 // Success.22 return result23 }24 25 def show(params) {26 def result = [:]27 def fail = { Map m ->28 result.error = [ code: m.code, args: ["AssignedPerson", params.id] ]29 return result30 }31 32 result.assignedPersonInstance = AssignedPerson.get(params.id)33 34 if(!result.assignedPersonInstance)35 return fail(code:"default.not.found")36 37 // Success.38 return result39 }40 6 41 7 def delete(params) { … … 86 52 return fail(code:"default.not.found") 87 53 54 result.person = result.assignedPersonInstance.person 55 result.groupsForPerson = result.person.personGroups.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } 56 88 57 // Success. 89 58 return result … … 101 70 return result 102 71 } 72 73 result.person = Person.get(params.person.id) 74 75 // Prevent a null property reference. 76 if(!result.person) 77 return fail(code:"person.not.found") 78 79 result.groupsForPerson = result.person.personGroups.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } 103 80 104 81 result.assignedPersonInstance = AssignedPerson.get(params.id) … … 144 121 result.assignedPersonInstance.properties = params 145 122 146 // success 123 result.person = Person.list().sort { p1, p2 -> p1.firstName.compareToIgnoreCase(p2.firstName) }[0] // Get the first result. 124 result.groupsForPerson = result.person.personGroups.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } 125 126 // Success. 147 127 return result 148 128 } … … 153 133 154 134 def fail = { Map m -> 135 status.setRollbackOnly() 155 136 if(result.assignedPersonInstance && m.field) 156 137 result.assignedPersonInstance.errors.rejectValue(m.field, m.code) … … 159 140 } 160 141 161 result.assignedPersonInstance = new AssignedPerson(params) 142 result.person = Person.get(params.person.id) 143 144 // Prevent a null property reference. 145 if(!result.person) 146 return fail(code:"person.not.found") 147 148 result.groupsForPerson = result.person.personGroups.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } 149 150 result.assignedPersonInstance = new AssignedPerson() 151 result.assignedPersonInstance.properties = params 162 152 163 153 if(result.assignedPersonInstance.hasErrors() || !result.assignedPersonInstance.save()) … … 180 170 } // end save() 181 171 172 def groupsForPerson(params) { 173 def result = [:] 174 175 def fail = { Map m -> 176 result.error = [ code: m.code, args: ["Person", params.person?.id] ] 177 return result 178 } 179 180 result.person = Person.get(params.person?.id) 181 182 if(!result.person) 183 return fail(code:"default.not.found") 184 185 result.groupsForPerson = result.person.personGroups.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } 186 187 // Success. 188 return result 189 } 190 182 191 } // end class -
trunk/grails-app/views/assignedPersonDetailed/create.gsp
r249 r255 5 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 6 6 <meta name="layout" content="main" /> 7 <title>Create AssignedPerson</title> 7 <title>Create AssignedPerson</title> 8 8 </head> 9 9 <body> … … 42 42 </td> 43 43 <td valign="top" class="value ${hasErrors(bean:assignedPersonInstance,field:'person','errors')}"> 44 <g:select optionKey="id" from="${Person.list()}" name="person.id" value="${assignedPersonInstance?.person?.id}" ></g:select> 44 <g:select optionKey="id" 45 from="${Person.list().sort { p1, p2 -> p1.firstName.compareToIgnoreCase(p2.firstName) }}" 46 name="person.id" 47 value="${assignedPersonInstance?.person?.id}" 48 onchange="${remoteFunction(action:'groupsForPerson', update:'groupsForPerson', params: '\'person.id=\' + this.value' )}"> 49 </g:select> 45 50 </td> 46 </tr> 51 </tr> 47 52 48 53 <tr class="prop"> … … 70 75 </div> 71 76 </g:form> 77 78 <br /> 79 80 <div id="groupsForPerson" class="dialog"> 81 <g:render template="groupsForPerson" /> 82 </div> 83 72 84 </div> 73 85 </body> -
trunk/grails-app/views/assignedPersonDetailed/edit.gsp
r249 r255 44 44 </td> 45 45 <td valign="top" class="value ${hasErrors(bean:assignedPersonInstance,field:'person','errors')}"> 46 <g:select optionKey="id" from="${Person.list()}" name="person.id" value="${assignedPersonInstance?.person?.id}" ></g:select> 46 <g:select optionKey="id" 47 from="${Person.list().sort { p1, p2 -> p1.firstName.compareToIgnoreCase(p2.firstName) }}" 48 name="person.id" 49 value="${assignedPersonInstance?.person?.id}" 50 onchange="${remoteFunction(action:'groupsForPerson', update:'groupsForPerson', params: '\'person.id=\' + this.value' )}"> 51 </g:select> 47 52 </td> 48 53 </tr> … … 72 77 </div> 73 78 </g:form> 79 80 <br /> 81 82 <div id="groupsForPerson" class="dialog"> 83 <g:render template="groupsForPerson" /> 84 </div> 85 74 86 </div> 75 87 </body>
Note: See TracChangeset
for help on using the changeset viewer.