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