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

Last change on this file since 399 was 377, checked in by gav, 15 years ago

Svn move InventoryLocation and InventoryStore controllers and views to detailed and complete detailing.

File size: 4.3 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3@Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager'])
4class InventoryStoreDetailedController extends BaseController {
5   
6    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser'])
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
17    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser'])
18    def show = {
19
20        // In the case of an actionSubmit button, rewrite action name from 'index'.
21        if(params._action_Show)
22            params.action='show'
23
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 {
37                inventoryStoreInstance.delete(flush:true)
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 = {
53
54        // In the case of an actionSubmit button, rewrite action name from 'index'.
55        if(params._action_Edit)
56            params.action='edit'
57
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                   
76                    inventoryStoreInstance.errors.rejectValue("version", "inventoryStore.optimistic.locking.failure", "Another user has updated this InventoryStore while you were editing.")
77                    render(view:'edit',model:[inventoryStoreInstance:inventoryStoreInstance])
78                    return
79                }
80            }
81            inventoryStoreInstance.properties = params
82            if(!inventoryStoreInstance.hasErrors() && inventoryStoreInstance.save(flush: true)) {
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}"
92            redirect(action:list)
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)
104        if(!inventoryStoreInstance.hasErrors() && inventoryStoreInstance.save(flush: true)) {
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.