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

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

Added an application log view.
Reduced log file size and added CSS and JavaScript? to suite.

File size: 3.6 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        def sectionInstance = Section.get( params.id )
23
24        if(!sectionInstance) {
25            flash.message = "Section not found with id ${params.id}"
26            redirect(action:list)
27        }
28        else { return [ sectionInstance : sectionInstance ] }
29    }
30
31    @Secured(['ROLE_AppAdmin'])
32    def delete = {
33        def result = sectionService.delete(params)
34
35        if(!result.error) {
36            flash.message = g.message(code: "default.delete.success", args: ["Section", params.id])
37            redirect(action:list)
38            return
39        }
40
41        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
42
43        if(result.error.code == "default.not.found") {
44            redirect(action:list)
45            return
46        }
47
48        redirect(action:show, id: params.id)
49    }
50
51    def edit = {
52        def sectionInstance = Section.get( params.id )
53
54        if(!sectionInstance) {
55            flash.message = "Section not found with id ${params.id}"
56            redirect(action:list)
57        }
58        else {
59            return [ sectionInstance : sectionInstance ]
60        }
61    }
62
63    def update = {
64        def sectionInstance = Section.get( params.id )
65        if(sectionInstance) {
66            if(params.version) {
67                def version = params.version.toLong()
68                if(sectionInstance.version > version) {
69                   
70                    sectionInstance.errors.rejectValue("version", "section.optimistic.locking.failure", "Another user has updated this Section while you were editing.")
71                    render(view:'edit',model:[sectionInstance:sectionInstance])
72                    return
73                }
74            }
75            sectionInstance.properties = params
76            if(!sectionInstance.hasErrors() && sectionInstance.save(flush: true)) {
77                flash.message = "Section ${params.id} updated"
78                redirect(action:show,id:sectionInstance.id)
79            }
80            else {
81                render(view:'edit',model:[sectionInstance:sectionInstance])
82            }
83        }
84        else {
85            flash.message = "Section not found with id ${params.id}"
86            redirect(action:list)
87        }
88    }
89
90    def create = {
91        def sectionInstance = new Section()
92        sectionInstance.properties = params
93        return ['sectionInstance':sectionInstance]
94    }
95
96    def save = {
97        def sectionInstance = new Section(params)
98        if(!sectionInstance.hasErrors() && sectionInstance.save(flush: true)) {
99            flash.message = "Section ${sectionInstance.id} created"
100            redirect(action:show,id:sectionInstance.id)
101        }
102        else {
103            render(view:'create',model:[sectionInstance:sectionInstance])
104        }
105    }
106}
Note: See TracBrowser for help on using the repository browser.