source: trunk/grails-app/controllers/TaskProcedureDetailedController.groovy @ 147

Last change on this file since 147 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.8 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class TaskProcedureDetailedController 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
13        if(!params.filter)
14        { return [taskProcedureInstanceList: TaskProcedure.list(params), taskProcedureInstanceTotal: TaskProcedure.count()] }
15
16        // filterPane:
17        return[ taskProcedureInstanceList: filterService.filter( params, TaskProcedure ),
18            taskProcedureInstanceTotal: filterService.count( params, TaskProcedure ),
19            filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params),
20            params:params ]
21    }
22
23    def search = {
24        redirect(action:list)
25    }
26
27    def show = {
28
29        // In the case of an actionSubmit button, rewrite action name from 'index'.
30        if(params._action_Show)
31        { params.action='show' }
32
33        def taskProcedureInstance = TaskProcedure.get( params.id )
34
35        if(!taskProcedureInstance) {
36            flash.message = "TaskProcedure not found with id ${params.id}"
37            redirect(action:list)
38        }
39        else { return [ taskProcedureInstance : taskProcedureInstance ] }
40    }
41
42    def delete = {
43        def taskProcedureInstance = TaskProcedure.get( params.id )
44        if(taskProcedureInstance) {
45            try {
46                taskProcedureInstance.delete()
47                flash.message = "TaskProcedure ${params.id} deleted"
48                redirect(action:list)
49            }
50            catch(org.springframework.dao.DataIntegrityViolationException e) {
51                flash.message = "TaskProcedure ${params.id} could not be deleted"
52                redirect(action:show,id:params.id)
53            }
54        }
55        else {
56            flash.message = "TaskProcedure not found with id ${params.id}"
57            redirect(action:list)
58        }
59    }
60
61    def edit = {
62
63        // In the case of an actionSubmit button, rewrite action name from 'index'.
64        if(params._action_Edit)
65        { params.action='edit' }
66
67        def taskProcedureInstance = TaskProcedure.get( params.id )
68
69        if(!taskProcedureInstance) {
70            flash.message = "TaskProcedure not found with id ${params.id}"
71            redirect(action:list)
72        }
73        else {
74            return [ taskProcedureInstance : taskProcedureInstance ]
75        }
76    }
77
78    def update = {
79        def taskProcedureInstance = TaskProcedure.get( params.id )
80        if(taskProcedureInstance) {
81            if(params.version) {
82                def version = params.version.toLong()
83                if(taskProcedureInstance.version > version) {
84
85                    taskProcedureInstance.errors.rejectValue("version", "taskProcedure.optimistic.locking.failure", "Another user has updated this TaskProcedure while you were editing.")
86                    render(view:'edit',model:[taskProcedureInstance:taskProcedureInstance])
87                    return
88                }
89            }
90            taskProcedureInstance.properties = params
91            if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save()) {
92                flash.message = "TaskProcedure ${params.id} updated"
93                redirect(action:show,id:taskProcedureInstance.id)
94            }
95            else {
96                render(view:'edit',model:[taskProcedureInstance:taskProcedureInstance])
97            }
98        }
99        else {
100            flash.message = "TaskProcedure not found with id ${params.id}"
101            redirect(action:edit,id:params.id)
102        }
103    }
104
105    def create = {
106        if(params.taskInstance?.id) {
107            def taskInstance = Task.get(params.taskInstance.id)
108
109            def taskProcedureInstance = new TaskProcedure()
110            taskProcedureInstance.properties = params
111            return ['taskProcedureInstance':taskProcedureInstance,
112                            taskInstance: taskInstance]
113        } else {
114            flash.message = "Please select a task, then the Procedure tab.'"
115            redirect(controller:"taskDetailed", action:"list")
116        }
117    }
118
119    def save = {
120        def taskProcedureInstance = new TaskProcedure(params)
121        def taskInstance = Task.get(params.taskInstance.id)
122
123        if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save()) {
124            taskProcedureInstance.addToTasks(taskInstance)
125            flash.message = "TaskProcedure ${taskProcedureInstance.id} created."
126            redirect(action:show,id:taskProcedureInstance.id)
127        }
128        else {
129            render(view:'create',model:[taskProcedureInstance:taskProcedureInstance, taskInstance: taskInstance])
130        }
131    }
132}
Note: See TracBrowser for help on using the repository browser.