| 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
|---|
| 2 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
|---|
| 3 | import com.zeddware.grails.plugins.filterpane.FilterUtils |
|---|
| 4 | |
|---|
| 5 | class TaskDetailedController extends BaseController { |
|---|
| 6 | |
|---|
| 7 | def personService |
|---|
| 8 | def taskService |
|---|
| 9 | def taskSearchService |
|---|
| 10 | def filterService |
|---|
| 11 | def exportService |
|---|
| 12 | |
|---|
| 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'] |
|---|
| 15 | |
|---|
| 16 | def index = { redirect(action: 'search', params: params) } |
|---|
| 17 | |
|---|
| 18 | def list = { |
|---|
| 19 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
|---|
| 20 | [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ] |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | def search = { |
|---|
| 24 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
|---|
| 25 | |
|---|
| 26 | // Quick Search: |
|---|
| 27 | if(!FilterUtils.isFilterApplied(params)) { |
|---|
| 28 | def taskInstanceList = [] |
|---|
| 29 | def personInstance = personService.currentUser() |
|---|
| 30 | |
|---|
| 31 | if(params.quickSearch == "searchMyTodays") { |
|---|
| 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 | } |
|---|
| 36 | else if(params.quickSearch == "searchInTheLastWeek") { |
|---|
| 37 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
|---|
| 38 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
|---|
| 39 | else { params.message = "No tasks found for the last week." } |
|---|
| 40 | } |
|---|
| 41 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
|---|
| 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}." } |
|---|
| 44 | else { params.message = "No tasks found for the last week." } |
|---|
| 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." } |
|---|
| 51 | params.quickSearch = "searchTodays" |
|---|
| 52 | } |
|---|
| 53 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
|---|
| 54 | } |
|---|
| 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 ] |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | def searchCalendar = { |
|---|
| 63 | params.max = 30 |
|---|
| 64 | |
|---|
| 65 | // Quick Search: |
|---|
| 66 | if(!FilterUtils.isFilterApplied(params)) { |
|---|
| 67 | def taskInstanceList = [] |
|---|
| 68 | def personInstance = personService.currentUser() |
|---|
| 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." } |
|---|
| 79 | else { params.message = "No tasks found for the last week." } |
|---|
| 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}." } |
|---|
| 85 | else { params.message = "No tasks found for the last week." } |
|---|
| 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] |
|---|
| 97 | } |
|---|
| 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 ] |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | def budget = { |
|---|
| 108 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
|---|
| 109 | |
|---|
| 110 | // Quick Search: |
|---|
| 111 | if(!FilterUtils.isFilterApplied(params)) { |
|---|
| 112 | def taskInstanceList = [] |
|---|
| 113 | def personInstance = personService.currentUser() |
|---|
| 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 | |
|---|
| 149 | def show = { |
|---|
| 150 | |
|---|
| 151 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
|---|
| 152 | if(params._action_Show) |
|---|
| 153 | { params.action='show' } |
|---|
| 154 | |
|---|
| 155 | def taskInstance = Task.get( params.id ) |
|---|
| 156 | |
|---|
| 157 | if(!taskInstance) { |
|---|
| 158 | flash.message = "Task not found with id ${params.id}" |
|---|
| 159 | redirect(action: 'search') |
|---|
| 160 | } |
|---|
| 161 | else { |
|---|
| 162 | params.max = 10 |
|---|
| 163 | params.order = "desc" |
|---|
| 164 | params.sort = "id" |
|---|
| 165 | |
|---|
| 166 | def entryWorkDoneList = Entry.withCriteria { |
|---|
| 167 | eq("entryType", EntryType.get(2)) |
|---|
| 168 | eq("task", taskInstance) |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | def entryFaultList = Entry.withCriteria { |
|---|
| 172 | eq("entryType", EntryType.get(1)) |
|---|
| 173 | eq("task", taskInstance) |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params) |
|---|
| 177 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false) |
|---|
| 178 | def showTaskTab = new String("true") |
|---|
| 179 | |
|---|
| 180 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
|---|
| 181 | |
|---|
| 182 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
|---|
| 183 | |
|---|
| 184 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
|---|
| 185 | def taskProcedureExits = new Boolean("true") |
|---|
| 186 | if(!taskProcedureInstance) { |
|---|
| 187 | taskProcedureExits = false |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | params.order = "asc" |
|---|
| 191 | params.sort = "procedureStepNumber" |
|---|
| 192 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
|---|
| 193 | |
|---|
| 194 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
|---|
| 195 | def taskRecurringScheduleExits= new Boolean("true") |
|---|
| 196 | if(!taskRecurringScheduleInstance) { |
|---|
| 197 | taskRecurringScheduleExits = false |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | return [ taskInstance: taskInstance, |
|---|
| 201 | entryWorkDoneList: entryWorkDoneList, |
|---|
| 202 | entryFaultList: entryFaultList, |
|---|
| 203 | taskProcedureInstance: taskProcedureInstance, |
|---|
| 204 | taskProcedureExits: taskProcedureExits, |
|---|
| 205 | showTaskTab: showTaskTab, |
|---|
| 206 | subTaskInstanceList: subTaskInstanceList, |
|---|
| 207 | subTaskInstanceTotal: subTaskInstanceTotal, |
|---|
| 208 | subTaskInstanceMax: params.max, |
|---|
| 209 | maintenanceActionList: maintenanceActionList, |
|---|
| 210 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
|---|
| 211 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
|---|
| 212 | inventoryMovementList: inventoryMovementList, |
|---|
| 213 | taskModificationList: taskModificationList] |
|---|
| 214 | } |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | def restore = { |
|---|
| 218 | |
|---|
| 219 | if(!Task.exists(params.id)) { |
|---|
| 220 | flash.message = "Task not found with id ${params.id}" |
|---|
| 221 | redirect(action: 'search') |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | def result = taskService.restore(params) |
|---|
| 225 | |
|---|
| 226 | if(!result.error) { |
|---|
| 227 | flash.message = "Task ${params.id} has been restored." |
|---|
| 228 | redirect(action: 'show', id: result.taskInstance.id) |
|---|
| 229 | } |
|---|
| 230 | else { |
|---|
| 231 | if(result.taskInstance) { |
|---|
| 232 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
|---|
| 233 | } |
|---|
| 234 | else { |
|---|
| 235 | flash.message = "Task could not be updated." |
|---|
| 236 | redirect(action: 'search') |
|---|
| 237 | } |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | def trash = { |
|---|
| 243 | |
|---|
| 244 | if(!Task.exists(params.id)) { |
|---|
| 245 | flash.message = "Task not found with id ${params.id}." |
|---|
| 246 | redirect(action: 'search') |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | def result = taskService.trash(params) |
|---|
| 250 | |
|---|
| 251 | if(!result.error) { |
|---|
| 252 | flash.message = "Task ${params.id} has been moved to trash." |
|---|
| 253 | redirect(action: 'search') |
|---|
| 254 | } |
|---|
| 255 | else { |
|---|
| 256 | if(result.taskInstance) { |
|---|
| 257 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
|---|
| 258 | } |
|---|
| 259 | else { |
|---|
| 260 | flash.message = "Task could not be updated." |
|---|
| 261 | redirect(action: 'search') |
|---|
| 262 | } |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | def approve = { |
|---|
| 268 | |
|---|
| 269 | if(!Task.exists(params.id)) { |
|---|
| 270 | flash.message = "Task not found with id ${params.id}." |
|---|
| 271 | redirect(action: 'search') |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | def result = taskService.approve(params) |
|---|
| 275 | |
|---|
| 276 | if(!result.error) { |
|---|
| 277 | flash.message = "Task ${params.id} has been approved." |
|---|
| 278 | redirect(action: 'show', id: result.taskInstance.id) |
|---|
| 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." |
|---|
| 286 | redirect(action: 'search') |
|---|
| 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}." |
|---|
| 296 | redirect(action: 'search') |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | def result = taskService.renegeApproval(params) |
|---|
| 300 | |
|---|
| 301 | if(!result.error) { |
|---|
| 302 | flash.message = "Task ${params.id} has had approval removed." |
|---|
| 303 | redirect(action: 'show', id: result.taskInstance.id) |
|---|
| 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." |
|---|
| 311 | redirect(action: 'search') |
|---|
| 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}." |
|---|
| 321 | redirect(action: 'search') |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | def result = taskService.complete(params) |
|---|
| 325 | |
|---|
| 326 | if(!result.error) { |
|---|
| 327 | flash.message = "Task ${params.id} has been completed." |
|---|
| 328 | redirect(action: 'show', id: result.taskInstance.id) |
|---|
| 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." |
|---|
| 336 | redirect(action: 'search') |
|---|
| 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}." |
|---|
| 346 | redirect(action: 'search') |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | def result = taskService.reopen(params) |
|---|
| 350 | |
|---|
| 351 | if(!result.error) { |
|---|
| 352 | flash.message = "Task ${params.id} has been reopened." |
|---|
| 353 | redirect(action: 'show', id: result.taskInstance.id) |
|---|
| 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." |
|---|
| 361 | redirect(action: 'search') |
|---|
| 362 | } |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | } |
|---|
| 366 | |
|---|
| 367 | def edit = { |
|---|
| 368 | |
|---|
| 369 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
|---|
| 370 | if(params._action_Edit) |
|---|
| 371 | { params.action='edit' } |
|---|
| 372 | |
|---|
| 373 | def taskInstance = Task.get( params.id ) |
|---|
| 374 | |
|---|
| 375 | if(!taskInstance) { |
|---|
| 376 | flash.message = "Task not found with id ${params.id}" |
|---|
| 377 | redirect(action: 'search') |
|---|
| 378 | } |
|---|
| 379 | else { |
|---|
| 380 | if(taskInstance.trash) { |
|---|
| 381 | flash.message = "You may not edit tasks that are in the trash." |
|---|
| 382 | redirect(action: 'show', id: taskInstance.id) |
|---|
| 383 | return |
|---|
| 384 | } |
|---|
| 385 | def possibleParentList = taskService.possibleParentList(taskInstance) |
|---|
| 386 | return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
|---|
| 387 | } |
|---|
| 388 | } |
|---|
| 389 | |
|---|
| 390 | def update = { |
|---|
| 391 | |
|---|
| 392 | if(!Task.exists(params.id)) { |
|---|
| 393 | flash.message = "Task not found with id ${params.id}" |
|---|
| 394 | redirect(action: 'search') |
|---|
| 395 | } |
|---|
| 396 | |
|---|
| 397 | def result = taskService.update(params) |
|---|
| 398 | |
|---|
| 399 | if(!result.error) { |
|---|
| 400 | flash.message = "Task ${params.id} updated" |
|---|
| 401 | redirect(action: 'show', id: result.taskInstance.id) |
|---|
| 402 | } |
|---|
| 403 | else { |
|---|
| 404 | render(view:'edit',model:[taskInstance:result.taskInstance.attach()]) |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | } |
|---|
| 408 | |
|---|
| 409 | def create = { |
|---|
| 410 | def taskInstance = new Task() |
|---|
| 411 | // Default leadPerson to current user, unless supplied in params. |
|---|
| 412 | taskInstance.leadPerson = personService.currentUser() |
|---|
| 413 | taskInstance.properties = params |
|---|
| 414 | return ['taskInstance': taskInstance] |
|---|
| 415 | } |
|---|
| 416 | |
|---|
| 417 | def save = { |
|---|
| 418 | def result = taskService.create(params) |
|---|
| 419 | |
|---|
| 420 | if(!result.error) { |
|---|
| 421 | flash.message = "Task ${result.taskInstance.id} created." |
|---|
| 422 | redirect(action: 'show', id: result.taskInstance.id) |
|---|
| 423 | } |
|---|
| 424 | else { |
|---|
| 425 | if(result.taskInstance) { |
|---|
| 426 | render(view:'create', model:[taskInstance:result.taskInstance]) |
|---|
| 427 | } |
|---|
| 428 | else { |
|---|
| 429 | flash.message = "Could not create task." |
|---|
| 430 | redirect(action: 'search') |
|---|
| 431 | } |
|---|
| 432 | |
|---|
| 433 | } |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | def listSubTasks = { |
|---|
| 437 | def parentTaskInstance = Task.get(params.id) |
|---|
| 438 | |
|---|
| 439 | if(!parentTaskInstance) { |
|---|
| 440 | flash.message = "Task not found with id ${params.id}" |
|---|
| 441 | redirect(action: 'search') |
|---|
| 442 | } |
|---|
| 443 | else { |
|---|
| 444 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
|---|
| 445 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params) |
|---|
| 446 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false) |
|---|
| 447 | |
|---|
| 448 | [ taskInstanceList: subTaskInstanceList, |
|---|
| 449 | taskInstanceTotal: subTaskInstanceTotal, |
|---|
| 450 | parentTaskInstance: parentTaskInstance] |
|---|
| 451 | } |
|---|
| 452 | } |
|---|
| 453 | |
|---|
| 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. |
|---|