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

Last change on this file since 113 was 106, checked in by gav, 16 years ago

Some CSS adjustments to text color, img border, remove body height:100%, add buttons input.add to CSS.
Move admin stuff to AppAdmin? to make it very clear that it is not for daily use.
TaskDetailed? list and delete now use the IsActive? attribute.
Remove Task.comment size constraint.
Add more help-ballons to TaskDetailed? create.
Clean loose comments from main.gsp and auth.gsp
Use pretty pictures in TaskDetailed? views instead of Edit and Show words.

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