1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
2 | |
---|
3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager']) |
---|
4 | class SiteDetailedController extends BaseController { |
---|
5 | |
---|
6 | def siteService |
---|
7 | |
---|
8 | // the delete, save and update actions only accept POST requests |
---|
9 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
10 | |
---|
11 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser']) |
---|
12 | def index = { redirect(action:list,params:params) } |
---|
13 | |
---|
14 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser']) |
---|
15 | def list = { |
---|
16 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
17 | [ siteInstanceList: Site.list( params ), siteInstanceTotal: Site.count() ] |
---|
18 | } |
---|
19 | |
---|
20 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser']) |
---|
21 | def show = { |
---|
22 | |
---|
23 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
24 | if(params._action_Show) |
---|
25 | params.action='show' |
---|
26 | |
---|
27 | def siteInstance = Site.get( params.id ) |
---|
28 | |
---|
29 | if(!siteInstance) { |
---|
30 | flash.message = "Site not found with id ${params.id}" |
---|
31 | redirect(action:list) |
---|
32 | } |
---|
33 | else { return [ siteInstance : siteInstance ] } |
---|
34 | } |
---|
35 | |
---|
36 | @Secured(['ROLE_AppAdmin']) |
---|
37 | def delete = { |
---|
38 | def result = siteService.delete(params) |
---|
39 | |
---|
40 | if(!result.error) { |
---|
41 | flash.message = g.message(code: "default.delete.success", args: ["Site", params.id]) |
---|
42 | redirect(action:list) |
---|
43 | return |
---|
44 | } |
---|
45 | |
---|
46 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
47 | |
---|
48 | if(result.error.code == "default.not.found") { |
---|
49 | redirect(action:list) |
---|
50 | return |
---|
51 | } |
---|
52 | |
---|
53 | redirect(action:show, id: params.id) |
---|
54 | } |
---|
55 | |
---|
56 | def edit = { |
---|
57 | |
---|
58 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
59 | if(params._action_Edit) |
---|
60 | params.action='edit' |
---|
61 | |
---|
62 | def siteInstance = Site.get( params.id ) |
---|
63 | |
---|
64 | if(!siteInstance) { |
---|
65 | flash.message = "Site not found with id ${params.id}" |
---|
66 | redirect(action:list) |
---|
67 | } |
---|
68 | else { |
---|
69 | return [ siteInstance : siteInstance ] |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | def update = { |
---|
74 | def siteInstance = Site.get( params.id ) |
---|
75 | if(siteInstance) { |
---|
76 | if(params.version) { |
---|
77 | def version = params.version.toLong() |
---|
78 | if(siteInstance.version > version) { |
---|
79 | |
---|
80 | siteInstance.errors.rejectValue("version", "site.optimistic.locking.failure", "Another user has updated this Site while you were editing.") |
---|
81 | render(view:'edit',model:[siteInstance:siteInstance]) |
---|
82 | return |
---|
83 | } |
---|
84 | } |
---|
85 | siteInstance.properties = params |
---|
86 | if(!siteInstance.hasErrors() && siteInstance.save(flush: true)) { |
---|
87 | flash.message = "Site ${params.id} updated" |
---|
88 | redirect(action:show,id:siteInstance.id) |
---|
89 | } |
---|
90 | else { |
---|
91 | render(view:'edit',model:[siteInstance:siteInstance]) |
---|
92 | } |
---|
93 | } |
---|
94 | else { |
---|
95 | flash.message = "Site not found with id ${params.id}" |
---|
96 | redirect(action:list) |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | def create = { |
---|
101 | def siteInstance = new Site() |
---|
102 | siteInstance.properties = params |
---|
103 | return ['siteInstance':siteInstance] |
---|
104 | } |
---|
105 | |
---|
106 | def save = { |
---|
107 | def siteInstance = new Site(params) |
---|
108 | if(!siteInstance.hasErrors() && siteInstance.save(flush: true)) { |
---|
109 | flash.message = "Site ${siteInstance.id} created" |
---|
110 | redirect(action:show,id:siteInstance.id) |
---|
111 | } |
---|
112 | else { |
---|
113 | render(view:'create',model:[siteInstance:siteInstance]) |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|