source: branches/TaskRewrite/src/grails-app/controllers/TaskDetailedController.groovy @ 86

Last change on this file since 86 was 85, checked in by gav, 16 years ago

Re-arrange the way 'Detailed is used, much nicer and more secure.

File size: 2.6 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        if(!params.max) params.max = 10
12        [ taskInstanceList: Task.list( params ) ]
13    }
14
15    def show = {
16        def taskInstance = Task.get( params.id )
17
18        if(!taskInstance) {
19            flash.message = "Task not found with id ${params.id}"
20            redirect(action:list)
21        }
22        else { return [ taskInstance : taskInstance ] }
23    }
24
25    def delete = {
26        def taskInstance = Task.get( params.id )
27        if(taskInstance) {
28            taskInstance.delete()
29            flash.message = "Task ${params.id} deleted"
30            redirect(action:list)
31        }
32        else {
33            flash.message = "Task not found with id ${params.id}"
34            redirect(action:list)
35        }
36    }
37
38    def edit = {
39        def taskInstance = Task.get( params.id )
40
41        if(!taskInstance) {
42            flash.message = "Task not found with id ${params.id}"
43            redirect(action:list)
44        }
45        else {
46            def criteria = taskInstance.createCriteria()
47            def results = criteria {
48                and {
49                    notEqual('id', taskInstance.id)
50                    }
51            }
52            return [ taskInstance : taskInstance, possibleParentList: results ]
53        }
54    }
55
56    def update = {
57        def taskInstance = Task.get( params.id )
58        if(taskInstance) {
59            taskInstance.properties = params
60            if(!taskInstance.hasErrors() && taskInstance.save()) {
61                flash.message = "Task ${params.id} updated"
62                redirect(action:show,id:taskInstance.id)
63            }
64            else {
65                render(view:'edit',model:[taskInstance:taskInstance])
66            }
67        }
68        else {
69            flash.message = "Task not found with id ${params.id}"
70            redirect(action:edit,id:params.id)
71        }
72    }
73
74    def create = {
75        def taskInstance = new Task()
76        taskInstance.properties = params
77        return ['taskInstance':taskInstance]
78    }
79
80    def save = {
81        def taskInstance = new Task(params)
82        if(!taskInstance.hasErrors() && taskInstance.save()) {
83            flash.message = "Task ${taskInstance.id} created"
84            redirect(action:show,id:taskInstance.id)
85        }
86        else {
87            render(view:'create',model:[taskInstance:taskInstance])
88        }
89    }
90}
Note: See TracBrowser for help on using the repository browser.