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

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

Finishing touches to recurring tasks.

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