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

Revision 1794, 7.2 KB (checked in by work@…, 3 years ago)

- added support for fuzzymatching (resolves #418)
- removed debug lines
- gdt up to 0.0.38

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