source: trunk/grails-app/controllers/InventoryStoreDetailedController.groovy @ 923

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

Svn merge -r875:r911 branches/features/grailsUpgrade/ into trunk/.

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