Changeset 395 for trunk/grails-app
- Timestamp:
- Feb 20, 2010, 9:41:04 PM (15 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/conf/Config.groovy
r387 r395 147 147 [order:11, controller:'taskDetailed', title:'Calendar', action:'searchCalendar', isVisible: { true }], 148 148 [order:20, controller:'taskDetailed', title:'Create', action:'create', isVisible: { true }], 149 [order:30, controller:'taskDetailed', title:'Breakin', action:'createBreakin', isVisible: { true }], 149 150 [order:90, controller:'taskDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }], 150 151 [order:91, controller:'taskDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }] -
trunk/grails-app/controllers/TaskDetailedController.groovy
r394 r395 586 586 } 587 587 588 @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) 589 def createBreakin = { 590 def taskInstance = new Task() 591 592 def entryFaultInstance = new Entry(entryType: EntryType.get(1)) // Fault. 593 def entryWorkDoneInstance = new Entry(entryType: EntryType.get(2)) // Work Done. 594 595 return ['taskInstance': taskInstance, 596 'entryFaultInstance': entryFaultInstance, 597 'entryWorkDoneInstance': entryWorkDoneInstance] 598 } 599 600 @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) 601 def saveBreakin = { 602 def result = taskService.saveBreakin(params) 603 604 if(!result.error) { 605 flash.message = "Task ${result.taskInstance.id} created." 606 redirect(action: 'show', id: result.taskInstance.id) 607 return 608 } 609 610 if(result.error.code == "task.modifications.failedToSave") 611 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 612 613 render(view:'createBreakin', 614 model: ['taskInstance': result.taskInstance, 615 'entryFaultInstance': result.entryFaultInstance, 616 'entryWorkDoneInstance': result.entryWorkDoneInstance]) 617 618 } 619 588 620 } // end of class. -
trunk/grails-app/services/TaskService.groovy
r394 r395 182 182 Task.withTransaction { status -> 183 183 def result = [:] 184 185 def fail = { Map m -> 186 status.setRollbackOnly() 187 if(result.taskInstance && m.field) 188 result.taskInstance.errors.rejectValue(m.field, m.code) 189 result.error = [ code: m.code, args: ["Entry", params.id] ] 190 return result 191 } 192 184 193 result.entryInstance = new Entry(params) 185 194 result.entryInstance.enteredBy = authService.currentUser 186 195 187 if(result.entryInstance.validate()) { 196 def taskInstance 197 if(result.entryInstance.task.id) { 188 198 result.taskId = result.entryInstance.task.id 189 def taskInstance = Task.lock(result.taskId) 190 191 if(!taskInstance) { 192 status.setRollbackOnly() 193 result.entryInstance.errors.rejectValue('task', "task.notFound") 194 result.error = true 195 return result 196 } 197 198 if(taskInstance.taskStatus.id == 3) { 199 status.setRollbackOnly() 200 result.entryInstance.errors.rejectValue('task', "task.operationNotPermittedOnCompleteTask") 201 result.error = true 202 return result 203 } 204 205 // If task status is "Not Started" and entry type is "Work Done" then we create the started modification and set the status. 206 if(taskInstance.taskStatus.id == 1 && result.entryInstance.entryType.id == 2) { 207 208 // Create the "Started" task modification, this provides the "Actual started date". 209 def taskModification = new TaskModification(person: authService.currentUser, 210 taskModificationType: TaskModificationType.get(2), 211 task: taskInstance) 212 213 if(!taskModification.save()) { 214 status.setRollbackOnly() 215 taskInstance.errors.rejectValue("task", "task.modifications.failedToSave") 216 result.error = true 217 return result 218 } 219 220 // Set task status to "In progress". 221 taskInstance.taskStatus = TaskStatus.get(2) 222 223 if(!taskInstance.save()) { 224 status.setRollbackOnly() 225 result.entryInstance.errors.rejectValue("task", "task.failedToSave") 226 result.error = true 227 return result 228 } 229 } 230 231 if(!result.entryInstance.save()) { 232 status.setRollbackOnly() 233 result.error = true 234 return result 235 } 236 237 // If we get here all went well. 238 return result 239 } 240 else { 241 result.error = true 242 return result 243 } 199 taskInstance = Task.lock(result.entryInstance.task.id) 200 } 201 202 if(!taskInstance) 203 return fail(field:"task", code:"task.notFound") 204 205 if(result.entryInstance.hasErrors() || !result.entryInstance.save()) 206 return fail(code:"default.create.failure") 207 208 if(taskInstance.taskStatus.id == 3) 209 return fail(field:"task", code:"task.operationNotPermittedOnCompleteTask") 210 211 // If task status is "Not Started" and entry type is "Work Done" then we create the started modification and set the status. 212 if(taskInstance.taskStatus.id == 1 && result.entryInstance.entryType.id == 2) { 213 214 // Create the "Started" task modification, this provides the "Actual Started Date". 215 def taskModification = new TaskModification(person: authService.currentUser, 216 taskModificationType: TaskModificationType.get(2), 217 task: taskInstance) 218 219 if(taskModification.hasErrors() || !taskModification.save()) 220 return fail(field:"task", code:"task.modifications.failedToSave") 221 222 // Set task status to "In Progress". 223 taskInstance.taskStatus = TaskStatus.get(2) 224 225 if(taskInstance.hasErrors() || !taskInstance.save()) 226 return fail(field:"task", code:"task.failedToSave") 227 } 228 229 if(result.entryInstance.hasErrors() || !result.entryInstance.save()) 230 return fail(field:"task", code:"default.create.failure") 231 232 // Success. 233 return result 244 234 245 235 } //end withTransaction … … 583 573 } // end renegeApproval() 584 574 575 /** 576 * Creates a new breakin task with the given params. 577 * @param params The params to use when creating the new task. 578 * @returns A map containing result.error=true (if any error) and result.taskInstance. 579 */ 580 def saveBreakin(params) { 581 Task.withTransaction { status -> 582 def result = [:] 583 584 def fail = { Map m -> 585 status.setRollbackOnly() 586 if(result.taskInstance && m.field) 587 result.taskInstance.errors.rejectValue(m.field, m.code) 588 result.error = [ code: m.code, args: ["Task", params.id] ] 589 return result 590 } 591 592 // If not supplied. 593 if(!params.taskStatus) 594 params.taskStatus = TaskStatus.get(1) // Not Started. 595 596 result.taskInstance = new Task(params) 597 598 // Always for a breakin. 599 result.taskInstance.taskType = TaskType.get(1) // Unscheduled Breakin. 600 result.taskInstance.taskBudgetStatus = TaskBudgetStatus.get(1) // Unplanned. 601 result.taskInstance.taskPriority = TaskPriority.get(4) // Immediate. 602 result.taskInstance.taskGroup = TaskGroup.get(1) // Engineering Activites. 603 result.taskInstance.approved = true 604 result.taskInstance.leadPerson = authService.currentUser 605 606 if(result.taskInstance.hasErrors() || !result.taskInstance.save()) 607 fail(code:"default.create.failure") 608 609 if(!result.error) { 610 def taskModification = new TaskModification(person: authService.currentUser, 611 taskModificationType: TaskModificationType.get(1), // Created. 612 task: result.taskInstance) 613 614 if(taskModification.hasErrors() || !taskModification.save()) 615 fail(field:"taskModifications", code:"task.modifications.failedToSave") 616 } 617 618 def faultParams = [task: result.taskInstance, 619 entryType: EntryType.get(1), 620 comment: params.entryFault.comment, 621 durationHour: params.entryFault.durationHour, 622 durationMinute: params.entryFault.durationMinute] 623 def faultResult = saveEntry(faultParams) 624 result.entryFaultInstance = faultResult.entryInstance 625 626 def workDoneParams = [task: result.taskInstance, 627 entryType: EntryType.get(2), 628 comment: params.entryWorkDone.comment, 629 durationHour: params.entryWorkDone.durationHour, 630 durationMinute: params.entryWorkDone.durationMinute] 631 def workDoneResult = saveEntry(workDoneParams) 632 result.entryWorkDoneInstance = workDoneResult.entryInstance 633 634 if(result.error) 635 return result 636 637 if(faultResult.error) 638 return fail(code: "default.create.failure") 639 640 if(workDoneResult.error) 641 return fail(code: "default.create.failure") 642 643 // Success. 644 return result 645 646 } //end withTransaction 647 } // end saveBreakin() 648 585 649 } // end TaskService -
trunk/grails-app/views/entryDetailed/edit.gsp
r218 r395 105 105 <div class="buttons"> 106 106 <span class="button"><g:actionSubmit class="save" value="Update" /></span> 107 <span class="button"><g:actionSubmit class="cancel" value="Cancel" action="Show"/></span> 107 108 <span class="button"><g:actionSubmit class="delete" onclick="return confirm('Are you sure?');" value="Delete" /></span> 108 109 </div>
Note: See TracChangeset
for help on using the changeset viewer.