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

Last change on this file since 673 was 298, checked in by gav, 15 years ago

Set base authorisations on all controllers.

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