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

Last change on this file since 208 was 208, checked in by gav, 10 years ago

Remove some no longer used imports and injections.

File size: 3.6 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()
84        taskRecurringScheduleInstance.properties = params
85        return [taskRecurringScheduleInstance: taskRecurringScheduleInstance]
86    } // end create()
87
88    def save = {
89        def result = taskRecurringScheduleService.create(params)
90
91        if(!result.error) {
92            flash.message = "Recurring Schedule ${result.taskRecurringScheduleInstance.id} created."
93            redirect(action:show, id: result.taskRecurringScheduleInstance.id)
94        }
95        else {
96            render(view:'create',model:[taskRecurringScheduleInstance: result.taskRecurringScheduleInstance])
97        }
98    } // end save()
99
100}
Note: See TracBrowser for help on using the repository browser.