source: trunk/grails-app/controllers/TaskDetailedController.groovy @ 131

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

Reconfigure Planned Maintenance again, now Preventative Maintenance, TaskProcedure? and MaintenanceAction?

File size: 3.9 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class TaskDetailedController 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//         def taskInstanceActives = Task.findAllByIsActive( true ).list( params )
13// //         def taskInstanceList = taskInstanceActives.list( params )
14//         return [ taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceActives.count() ]
15//     }
16
17    def list = {
18        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
19        [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ]
20    }
21
22    def show = {
23        def taskInstance = Task.get( params.id )
24
25        if(!taskInstance) {
26            flash.message = "Task not found with id ${params.id}"
27            redirect(action:list)
28        }
29        else { 
30            def taskProcedureInstance = TaskProcedure.get(taskInstance?.taskProcedure?.id)
31            return [ taskInstance : taskInstance,  taskProcedureInstance: taskProcedureInstance] 
32
33        }
34    }
35
36    def delete = {
37        def taskInstance = Task.get( params.id )
38        if(taskInstance) {
39            try {
40                taskInstance.isActive = false
41                flash.message = "Task ${params.id} has been set to inactive."
42                redirect(action:list)
43            }
44            catch(org.springframework.dao.DataIntegrityViolationException e) {
45                flash.message = "Task ${params.id} could not be deleted"
46                redirect(action:show,id:params.id)
47            }
48        }
49        else {
50            flash.message = "Task not found with id ${params.id}"
51            redirect(action:list)
52        }
53    }
54
55    def edit = {
56        def taskInstance = Task.get( params.id )
57
58        if(!taskInstance) {
59            flash.message = "Task not found with id ${params.id}"
60            redirect(action:list)
61        }
62        else {
63            def criteria = taskInstance.createCriteria()
64            def results = criteria {
65                and {
66                    notEqual('id', taskInstance.id)
67                    }
68            }
69            return [ taskInstance : taskInstance, possibleParentList: results ]
70        }
71    }
72
73    def update = {
74        def taskInstance = Task.get( params.id )
75        if(taskInstance) {
76            if(params.version) {
77                def version = params.version.toLong()
78                if(taskInstance.version > version) {
79                   
80                    taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.")
81                    render(view:'edit',model:[taskInstance:taskInstance])
82                    return
83                }
84            }
85            taskInstance.properties = params
86            if(!taskInstance.hasErrors() && taskInstance.save()) {
87                flash.message = "Task ${params.id} updated"
88                redirect(action:show,id:taskInstance.id)
89            }
90            else {
91                render(view:'edit',model:[taskInstance:taskInstance])
92            }
93        }
94        else {
95            flash.message = "Task not found with id ${params.id}"
96            redirect(action:edit,id:params.id)
97        }
98    }
99
100    def create = {
101        def taskInstance = new Task()
102        taskInstance.properties = params
103        return ['taskInstance':taskInstance]
104    }
105
106    def save = {
107        def taskInstance = new Task(params)
108        if(!taskInstance.hasErrors() && taskInstance.save()) {
109            flash.message = "Task ${taskInstance.id} created"
110            redirect(action:show,id:taskInstance.id)
111        }
112        else {
113            render(view:'create',model:[taskInstance:taskInstance])
114        }
115    }
116}
Note: See TracBrowser for help on using the repository browser.