root/trunk/grails-app/controllers/dbnp/studycapturing/PersonRoleController.groovy @ 1921

Revision 1921, 7.2 KB (checked in by t.w.abma@…, 3 years ago)

- added filter to BaseFilters?
- added security annotation to all controllers where needed (except for Home, (Advanced) Search and Publications)
- added tags to top navigation menus showing only menu(items) dependent on whether a user is logged in or not

  • Property svn:keywords set to Rev Author Date
Line 
1package dbnp.studycapturing
2
3import grails.plugins.springsecurity.Secured
4/**
5 * 888       888 888    888 8888888888 8888888b.  8888888888
6 * 888   o   888 888    888 888        888   Y88b 888
7 * 888  d8b  888 888    888 888        888    888 888
8 * 888 d888b 888 8888888888 8888888    888   d88P 8888888
9 * 888d88888b888 888    888 888        8888888P"  888
10 * 88888P Y88888 888    888 888        888 T88b   888
11 * 8888P   Y8888 888    888 888        888  T88b  888
12 * 888P     Y888 888    888 8888888888 888   T88b 8888888888
13 *
14 * 8888888 .d8888b.     88888888888 888    888 8888888888
15 *   888  d88P  Y88b        888     888    888 888
16 *   888  Y88b.             888     888    888 888
17 *   888   "Y888b.          888     8888888888 8888888
18 *   888      "Y88b.        888     888    888 888
19 *   888        "888        888     888    888 888
20 *   888  Y88b  d88P        888     888    888 888
21 * 8888888 "Y8888P"         888     888    888 8888888888
22 *
23 *   888888        d8888 888     888     d8888 8888888b.   .d88888b.   .d8888b.
24 *     "88b       d88888 888     888    d88888 888  "Y88b d88P" "Y88b d88P  Y88b
25 *      888      d88P888 888     888   d88P888 888    888 888     888 888    888
26 *      888     d88P 888 Y88b   d88P  d88P 888 888    888 888     888 888
27 *      888    d88P  888  Y88b d88P  d88P  888 888    888 888     888 888
28 *      888   d88P   888   Y88o88P  d88P   888 888    888 888     888 888    888
29 *      88P  d8888888888    Y888P  d8888888888 888  .d88P Y88b. .d88P Y88b  d88P
30 *      888 d88P     888     Y8P  d88P     888 8888888P"   "Y88888P"   "Y8888P"
31 *    .d88P
32 *  .d88P"
33 * 888P"
34 *
35 *  .d8888b.  888  .d8888b.  888  .d8888b.  888
36 * d88P  Y88b 888 d88P  Y88b 888 d88P  Y88b 888
37 *      .d88P 888      .d88P 888      .d88P 888
38 *    .d88P"  888    .d88P"  888    .d88P"  888
39 *    888"    888    888"    888    888"    888
40 *    888     Y8P    888     Y8P    888     Y8P
41 *             "              "              "
42 *    888     888    888     888    888     888
43 *
44 *
45 * TODO: add PROPER class and method documentation, just like have
46 *       agreed upon hundreds of times!!!!
47 */
48@Secured(['IS_AUTHENTICATED_REMEMBERED'])
49class PersonRoleController {
50
51    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
52
53    /**
54     * Fires after every action and determines the layout of the page
55     */
56    def afterInterceptor = { model, modelAndView ->
57      if ( params['dialog'] ) {
58        model.layout = 'dialog';
59        model.extraparams = [ 'dialog': 'true' ] ;
60      } else {
61        model.layout = 'main';
62        model.extraparams = [] ;
63      }
64    }
65
66    def index = {
67        redirect(action: "list", params: params)
68    }
69
70    def list = {
71        params.max = Math.min(params.max ? params.int('max') : 10, 100)
72        [personRoleInstanceList: PersonRole.list(params), personRoleInstanceTotal: PersonRole.count()]
73    }
74
75    def create = {
76        def personRoleInstance = new PersonRole()
77        personRoleInstance.properties = params
78        return [personRoleInstance: personRoleInstance]
79    }
80
81    def save = {
82        def personRoleInstance = new PersonRole(params)
83        def extraparams = new LinkedHashMap();
84
85        if( params[ 'dialog' ] ) {
86          extraparams[ 'dialog' ] = params[ 'dialog' ]
87        }
88
89        if (personRoleInstance.save(flush: true)) {
90            flash.message = "${message(code: 'default.created.message', args: [message(code: 'personRole.label', default: 'Role'), personRoleInstance.name])}"
91            //redirect(action: "show", id: personRoleInstance.id)
92            redirect(action: "list", params: extraparams)
93        }
94        else {
95            render(view: "create", model: [personRoleInstance: personRoleInstance])
96        }
97    }
98
99    def show = {
100        def personRoleInstance = PersonRole.get(params.id)
101        if (!personRoleInstance) {
102            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personRole.label', default: 'Role'), params.id])}"
103            redirect(action: "list")
104        }
105        else {
106            [personRoleInstance: personRoleInstance]
107        }
108    }
109
110    def edit = {
111        def personRoleInstance = PersonRole.get(params.id)
112        if (!personRoleInstance) {
113            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personRole.label', default: 'Role'), params.id])}"
114            redirect(action: "list")
115        }
116        else {
117            return [personRoleInstance: personRoleInstance]
118        }
119    }
120
121    def update = {
122        def personRoleInstance = PersonRole.get(params.id)
123        def extraparams = new LinkedHashMap();
124
125        if( params[ 'dialog' ] ) {
126          extraparams[ 'dialog' ] = params[ 'dialog' ]
127        }
128
129        if (personRoleInstance) {
130            if (params.version) {
131                def version = params.version.toLong()
132                if (personRoleInstance.version > version) {
133                   
134                    personRoleInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'personRole.label', default: 'Role')] as Object[], "Another user has updated this PersonRole while you were editing")
135                    render(view: "edit", model: [personRoleInstance: personRoleInstance])
136                    return
137                }
138            }
139            personRoleInstance.properties = params
140            if (!personRoleInstance.hasErrors() && personRoleInstance.save(flush: true)) {
141                flash.message = "${message(code: 'default.updated.message', args: [message(code: 'personRole.label', default: 'Role'), personRoleInstance.name])}"
142                //redirect(action: "show", id: personRoleInstance.id)
143                redirect(action: "list", params: extraparams)
144
145            }
146            else {
147                render(view: "edit", model: [personRoleInstance: personRoleInstance])
148            }
149        }
150        else {
151            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personRole.label', default: 'Role'), params.id])}"
152            redirect(action: "list", params: extraparams)
153        }
154    }
155
156    def delete = {
157        def personRoleInstance = PersonRole.get(params.id)
158        def extraparams = new LinkedHashMap();
159
160        if( params[ 'dialog' ] ) {
161          extraparams[ 'dialog' ] = params[ 'dialog' ]
162        }
163
164
165        if (personRoleInstance) {
166            def roleName = personRoleInstance.name
167            try {
168                personRoleInstance.delete(flush: true)
169                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'personRole.label', default: 'Role'), roleName])}"
170                redirect(action: "list", params: extraparams)
171            }
172            catch (org.springframework.dao.DataIntegrityViolationException e) {
173                flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'personRole.label', default: 'Role'), roleName])}"
174                // redirect(action: "show", id: params.id)
175                redirect(action: "list", params: extraparams)
176            }
177        }
178        else {
179            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personRole.label', default: 'Role'), params.id])}"
180            redirect(action: "list", params: extraparams)
181        }
182    }
183}
Note: See TracBrowser for help on using the browser.