source: trunk/grails-app/controllers/PurchasingGroupDetailedController.groovy @ 816

Last change on this file since 816 was 633, checked in by gav, 14 years ago

Domain change: Add PurchasingGroup?.
Logic and views to suite.

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