source: trunk/grails-app/controllers/SupplierTypeDetailedController.groovy @ 383

Last change on this file since 383 was 383, checked in by gav, 14 years ago

Svn move SupplierType and ManufacturerType controllers and views to detailed and complete detailing.

File size: 4.2 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3@Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager'])
4class SupplierTypeDetailedController extends BaseController {
5
6    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser'])
7    def index = { redirect(action:list,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    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser'])
13    def list = {
14        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
15        [ supplierTypeInstanceList: SupplierType.list( params ), supplierTypeInstanceTotal: SupplierType.count() ]
16    }
17
18    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser'])
19    def show = {
20
21        // In the case of an actionSubmit button, rewrite action name from 'index'.
22        if(params._action_Show)
23            params.action='show'
24
25        def supplierTypeInstance = SupplierType.get( params.id )
26
27        if(!supplierTypeInstance) {
28            flash.message = "SupplierType not found with id ${params.id}"
29            redirect(action:list)
30        }
31        else { return [ supplierTypeInstance : supplierTypeInstance ] }
32    }
33
34    def delete = {
35        def supplierTypeInstance = SupplierType.get( params.id )
36        if(supplierTypeInstance) {
37            try {
38                supplierTypeInstance.delete(flush:true)
39                flash.message = "SupplierType ${params.id} deleted"
40                redirect(action:list)
41            }
42            catch(org.springframework.dao.DataIntegrityViolationException e) {
43                flash.message = "SupplierType ${params.id} could not be deleted"
44                redirect(action:show,id:params.id)
45            }
46        }
47        else {
48            flash.message = "SupplierType not found with id ${params.id}"
49            redirect(action:list)
50        }
51    }
52
53    def edit = {
54
55        // In the case of an actionSubmit button, rewrite action name from 'index'.
56        if(params._action_Edit)
57            params.action='edit'
58
59        def supplierTypeInstance = SupplierType.get( params.id )
60
61        if(!supplierTypeInstance) {
62            flash.message = "SupplierType not found with id ${params.id}"
63            redirect(action:list)
64        }
65        else {
66            return [ supplierTypeInstance : supplierTypeInstance ]
67        }
68    }
69
70    def update = {
71        def supplierTypeInstance = SupplierType.get( params.id )
72        if(supplierTypeInstance) {
73            if(params.version) {
74                def version = params.version.toLong()
75                if(supplierTypeInstance.version > version) {
76                   
77                    supplierTypeInstance.errors.rejectValue("version", "supplierType.optimistic.locking.failure", "Another user has updated this SupplierType while you were editing.")
78                    render(view:'edit',model:[supplierTypeInstance:supplierTypeInstance])
79                    return
80                }
81            }
82            supplierTypeInstance.properties = params
83            if(!supplierTypeInstance.hasErrors() && supplierTypeInstance.save(flush: true)) {
84                flash.message = "SupplierType ${params.id} updated"
85                redirect(action:show,id:supplierTypeInstance.id)
86            }
87            else {
88                render(view:'edit',model:[supplierTypeInstance:supplierTypeInstance])
89            }
90        }
91        else {
92            flash.message = "SupplierType not found with id ${params.id}"
93            redirect(action:list)
94        }
95    }
96
97    def create = {
98        def supplierTypeInstance = new SupplierType()
99        supplierTypeInstance.properties = params
100        return ['supplierTypeInstance':supplierTypeInstance]
101    }
102
103    def save = {
104        def supplierTypeInstance = new SupplierType(params)
105        if(!supplierTypeInstance.hasErrors() && supplierTypeInstance.save(flush: true)) {
106            flash.message = "SupplierType ${supplierTypeInstance.id} created"
107            redirect(action:show,id:supplierTypeInstance.id)
108        }
109        else {
110            render(view:'create',model:[supplierTypeInstance:supplierTypeInstance])
111        }
112    }
113}
Note: See TracBrowser for help on using the repository browser.