1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
2 | |
---|
3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager']) |
---|
4 | class SectionDetailedController extends BaseController { |
---|
5 | |
---|
6 | // the delete, save and update actions only accept POST requests |
---|
7 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
8 | |
---|
9 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser']) |
---|
10 | def index = { redirect(action:list,params:params) } |
---|
11 | |
---|
12 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser']) |
---|
13 | def list = { |
---|
14 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
15 | [ sectionInstanceList: Section.list( params ), sectionInstanceTotal: Section.count() ] |
---|
16 | } |
---|
17 | |
---|
18 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser']) |
---|
19 | def show = { |
---|
20 | def sectionInstance = Section.get( params.id ) |
---|
21 | |
---|
22 | if(!sectionInstance) { |
---|
23 | flash.message = "Section not found with id ${params.id}" |
---|
24 | redirect(action:list) |
---|
25 | } |
---|
26 | else { return [ sectionInstance : sectionInstance ] } |
---|
27 | } |
---|
28 | |
---|
29 | @Secured(['ROLE_AppAdmin']) |
---|
30 | def delete = { |
---|
31 | def sectionInstance = Section.get( params.id ) |
---|
32 | if(sectionInstance) { |
---|
33 | try { |
---|
34 | sectionInstance.delete(flush:true) |
---|
35 | flash.message = "Section ${params.id} deleted" |
---|
36 | redirect(action:list) |
---|
37 | } |
---|
38 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
39 | flash.message = "Section ${params.id} could not be deleted" |
---|
40 | redirect(action:show,id:params.id) |
---|
41 | } |
---|
42 | } |
---|
43 | else { |
---|
44 | flash.message = "Section not found with id ${params.id}" |
---|
45 | redirect(action:list) |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | def edit = { |
---|
50 | def sectionInstance = Section.get( params.id ) |
---|
51 | |
---|
52 | if(!sectionInstance) { |
---|
53 | flash.message = "Section not found with id ${params.id}" |
---|
54 | redirect(action:list) |
---|
55 | } |
---|
56 | else { |
---|
57 | return [ sectionInstance : sectionInstance ] |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | def update = { |
---|
62 | def sectionInstance = Section.get( params.id ) |
---|
63 | if(sectionInstance) { |
---|
64 | if(params.version) { |
---|
65 | def version = params.version.toLong() |
---|
66 | if(sectionInstance.version > version) { |
---|
67 | |
---|
68 | sectionInstance.errors.rejectValue("version", "section.optimistic.locking.failure", "Another user has updated this Section while you were editing.") |
---|
69 | render(view:'edit',model:[sectionInstance:sectionInstance]) |
---|
70 | return |
---|
71 | } |
---|
72 | } |
---|
73 | sectionInstance.properties = params |
---|
74 | if(!sectionInstance.hasErrors() && sectionInstance.save(flush: true)) { |
---|
75 | flash.message = "Section ${params.id} updated" |
---|
76 | redirect(action:show,id:sectionInstance.id) |
---|
77 | } |
---|
78 | else { |
---|
79 | render(view:'edit',model:[sectionInstance:sectionInstance]) |
---|
80 | } |
---|
81 | } |
---|
82 | else { |
---|
83 | flash.message = "Section not found with id ${params.id}" |
---|
84 | redirect(action:list) |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | def create = { |
---|
89 | def sectionInstance = new Section() |
---|
90 | sectionInstance.properties = params |
---|
91 | return ['sectionInstance':sectionInstance] |
---|
92 | } |
---|
93 | |
---|
94 | def save = { |
---|
95 | def sectionInstance = new Section(params) |
---|
96 | if(!sectionInstance.hasErrors() && sectionInstance.save(flush: true)) { |
---|
97 | flash.message = "Section ${sectionInstance.id} created" |
---|
98 | redirect(action:show,id:sectionInstance.id) |
---|
99 | } |
---|
100 | else { |
---|
101 | render(view:'create',model:[sectionInstance:sectionInstance]) |
---|
102 | } |
---|
103 | } |
---|
104 | } |
---|