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

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

Set base authorisations on all controllers.

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