1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
2 | |
---|
3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager']) |
---|
4 | class AssetSubItemExtendedAttributeDetailedController 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 | def index = { redirect(controller: "assetDetailed", action: "search", params:params) } |
---|
10 | |
---|
11 | def show = { |
---|
12 | def assetSubItemExtendedAttributeInstance = AssetSubItemExtendedAttribute.get( params.id ) |
---|
13 | |
---|
14 | if(!assetSubItemExtendedAttributeInstance) { |
---|
15 | flash.message = "AssetSubItemExtendedAttribute not found with id ${params.id}" |
---|
16 | redirect(controller: "assetDetailed", action: "search") |
---|
17 | } |
---|
18 | else { return [ assetSubItemExtendedAttributeInstance : assetSubItemExtendedAttributeInstance ] } |
---|
19 | } |
---|
20 | |
---|
21 | def delete = { |
---|
22 | def assetSubItemExtendedAttributeInstance = AssetSubItemExtendedAttribute.get( params.id ) |
---|
23 | if(assetSubItemExtendedAttributeInstance) { |
---|
24 | def assetSubItem = assetSubItemExtendedAttributeInstance.assetSubItem |
---|
25 | try { |
---|
26 | assetSubItemExtendedAttributeInstance.delete(flush:true) |
---|
27 | flash.message = "AssetSubItemExtendedAttribute ${params.id} deleted" |
---|
28 | redirect(controller: "assetSubItemDetailed", action: 'show', id: assetSubItem.id) |
---|
29 | } |
---|
30 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
31 | flash.message = "AssetSubItemExtendedAttribute ${params.id} could not be deleted" |
---|
32 | redirect(action:show,id:params.id) |
---|
33 | } |
---|
34 | } |
---|
35 | else { |
---|
36 | flash.message = "AssetSubItemExtendedAttribute not found with id ${params.id}" |
---|
37 | redirect(controller: "assetDetailed", action: "search") |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | def edit = { |
---|
42 | def assetSubItemExtendedAttributeInstance = AssetSubItemExtendedAttribute.get( params.id ) |
---|
43 | |
---|
44 | if(!assetSubItemExtendedAttributeInstance) { |
---|
45 | flash.message = "AssetSubItemExtendedAttribute not found with id ${params.id}" |
---|
46 | redirect(controller: "assetDetailed", action: "search") |
---|
47 | } |
---|
48 | else { |
---|
49 | return [ assetSubItemExtendedAttributeInstance : assetSubItemExtendedAttributeInstance ] |
---|
50 | } |
---|
51 | } |
---|
52 | |
---|
53 | def update = { |
---|
54 | def assetSubItemExtendedAttributeInstance = AssetSubItemExtendedAttribute.get( params.id ) |
---|
55 | if(assetSubItemExtendedAttributeInstance) { |
---|
56 | if(params.version) { |
---|
57 | def version = params.version.toLong() |
---|
58 | if(assetSubItemExtendedAttributeInstance.version > version) { |
---|
59 | |
---|
60 | assetSubItemExtendedAttributeInstance.errors.rejectValue("version", "default.optimistic.locking.failure") |
---|
61 | render(view:'edit',model:[assetSubItemExtendedAttributeInstance:assetSubItemExtendedAttributeInstance]) |
---|
62 | return |
---|
63 | } |
---|
64 | } |
---|
65 | assetSubItemExtendedAttributeInstance.properties = params |
---|
66 | if(!assetSubItemExtendedAttributeInstance.hasErrors() && assetSubItemExtendedAttributeInstance.save(flush: true)) { |
---|
67 | flash.message = "AssetSubItemExtendedAttribute ${params.id} updated" |
---|
68 | //redirect(action:show,id:assetSubItemExtendedAttributeInstance.id) |
---|
69 | redirect(controller: 'assetSubItemDetailed', action: 'show', id: assetSubItemExtendedAttributeInstance.assetSubItem.id) |
---|
70 | } |
---|
71 | else { |
---|
72 | render(view:'edit',model:[assetSubItemExtendedAttributeInstance:assetSubItemExtendedAttributeInstance]) |
---|
73 | } |
---|
74 | } |
---|
75 | else { |
---|
76 | flash.message = "AssetSubItemExtendedAttribute not found with id ${params.id}" |
---|
77 | redirect(controller: "assetDetailed", action: "search") |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | def create = { |
---|
82 | def assetSubItemExtendedAttributeInstance = new AssetSubItemExtendedAttribute() |
---|
83 | assetSubItemExtendedAttributeInstance.properties = params |
---|
84 | return ['assetSubItemExtendedAttributeInstance':assetSubItemExtendedAttributeInstance] |
---|
85 | } |
---|
86 | |
---|
87 | def save = { |
---|
88 | def assetSubItemExtendedAttributeInstance = new AssetSubItemExtendedAttribute(params) |
---|
89 | if(!assetSubItemExtendedAttributeInstance.hasErrors() && assetSubItemExtendedAttributeInstance.save(flush: true)) { |
---|
90 | flash.message = "AssetSubItemExtendedAttribute ${assetSubItemExtendedAttributeInstance.id} created" |
---|
91 | redirect(controller:'assetSubItemDetailed', action:'edit',id:assetSubItemExtendedAttributeInstance.assetSubItem.id) |
---|
92 | } |
---|
93 | else { |
---|
94 | render(view:'create',model:[assetSubItemExtendedAttributeInstance:assetSubItemExtendedAttributeInstance]) |
---|
95 | } |
---|
96 | } |
---|
97 | } |
---|