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