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