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