[69] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
[556] | 3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
| 4 | class TaskGroupDetailedController extends BaseController { |
---|
[66] | 5 | |
---|
| 6 | def index = { redirect(action:list,params:params) } |
---|
| 7 | |
---|
| 8 | // the delete, save and update actions only accept POST requests |
---|
[74] | 9 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
[66] | 10 | |
---|
| 11 | def list = { |
---|
[122] | 12 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
| 13 | [ taskGroupInstanceList: TaskGroup.list( params ), taskGroupInstanceTotal: TaskGroup.count() ] |
---|
[66] | 14 | } |
---|
| 15 | |
---|
| 16 | def show = { |
---|
[558] | 17 | |
---|
| 18 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 19 | if(params._action_Show) |
---|
| 20 | params.action='show' |
---|
| 21 | |
---|
[66] | 22 | def taskGroupInstance = TaskGroup.get( params.id ) |
---|
| 23 | |
---|
| 24 | if(!taskGroupInstance) { |
---|
| 25 | flash.message = "TaskGroup not found with id ${params.id}" |
---|
| 26 | redirect(action:list) |
---|
| 27 | } |
---|
| 28 | else { return [ taskGroupInstance : taskGroupInstance ] } |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | def delete = { |
---|
| 32 | def taskGroupInstance = TaskGroup.get( params.id ) |
---|
| 33 | if(taskGroupInstance) { |
---|
[122] | 34 | try { |
---|
[178] | 35 | taskGroupInstance.delete(flush:true) |
---|
[122] | 36 | flash.message = "TaskGroup ${params.id} deleted" |
---|
| 37 | redirect(action:list) |
---|
| 38 | } |
---|
| 39 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
| 40 | flash.message = "TaskGroup ${params.id} could not be deleted" |
---|
| 41 | redirect(action:show,id:params.id) |
---|
| 42 | } |
---|
[66] | 43 | } |
---|
| 44 | else { |
---|
| 45 | flash.message = "TaskGroup not found with id ${params.id}" |
---|
| 46 | redirect(action:list) |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | def edit = { |
---|
[558] | 51 | |
---|
| 52 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 53 | if(params._action_Edit) |
---|
| 54 | params.action='edit' |
---|
| 55 | |
---|
[66] | 56 | def taskGroupInstance = TaskGroup.get( params.id ) |
---|
| 57 | |
---|
| 58 | if(!taskGroupInstance) { |
---|
| 59 | flash.message = "TaskGroup not found with id ${params.id}" |
---|
| 60 | redirect(action:list) |
---|
| 61 | } |
---|
| 62 | else { |
---|
| 63 | return [ taskGroupInstance : taskGroupInstance ] |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | def update = { |
---|
| 68 | def taskGroupInstance = TaskGroup.get( params.id ) |
---|
| 69 | if(taskGroupInstance) { |
---|
[122] | 70 | if(params.version) { |
---|
| 71 | def version = params.version.toLong() |
---|
| 72 | if(taskGroupInstance.version > version) { |
---|
| 73 | |
---|
[403] | 74 | taskGroupInstance.errors.rejectValue("version", "default.optimistic.locking.failure") |
---|
[122] | 75 | render(view:'edit',model:[taskGroupInstance:taskGroupInstance]) |
---|
| 76 | return |
---|
| 77 | } |
---|
| 78 | } |
---|
[66] | 79 | taskGroupInstance.properties = params |
---|
[178] | 80 | if(!taskGroupInstance.hasErrors() && taskGroupInstance.save(flush: true)) { |
---|
[66] | 81 | flash.message = "TaskGroup ${params.id} updated" |
---|
| 82 | redirect(action:show,id:taskGroupInstance.id) |
---|
| 83 | } |
---|
| 84 | else { |
---|
| 85 | render(view:'edit',model:[taskGroupInstance:taskGroupInstance]) |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | else { |
---|
| 89 | flash.message = "TaskGroup not found with id ${params.id}" |
---|
[178] | 90 | redirect(action:list) |
---|
[66] | 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | def create = { |
---|
| 95 | def taskGroupInstance = new TaskGroup() |
---|
| 96 | taskGroupInstance.properties = params |
---|
| 97 | return ['taskGroupInstance':taskGroupInstance] |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | def save = { |
---|
| 101 | def taskGroupInstance = new TaskGroup(params) |
---|
[178] | 102 | if(!taskGroupInstance.hasErrors() && taskGroupInstance.save(flush: true)) { |
---|
[66] | 103 | flash.message = "TaskGroup ${taskGroupInstance.id} created" |
---|
| 104 | redirect(action:show,id:taskGroupInstance.id) |
---|
| 105 | } |
---|
| 106 | else { |
---|
| 107 | render(view:'create',model:[taskGroupInstance:taskGroupInstance]) |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | } |
---|