[69] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
[165] | 2 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
---|
[69] | 3 | |
---|
[85] | 4 | class TaskDetailedController extends BaseController { |
---|
[66] | 5 | |
---|
[185] | 6 | def personService |
---|
[180] | 7 | def taskService |
---|
[143] | 8 | def taskSearchService |
---|
[140] | 9 | def filterService |
---|
[165] | 10 | def exportService |
---|
[139] | 11 | |
---|
[181] | 12 | // these actions only accept POST requests |
---|
| 13 | static allowedMethods = [save:'POST', update:'POST', restore:'POST', trash:'POST', approve:'POST', renegeApproval:'POST', complete:'POST', reopen:'POST'] |
---|
[66] | 14 | |
---|
[196] | 15 | def index = { redirect(action: 'search', params: params) } |
---|
[140] | 16 | |
---|
[66] | 17 | def list = { |
---|
[143] | 18 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
[124] | 19 | [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ] |
---|
[66] | 20 | } |
---|
[143] | 21 | |
---|
[139] | 22 | def search = { |
---|
[144] | 23 | // println params |
---|
[143] | 24 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
| 25 | |
---|
[155] | 26 | // Quick Search: |
---|
[143] | 27 | if(!params.filter) |
---|
[139] | 28 | { |
---|
[144] | 29 | def taskInstanceList = [] |
---|
[185] | 30 | def personInstance = personService.currentUser() |
---|
[143] | 31 | |
---|
[155] | 32 | if(params.quickSearch == "searchMyTodays") { |
---|
[144] | 33 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
| 34 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
| 35 | else { params.message = "No tasks found for today." } |
---|
| 36 | } |
---|
[155] | 37 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
[144] | 38 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
| 39 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
[185] | 40 | else { params.message = "No tasks found for the last week." } |
---|
[144] | 41 | } |
---|
[155] | 42 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
[144] | 43 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
| 44 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
[185] | 45 | else { params.message = "No tasks found for the last week." } |
---|
[144] | 46 | } |
---|
| 47 | else { |
---|
| 48 | //Default: |
---|
| 49 | taskInstanceList = taskSearchService.getTodays(params) |
---|
| 50 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
| 51 | else { params.message = "No tasks found for today." } |
---|
[155] | 52 | params.quickSearch = "searchTodays" |
---|
[144] | 53 | } |
---|
[155] | 54 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
[139] | 55 | } |
---|
[143] | 56 | // filterPane: |
---|
| 57 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
| 58 | taskInstanceTotal: filterService.count( params, Task ), |
---|
| 59 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
| 60 | params:params ] |
---|
[140] | 61 | } |
---|
[143] | 62 | |
---|
[155] | 63 | def searchCalendar = { |
---|
| 64 | // println params |
---|
| 65 | params.max = 30 |
---|
[140] | 66 | |
---|
[155] | 67 | // Quick Search: |
---|
| 68 | if(!params.filter) |
---|
[139] | 69 | { |
---|
[155] | 70 | def taskInstanceList = [] |
---|
[185] | 71 | def personInstance = personService.currentUser() |
---|
[155] | 72 | |
---|
| 73 | if(params.quickSearch == "searchMyTodays") { |
---|
| 74 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
| 75 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
| 76 | else { params.message = "No tasks found for today." } |
---|
| 77 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
| 78 | } |
---|
| 79 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
| 80 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
| 81 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
[185] | 82 | else { params.message = "No tasks found for the last week." } |
---|
[155] | 83 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
| 84 | } |
---|
| 85 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
| 86 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
| 87 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
[185] | 88 | else { params.message = "No tasks found for the last week." } |
---|
[155] | 89 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
| 90 | } |
---|
| 91 | else { |
---|
| 92 | //Default: |
---|
| 93 | taskInstanceList = taskSearchService.getTodays(params) |
---|
| 94 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
| 95 | else { params.message = "No tasks found for today." } |
---|
| 96 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
| 97 | params.quickSearch = "searchTodays" |
---|
| 98 | } |
---|
| 99 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
[139] | 100 | } |
---|
[155] | 101 | // filterPane: |
---|
| 102 | def taskInstanceTotal = filterService.count( params, Task ) |
---|
| 103 | if(taskInstanceTotal > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
| 104 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
| 105 | taskInstanceTotal: taskInstanceTotal, |
---|
| 106 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
| 107 | params:params ] |
---|
[139] | 108 | } |
---|
[140] | 109 | |
---|
[165] | 110 | def budget = { |
---|
| 111 | // println params |
---|
| 112 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
| 113 | |
---|
| 114 | // Quick Search: |
---|
| 115 | if(!params.filter) |
---|
| 116 | { |
---|
| 117 | def taskInstanceList = [] |
---|
[185] | 118 | def personInstance = personService.currentUser() |
---|
[165] | 119 | |
---|
| 120 | if(params.quickSearch == "budgetUnplanned") { |
---|
| 121 | taskInstanceList = taskSearchService.getBudgetUnplanned(params) |
---|
| 122 | if(taskInstanceList.totalCount > 0) { params.message = "Budget unplanned tasks in the last week." } |
---|
| 123 | else { params.message = "No tasks found." } |
---|
| 124 | } |
---|
| 125 | //else if(params.quickSearch == "budgetPlanned") { |
---|
| 126 | else { |
---|
| 127 | //Default: |
---|
| 128 | taskInstanceList = taskSearchService.getBudgetPlanned(params) |
---|
| 129 | if(taskInstanceList.totalCount > 0) { params.message = "Budget planned Tasks in the last week." } |
---|
| 130 | else { params.message = "No tasks found.." } |
---|
| 131 | } |
---|
| 132 | // export plugin: |
---|
| 133 | if(params?.format && params.format != "html") { |
---|
| 134 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
| 135 | response.setHeader("Content-disposition", "attachment; filename=tasks.${params.extension}") |
---|
| 136 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskStatus", "taskType"] |
---|
| 137 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
| 138 | "leadPerson": "Lead Person", "taskStatus": "Task Status", "taskType": "Task Type"] |
---|
| 139 | Map formatters = [:] |
---|
| 140 | String title = "${params.quickSearch} tasks in the last week." |
---|
| 141 | Map parameters = [title: title] |
---|
| 142 | |
---|
| 143 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
| 144 | } |
---|
| 145 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
| 146 | } |
---|
| 147 | // filterPane: |
---|
| 148 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
| 149 | taskInstanceTotal: filterService.count( params, Task ), |
---|
| 150 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
| 151 | params:params ] |
---|
| 152 | } |
---|
| 153 | |
---|
[66] | 154 | def show = { |
---|
[147] | 155 | |
---|
[139] | 156 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 157 | if(params._action_Show) |
---|
| 158 | { params.action='show' } |
---|
| 159 | |
---|
[66] | 160 | def taskInstance = Task.get( params.id ) |
---|
| 161 | |
---|
| 162 | if(!taskInstance) { |
---|
| 163 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 164 | redirect(action: 'search') |
---|
[66] | 165 | } |
---|
[133] | 166 | else { |
---|
[179] | 167 | params.max = 10 |
---|
| 168 | params.order = "desc" |
---|
| 169 | params.sort = "id" |
---|
[134] | 170 | |
---|
[179] | 171 | def entryWorkDoneList = Entry.withCriteria { |
---|
[190] | 172 | eq("entryType", EntryType.get(2)) |
---|
[179] | 173 | eq("task", taskInstance) |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | def entryFaultList = Entry.withCriteria { |
---|
[190] | 177 | eq("entryType", EntryType.get(1)) |
---|
[179] | 178 | eq("task", taskInstance) |
---|
| 179 | } |
---|
| 180 | |
---|
[196] | 181 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params) |
---|
| 182 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false) |
---|
[134] | 183 | def showTaskTab = new String("true") |
---|
| 184 | |
---|
[175] | 185 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
---|
| 186 | |
---|
[180] | 187 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
---|
| 188 | |
---|
[133] | 189 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
| 190 | def taskProcedureExits = new Boolean("true") |
---|
| 191 | if(!taskProcedureInstance) { |
---|
| 192 | taskProcedureExits = false |
---|
| 193 | } |
---|
[175] | 194 | |
---|
| 195 | params.order = "asc" |
---|
| 196 | params.sort = "procedureStepNumber" |
---|
| 197 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
| 198 | |
---|
[134] | 199 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
| 200 | def taskRecurringScheduleExits= new Boolean("true") |
---|
[175] | 201 | if(!taskRecurringScheduleInstance) { |
---|
[134] | 202 | taskRecurringScheduleExits = false |
---|
| 203 | } |
---|
[179] | 204 | |
---|
[137] | 205 | return [ taskInstance: taskInstance, |
---|
[179] | 206 | entryWorkDoneList: entryWorkDoneList, |
---|
| 207 | entryFaultList: entryFaultList, |
---|
[133] | 208 | taskProcedureInstance: taskProcedureInstance, |
---|
| 209 | taskProcedureExits: taskProcedureExits, |
---|
[134] | 210 | showTaskTab: showTaskTab, |
---|
[179] | 211 | subTaskInstanceList: subTaskInstanceList, |
---|
| 212 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
| 213 | subTaskInstanceMax: params.max, |
---|
| 214 | maintenanceActionList: maintenanceActionList, |
---|
| 215 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
| 216 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
---|
[180] | 217 | inventoryMovementList: inventoryMovementList, |
---|
| 218 | taskModificationList: taskModificationList] |
---|
[131] | 219 | } |
---|
[66] | 220 | } |
---|
| 221 | |
---|
[181] | 222 | def restore = { |
---|
| 223 | |
---|
| 224 | if(!Task.exists(params.id)) { |
---|
| 225 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 226 | redirect(action: 'search') |
---|
[181] | 227 | } |
---|
| 228 | |
---|
| 229 | def result = taskService.restore(params) |
---|
| 230 | |
---|
| 231 | if(!result.error) { |
---|
| 232 | flash.message = "Task ${params.id} has been restored." |
---|
[196] | 233 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 234 | } |
---|
| 235 | else { |
---|
| 236 | if(result.taskInstance) { |
---|
| 237 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
[96] | 238 | } |
---|
[181] | 239 | else { |
---|
| 240 | flash.message = "Task could not be updated." |
---|
[196] | 241 | redirect(action: 'search') |
---|
[96] | 242 | } |
---|
[66] | 243 | } |
---|
[181] | 244 | |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | def trash = { |
---|
| 248 | |
---|
| 249 | if(!Task.exists(params.id)) { |
---|
| 250 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 251 | redirect(action: 'search') |
---|
[181] | 252 | } |
---|
| 253 | |
---|
| 254 | def result = taskService.trash(params) |
---|
| 255 | |
---|
| 256 | if(!result.error) { |
---|
| 257 | flash.message = "Task ${params.id} has been moved to trash." |
---|
[196] | 258 | redirect(action: 'search') |
---|
[181] | 259 | } |
---|
[66] | 260 | else { |
---|
[181] | 261 | if(result.taskInstance) { |
---|
| 262 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 263 | } |
---|
| 264 | else { |
---|
| 265 | flash.message = "Task could not be updated." |
---|
[196] | 266 | redirect(action: 'search') |
---|
[181] | 267 | } |
---|
[66] | 268 | } |
---|
[181] | 269 | |
---|
[66] | 270 | } |
---|
| 271 | |
---|
[181] | 272 | def approve = { |
---|
| 273 | |
---|
| 274 | if(!Task.exists(params.id)) { |
---|
| 275 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 276 | redirect(action: 'search') |
---|
[181] | 277 | } |
---|
| 278 | |
---|
| 279 | def result = taskService.approve(params) |
---|
| 280 | |
---|
| 281 | if(!result.error) { |
---|
| 282 | flash.message = "Task ${params.id} has been approved." |
---|
[196] | 283 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 284 | } |
---|
| 285 | else { |
---|
| 286 | if(result.taskInstance) { |
---|
| 287 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 288 | } |
---|
| 289 | else { |
---|
| 290 | flash.message = "Task could not be updated." |
---|
[196] | 291 | redirect(action: 'search') |
---|
[181] | 292 | } |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | def renegeApproval = { |
---|
| 298 | |
---|
| 299 | if(!Task.exists(params.id)) { |
---|
| 300 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 301 | redirect(action: 'search') |
---|
[181] | 302 | } |
---|
| 303 | |
---|
| 304 | def result = taskService.renegeApproval(params) |
---|
| 305 | |
---|
| 306 | if(!result.error) { |
---|
| 307 | flash.message = "Task ${params.id} has had approval removed." |
---|
[196] | 308 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 309 | } |
---|
| 310 | else { |
---|
| 311 | if(result.taskInstance) { |
---|
| 312 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 313 | } |
---|
| 314 | else { |
---|
| 315 | flash.message = "Task could not be updated." |
---|
[196] | 316 | redirect(action: 'search') |
---|
[181] | 317 | } |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | def complete = { |
---|
| 323 | |
---|
| 324 | if(!Task.exists(params.id)) { |
---|
| 325 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 326 | redirect(action: 'search') |
---|
[181] | 327 | } |
---|
| 328 | |
---|
| 329 | def result = taskService.complete(params) |
---|
| 330 | |
---|
| 331 | if(!result.error) { |
---|
| 332 | flash.message = "Task ${params.id} has been completed." |
---|
[196] | 333 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 334 | } |
---|
| 335 | else { |
---|
| 336 | if(result.taskInstance) { |
---|
| 337 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 338 | } |
---|
| 339 | else { |
---|
| 340 | flash.message = "Task could not be updated." |
---|
[196] | 341 | redirect(action: 'search') |
---|
[181] | 342 | } |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | def reopen = { |
---|
| 348 | |
---|
| 349 | if(!Task.exists(params.id)) { |
---|
| 350 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 351 | redirect(action: 'search') |
---|
[181] | 352 | } |
---|
| 353 | |
---|
| 354 | def result = taskService.reopen(params) |
---|
| 355 | |
---|
| 356 | if(!result.error) { |
---|
| 357 | flash.message = "Task ${params.id} has been reopened." |
---|
[196] | 358 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 359 | } |
---|
| 360 | else { |
---|
| 361 | if(result.taskInstance) { |
---|
| 362 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 363 | } |
---|
| 364 | else { |
---|
| 365 | flash.message = "Task could not be updated." |
---|
[196] | 366 | redirect(action: 'search') |
---|
[181] | 367 | } |
---|
| 368 | } |
---|
| 369 | |
---|
| 370 | } |
---|
| 371 | |
---|
[66] | 372 | def edit = { |
---|
[147] | 373 | |
---|
[139] | 374 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 375 | if(params._action_Edit) |
---|
| 376 | { params.action='edit' } |
---|
[169] | 377 | |
---|
[66] | 378 | def taskInstance = Task.get( params.id ) |
---|
| 379 | |
---|
| 380 | if(!taskInstance) { |
---|
| 381 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 382 | redirect(action: 'search') |
---|
[66] | 383 | } |
---|
| 384 | else { |
---|
[181] | 385 | if(taskInstance.trash) { |
---|
[196] | 386 | flash.message = "You may not edit tasks that are in the trash." |
---|
| 387 | redirect(action: 'show', id: taskInstance.id) |
---|
| 388 | return |
---|
[181] | 389 | } |
---|
[196] | 390 | def possibleParentList = taskService.possibleParentList(taskInstance) |
---|
[169] | 391 | return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
[84] | 392 | } |
---|
| 393 | } |
---|
| 394 | |
---|
[66] | 395 | def update = { |
---|
[179] | 396 | |
---|
[180] | 397 | if(!Task.exists(params.id)) { |
---|
| 398 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 399 | redirect(action: 'search') |
---|
[180] | 400 | } |
---|
| 401 | |
---|
| 402 | def result = taskService.update(params) |
---|
| 403 | |
---|
| 404 | if(!result.error) { |
---|
[66] | 405 | flash.message = "Task ${params.id} updated" |
---|
[196] | 406 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[180] | 407 | } |
---|
| 408 | else { |
---|
[206] | 409 | render(view:'edit',model:[taskInstance:result.taskInstance.attach()]) |
---|
[66] | 410 | } |
---|
[180] | 411 | |
---|
[66] | 412 | } |
---|
| 413 | |
---|
| 414 | def create = { |
---|
| 415 | def taskInstance = new Task() |
---|
[196] | 416 | // Default leadPerson to current user, unless supplied in params. |
---|
[185] | 417 | taskInstance.leadPerson = personService.currentUser() |
---|
[66] | 418 | taskInstance.properties = params |
---|
[196] | 419 | return ['taskInstance': taskInstance] |
---|
[66] | 420 | } |
---|
| 421 | |
---|
| 422 | def save = { |
---|
[180] | 423 | def result = taskService.create(params) |
---|
| 424 | |
---|
| 425 | if(!result.error) { |
---|
| 426 | flash.message = "Task ${result.taskInstance.id} created." |
---|
[196] | 427 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[66] | 428 | } |
---|
| 429 | else { |
---|
[180] | 430 | if(result.taskInstance) { |
---|
[196] | 431 | render(view:'create', model:[taskInstance:result.taskInstance]) |
---|
[180] | 432 | } |
---|
| 433 | else { |
---|
| 434 | flash.message = "Could not create task." |
---|
[196] | 435 | redirect(action: 'search') |
---|
[180] | 436 | } |
---|
| 437 | |
---|
[66] | 438 | } |
---|
| 439 | } |
---|
[179] | 440 | |
---|
| 441 | def listSubTasks = { |
---|
| 442 | def parentTaskInstance = Task.get(params.id) |
---|
| 443 | |
---|
[134] | 444 | if(!parentTaskInstance) { |
---|
| 445 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 446 | redirect(action: 'search') |
---|
[133] | 447 | } |
---|
| 448 | else { |
---|
[179] | 449 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
[196] | 450 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params) |
---|
| 451 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false) |
---|
[179] | 452 | |
---|
[134] | 453 | [ taskInstanceList: subTaskInstanceList, |
---|
[179] | 454 | taskInstanceTotal: subTaskInstanceTotal, |
---|
| 455 | parentTaskInstance: parentTaskInstance] |
---|
| 456 | } |
---|
| 457 | } |
---|
| 458 | |
---|
[196] | 459 | def createSubTask = { |
---|
| 460 | def parentTaskInstance = Task.get(params.id) |
---|
| 461 | |
---|
| 462 | if(parentTaskInstance) { |
---|
| 463 | |
---|
| 464 | def result = taskService.createSubTask(parentTaskInstance) |
---|
| 465 | if(!result.error) { |
---|
| 466 | flash.message = "Sub Task ${result.taskInstance.id} created, please edit and update to your requirements." |
---|
| 467 | redirect(action: 'edit', id: result.taskInstance.id) |
---|
| 468 | } |
---|
| 469 | else { |
---|
| 470 | if(result.taskInstance.errors.hasFieldErrors("parentTask")) { |
---|
| 471 | flash.message = g.message(code:"task.operationNotPermittedOnTaskInTrash") |
---|
| 472 | redirect(action: 'show', id: parentTaskInstance.id) |
---|
| 473 | } |
---|
| 474 | else { |
---|
| 475 | render(view: 'create', model:[taskInstance: result.taskInstance]) |
---|
| 476 | } |
---|
| 477 | } |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | else { |
---|
| 481 | flash.message = "Task not found with id ${params.id}" |
---|
| 482 | redirect(action: 'search') |
---|
| 483 | } |
---|
| 484 | } |
---|
| 485 | |
---|
| 486 | } // end of class. |
---|