source: trunk/grails-app/controllers/dbnp/studycapturing/PersonRoleController.groovy @ 379

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

Updated the person, personrole and personaffiliation view templates in order to create a consistent example for simple tables.
Also updated bootstrap.groovy to contain several persons and roles

File size: 4.2 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            redirect(action: "list")
28        }
29        else {
30            render(view: "create", model: [personRoleInstance: personRoleInstance])
31        }
32    }
33
34    def show = {
35        def personRoleInstance = PersonRole.get(params.id)
36        if (!personRoleInstance) {
37            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personRole.label', default: 'Role'), params.id])}"
38            redirect(action: "list")
39        }
40        else {
41            [personRoleInstance: personRoleInstance]
42        }
43    }
44
45    def edit = {
46        def personRoleInstance = PersonRole.get(params.id)
47        if (!personRoleInstance) {
48            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personRole.label', default: 'Role'), params.id])}"
49            redirect(action: "list")
50        }
51        else {
52            return [personRoleInstance: personRoleInstance]
53        }
54    }
55
56    def update = {
57        def personRoleInstance = PersonRole.get(params.id)
58        if (personRoleInstance) {
59            if (params.version) {
60                def version = params.version.toLong()
61                if (personRoleInstance.version > version) {
62                   
63                    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")
64                    render(view: "edit", model: [personRoleInstance: personRoleInstance])
65                    return
66                }
67            }
68            personRoleInstance.properties = params
69            if (!personRoleInstance.hasErrors() && personRoleInstance.save(flush: true)) {
70                flash.message = "${message(code: 'default.updated.message', args: [message(code: 'personRole.label', default: 'Role'), personRoleInstance.name])}"
71                //redirect(action: "show", id: personRoleInstance.id)
72                redirect(action: "list")
73
74            }
75            else {
76                render(view: "edit", model: [personRoleInstance: personRoleInstance])
77            }
78        }
79        else {
80            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personRole.label', default: 'Role'), params.id])}"
81            redirect(action: "list")
82        }
83    }
84
85    def delete = {
86        def personRoleInstance = PersonRole.get(params.id)
87
88        if (personRoleInstance) {
89            def roleName = personRoleInstance.name
90            try {
91                personRoleInstance.delete(flush: true)
92                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'personRole.label', default: 'Role'), roleName])}"
93                redirect(action: "list")
94            }
95            catch (org.springframework.dao.DataIntegrityViolationException e) {
96                flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'personRole.label', default: 'Role'), roleName])}"
97                // redirect(action: "show", id: params.id)
98                redirect(action: "list")
99            }
100        }
101        else {
102            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personRole.label', default: 'Role'), params.id])}"
103            redirect(action: "list")
104        }
105    }
106}
Note: See TracBrowser for help on using the repository browser.