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 | def siteInstance = Site.get( params.id ) |
---|
23 | |
---|
24 | if(!siteInstance) { |
---|
25 | flash.message = "Site not found with id ${params.id}" |
---|
26 | redirect(action:list) |
---|
27 | } |
---|
28 | else { return [ siteInstance : siteInstance ] } |
---|
29 | } |
---|
30 | |
---|
31 | @Secured(['ROLE_AppAdmin']) |
---|
32 | def delete = { |
---|
33 | def result = siteService.delete(params) |
---|
34 | |
---|
35 | if(!result.error) { |
---|
36 | flash.message = g.message(code: "default.delete.success", args: ["Site", params.id]) |
---|
37 | redirect(action:list) |
---|
38 | return |
---|
39 | } |
---|
40 | |
---|
41 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
42 | |
---|
43 | if(result.error.code == "default.not.found") { |
---|
44 | redirect(action:list) |
---|
45 | return |
---|
46 | } |
---|
47 | |
---|
48 | redirect(action:show, id: params.id) |
---|
49 | } |
---|
50 | |
---|
51 | def edit = { |
---|
52 | def siteInstance = Site.get( params.id ) |
---|
53 | |
---|
54 | if(!siteInstance) { |
---|
55 | flash.message = "Site not found with id ${params.id}" |
---|
56 | redirect(action:list) |
---|
57 | } |
---|
58 | else { |
---|
59 | return [ siteInstance : siteInstance ] |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | def update = { |
---|
64 | def siteInstance = Site.get( params.id ) |
---|
65 | if(siteInstance) { |
---|
66 | if(params.version) { |
---|
67 | def version = params.version.toLong() |
---|
68 | if(siteInstance.version > version) { |
---|
69 | |
---|
70 | siteInstance.errors.rejectValue("version", "site.optimistic.locking.failure", "Another user has updated this Site while you were editing.") |
---|
71 | render(view:'edit',model:[siteInstance:siteInstance]) |
---|
72 | return |
---|
73 | } |
---|
74 | } |
---|
75 | siteInstance.properties = params |
---|
76 | if(!siteInstance.hasErrors() && siteInstance.save(flush: true)) { |
---|
77 | flash.message = "Site ${params.id} updated" |
---|
78 | redirect(action:show,id:siteInstance.id) |
---|
79 | } |
---|
80 | else { |
---|
81 | render(view:'edit',model:[siteInstance:siteInstance]) |
---|
82 | } |
---|
83 | } |
---|
84 | else { |
---|
85 | flash.message = "Site not found with id ${params.id}" |
---|
86 | redirect(action:list) |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | def create = { |
---|
91 | def siteInstance = new Site() |
---|
92 | siteInstance.properties = params |
---|
93 | return ['siteInstance':siteInstance] |
---|
94 | } |
---|
95 | |
---|
96 | def save = { |
---|
97 | def siteInstance = new Site(params) |
---|
98 | if(!siteInstance.hasErrors() && siteInstance.save(flush: true)) { |
---|
99 | flash.message = "Site ${siteInstance.id} created" |
---|
100 | redirect(action:show,id:siteInstance.id) |
---|
101 | } |
---|
102 | else { |
---|
103 | render(view:'create',model:[siteInstance:siteInstance]) |
---|
104 | } |
---|
105 | } |
---|
106 | } |
---|