source: trunk/grails-app/controllers/dbnp/studycapturing/PersonAffiliationController.groovy @ 361

Last change on this file since 361 was 361, checked in by roberth, 9 years ago

Added controllers and views for Person, PersonAffiliation? and PersonRole? and added them to the menu. Also removed the link between Person and PersonRole?, in line with the datamodel

File size: 4.6 KB
Line 
1package dbnp.studycapturing
2
3class PersonAffiliationController {
4
5    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
6
7    def index = {
8        redirect(action: "list", params: params)
9    }
10
11    def list = {
12        params.max = Math.min(params.max ? params.int('max') : 10, 100)
13        [personAffiliationInstanceList: PersonAffiliation.list(params), personAffiliationInstanceTotal: PersonAffiliation.count()]
14    }
15
16    def create = {
17        def personAffiliationInstance = new PersonAffiliation()
18        personAffiliationInstance.properties = params
19        return [personAffiliationInstance: personAffiliationInstance]
20    }
21
22    def save = {
23        def personAffiliationInstance = new PersonAffiliation(params)
24        if (personAffiliationInstance.save(flush: true)) {
25            flash.message = "${message(code: 'default.created.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), personAffiliationInstance.name])}"
26            redirect(action: "show", id: personAffiliationInstance.id)
27        }
28        else {
29            render(view: "create", model: [personAffiliationInstance: personAffiliationInstance])
30        }
31    }
32
33    def show = {
34        def personAffiliationInstance = PersonAffiliation.get(params.id)
35        if (!personAffiliationInstance) {
36            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), params.id])}"
37            redirect(action: "list")
38        }
39        else {
40            [personAffiliationInstance: personAffiliationInstance]
41        }
42    }
43
44    def edit = {
45        def personAffiliationInstance = PersonAffiliation.get(params.id)
46        if (!personAffiliationInstance) {
47            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), params.id])}"
48            redirect(action: "list")
49        }
50        else {
51            return [personAffiliationInstance: personAffiliationInstance]
52        }
53    }
54
55    def update = {
56        def personAffiliationInstance = PersonAffiliation.get(params.id)
57        if (personAffiliationInstance) {
58            if (params.version) {
59                def version = params.version.toLong()
60                if (personAffiliationInstance.version > version) {
61                   
62                    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")
63                    render(view: "edit", model: [personAffiliationInstance: personAffiliationInstance])
64                    return
65                }
66            }
67            personAffiliationInstance.properties = params
68            if (!personAffiliationInstance.hasErrors() && personAffiliationInstance.save(flush: true)) {
69                flash.message = "${message(code: 'default.updated.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), personAffiliationInstance.name])}"
70                redirect(action: "show", id: personAffiliationInstance.id)
71            }
72            else {
73                render(view: "edit", model: [personAffiliationInstance: personAffiliationInstance])
74            }
75        }
76        else {
77            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), params.id])}"
78            redirect(action: "list")
79        }
80    }
81
82    def delete = {
83        def personAffiliationInstance = PersonAffiliation.get(params.id)
84        if (personAffiliationInstance) {
85            def affiliationName = personAffiliationInstance.name
86            try {
87                personAffiliationInstance.delete(flush: true)
88                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), affiliationName])}"
89                redirect(action: "list")
90            }
91            catch (org.springframework.dao.DataIntegrityViolationException e) {
92                flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), affiliationName])}"
93                redirect(action: "show", id: params.id)
94            }
95        }
96        else {
97            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), params.id])}"
98            redirect(action: "list")
99        }
100    }
101}
Note: See TracBrowser for help on using the repository browser.