[133] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
[298] | 3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[133] | 4 | class TaskProcedureDetailedController extends BaseController { |
---|
[147] | 5 | |
---|
[155] | 6 | def filterService |
---|
| 7 | |
---|
[133] | 8 | def index = { redirect(action:list,params:params) } |
---|
| 9 | |
---|
| 10 | // the delete, save and update actions only accept POST requests |
---|
| 11 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
| 12 | |
---|
[298] | 13 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[133] | 14 | def list = { |
---|
| 15 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
[147] | 16 | |
---|
| 17 | if(!params.filter) |
---|
| 18 | { return [taskProcedureInstanceList: TaskProcedure.list(params), taskProcedureInstanceTotal: TaskProcedure.count()] } |
---|
| 19 | |
---|
| 20 | // filterPane: |
---|
| 21 | return[ taskProcedureInstanceList: filterService.filter( params, TaskProcedure ), |
---|
| 22 | taskProcedureInstanceTotal: filterService.count( params, TaskProcedure ), |
---|
| 23 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
| 24 | params:params ] |
---|
[133] | 25 | } |
---|
[147] | 26 | |
---|
[298] | 27 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[134] | 28 | def search = { |
---|
| 29 | redirect(action:list) |
---|
| 30 | } |
---|
[133] | 31 | |
---|
[298] | 32 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[133] | 33 | def show = { |
---|
[147] | 34 | |
---|
| 35 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 36 | if(params._action_Show) |
---|
[375] | 37 | params.action='show' |
---|
[147] | 38 | |
---|
[133] | 39 | def taskProcedureInstance = TaskProcedure.get( params.id ) |
---|
| 40 | |
---|
| 41 | if(!taskProcedureInstance) { |
---|
| 42 | flash.message = "TaskProcedure not found with id ${params.id}" |
---|
| 43 | redirect(action:list) |
---|
| 44 | } |
---|
| 45 | else { return [ taskProcedureInstance : taskProcedureInstance ] } |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | def delete = { |
---|
| 49 | def taskProcedureInstance = TaskProcedure.get( params.id ) |
---|
| 50 | if(taskProcedureInstance) { |
---|
| 51 | try { |
---|
[758] | 52 | taskProcedureInstance.tasks.each { |
---|
| 53 | it.taskProcedure = null |
---|
| 54 | } |
---|
[365] | 55 | taskProcedureInstance.delete(flush:true) |
---|
[133] | 56 | flash.message = "TaskProcedure ${params.id} deleted" |
---|
| 57 | redirect(action:list) |
---|
| 58 | } |
---|
| 59 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
| 60 | flash.message = "TaskProcedure ${params.id} could not be deleted" |
---|
| 61 | redirect(action:show,id:params.id) |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | else { |
---|
| 65 | flash.message = "TaskProcedure not found with id ${params.id}" |
---|
| 66 | redirect(action:list) |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | def edit = { |
---|
[147] | 71 | |
---|
| 72 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 73 | if(params._action_Edit) |
---|
[375] | 74 | params.action='edit' |
---|
[147] | 75 | |
---|
[133] | 76 | def taskProcedureInstance = TaskProcedure.get( params.id ) |
---|
| 77 | |
---|
| 78 | if(!taskProcedureInstance) { |
---|
| 79 | flash.message = "TaskProcedure not found with id ${params.id}" |
---|
| 80 | redirect(action:list) |
---|
| 81 | } |
---|
| 82 | else { |
---|
| 83 | return [ taskProcedureInstance : taskProcedureInstance ] |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | def update = { |
---|
| 88 | def taskProcedureInstance = TaskProcedure.get( params.id ) |
---|
| 89 | if(taskProcedureInstance) { |
---|
| 90 | if(params.version) { |
---|
| 91 | def version = params.version.toLong() |
---|
| 92 | if(taskProcedureInstance.version > version) { |
---|
[147] | 93 | |
---|
[403] | 94 | taskProcedureInstance.errors.rejectValue("version", "default.optimistic.locking.failure") |
---|
[133] | 95 | render(view:'edit',model:[taskProcedureInstance:taskProcedureInstance]) |
---|
| 96 | return |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | taskProcedureInstance.properties = params |
---|
[760] | 100 | |
---|
[762] | 101 | def toBeDeleted = taskProcedureInstance.maintenanceActions.findAll {it.deleted} |
---|
[760] | 102 | if(toBeDeleted) { |
---|
| 103 | taskProcedureInstance.maintenanceActions.removeAll(toBeDeleted) |
---|
| 104 | } |
---|
| 105 | |
---|
[178] | 106 | if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { |
---|
[133] | 107 | flash.message = "TaskProcedure ${params.id} updated" |
---|
| 108 | redirect(action:show,id:taskProcedureInstance.id) |
---|
| 109 | } |
---|
| 110 | else { |
---|
| 111 | render(view:'edit',model:[taskProcedureInstance:taskProcedureInstance]) |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | else { |
---|
| 115 | flash.message = "TaskProcedure not found with id ${params.id}" |
---|
[365] | 116 | redirect(action:list) |
---|
[133] | 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | def create = { |
---|
[147] | 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 { |
---|
[368] | 129 | flash.message = "Please select or create a task, then go to the Procedure tab." |
---|
[155] | 130 | redirect(controller:"taskDetailed", action:"search") |
---|
[147] | 131 | } |
---|
[133] | 132 | } |
---|
| 133 | |
---|
| 134 | def save = { |
---|
| 135 | def taskProcedureInstance = new TaskProcedure(params) |
---|
[762] | 136 | def taskInstance = Task.get(params.linkedTask.id) |
---|
[147] | 137 | |
---|
[178] | 138 | if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { |
---|
[758] | 139 | taskProcedureInstance.addToTasks(taskInstance) // also sets: taskInstance.taskProcedure = taskProcedureInstance |
---|
[147] | 140 | flash.message = "TaskProcedure ${taskProcedureInstance.id} created." |
---|
[133] | 141 | redirect(action:show,id:taskProcedureInstance.id) |
---|
| 142 | } |
---|
| 143 | else { |
---|
[147] | 144 | render(view:'create',model:[taskProcedureInstance:taskProcedureInstance, taskInstance: taskInstance]) |
---|
[133] | 145 | } |
---|
| 146 | } |
---|
| 147 | } |
---|