source: trunk/grails-app/controllers/TaskRecurringScheduleDetailedController.groovy @ 272

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

Finishing touches to recurring tasks.

File size: 3.5 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class TaskRecurringScheduleDetailedController extends BaseController {
4
5    def taskRecurringScheduleService
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        [ taskRecurringScheduleInstanceList: TaskRecurringSchedule.list( params ), taskRecurringScheduleInstanceTotal: TaskRecurringSchedule.count() ]
15    }
16
17    def show = {
18        def taskRecurringScheduleInstance = TaskRecurringSchedule.get( params.id )
19
20        if(!taskRecurringScheduleInstance) {
21            flash.message = "Recurring Schedule not found with id ${params.id}"
22            redirect(action:list)
23        }
24        else { return [ taskRecurringScheduleInstance : taskRecurringScheduleInstance ] }
25    }
26
27    def delete = {
28        def taskRecurringScheduleInstance = TaskRecurringSchedule.get( params.id )
29        if(taskRecurringScheduleInstance) {
30            try {
31                taskRecurringScheduleInstance.delete(flush: true)
32                flash.message = "Recurring Schedule ${params.id} deleted"
33                redirect(action:list)
34            }
35            catch(org.springframework.dao.DataIntegrityViolationException e) {
36                flash.message = "Recurring Schedule ${params.id} could not be deleted"
37                redirect(action:show,id:params.id)
38            }
39        }
40        else {
41            flash.message = "Recurring Schedule not found with id ${params.id}"
42            redirect(action:list)
43        }
44    }
45
46    def edit = {
47        def taskRecurringScheduleInstance = TaskRecurringSchedule.get( params.id )
48
49        if(!taskRecurringScheduleInstance) {
50            flash.message = "Recurring Schedule not found with id ${params.id}"
51            redirect(action:list)
52        }
53        else {
54            return [ taskRecurringScheduleInstance : taskRecurringScheduleInstance]
55        }
56    }
57
58    def update = {
59
60        if(!TaskRecurringSchedule.exists(params.id)) {
61            flash.message = "Recurring Schedule not found with id ${params.id}"
62            redirect(action: 'list')
63        }
64
65        def result = taskRecurringScheduleService.update(params)
66
67        if(!result.error) {
68                flash.message = "Recurring Schedule ${params.id} updated"
69                redirect(action: 'show', id: result.taskRecurringScheduleInstance.id)
70        }
71        else {
72            render(view:'edit',model:[taskRecurringScheduleInstance: result.taskRecurringScheduleInstance.attach()])
73        }
74
75    }
76
77    def create = {
78        if(!params.task?.id || !Task.exists(params.task?.id)) {
79            flash.message = "Please select a task, then create a recurring schedule for it."
80            redirect(controller:"taskDetailed", action:"search")
81            return
82        }
83        def taskRecurringScheduleInstance = new TaskRecurringSchedule(params)
84        return [taskRecurringScheduleInstance: taskRecurringScheduleInstance]
85    }
86
87    def save = {
88        def result = taskRecurringScheduleService.create(params)
89
90        if(!result.error) {
91            flash.message = "Recurring Schedule ${result.taskRecurringScheduleInstance.id} created."
92            redirect(action:show, id: result.taskRecurringScheduleInstance.id)
93        }
94        else {
95            render(view:'create',model:[taskRecurringScheduleInstance: result.taskRecurringScheduleInstance])
96        }
97    }
98
99}
Note: See TracBrowser for help on using the repository browser.