[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 { |
---|
[365] | 52 | taskProcedureInstance.delete(flush:true) |
---|
[133] | 53 | flash.message = "TaskProcedure ${params.id} deleted" |
---|
| 54 | redirect(action:list) |
---|
| 55 | } |
---|
| 56 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
| 57 | flash.message = "TaskProcedure ${params.id} could not be deleted" |
---|
| 58 | redirect(action:show,id:params.id) |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | else { |
---|
| 62 | flash.message = "TaskProcedure not found with id ${params.id}" |
---|
| 63 | redirect(action:list) |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | def edit = { |
---|
[147] | 68 | |
---|
| 69 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 70 | if(params._action_Edit) |
---|
[375] | 71 | params.action='edit' |
---|
[147] | 72 | |
---|
[133] | 73 | def taskProcedureInstance = TaskProcedure.get( params.id ) |
---|
| 74 | |
---|
| 75 | if(!taskProcedureInstance) { |
---|
| 76 | flash.message = "TaskProcedure not found with id ${params.id}" |
---|
| 77 | redirect(action:list) |
---|
| 78 | } |
---|
| 79 | else { |
---|
| 80 | return [ taskProcedureInstance : taskProcedureInstance ] |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | 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) { |
---|
[147] | 90 | |
---|
[403] | 91 | taskProcedureInstance.errors.rejectValue("version", "default.optimistic.locking.failure") |
---|
[133] | 92 | render(view:'edit',model:[taskProcedureInstance:taskProcedureInstance]) |
---|
| 93 | return |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | taskProcedureInstance.properties = params |
---|
[178] | 97 | if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { |
---|
[133] | 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}" |
---|
[365] | 107 | redirect(action:list) |
---|
[133] | 108 | } |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | def create = { |
---|
[147] | 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 { |
---|
[368] | 120 | flash.message = "Please select or create a task, then go to the Procedure tab." |
---|
[155] | 121 | redirect(controller:"taskDetailed", action:"search") |
---|
[147] | 122 | } |
---|
[133] | 123 | } |
---|
| 124 | |
---|
| 125 | def save = { |
---|
| 126 | def taskProcedureInstance = new TaskProcedure(params) |
---|
[147] | 127 | def taskInstance = Task.get(params.taskInstance.id) |
---|
| 128 | |
---|
[178] | 129 | if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { |
---|
[147] | 130 | taskProcedureInstance.addToTasks(taskInstance) |
---|
| 131 | flash.message = "TaskProcedure ${taskProcedureInstance.id} created." |
---|
[133] | 132 | redirect(action:show,id:taskProcedureInstance.id) |
---|
| 133 | } |
---|
| 134 | else { |
---|
[147] | 135 | render(view:'create',model:[taskProcedureInstance:taskProcedureInstance, taskInstance: taskInstance]) |
---|
[133] | 136 | } |
---|
| 137 | } |
---|
| 138 | } |
---|