source: trunk/grails-app/controllers/ManufacturerDetailedController.groovy @ 450

Last change on this file since 450 was 403, checked in by gav, 15 years ago

Change all controllers to use default.optimistic.locking.failure.

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