source: trunk/grails-app/controllers/SupplierDetailedController.groovy @ 964

Last change on this file since 964 was 961, checked in by gav, 13 years ago

Set params.max to 100, 1000 for list views of CostCode, InventoryLocation, InventoryStore, Supplier.

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