Changeset 798 for trunk/grails-app/controllers
- Timestamp:
- Feb 8, 2011, 11:00:27 PM (14 years ago)
- Location:
- trunk/grails-app/controllers
- Files:
-
- 2 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/TaskProcedureDetailedController.groovy
r403 r798 5 5 6 6 def filterService 7 def assetService 8 def taskProcedureService 7 9 8 10 def index = { redirect(action:list,params:params) } … … 40 42 41 43 if(!taskProcedureInstance) { 42 flash.message = "TaskProcedure not found with id ${params.id}" 43 redirect(action:list) 44 } 45 else { return [ taskProcedureInstance : taskProcedureInstance ] } 44 flash.errorMessage = "TaskProcedure not found with id ${params.id}" 45 redirect(controller:'taskDetailed', action:'search') 46 return 47 } 48 49 redirect(controller:'taskDetailed', 50 action:'show', 51 id:taskProcedureInstance.linkedTask?.id, 52 params:[showTab:"showProcedureTab"]) 46 53 } 47 54 … … 49 56 def taskProcedureInstance = TaskProcedure.get( params.id ) 50 57 if(taskProcedureInstance) { 58 def taskInstance = taskProcedureInstance.linkedTask 51 59 try { 60 taskProcedureInstance.tasks.each { 61 it.taskProcedure = null 62 } 52 63 taskProcedureInstance.delete(flush:true) 53 64 flash.message = "TaskProcedure ${params.id} deleted" 54 redirect(action:list) 65 redirect(controller:'taskDetailed', 66 action:'show', 67 id:taskInstance.id, 68 params:[showTab:"showProcedureTab"]) 55 69 } 56 70 catch(org.springframework.dao.DataIntegrityViolationException e) { 57 flash.message = "TaskProcedure ${params.id} could not be deleted" 58 redirect(action:show,id:params.id) 71 flash.errorMessage = "TaskProcedure ${params.id} could not be deleted" 72 redirect(controller:'taskDetailed', 73 action:'show', 74 id:taskInstance.id, 75 params:[showTab:"showProcedureTab"]) 59 76 } 60 77 } 61 78 else { 62 flash. message = "TaskProcedure not found with id ${params.id}"79 flash.errorMessage = "TaskProcedure not found with id ${params.id}" 63 80 redirect(action:list) 64 81 } … … 74 91 75 92 if(!taskProcedureInstance) { 76 flash. message = "TaskProcedure not found with id ${params.id}"93 flash.errorMessage = "TaskProcedure not found with id ${params.id}" 77 94 redirect(action:list) 78 95 } 79 96 else { 80 return [ taskProcedureInstance : taskProcedureInstance ] 97 def assemblies = assetService.getAssemblies(taskProcedureInstance.linkedTask.primaryAsset) 98 return [ taskProcedureInstance : taskProcedureInstance, 99 assemblies: assemblies ] 81 100 } 82 101 } 83 102 84 103 def update = { 85 def taskProcedureInstance = TaskProcedure.get( params.id ) 86 if(taskProcedureInstance) { 87 if(params.version) { 88 def version = params.version.toLong() 89 if(taskProcedureInstance.version > version) { 90 91 taskProcedureInstance.errors.rejectValue("version", "default.optimistic.locking.failure") 92 render(view:'edit',model:[taskProcedureInstance:taskProcedureInstance]) 93 return 94 } 95 } 96 taskProcedureInstance.properties = params 97 if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { 98 flash.message = "TaskProcedure ${params.id} updated" 99 redirect(action:show,id:taskProcedureInstance.id) 100 } 101 else { 102 render(view:'edit',model:[taskProcedureInstance:taskProcedureInstance]) 103 } 104 } 105 else { 106 flash.message = "TaskProcedure not found with id ${params.id}" 104 def result = taskProcedureService.update(params) 105 106 if(!result.error) { 107 flash.message = g.message(code: "default.update.success", args: ["TaskProcedure", params.id]) 108 redirect(controller:'taskDetailed', 109 action:'show', 110 id:result.taskProcedureInstance.linkedTask.id, 111 params:[showTab:"showProcedureTab"]) 112 return 113 } 114 115 if(result.error.code == "default.not.found") { 116 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 107 117 redirect(action:list) 108 } 118 return 119 } 120 121 if(result.error.code == "default.optimistic.locking.failure") { 122 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 123 redirect(controller:'taskDetailed', 124 action:'show', 125 id:result.taskProcedureInstance.linkedTask.id, 126 params:[showTab:"showProcedureTab"]) 127 return 128 } 129 130 def assemblies = assetService.getAssemblies(result.taskProcedureInstance.linkedTask.primaryAsset) 131 render(view:'edit', model:[taskProcedureInstance: result.taskProcedureInstance, 132 assemblies: assemblies]) 109 133 } 110 134 111 135 def create = { 112 if(params.taskInstance?.id) { 113 def taskInstance = Task.get(params.taskInstance.id) 114 115 def taskProcedureInstance = new TaskProcedure() 116 taskProcedureInstance.properties = params 117 return ['taskProcedureInstance':taskProcedureInstance, 118 taskInstance: taskInstance] 119 } else { 120 flash.message = "Please select or create a task, then go to the Procedure tab." 136 137 if(!params.taskInstance?.id) { 138 flash.errorMessage = "Please select or create a task, then go to the Procedure tab." 121 139 redirect(controller:"taskDetailed", action:"search") 122 } 140 return 141 } 142 143 params.linkedTask = Task.get(params.taskInstance.id) 144 145 // Task already has a taskProcedure. 146 if(params.linkedTask.taskProcedure) { 147 flash.errorMessage = g.message(code: 'default.optimistic.locking.failure') 148 redirect(controller:'taskDetailed', 149 action:'show', 150 id:params.linkedTask.id, 151 params:[showTab:"showProcedureTab"]) 152 return 153 } 154 155 // Task does not have a primaryAsset. 156 if(!params.linkedTask?.primaryAsset) { 157 flash.errorMessage = "Please set a Primary Asset first, then go to the Procedure tab." 158 redirect(controller:"taskDetailed", action:"show", id:params.linkedTask?.id) 159 return 160 } 161 162 def taskProcedureInstance = new TaskProcedure() 163 taskProcedureInstance.properties = params 164 165 // Populate a couple of maintenanceActions for the first assembly. 166 def assemblies = assetService.getAssemblies(params.linkedTask.primaryAsset) 167 if(assemblies) { 168 def assembly = assemblies[0] 169 def ma = taskProcedureInstance.maintenanceActionLazyList.get(0) 170 ma.assetSubItem = assembly 171 ma.procedureStepNumber = 10 172 ma = taskProcedureInstance.maintenanceActionLazyList.get(1) 173 ma.assetSubItem = assembly 174 ma.procedureStepNumber = 20 175 } 176 177 return ['taskProcedureInstance':taskProcedureInstance, 'assemblies': assemblies] 123 178 } 124 179 125 180 def save = { 126 def taskProcedureInstance = new TaskProcedure(params) 127 def taskInstance = Task.get(params.taskInstance.id) 128 129 if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { 130 taskProcedureInstance.addToTasks(taskInstance) 131 flash.message = "TaskProcedure ${taskProcedureInstance.id} created." 132 redirect(action:show,id:taskProcedureInstance.id) 133 } 134 else { 135 render(view:'create',model:[taskProcedureInstance:taskProcedureInstance, taskInstance: taskInstance]) 136 } 137 } 181 def result = taskProcedureService.save(params) 182 183 if(!result.error) { 184 flash.message = g.message(code: "default.create.success", args: ["TaskProcedure", result.taskProcedureInstance.id]) 185 redirect(controller:'taskDetailed', 186 action:'show', 187 id:result.taskProcedureInstance.linkedTask.id, 188 params:[showTab:"showProcedureTab"]) 189 return 190 } 191 192 if(result.error.code == "default.optimistic.locking.failure") { 193 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 194 redirect(controller:'taskDetailed', 195 action:'show', 196 id:result.taskProcedureInstance.linkedTask.id, 197 params:[showTab:"showProcedureTab"]) 198 return 199 } 200 201 def assemblies = assetService.getAssemblies(result.taskProcedureInstance.linkedTask.primaryAsset) 202 render(view:'create', model:[taskProcedureInstance: result.taskProcedureInstance, 203 assemblies: assemblies]) 204 } 205 138 206 }
Note: See TracChangeset
for help on using the changeset viewer.