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

Last change on this file was 913, checked in by gav, 13 years ago

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

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