[69] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
| 3 | class TaskController extends BaseController { |
---|
[66] | 4 | |
---|
| 5 | def index = { redirect(action:list,params:params) } |
---|
| 6 | |
---|
| 7 | // the delete, save and update actions only accept POST requests |
---|
[84] | 8 | static allowedMethods = [delete:'POST', deleteDetailed:'POST', save:'POST', saveDetailed:'POST', updateDetailed:'POST'] |
---|
[66] | 9 | |
---|
[84] | 10 | @Secured(['ROLE_AppAdmin']) |
---|
[66] | 11 | def list = { |
---|
| 12 | if(!params.max) params.max = 10 |
---|
| 13 | [ taskInstanceList: Task.list( params ) ] |
---|
| 14 | } |
---|
| 15 | |
---|
[84] | 16 | def listDetailed = { |
---|
| 17 | if(!params.max) params.max = 10 |
---|
| 18 | [ taskInstanceList: Task.list( params ) ] |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | @Secured(['ROLE_AppAdmin']) |
---|
[66] | 22 | def show = { |
---|
| 23 | def taskInstance = Task.get( params.id ) |
---|
| 24 | |
---|
| 25 | if(!taskInstance) { |
---|
| 26 | flash.message = "Task not found with id ${params.id}" |
---|
| 27 | redirect(action:list) |
---|
| 28 | } |
---|
| 29 | else { return [ taskInstance : taskInstance ] } |
---|
| 30 | } |
---|
| 31 | |
---|
[84] | 32 | def showDetailed = { |
---|
| 33 | def taskInstance = Task.get( params.id ) |
---|
| 34 | |
---|
| 35 | if(!taskInstance) { |
---|
| 36 | flash.message = "Task not found with id ${params.id}" |
---|
| 37 | redirect(action:list) |
---|
| 38 | } |
---|
| 39 | else { return [ taskInstance : taskInstance ] } |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | @Secured(['ROLE_AppAdmin']) |
---|
[66] | 43 | def delete = { |
---|
| 44 | def taskInstance = Task.get( params.id ) |
---|
| 45 | if(taskInstance) { |
---|
| 46 | taskInstance.delete() |
---|
| 47 | flash.message = "Task ${params.id} deleted" |
---|
| 48 | redirect(action:list) |
---|
| 49 | } |
---|
| 50 | else { |
---|
| 51 | flash.message = "Task not found with id ${params.id}" |
---|
| 52 | redirect(action:list) |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | |
---|
[84] | 56 | def deleteDetailed = { |
---|
| 57 | def taskInstance = Task.get( params.id ) |
---|
| 58 | if(taskInstance) { |
---|
| 59 | taskInstance.delete() |
---|
| 60 | flash.message = "Task ${params.id} deleted" |
---|
| 61 | redirect(action:list) |
---|
| 62 | } |
---|
| 63 | else { |
---|
| 64 | flash.message = "Task not found with id ${params.id}" |
---|
| 65 | redirect(action:list) |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | @Secured(['ROLE_AppAdmin']) |
---|
[66] | 70 | def edit = { |
---|
| 71 | def taskInstance = Task.get( params.id ) |
---|
| 72 | |
---|
| 73 | if(!taskInstance) { |
---|
| 74 | flash.message = "Task not found with id ${params.id}" |
---|
| 75 | redirect(action:list) |
---|
| 76 | } |
---|
| 77 | else { |
---|
| 78 | return [ taskInstance : taskInstance ] |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
[84] | 82 | def editDetailed = { |
---|
| 83 | def taskInstance = Task.get( params.id ) |
---|
| 84 | |
---|
| 85 | if(!taskInstance) { |
---|
| 86 | flash.message = "Task not found with id ${params.id}" |
---|
| 87 | redirect(action:list) |
---|
| 88 | } |
---|
| 89 | else { |
---|
| 90 | def criteria = taskInstance.createCriteria() |
---|
| 91 | def results = criteria { |
---|
| 92 | and { |
---|
| 93 | notEqual('id', taskInstance.id) |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | return [ taskInstance : taskInstance, possibleParentList: results ] |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | @Secured(['ROLE_AppAdmin']) |
---|
[66] | 101 | def update = { |
---|
| 102 | def taskInstance = Task.get( params.id ) |
---|
| 103 | if(taskInstance) { |
---|
| 104 | taskInstance.properties = params |
---|
| 105 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
---|
| 106 | flash.message = "Task ${params.id} updated" |
---|
| 107 | redirect(action:show,id:taskInstance.id) |
---|
| 108 | } |
---|
| 109 | else { |
---|
| 110 | render(view:'edit',model:[taskInstance:taskInstance]) |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | else { |
---|
| 114 | flash.message = "Task not found with id ${params.id}" |
---|
| 115 | redirect(action:edit,id:params.id) |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
[84] | 119 | def updateDetailed = { |
---|
| 120 | def taskInstance = Task.get( params.id ) |
---|
| 121 | if(taskInstance) { |
---|
| 122 | taskInstance.properties = params |
---|
| 123 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
---|
| 124 | flash.message = "Task ${params.id} updated" |
---|
| 125 | redirect(action:show,id:taskInstance.id) |
---|
| 126 | } |
---|
| 127 | else { |
---|
| 128 | render(view:'edit',model:[taskInstance:taskInstance]) |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | else { |
---|
| 132 | flash.message = "Task not found with id ${params.id}" |
---|
| 133 | redirect(action:edit,id:params.id) |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | @Secured(['ROLE_AppAdmin']) |
---|
[66] | 138 | def create = { |
---|
| 139 | def taskInstance = new Task() |
---|
| 140 | taskInstance.properties = params |
---|
| 141 | return ['taskInstance':taskInstance] |
---|
| 142 | } |
---|
| 143 | |
---|
[84] | 144 | def createDetailed = { |
---|
| 145 | def taskInstance = new Task() |
---|
| 146 | taskInstance.properties = params |
---|
| 147 | return ['taskInstance':taskInstance] |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | @Secured(['ROLE_AppAdmin']) |
---|
[66] | 151 | def save = { |
---|
| 152 | def taskInstance = new Task(params) |
---|
| 153 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
---|
| 154 | flash.message = "Task ${taskInstance.id} created" |
---|
| 155 | redirect(action:show,id:taskInstance.id) |
---|
| 156 | } |
---|
| 157 | else { |
---|
| 158 | render(view:'create',model:[taskInstance:taskInstance]) |
---|
| 159 | } |
---|
| 160 | } |
---|
[84] | 161 | |
---|
| 162 | def saveDetailed = { |
---|
| 163 | def taskInstance = new Task(params) |
---|
| 164 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
---|
| 165 | flash.message = "Task ${taskInstance.id} created" |
---|
| 166 | redirect(action:showDetailed,id:taskInstance.id) |
---|
| 167 | } |
---|
| 168 | else { |
---|
| 169 | render(view:'createDetailed',model:[taskInstance:taskInstance]) |
---|
| 170 | } |
---|
| 171 | } |
---|
[66] | 172 | } |
---|