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