source: trunk/grails-app/controllers/InventoryLocationDetailedController.groovy @ 958

Last change on this file since 958 was 958, checked in by gav, 8 years ago

Add filterpane search to InventoryLocation? list view.

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