- Timestamp:
- Feb 2, 2011, 8:38:20 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/features/taskProcedureRework/grails-app/controllers/TaskProcedureDetailedController.groovy
r762 r770 40 40 41 41 if(!taskProcedureInstance) { 42 flash.message = "TaskProcedure not found with id ${params.id}" 43 redirect(action:list) 44 } 45 else { return [ taskProcedureInstance : taskProcedureInstance ] } 42 flash.errorMessage = "TaskProcedure not found with id ${params.id}" 43 redirect(controller:'taskDetailed', action:'search') 44 return 45 } 46 47 redirect(controller:'taskDetailed', 48 action:'show', 49 id:taskProcedureInstance.linkedTask?.id, 50 params:[showTab:"showProcedureTab"]) 46 51 } 47 52 … … 49 54 def taskProcedureInstance = TaskProcedure.get( params.id ) 50 55 if(taskProcedureInstance) { 56 def taskInstance = taskProcedureInstance.linkedTask 51 57 try { 52 58 taskProcedureInstance.tasks.each { … … 55 61 taskProcedureInstance.delete(flush:true) 56 62 flash.message = "TaskProcedure ${params.id} deleted" 57 redirect(action:list) 63 redirect(controller:'taskDetailed', 64 action:'show', 65 id:taskInstance.id, 66 params:[showTab:"showProcedureTab"]) 58 67 } 59 68 catch(org.springframework.dao.DataIntegrityViolationException e) { 60 69 flash.message = "TaskProcedure ${params.id} could not be deleted" 61 redirect(action:show,id:params.id) 70 redirect(controller:'taskDetailed', 71 action:'show', 72 id:taskInstance.id, 73 params:[showTab:"showProcedureTab"]) 62 74 } 63 75 } … … 99 111 taskProcedureInstance.properties = params 100 112 101 def toBeDeleted = taskProcedureInstance.maintenanceActions.findAll {it.deleted} 102 if(toBeDeleted) { 113 // Gaps in the html index's can be created by adding 2 items and removing the first one. 114 // This creates a gap at the missing index where LazyList will return a null. 115 def nullMaintenanceActions = taskProcedureInstance.maintenanceActions.findAll {!it} 116 if (nullMaintenanceActions) { 117 taskProcedureInstance.maintenanceActions.removeAll(nullMaintenanceActions) 118 } 119 120 // Save for restoration if validation fails. 121 def savedMaintenanceActions = new ArrayList(taskProcedureInstance.maintenanceActions) 122 123 // Remove toBeDeleted before validation. 124 def toBeDeleted = taskProcedureInstance.maintenanceActions.findAll {it.toBeDeleted} 125 if (toBeDeleted) { 103 126 taskProcedureInstance.maintenanceActions.removeAll(toBeDeleted) 104 127 } … … 106 129 if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { 107 130 flash.message = "TaskProcedure ${params.id} updated" 108 redirect(action:show,id:taskProcedureInstance.id) 131 redirect(controller:'taskDetailed', 132 action:'show', 133 id:taskProcedureInstance.linkedTask.id, 134 params:[showTab:"showProcedureTab"]) 109 135 } 110 136 else { 137 // Restore the saved items, some of which contain toBeDeleted flags but 138 // have not been deleted yet since validation failed. 139 // The toBeDeleted items are hidden in the view. 140 taskProcedureInstance.maintenanceActions = savedMaintenanceActions 141 // Populate maintenanceAction errors for display. 142 taskProcedureInstance.maintenanceActions.each { it.validate() } 111 143 render(view:'edit',model:[taskProcedureInstance:taskProcedureInstance]) 112 144 } … … 119 151 120 152 def create = { 121 if(params.taskInstance?.id) { 122 def taskInstance = Task.get(params.taskInstance.id) 123 124 def taskProcedureInstance = new TaskProcedure() 125 taskProcedureInstance.properties = params 126 return ['taskProcedureInstance':taskProcedureInstance, 127 taskInstance: taskInstance] 128 } else { 129 flash.message = "Please select or create a task, then go to the Procedure tab." 153 154 if(!params.taskInstance?.id) { 155 flash.errorMessage = "Please select or create a task, then go to the Procedure tab." 130 156 redirect(controller:"taskDetailed", action:"search") 131 } 157 return 158 } 159 160 params.linkedTask = Task.get(params.taskInstance.id) 161 162 if(!params.linkedTask?.primaryAsset) { 163 flash.errorMessage = "Please set a Primary Asset first, then go to the Procedure tab." 164 redirect(controller:"taskDetailed", action:"show", id:params.linkedTask?.id) 165 return 166 } 167 168 def taskProcedureInstance = new TaskProcedure() 169 taskProcedureInstance.properties = params 170 return ['taskProcedureInstance':taskProcedureInstance] 132 171 } 133 172 … … 136 175 def taskInstance = Task.get(params.linkedTask.id) 137 176 177 // Gaps in the html index's can be created by adding 2 items and removing the first one. 178 // This creates a gap at the missing index where LazyList will return a null. 179 def nullMaintenanceActions = taskProcedureInstance.maintenanceActions.findAll {!it} 180 if (nullMaintenanceActions) { 181 taskProcedureInstance.maintenanceActions.removeAll(nullMaintenanceActions) 182 } 183 138 184 if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { 139 taskProcedureInstance.addToTasks(taskInstance) // also sets: taskInstance.taskProcedure = taskProcedureInstance 185 // Also sets: taskInstance.taskProcedure = taskProcedureInstance 186 taskProcedureInstance.addToTasks(taskInstance) 140 187 flash.message = "TaskProcedure ${taskProcedureInstance.id} created." 141 redirect(action:show,id:taskProcedureInstance.id) 142 } 143 else { 144 render(view:'create',model:[taskProcedureInstance:taskProcedureInstance, taskInstance: taskInstance]) 145 } 146 } 188 redirect(controller:'taskDetailed', 189 action:'show', 190 id:taskProcedureInstance.linkedTask.id, 191 params:[showTab:"showProcedureTab"]) 192 } 193 else { 194 // Populate maintenanceAction errors for display. 195 taskProcedureInstance.maintenanceActions.each { it.validate() } 196 render(view:'create',model:[taskProcedureInstance:taskProcedureInstance]) 197 } 198 } 199 147 200 }
Note: See TracChangeset
for help on using the changeset viewer.