root/trunk/grails-app/controllers/dbnp/studycapturing/PersonAffiliationController.groovy @ 1430

Revision 1430, 7.5 KB (checked in by work@…, 3 years ago)

- set keyword expansion

  • 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 PersonAffiliationController {
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      println( params );
55
56      if ( params['dialog'] ) {
57        model.layout = 'dialog';
58        model.extraparams = [ 'dialog': 'true' ] ;
59      } else {
60        model.layout = 'main';
61        model.extraparams = [] ;
62      }
63    }
64
65    def index = {
66        redirect(action: "list", params: params)
67    }
68
69    def list = {
70        params.max = Math.min(params.max ? params.int('max') : 10, 100)
71        [personAffiliationInstanceList: PersonAffiliation.list(params), personAffiliationInstanceTotal: PersonAffiliation.count()]
72    }
73
74    def create = {
75        def personAffiliationInstance = new PersonAffiliation()
76        personAffiliationInstance.properties = params
77        return [personAffiliationInstance: personAffiliationInstance]
78    }
79
80    def save = {
81        def personAffiliationInstance = new PersonAffiliation(params)
82        def extraparams = new LinkedHashMap();
83
84        if( params[ 'dialog' ] ) {
85          extraparams[ 'dialog' ] = params[ 'dialog' ]
86        }
87
88        if (personAffiliationInstance.save(flush: true)) {
89            flash.message = "${message(code: 'default.created.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), personAffiliationInstance])}"
90            redirect(action: "show", id: personAffiliationInstance.id, params: extraparams)
91        }
92        else {
93            render(view: "create", model: [personAffiliationInstance: personAffiliationInstance])
94        }
95    }
96
97    def show = {
98        def personAffiliationInstance = PersonAffiliation.get(params.id)
99        if (!personAffiliationInstance) {
100            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), params.id])}"
101            redirect(action: "list")
102        }
103        else {
104            [personAffiliationInstance: personAffiliationInstance]
105        }
106    }
107
108    def edit = {
109        def personAffiliationInstance = PersonAffiliation.get(params.id)
110        if (!personAffiliationInstance) {
111            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), params.id])}"
112            redirect(action: "list")
113        }
114        else {
115            return [personAffiliationInstance: personAffiliationInstance]
116        }
117    }
118
119    def update = {
120        def personAffiliationInstance = PersonAffiliation.get(params.id)
121
122        def extraparams = new LinkedHashMap();
123
124        if( params[ 'dialog' ] ) {
125          extraparams[ 'dialog' ] = params[ 'dialog' ]
126        }
127
128        if (personAffiliationInstance) {
129            if (params.version) {
130                def version = params.version.toLong()
131                if (personAffiliationInstance.version > version) {
132                   
133                    personAffiliationInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'personAffiliation.label', default: 'Affiliation')] as Object[], "Another user has updated this PersonAffiliation while you were editing")
134                    render(view: "edit", model: [personAffiliationInstance: personAffiliationInstance])
135                    return
136                }
137            }
138            personAffiliationInstance.properties = params
139            if (!personAffiliationInstance.hasErrors() && personAffiliationInstance.save(flush: true)) {
140                flash.message = "${message(code: 'default.updated.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), personAffiliationInstance])}"
141                redirect(action: "show", id: personAffiliationInstance.id, params: extraparams)
142            }
143            else {
144                render(view: "edit", model: [personAffiliationInstance: personAffiliationInstance])
145            }
146        }
147        else {
148            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), params.id])}"
149            redirect(action: "list", params: extraparams)
150        }
151    }
152
153    def delete = {
154        def personAffiliationInstance = PersonAffiliation.get(params.id)
155
156        def extraparams = new LinkedHashMap();
157
158        if( params[ 'dialog' ] ) {
159          extraparams[ 'dialog' ] = params[ 'dialog' ]
160        }
161
162        if (personAffiliationInstance) {
163            def affiliationName = personAffiliationInstance.toString()
164            try {
165                personAffiliationInstance.delete(flush: true)
166                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), affiliationName])}"
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: 'personAffiliation.label', default: 'Affiliation'), affiliationName])}"
171                redirect(action: "show", id: params.id, params: extraparams)
172            }
173        }
174        else {
175            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), params.id])}"
176            redirect(action: "list", params: extraparams)
177        }
178    }
179}
Note: See TracBrowser for help on using the browser.