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