source: trunk/grails-app/controllers/SectionDetailedController.groovy @ 967

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

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

File size: 3.8 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3@Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager'])
4class SectionDetailedController extends BaseController {
5
6    def sectionService
7
8    // the delete, save and update actions only accept POST requests
9    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
10
11    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser'])
12    def index = { redirect(action:list,params:params) }
13
14    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser'])
15    def list = {
16        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
17        [ sectionInstanceList: Section.list( params ), sectionInstanceTotal: Section.count() ]
18    }
19
20    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser'])
21    def show = {
22
23        // In the case of an actionSubmit button, rewrite action name from 'index'.
24        if(params._action_Show)
25            params.action='show'
26
27        def sectionInstance = Section.get( params.id )
28
29        if(!sectionInstance) {
30            flash.message = "Section not found with id ${params.id}"
31            redirect(action:list)
32        }
33        else { return [ sectionInstance : sectionInstance ] }
34    }
35
36    @Secured(['ROLE_AppAdmin'])
37    def delete = {
38        def result = sectionService.delete(params)
39
40        if(!result.error) {
41            flash.message = g.message(code: "default.delete.success", args: ["Section", params.id])
42            redirect(action:list)
43            return
44        }
45
46        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
47
48        if(result.error.code == "default.not.found") {
49            redirect(action:list)
50            return
51        }
52
53        redirect(action:show, id: params.id)
54    }
55
56    def edit = {
57
58        // In the case of an actionSubmit button, rewrite action name from 'index'.
59        if(params._action_Edit)
60            params.action='edit'
61
62        def sectionInstance = Section.get( params.id )
63
64        if(!sectionInstance) {
65            flash.message = "Section not found with id ${params.id}"
66            redirect(action:list)
67        }
68        else {
69            return [ sectionInstance : sectionInstance ]
70        }
71    }
72
73    def update = {
74        def sectionInstance = Section.get( params.id )
75        if(sectionInstance) {
76            if(params.version) {
77                def version = params.version.toLong()
78                if(sectionInstance.version > version) {
79                   
80                    sectionInstance.errors.rejectValue("version", "default.optimistic.locking.failure")
81                    render(view:'edit',model:[sectionInstance:sectionInstance])
82                    return
83                }
84            }
85            sectionInstance.properties = params
86            if(!sectionInstance.hasErrors() && sectionInstance.save(flush: true)) {
87                flash.message = "Section ${params.id} updated"
88                redirect(action:show,id:sectionInstance.id)
89            }
90            else {
91                render(view:'edit',model:[sectionInstance:sectionInstance])
92            }
93        }
94        else {
95            flash.message = "Section not found with id ${params.id}"
96            redirect(action:list)
97        }
98    }
99
100    def create = {
101        def sectionInstance = new Section()
102        sectionInstance.properties = params
103        return ['sectionInstance':sectionInstance]
104    }
105
106    def save = {
107        def sectionInstance = new Section(params)
108        if(!sectionInstance.hasErrors() && sectionInstance.save(flush: true)) {
109            flash.message = "Section ${sectionInstance.id} created"
110            redirect(action:show,id:sectionInstance.id)
111        }
112        else {
113            render(view:'create',model:[sectionInstance:sectionInstance])
114        }
115    }
116}
Note: See TracBrowser for help on using the repository browser.