Changeset 775 for branches/features/taskProcedureRework/grails-app/controllers/TaskProcedureDetailedController.groovy
- Timestamp:
- Feb 3, 2011, 5:12:40 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/features/taskProcedureRework/grails-app/controllers/TaskProcedureDetailedController.groovy
r774 r775 5 5 6 6 def filterService 7 def authService8 7 def taskProcedureService 9 8 … … 69 68 } 70 69 catch(org.springframework.dao.DataIntegrityViolationException e) { 71 flash. message = "TaskProcedure ${params.id} could not be deleted"70 flash.errorMessage = "TaskProcedure ${params.id} could not be deleted" 72 71 redirect(controller:'taskDetailed', 73 72 action:'show', … … 77 76 } 78 77 else { 79 flash. message = "TaskProcedure not found with id ${params.id}"78 flash.errorMessage = "TaskProcedure not found with id ${params.id}" 80 79 redirect(action:list) 81 80 } … … 91 90 92 91 if(!taskProcedureInstance) { 93 flash. message = "TaskProcedure not found with id ${params.id}"92 flash.errorMessage = "TaskProcedure not found with id ${params.id}" 94 93 redirect(action:list) 95 94 } … … 112 111 113 112 if(result.error.code == "default.not.found") { 114 flash. message = g.message(code: result.error.code, args: result.error.args)113 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 115 114 redirect(action:list) 115 return 116 } 117 118 if(result.error.code == "default.optimistic.locking.failure") { 119 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 120 redirect(controller:'taskDetailed', 121 action:'show', 122 id:result.taskProcedureInstance.linkedTask.id, 123 params:[showTab:"showProcedureTab"]) 116 124 return 117 125 } … … 130 138 params.linkedTask = Task.get(params.taskInstance.id) 131 139 140 // Task already has a taskProcedure. 141 if(params.linkedTask.taskProcedure) { 142 flash.errorMessage = g.message(code: 'default.optimistic.locking.failure') 143 redirect(controller:'taskDetailed', 144 action:'show', 145 id:params.linkedTask.id, 146 params:[showTab:"showProcedureTab"]) 147 return 148 } 149 150 // Task does not have a primaryAsset. 132 151 if(!params.linkedTask?.primaryAsset) { 133 152 flash.errorMessage = "Please set a Primary Asset first, then go to the Procedure tab." … … 142 161 143 162 def save = { 144 def taskProcedureInstance = new TaskProcedure(params) 145 taskProcedureInstance.createdBy = authService.currentUser 146 taskProcedureInstance.lastUpdatedBy = authService.currentUser 147 def taskInstance = Task.get(params.linkedTask.id) 163 def result = taskProcedureService.save(params) 148 164 149 // Gaps in the html index's can be created by adding 2 items and removing the first one. 150 // This creates a gap at the missing index where LazyList will return a null. 151 def nullMaintenanceActions = taskProcedureInstance.maintenanceActions.findAll {!it} 152 if (nullMaintenanceActions) { 153 taskProcedureInstance.maintenanceActions.removeAll(nullMaintenanceActions) 165 if(!result.error) { 166 flash.message = g.message(code: "default.create.success", args: ["TaskProcedure", result.taskProcedureInstance.id]) 167 redirect(controller:'taskDetailed', 168 action:'show', 169 id:result.taskProcedureInstance.linkedTask.id, 170 params:[showTab:"showProcedureTab"]) 171 return 154 172 } 155 173 156 if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { 157 // Also sets: taskInstance.taskProcedure = taskProcedureInstance 158 taskProcedureInstance.addToTasks(taskInstance) 159 flash.message = "TaskProcedure ${taskProcedureInstance.id} created." 174 if(result.error.code == "default.optimistic.locking.failure") { 175 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 160 176 redirect(controller:'taskDetailed', 161 177 action:'show', 162 id: taskProcedureInstance.linkedTask.id,178 id:result.taskProcedureInstance.linkedTask.id, 163 179 params:[showTab:"showProcedureTab"]) 180 return 164 181 } 165 else { 166 // Populate maintenanceAction errors for display. 167 taskProcedureInstance.maintenanceActions.each { it.validate() } 168 render(view:'create',model:[taskProcedureInstance:taskProcedureInstance]) 169 } 182 183 render(view:'create', model:[taskProcedureInstance: result.taskProcedureInstance]) 170 184 } 171 185
Note: See TracChangeset
for help on using the changeset viewer.