1 | package dbnp.studycapturing |
---|
2 | /** |
---|
3 | * 888 888 888 888 8888888888 8888888b. 8888888888 |
---|
4 | * 888 o 888 888 888 888 888 Y88b 888 |
---|
5 | * 888 d8b 888 888 888 888 888 888 888 |
---|
6 | * 888 d888b 888 8888888888 8888888 888 d88P 8888888 |
---|
7 | * 888d88888b888 888 888 888 8888888P" 888 |
---|
8 | * 88888P Y88888 888 888 888 888 T88b 888 |
---|
9 | * 8888P Y8888 888 888 888 888 T88b 888 |
---|
10 | * 888P Y888 888 888 8888888888 888 T88b 8888888888 |
---|
11 | * |
---|
12 | * 8888888 .d8888b. 88888888888 888 888 8888888888 |
---|
13 | * 888 d88P Y88b 888 888 888 888 |
---|
14 | * 888 Y88b. 888 888 888 888 |
---|
15 | * 888 "Y888b. 888 8888888888 8888888 |
---|
16 | * 888 "Y88b. 888 888 888 888 |
---|
17 | * 888 "888 888 888 888 888 |
---|
18 | * 888 Y88b d88P 888 888 888 888 |
---|
19 | * 8888888 "Y8888P" 888 888 888 8888888888 |
---|
20 | * |
---|
21 | * 888888 d8888 888 888 d8888 8888888b. .d88888b. .d8888b. |
---|
22 | * "88b d88888 888 888 d88888 888 "Y88b d88P" "Y88b d88P Y88b |
---|
23 | * 888 d88P888 888 888 d88P888 888 888 888 888 888 888 |
---|
24 | * 888 d88P 888 Y88b d88P d88P 888 888 888 888 888 888 |
---|
25 | * 888 d88P 888 Y88b d88P d88P 888 888 888 888 888 888 |
---|
26 | * 888 d88P 888 Y88o88P d88P 888 888 888 888 888 888 888 |
---|
27 | * 88P d8888888888 Y888P d8888888888 888 .d88P Y88b. .d88P Y88b d88P |
---|
28 | * 888 d88P 888 Y8P d88P 888 8888888P" "Y88888P" "Y8888P" |
---|
29 | * .d88P |
---|
30 | * .d88P" |
---|
31 | * 888P" |
---|
32 | * |
---|
33 | * .d8888b. 888 .d8888b. 888 .d8888b. 888 |
---|
34 | * d88P Y88b 888 d88P Y88b 888 d88P Y88b 888 |
---|
35 | * .d88P 888 .d88P 888 .d88P 888 |
---|
36 | * .d88P" 888 .d88P" 888 .d88P" 888 |
---|
37 | * 888" 888 888" 888 888" 888 |
---|
38 | * 888 Y8P 888 Y8P 888 Y8P |
---|
39 | * " " " |
---|
40 | * 888 888 888 888 888 888 |
---|
41 | * |
---|
42 | * |
---|
43 | * TODO: add PROPER class and method documentation, just like have |
---|
44 | * agreed upon hundreds of times!!!! |
---|
45 | */ |
---|
46 | class PersonRoleController { |
---|
47 | |
---|
48 | static allowedMethods = [save: "POST", update: "POST", delete: "POST"] |
---|
49 | |
---|
50 | /** |
---|
51 | * Fires after every action and determines the layout of the page |
---|
52 | */ |
---|
53 | def afterInterceptor = { model, modelAndView -> |
---|
54 | println( params ); |
---|
55 | |
---|
56 | if ( params['dialog'] ) { |
---|
57 | model.layout = 'dialog'; |
---|
58 | model.extraparams = [ 'dialog': 'true' ] ; |
---|
59 | } else { |
---|
60 | model.layout = 'main'; |
---|
61 | model.extraparams = [] ; |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | def index = { |
---|
66 | redirect(action: "list", params: params) |
---|
67 | } |
---|
68 | |
---|
69 | def list = { |
---|
70 | params.max = Math.min(params.max ? params.int('max') : 10, 100) |
---|
71 | [personRoleInstanceList: PersonRole.list(params), personRoleInstanceTotal: PersonRole.count()] |
---|
72 | } |
---|
73 | |
---|
74 | def create = { |
---|
75 | def personRoleInstance = new PersonRole() |
---|
76 | personRoleInstance.properties = params |
---|
77 | return [personRoleInstance: personRoleInstance] |
---|
78 | } |
---|
79 | |
---|
80 | def save = { |
---|
81 | def personRoleInstance = new PersonRole(params) |
---|
82 | def extraparams = new LinkedHashMap(); |
---|
83 | |
---|
84 | if( params[ 'dialog' ] ) { |
---|
85 | extraparams[ 'dialog' ] = params[ 'dialog' ] |
---|
86 | } |
---|
87 | |
---|
88 | if (personRoleInstance.save(flush: true)) { |
---|
89 | flash.message = "${message(code: 'default.created.message', args: [message(code: 'personRole.label', default: 'Role'), personRoleInstance.name])}" |
---|
90 | //redirect(action: "show", id: personRoleInstance.id) |
---|
91 | redirect(action: "list", params: extraparams) |
---|
92 | } |
---|
93 | else { |
---|
94 | render(view: "create", model: [personRoleInstance: personRoleInstance]) |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | def show = { |
---|
99 | def personRoleInstance = PersonRole.get(params.id) |
---|
100 | if (!personRoleInstance) { |
---|
101 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personRole.label', default: 'Role'), params.id])}" |
---|
102 | redirect(action: "list") |
---|
103 | } |
---|
104 | else { |
---|
105 | [personRoleInstance: personRoleInstance] |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | def edit = { |
---|
110 | def personRoleInstance = PersonRole.get(params.id) |
---|
111 | if (!personRoleInstance) { |
---|
112 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personRole.label', default: 'Role'), params.id])}" |
---|
113 | redirect(action: "list") |
---|
114 | } |
---|
115 | else { |
---|
116 | return [personRoleInstance: personRoleInstance] |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | def update = { |
---|
121 | def personRoleInstance = PersonRole.get(params.id) |
---|
122 | def extraparams = new LinkedHashMap(); |
---|
123 | |
---|
124 | if( params[ 'dialog' ] ) { |
---|
125 | extraparams[ 'dialog' ] = params[ 'dialog' ] |
---|
126 | } |
---|
127 | |
---|
128 | if (personRoleInstance) { |
---|
129 | if (params.version) { |
---|
130 | def version = params.version.toLong() |
---|
131 | if (personRoleInstance.version > version) { |
---|
132 | |
---|
133 | personRoleInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'personRole.label', default: 'Role')] as Object[], "Another user has updated this PersonRole while you were editing") |
---|
134 | render(view: "edit", model: [personRoleInstance: personRoleInstance]) |
---|
135 | return |
---|
136 | } |
---|
137 | } |
---|
138 | personRoleInstance.properties = params |
---|
139 | if (!personRoleInstance.hasErrors() && personRoleInstance.save(flush: true)) { |
---|
140 | flash.message = "${message(code: 'default.updated.message', args: [message(code: 'personRole.label', default: 'Role'), personRoleInstance.name])}" |
---|
141 | //redirect(action: "show", id: personRoleInstance.id) |
---|
142 | redirect(action: "list", params: extraparams) |
---|
143 | |
---|
144 | } |
---|
145 | else { |
---|
146 | render(view: "edit", model: [personRoleInstance: personRoleInstance]) |
---|
147 | } |
---|
148 | } |
---|
149 | else { |
---|
150 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personRole.label', default: 'Role'), params.id])}" |
---|
151 | redirect(action: "list", params: extraparams) |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | def delete = { |
---|
156 | def personRoleInstance = PersonRole.get(params.id) |
---|
157 | def extraparams = new LinkedHashMap(); |
---|
158 | |
---|
159 | if( params[ 'dialog' ] ) { |
---|
160 | extraparams[ 'dialog' ] = params[ 'dialog' ] |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | if (personRoleInstance) { |
---|
165 | def roleName = personRoleInstance.name |
---|
166 | try { |
---|
167 | personRoleInstance.delete(flush: true) |
---|
168 | flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'personRole.label', default: 'Role'), roleName])}" |
---|
169 | redirect(action: "list", params: extraparams) |
---|
170 | } |
---|
171 | catch (org.springframework.dao.DataIntegrityViolationException e) { |
---|
172 | flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'personRole.label', default: 'Role'), roleName])}" |
---|
173 | // redirect(action: "show", id: params.id) |
---|
174 | redirect(action: "list", params: extraparams) |
---|
175 | } |
---|
176 | } |
---|
177 | else { |
---|
178 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personRole.label', default: 'Role'), params.id])}" |
---|
179 | redirect(action: "list", params: extraparams) |
---|
180 | } |
---|
181 | } |
---|
182 | } |
---|