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

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

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

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