source: trunk/grails-app/controllers/ExtendedAttributeTypeDetailedController.groovy @ 897

Last change on this file since 897 was 628, checked in by gav, 14 years ago

Full authorisation review.
Add manager role to BaseController.
Remove inventory manager role from CostCode controller as per ticket #77.
Remove inventory manager role from InventoryGroup controller CUD actions.
Add all manager roles to Address and Contact controllers.
Add production and task manager roles to ProductionReference controller.

File size: 4.3 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3@Secured(['ROLE_AppAdmin', 'ROLE_Manager'])
4class ExtendedAttributeTypeDetailedController 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        [ extendedAttributeTypeInstanceList: ExtendedAttributeType.list( params ), extendedAttributeTypeInstanceTotal: ExtendedAttributeType.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 extendedAttributeTypeInstance = ExtendedAttributeType.get( params.id )
23
24        if(!extendedAttributeTypeInstance) {
25            flash.message = "ExtendedAttributeType not found with id ${params.id}"
26            redirect(action:list)
27        }
28        else { return [ extendedAttributeTypeInstance : extendedAttributeTypeInstance ] }
29    }
30
31    def delete = {
32        def extendedAttributeTypeInstance = ExtendedAttributeType.get( params.id )
33        if(extendedAttributeTypeInstance) {
34            try {
35                extendedAttributeTypeInstance.delete(flush:true)
36                flash.message = "ExtendedAttributeType ${params.id} deleted"
37                redirect(action:list)
38            }
39            catch(org.springframework.dao.DataIntegrityViolationException e) {
40                flash.message = "ExtendedAttributeType ${params.id} could not be deleted"
41                redirect(action:show,id:params.id)
42            }
43        }
44        else {
45            flash.message = "ExtendedAttributeType 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 extendedAttributeTypeInstance = ExtendedAttributeType.get( params.id )
57
58        if(!extendedAttributeTypeInstance) {
59            flash.message = "ExtendedAttributeType not found with id ${params.id}"
60            redirect(action:list)
61        }
62        else {
63            return [ extendedAttributeTypeInstance : extendedAttributeTypeInstance ]
64        }
65    }
66
67    def update = {
68        def extendedAttributeTypeInstance = ExtendedAttributeType.get( params.id )
69        if(extendedAttributeTypeInstance) {
70            if(params.version) {
71                def version = params.version.toLong()
72                if(extendedAttributeTypeInstance.version > version) {
73                   
74                    extendedAttributeTypeInstance.errors.rejectValue("version", "default.optimistic.locking.failure")
75                    render(view:'edit',model:[extendedAttributeTypeInstance:extendedAttributeTypeInstance])
76                    return
77                }
78            }
79            extendedAttributeTypeInstance.properties = params
80            if(!extendedAttributeTypeInstance.hasErrors() && extendedAttributeTypeInstance.save(flush: true)) {
81                flash.message = "ExtendedAttributeType ${params.id} updated"
82                redirect(action:show,id:extendedAttributeTypeInstance.id)
83            }
84            else {
85                render(view:'edit',model:[extendedAttributeTypeInstance:extendedAttributeTypeInstance])
86            }
87        }
88        else {
89            flash.message = "ExtendedAttributeType not found with id ${params.id}"
90            redirect(action:list)
91        }
92    }
93
94    def create = {
95        def extendedAttributeTypeInstance = new ExtendedAttributeType()
96        extendedAttributeTypeInstance.properties = params
97        return ['extendedAttributeTypeInstance':extendedAttributeTypeInstance]
98    }
99
100    def save = {
101        def extendedAttributeTypeInstance = new ExtendedAttributeType(params)
102        if(!extendedAttributeTypeInstance.hasErrors() && extendedAttributeTypeInstance.save(flush: true)) {
103            flash.message = "ExtendedAttributeType ${extendedAttributeTypeInstance.id} created"
104            redirect(action:show,id:extendedAttributeTypeInstance.id)
105        }
106        else {
107            render(view:'create',model:[extendedAttributeTypeInstance:extendedAttributeTypeInstance])
108        }
109    }
110}
Note: See TracBrowser for help on using the repository browser.