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.tasks.each { |
---|
53 | it.taskProcedure = null |
---|
54 | } |
---|
55 | taskProcedureInstance.delete(flush:true) |
---|
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 = { |
---|
71 | |
---|
72 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
73 | if(params._action_Edit) |
---|
74 | params.action='edit' |
---|
75 | |
---|
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) { |
---|
93 | |
---|
94 | taskProcedureInstance.errors.rejectValue("version", "default.optimistic.locking.failure") |
---|
95 | render(view:'edit',model:[taskProcedureInstance:taskProcedureInstance]) |
---|
96 | return |
---|
97 | } |
---|
98 | } |
---|
99 | taskProcedureInstance.properties = params |
---|
100 | |
---|
101 | def toBeDeleted = taskProcedureInstance.maintenanceActions.findAll {it.deleted} |
---|
102 | if(toBeDeleted) { |
---|
103 | taskProcedureInstance.maintenanceActions.removeAll(toBeDeleted) |
---|
104 | } |
---|
105 | |
---|
106 | if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { |
---|
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}" |
---|
116 | redirect(action:list) |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | 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." |
---|
130 | redirect(controller:"taskDetailed", action:"search") |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | def save = { |
---|
135 | def taskProcedureInstance = new TaskProcedure(params) |
---|
136 | def taskInstance = Task.get(params.linkedTask.id) |
---|
137 | |
---|
138 | if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { |
---|
139 | taskProcedureInstance.addToTasks(taskInstance) // also sets: taskInstance.taskProcedure = taskProcedureInstance |
---|
140 | 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 | } |
---|
147 | } |
---|