source: trunk/grails-app/controllers/AssignedPersonDetailedController.groovy @ 169

Last change on this file since 169 was 147, checked in by gav, 15 years ago

Re-install class-diagram from local svn build with patch to allow war deployment.
Class-diagram overrides removed from Config.groovy since these have all been included upstream.
Tidy comments in SecurityConfig?.groovy
Some work on adding assignedPerson work flow and PersonController?.
Add navAlt and filterPane search to Person and TaskProcedure?.

File size: 4.0 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class AssignedPersonDetailedController extends BaseController {
4
5    def index = { redirect(action:list,params:params) }
6
7    // the delete, save and update actions only accept POST requests
8    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
9
10    def list = {
11        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
12        [ assignedPersonInstanceList: AssignedPerson.list( params ), assignedPersonInstanceTotal: AssignedPerson.count() ]
13    }
14
15    def show = {
16        def assignedPersonInstance = AssignedPerson.get( params.id )
17
18        if(!assignedPersonInstance) {
19            flash.message = "AssignedPerson not found with id ${params.id}"
20            redirect(action:list)
21        }
22        else { return [ assignedPersonInstance : assignedPersonInstance ] }
23    }
24
25    def delete = {
26        def assignedPersonInstance = AssignedPerson.get( params.id )
27        if(assignedPersonInstance) {
28            try {
29                def taskId = assignedPersonInstance.task.id
30                assignedPersonInstance.delete()
31                flash.message = "AssignedPerson ${params.id} deleted"
32                redirect(controller:"taskDetailed", action:"show", id: taskId)
33            }
34            catch(org.springframework.dao.DataIntegrityViolationException e) {
35                flash.message = "AssignedPerson ${params.id} could not be deleted"
36                redirect(action:show,id:params.id)
37            }
38        }
39        else {
40            flash.message = "AssignedPerson not found with id ${params.id}"
41            redirect(action:list)
42        }
43    }
44
45    def edit = {
46        def assignedPersonInstance = AssignedPerson.get( params.id )
47
48        if(!assignedPersonInstance) {
49            flash.message = "AssignedPerson not found with id ${params.id}"
50            redirect(action:list)
51        }
52        else {
53            return [ assignedPersonInstance : assignedPersonInstance ]
54        }
55    }
56
57    def update = {
58        def assignedPersonInstance = AssignedPerson.get( params.id )
59        if(assignedPersonInstance) {
60            if(params.version) {
61                def version = params.version.toLong()
62                if(assignedPersonInstance.version > version) {
63
64                    assignedPersonInstance.errors.rejectValue("version", "assignedPerson.optimistic.locking.failure", "Another user has updated this AssignedPerson while you were editing.")
65                    render(view:'edit',model:[assignedPersonInstance:assignedPersonInstance])
66                    return
67                }
68            }
69            assignedPersonInstance.properties = params
70            if(!assignedPersonInstance.hasErrors() && assignedPersonInstance.save()) {
71                flash.message = "AssignedPerson ${params.id} updated"
72                redirect(action:show,id:assignedPersonInstance.id)
73            }
74            else {
75                render(view:'edit',model:[assignedPersonInstance:assignedPersonInstance])
76            }
77        }
78        else {
79            flash.message = "AssignedPerson not found with id ${params.id}"
80            redirect(action:edit,id:params.id)
81        }
82    }
83
84    def create = {
85        if(!params.task?.id) {
86            flash.message = "Please select a task and then 'Add Assigned Person'"
87            redirect(controller: "taskDetailed", action: list)
88        }
89        else {
90            def assignedPersonInstance = new AssignedPerson()
91            assignedPersonInstance.properties = params
92            return ['assignedPersonInstance':assignedPersonInstance]
93        }
94    }
95
96    def save = {
97        def assignedPersonInstance = new AssignedPerson(params)
98
99        if(!assignedPersonInstance.hasErrors() && assignedPersonInstance.save()) {
100            flash.message = "AssignedPerson ${assignedPersonInstance.id} created"
101            redirect(controller:"taskDetailed", action:"show", id: params.task.id)
102        }
103        else {
104            render(view:'create',model:[assignedPersonInstance:assignedPersonInstance])
105        }
106    }
107}
Note: See TracBrowser for help on using the repository browser.