1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
2 | |
---|
3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
4 | class AssignedPersonDetailedController extends BaseController { |
---|
5 | |
---|
6 | def assignedPersonService |
---|
7 | |
---|
8 | def index = { |
---|
9 | flash.message = g.message(code: "assignedPerson.task.not.found") |
---|
10 | redirect(controller:"taskDetailed", action:"search") |
---|
11 | } |
---|
12 | |
---|
13 | // the delete, save and update actions only accept POST requests |
---|
14 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
15 | |
---|
16 | def delete = { |
---|
17 | def result = assignedPersonService.delete(params) |
---|
18 | |
---|
19 | if(!result.error) { |
---|
20 | flash.message = g.message(code: "default.delete.success", args: ["AssignedPerson", params.id]) |
---|
21 | redirect(controller:"taskDetailed", action:"show", id: params.task?.id) |
---|
22 | return |
---|
23 | } |
---|
24 | |
---|
25 | flash.message = g.message(code: result.error.code, args: result.error.args) |
---|
26 | |
---|
27 | if(result.error.code == "default.not.found") { |
---|
28 | redirect(controller:"taskDetailed", action:"show", id: params.task?.id) |
---|
29 | return |
---|
30 | } |
---|
31 | |
---|
32 | redirect(action:show, id: params.id) |
---|
33 | } |
---|
34 | |
---|
35 | def edit = { |
---|
36 | def result = assignedPersonService.edit(params) |
---|
37 | |
---|
38 | if(!result.error) { |
---|
39 | return [assignedPersonInstance: result.assignedPersonInstance, |
---|
40 | person: result.person, |
---|
41 | groupsForPerson: result.groupsForPerson] |
---|
42 | } |
---|
43 | |
---|
44 | flash.message = g.message(code: result.error.code, args: result.error.args) |
---|
45 | |
---|
46 | redirect(controller:"taskDetailed", action:"show", id: params.task?.id) |
---|
47 | |
---|
48 | } |
---|
49 | |
---|
50 | def update = { |
---|
51 | def result = assignedPersonService.update(params) |
---|
52 | |
---|
53 | if(!result.error) { |
---|
54 | flash.message = g.message(code: "default.update.success", args: ["AssignedPerson", params.id]) |
---|
55 | redirect(controller:"taskDetailed", action:"show", id: result.assignedPersonInstance.task.id) |
---|
56 | return |
---|
57 | } |
---|
58 | |
---|
59 | if(result.error.code == "default.not.found") { |
---|
60 | flash.message = g.message(code: result.error.code, args: result.error.args) |
---|
61 | redirect(controller:"taskDetailed", action:"show", id: params.task?.id) |
---|
62 | return |
---|
63 | } |
---|
64 | |
---|
65 | if(result.error.code == "person.not.found") { |
---|
66 | flash.message = g.message(code: result.error.code, args: result.error.args) |
---|
67 | redirect(action:"edit", id: params.id) |
---|
68 | return |
---|
69 | } |
---|
70 | |
---|
71 | render(view:'edit', model:[assignedPersonInstance: result.assignedPersonInstance.attach(), |
---|
72 | person: result.person.attach(), |
---|
73 | groupsForPerson: result.groupsForPerson]) |
---|
74 | } |
---|
75 | |
---|
76 | def create = { |
---|
77 | def result = assignedPersonService.create(params) |
---|
78 | |
---|
79 | if(!result.error) { |
---|
80 | return [assignedPersonInstance: result.assignedPersonInstance, |
---|
81 | person: result.person, |
---|
82 | groupsForPerson: result.groupsForPerson] |
---|
83 | } |
---|
84 | |
---|
85 | if(result.error.code == "assignedPerson.task.not.found") { |
---|
86 | flash.message = g.message(code: result.error.code, args: result.error.args) |
---|
87 | redirect(controller: "taskDetailed", action: "search") |
---|
88 | return |
---|
89 | } |
---|
90 | |
---|
91 | flash.message = g.message(code: result.error.code, args: result.error.args) |
---|
92 | redirect(controller:"taskDetailed", action:"show", id: params.task?.id) |
---|
93 | } |
---|
94 | |
---|
95 | def save = { |
---|
96 | def result = assignedPersonService.save(params) |
---|
97 | |
---|
98 | if(!result.error) { |
---|
99 | flash.message = g.message(code: "default.create.success", args: ["AssignedPerson", result.assignedPersonInstance.id]) |
---|
100 | redirect(controller:"taskDetailed", action:"show", id: result.assignedPersonInstance.task.id) |
---|
101 | return |
---|
102 | } |
---|
103 | |
---|
104 | if(result.error.code == "person.not.found") { |
---|
105 | flash.message = g.message(code: result.error.code, args: result.error.args) |
---|
106 | redirect(action:"create", params:["task.id": params.task?.id]) |
---|
107 | return |
---|
108 | } |
---|
109 | |
---|
110 | render(view:'create', model:[assignedPersonInstance: result.assignedPersonInstance, |
---|
111 | person: result.person.attach(), |
---|
112 | groupsForPerson: result.groupsForPerson]) |
---|
113 | } |
---|
114 | |
---|
115 | def groupsForPerson = { |
---|
116 | def result = assignedPersonService.groupsForPerson(params) |
---|
117 | |
---|
118 | if(!result.error) { |
---|
119 | render ( template:"groupsForPerson", |
---|
120 | model: [person: result.person, groupsForPerson: result.groupsForPerson] ) |
---|
121 | return |
---|
122 | } |
---|
123 | |
---|
124 | render { |
---|
125 | div(id:"groupsForPerson", g.message(code: result.error.code, args: result.error.args) ) |
---|
126 | } |
---|
127 | |
---|
128 | } |
---|
129 | |
---|
130 | } |
---|