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

Last change on this file since 271 was 178, checked in by gav, 15 years ago

Resolve ticket #12 again.
Turn query cache on again since this did not resolve the problem.
Implement fix as per http://jira.codehaus.org/browse/GRAILS-5111, add flush:true to save.
Adjust templates to include above and remove home url.
Re-generate all non detailed views and controllers.
Manually add flush:true and remove home url to detailed views and controllers.

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