1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
2 | |
---|
3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager']) |
---|
4 | class InventoryStoreDetailedController extends BaseController { |
---|
5 | |
---|
6 | def filterService |
---|
7 | |
---|
8 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser']) |
---|
9 | def index = { redirect(action:list,params:params) } |
---|
10 | |
---|
11 | // the delete, save and update actions only accept POST requests |
---|
12 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
13 | |
---|
14 | def list = { |
---|
15 | params.max = Math.min( params.max ? params.max.toInteger() : 100, 1000 ) |
---|
16 | def associatedPropertyMax = 1000 |
---|
17 | def associatedPropertyValues = [:] |
---|
18 | def siteNameQuery = 'select distinct a.name from Site a where a.isActive = ? order by a.name' |
---|
19 | associatedPropertyValues.siteList = Site.executeQuery(siteNameQuery, [true], [max:associatedPropertyMax]) |
---|
20 | |
---|
21 | if(!params.filter) { |
---|
22 | return [inventoryStoreInstanceList: InventoryStore.list(params), |
---|
23 | inventoryStoreInstanceTotal: InventoryStore.count(), |
---|
24 | associatedPropertyValues: associatedPropertyValues, |
---|
25 | filterParams: params] |
---|
26 | } |
---|
27 | |
---|
28 | // filterPane: |
---|
29 | return[ inventoryStoreInstanceList: filterService.filter( params, InventoryStore ), |
---|
30 | inventoryStoreInstanceTotal: filterService.count( params, InventoryStore ), |
---|
31 | associatedPropertyValues: associatedPropertyValues, |
---|
32 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
33 | params:params ] |
---|
34 | } |
---|
35 | |
---|
36 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser']) |
---|
37 | def show = { |
---|
38 | |
---|
39 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
40 | if(params._action_Show) |
---|
41 | params.action='show' |
---|
42 | |
---|
43 | def inventoryStoreInstance = InventoryStore.get( params.id ) |
---|
44 | |
---|
45 | if(!inventoryStoreInstance) { |
---|
46 | flash.message = "InventoryStore not found with id ${params.id}" |
---|
47 | redirect(action:list) |
---|
48 | } |
---|
49 | else { return [ inventoryStoreInstance : inventoryStoreInstance ] } |
---|
50 | } |
---|
51 | |
---|
52 | def delete = { |
---|
53 | def inventoryStoreInstance = InventoryStore.get( params.id ) |
---|
54 | if(inventoryStoreInstance) { |
---|
55 | try { |
---|
56 | inventoryStoreInstance.delete(flush:true) |
---|
57 | flash.message = "InventoryStore ${params.id} deleted" |
---|
58 | redirect(action:list) |
---|
59 | } |
---|
60 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
61 | flash.message = "InventoryStore ${params.id} could not be deleted" |
---|
62 | redirect(action:show,id:params.id) |
---|
63 | } |
---|
64 | } |
---|
65 | else { |
---|
66 | flash.message = "InventoryStore not found with id ${params.id}" |
---|
67 | redirect(action:list) |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | def edit = { |
---|
72 | |
---|
73 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
74 | if(params._action_Edit) |
---|
75 | params.action='edit' |
---|
76 | |
---|
77 | def inventoryStoreInstance = InventoryStore.get( params.id ) |
---|
78 | |
---|
79 | if(!inventoryStoreInstance) { |
---|
80 | flash.message = "InventoryStore not found with id ${params.id}" |
---|
81 | redirect(action:list) |
---|
82 | } |
---|
83 | else { |
---|
84 | return [ inventoryStoreInstance : inventoryStoreInstance ] |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | def update = { |
---|
89 | def inventoryStoreInstance = InventoryStore.get( params.id ) |
---|
90 | if(inventoryStoreInstance) { |
---|
91 | if(params.version) { |
---|
92 | def version = params.version.toLong() |
---|
93 | if(inventoryStoreInstance.version > version) { |
---|
94 | |
---|
95 | inventoryStoreInstance.errors.rejectValue("version", "default.optimistic.locking.failure") |
---|
96 | render(view:'edit',model:[inventoryStoreInstance:inventoryStoreInstance]) |
---|
97 | return |
---|
98 | } |
---|
99 | } |
---|
100 | inventoryStoreInstance.properties = params |
---|
101 | if(!inventoryStoreInstance.hasErrors() && inventoryStoreInstance.save(flush: true)) { |
---|
102 | flash.message = "InventoryStore ${params.id} updated" |
---|
103 | redirect(action:show,id:inventoryStoreInstance.id) |
---|
104 | } |
---|
105 | else { |
---|
106 | render(view:'edit',model:[inventoryStoreInstance:inventoryStoreInstance]) |
---|
107 | } |
---|
108 | } |
---|
109 | else { |
---|
110 | flash.message = "InventoryStore not found with id ${params.id}" |
---|
111 | redirect(action:list) |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | def create = { |
---|
116 | def inventoryStoreInstance = new InventoryStore() |
---|
117 | inventoryStoreInstance.properties = params |
---|
118 | return ['inventoryStoreInstance':inventoryStoreInstance] |
---|
119 | } |
---|
120 | |
---|
121 | def save = { |
---|
122 | def inventoryStoreInstance = new InventoryStore(params) |
---|
123 | if(!inventoryStoreInstance.hasErrors() && inventoryStoreInstance.save(flush: true)) { |
---|
124 | flash.message = "InventoryStore ${inventoryStoreInstance.id} created" |
---|
125 | redirect(action:show,id:inventoryStoreInstance.id) |
---|
126 | } |
---|
127 | else { |
---|
128 | render(view:'create',model:[inventoryStoreInstance:inventoryStoreInstance]) |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|