1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
2 | |
---|
3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
4 | class TaskProcedureDetailedController extends BaseController { |
---|
5 | |
---|
6 | def filterService |
---|
7 | |
---|
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 | |
---|
13 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
14 | def list = { |
---|
15 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
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 ] |
---|
25 | } |
---|
26 | |
---|
27 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
28 | def search = { |
---|
29 | redirect(action:list) |
---|
30 | } |
---|
31 | |
---|
32 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
33 | def show = { |
---|
34 | |
---|
35 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
36 | if(params._action_Show) |
---|
37 | { params.action='show' } |
---|
38 | |
---|
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 { |
---|
52 | taskProcedureInstance.delete(flush:true) |
---|
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 = { |
---|
68 | |
---|
69 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
70 | if(params._action_Edit) |
---|
71 | { params.action='edit' } |
---|
72 | |
---|
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) { |
---|
90 | |
---|
91 | taskProcedureInstance.errors.rejectValue("version", "taskProcedure.optimistic.locking.failure", "Another user has updated this TaskProcedure while you were editing.") |
---|
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}" |
---|
107 | redirect(action:list) |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | 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 a task, then the Procedure tab." |
---|
121 | redirect(controller:"taskDetailed", action:"search") |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | 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 | } |
---|
138 | } |
---|