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

Last change on this file since 302 was 298, checked in by gav, 15 years ago

Set base authorisations on all controllers.

File size: 4.2 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 = {
[175]20        def inventoryLocationInstance = InventoryLocation.get( params.id )
[125]21
[175]22        if(!inventoryLocationInstance) {
23            flash.message = "InventoryLocation not found with id ${params.id}"
[125]24            redirect(action:list)
25        }
[175]26        else { return [ inventoryLocationInstance : inventoryLocationInstance ] }
[125]27    }
28
29    def delete = {
[175]30        def inventoryLocationInstance = InventoryLocation.get( params.id )
31        if(inventoryLocationInstance) {
[125]32            try {
[175]33                inventoryLocationInstance.delete(flush:true)
34                flash.message = "InventoryLocation ${params.id} deleted"
[125]35                redirect(action:list)
36            }
37            catch(org.springframework.dao.DataIntegrityViolationException e) {
[175]38                flash.message = "InventoryLocation ${params.id} could not be deleted"
[125]39                redirect(action:show,id:params.id)
40            }
41        }
42        else {
[175]43            flash.message = "InventoryLocation not found with id ${params.id}"
[125]44            redirect(action:list)
45        }
46    }
47
48    def edit = {
[175]49        def inventoryLocationInstance = InventoryLocation.get( params.id )
[125]50
[175]51        if(!inventoryLocationInstance) {
52            flash.message = "InventoryLocation not found with id ${params.id}"
[125]53            redirect(action:list)
54        }
55        else {
[175]56            return [ inventoryLocationInstance : inventoryLocationInstance ]
[125]57        }
58    }
59
60    def update = {
[175]61        def inventoryLocationInstance = InventoryLocation.get( params.id )
62        if(inventoryLocationInstance) {
[125]63            if(params.version) {
64                def version = params.version.toLong()
[175]65                if(inventoryLocationInstance.version > version) {
[125]66                   
[175]67                    inventoryLocationInstance.errors.rejectValue("version", "inventoryLocation.optimistic.locking.failure", "Another user has updated this InventoryLocation while you were editing.")
68                    render(view:'edit',model:[inventoryLocationInstance:inventoryLocationInstance])
[125]69                    return
70                }
71            }
[175]72            inventoryLocationInstance.properties = params
[178]73            if(!inventoryLocationInstance.hasErrors() && inventoryLocationInstance.save(flush: true)) {
[175]74                flash.message = "InventoryLocation ${params.id} updated"
75                redirect(action:show,id:inventoryLocationInstance.id)
[125]76            }
77            else {
[175]78                render(view:'edit',model:[inventoryLocationInstance:inventoryLocationInstance])
[125]79            }
80        }
81        else {
[175]82            flash.message = "InventoryLocation not found with id ${params.id}"
83            redirect(action:list)
[125]84        }
85    }
86
87    def create = {
[175]88        def inventoryLocationInstance = new InventoryLocation()
89        inventoryLocationInstance.properties = params
90        return ['inventoryLocationInstance':inventoryLocationInstance]
[125]91    }
92
93    def save = {
[175]94        def inventoryLocationInstance = new InventoryLocation(params)
[178]95        if(!inventoryLocationInstance.hasErrors() && inventoryLocationInstance.save(flush: true)) {
[175]96            flash.message = "InventoryLocation ${inventoryLocationInstance.id} created"
97            redirect(action:show,id:inventoryLocationInstance.id)
[125]98        }
99        else {
[175]100            render(view:'create',model:[inventoryLocationInstance:inventoryLocationInstance])
[125]101        }
102    }
103}
Note: See TracBrowser for help on using the repository browser.