Changeset 774 for branches/features
- Timestamp:
- Feb 3, 2011, 2:50:45 AM (14 years ago)
- Location:
- branches/features/taskProcedureRework/grails-app
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/features/taskProcedureRework/grails-app/controllers/TaskProcedureDetailedController.groovy
r772 r774 6 6 def filterService 7 7 def authService 8 def taskProcedureService 8 9 9 10 def index = { redirect(action:list,params:params) } … … 99 100 100 101 def update = { 101 def taskProcedureInstance = TaskProcedure.get( params.id ) 102 if(taskProcedureInstance) { 103 if(params.version) { 104 def version = params.version.toLong() 105 if(taskProcedureInstance.version > version) { 102 def result = taskProcedureService.update(params) 106 103 107 taskProcedureInstance.errors.rejectValue("version", "default.optimistic.locking.failure")108 render(view:'edit',model:[taskProcedureInstance:taskProcedureInstance])109 return110 }111 }112 taskProcedureInstance.properties = params113 taskProcedureInstance.lastUpdatedBy = authService.currentUser114 taskProcedureInstance.lastUpdated = new Date() // Required to trigger version increment.104 if(!result.error) { 105 flash.message = g.message(code: "default.update.success", args: ["TaskProcedure", params.id]) 106 redirect(controller:'taskDetailed', 107 action:'show', 108 id:result.taskProcedureInstance.linkedTask.id, 109 params:[showTab:"showProcedureTab"]) 110 return 111 } 115 112 116 // Gaps in the html index's can be created by adding 2 items and removing the first one. 117 // This creates a gap at the missing index where LazyList will return a null. 118 def nullMaintenanceActions = taskProcedureInstance.maintenanceActions.findAll {!it} 119 if (nullMaintenanceActions) { 120 taskProcedureInstance.maintenanceActions.removeAll(nullMaintenanceActions) 121 } 113 if(result.error.code == "default.not.found") { 114 flash.message = g.message(code: result.error.code, args: result.error.args) 115 redirect(action:list) 116 return 117 } 122 118 123 // Save for restoration if validation fails. 124 def savedMaintenanceActions = new ArrayList(taskProcedureInstance.maintenanceActions) 125 126 // Remove toBeDeleted before validation. 127 def toBeDeleted = taskProcedureInstance.maintenanceActions.findAll {it.toBeDeleted} 128 if (toBeDeleted) { 129 taskProcedureInstance.maintenanceActions.removeAll(toBeDeleted) 130 } 131 132 if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { 133 flash.message = "TaskProcedure ${params.id} updated" 134 redirect(controller:'taskDetailed', 135 action:'show', 136 id:taskProcedureInstance.linkedTask.id, 137 params:[showTab:"showProcedureTab"]) 138 } 139 else { 140 // Restore the saved items, some of which contain toBeDeleted flags but 141 // have not been deleted yet since validation failed. 142 // The toBeDeleted items are hidden in the view. 143 taskProcedureInstance.maintenanceActions = savedMaintenanceActions 144 // Populate maintenanceAction errors for display. 145 taskProcedureInstance.maintenanceActions.each { it.validate() } 146 render(view:'edit',model:[taskProcedureInstance:taskProcedureInstance]) 147 } 148 } 149 else { 150 flash.message = "TaskProcedure not found with id ${params.id}" 151 redirect(action:list) 152 } 119 render(view:'edit', model:[taskProcedureInstance: result.taskProcedureInstance]) 153 120 } 154 121
Note: See TracChangeset
for help on using the changeset viewer.