Changeset 203
- Timestamp:
- Nov 30, 2009, 10:28:58 PM (15 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/TaskRecurringScheduleDetailedController.groovy
r199 r203 6 6 7 7 def dateUtilService 8 def taskRecurringScheduleService 8 9 9 10 def index = { redirect(action:list,params:params) } … … 112 113 113 114 def create = { 114 try { 115 def taskInstance = Task.get(params.taskInstance.id) 116 def taskRecurringScheduleInstance = new TaskRecurringSchedule() 117 taskRecurringScheduleInstance.task = taskInstance 118 return [taskRecurringScheduleInstance: taskRecurringScheduleInstance] 115 if(!params.task?.id || !Task.exists(params.task?.id)) { 116 flash.message = "Please select a task, then Create a Recurring Schedule for it." 117 redirect(controller:"taskDetailed", action:"search") 118 return 119 119 } 120 catch(Exception e) { 121 flash.message = "Please select a task, then Create a Recurring Schedule for it" 122 redirect(controller:"taskDetailed", action:"search") 123 } 120 def taskRecurringScheduleInstance = new TaskRecurringSchedule() 121 taskRecurringScheduleInstance.properties = params 122 return [taskRecurringScheduleInstance: taskRecurringScheduleInstance] 124 123 } // end create() 125 124 126 125 def save = { 127 def taskRecurringScheduleInstance = new TaskRecurringSchedule(params) 128 def taskInstance = Task.get(params.task.id) 126 def result = taskRecurringScheduleService.create(params) 129 127 130 if( taskInstance.taskRecurringSchedule) {131 flash.message = " This task already has a recurring schedule"132 redirect( controller:"taskDetailed", action:"show", id: params.task.id)128 if(!result.error) { 129 flash.message = "Recurring Schedule ${result.taskRecurringScheduleInstance.id} created." 130 redirect(action:show, id: result.taskRecurringScheduleInstance.id) 133 131 } 134 132 else { 135 136 if(taskRecurringScheduleInstance.nextTargetStartDate < dateUtilService.getToday()) { 137 taskRecurringScheduleInstance.errors.rejectValue("nextTargetStartDate", "taskRecurring.nextTargetStartDate.NotInTheFuture") 138 } 139 140 if(!taskRecurringScheduleInstance.hasErrors() && taskRecurringScheduleInstance.save(flush: true)) { 141 142 taskInstance.taskRecurringSchedule = taskRecurringScheduleInstance 143 144 if(taskInstance.save(flush: true)) { 145 flash.message = "Recurring Schedule ${taskRecurringScheduleInstance.id} created" 146 redirect(action:show,id:taskRecurringScheduleInstance.id) 147 } 148 else { 149 flash.message = "Task could not be saved and therefore the Recurring Schedule has been disgarded, cause unknown." 150 render(view:'create',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance]) 151 } 152 } 153 else { 154 render(view:'create',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance]) 155 } 133 render(view:'create',model:[taskRecurringScheduleInstance: result.taskRecurringScheduleInstance]) 156 134 } 157 158 135 } // end save() 159 136 -
trunk/grails-app/i18n/messages.properties
r199 r203 25 25 assignedPerson.estimatedDuration.help=The estimated amount of time (hh:mm) that you would like to assign this person to the task. 26 26 27 task. modifications.failedToSave=Could not complete operation, as task modification record failed to save.27 task.notFound=Could not complete operation, task not found. 28 28 task.operationNotPermittedOnCompleteTask=This operation is not permitted on a complete task. 29 29 task.operationNotPermittedOnTaskInTrash=This operation is not permitted on a task that is in the trash. 30 task.failedToSave=Could not complete operation, task failed to save. 31 task.modifications.failedToSave=Could not complete operation, as task modification record failed to save. 32 tast.taskRecurringSchedule.alreadyExists=This task already has a recurring schedule. 30 33 31 34 task.assignedPersons=Assigned Persons … … 53 56 inventoryMovement.quantity.insufficientItemsInStock=Could not complete operation, insufficient items in stock. 54 57 inventoryMovement.inventoryItem.notFound=Inventory Item not found. 55 56 entry.task.notFound=Could not complete operation, task not found.57 entry.task.failedToSave=Could not complete operation, task failed to save.58 entry.task.failedToSaveTaskModification=Could not complete operation, task modification failed to save.59 58 60 59 default.doesnt.match.message=Property [{0}] of class [{1}] with value [{2}] does not match the required pattern [{3}] -
trunk/grails-app/services/TaskRecurringScheduleService.groovy
r199 r203 6 6 def taskService 7 7 8 /** 9 * Generate all enabled recurring tasks. 10 */ 8 11 def generateAll() { 9 12 10 /// @todo: disable recurringSchedule when moving a task to trash.11 13 def taskRecurringScheduleList = TaskRecurringSchedule.findAllByEnabled(true) 12 14 … … 17 19 p.targetStartDate = it.nextTargetStartDate 18 20 p.targetCompletionDate = it.nextTargetCompletionDate 21 if(it.task.taskProcedure) p.taskProcedure = it.task.taskProcedure 19 22 def result = taskService.createSubTask(it.task, p) 20 23 if( !result.error ) { … … 26 29 } 27 30 else { 28 log.error result 31 log.error "Sub task generation for recurring schedule ${it.id} failed." 32 log.error result.taskInstance.errors 29 33 } 30 34 } … … 33 37 } 34 38 39 /** 40 * Creates a new recurring schedule for a task with the given params. 41 * @param params The params to use when creating the new recurring schedule. 42 * @returns A map containing result.error=true (if any error) and result.taskRecurringScheduleInstance and result.taskId. 43 */ 44 def create(params) { 45 TaskRecurringSchedule.withTransaction { status -> 46 def result = [:] 47 48 def fail = { Object[] args -> 49 status.setRollbackOnly() 50 if(args.size() == 2) result.taskRecurringScheduleInstance.errors.rejectValue(args[0], args[1]) 51 result.error = true 52 return result 53 } 54 55 result.taskRecurringScheduleInstance = new TaskRecurringSchedule(params) 56 result.taskId = result.taskRecurringScheduleInstance.task.id 57 58 if(!result.taskRecurringScheduleInstance.validate()) 59 return fail() 60 61 def taskInstance = Task.lock(result.taskId) 62 63 if(!taskInstance) 64 return fail('task', "task.notFound") 65 66 if(taskInstance.taskRecurringSchedule) 67 return fail('task', "tast.taskRecurringSchedule.alreadyExists") 68 69 if(taskInstance.taskStatus.id == 3) 70 return fail('task', "task.operationNotPermittedOnCompleteTask") 71 72 if(taskInstance.trash) 73 return fail('task', "task.operationNotPermittedOnTaskInTrash") 74 75 if(result.taskRecurringScheduleInstance.nextTargetStartDate < dateUtilService.getToday()) 76 return fail("nextTargetStartDate", "taskRecurring.nextTargetStartDate.NotInTheFuture") 77 78 taskInstance.taskRecurringSchedule = result.taskRecurringScheduleInstance 79 80 if(!result.taskRecurringScheduleInstance.save() || !taskInstance.save()) 81 return fail() 82 83 // All went well if we get to here. 84 return result 85 86 } //end withTransaction 87 } // end create() 88 35 89 } // end of class -
trunk/grails-app/services/TaskService.groovy
r202 r203 11 11 12 12 /** 13 * Determines and returns a possible parent list 13 * Determines and returns a possible parent list for a task. 14 14 * @param taskInstance The task to use when determining the possible parent list. 15 15 * @returns A list of the possible parents. … … 123 123 124 124 if(result.entryInstance.validate()) { 125 def taskInstance = Task.lock(result.entryInstance.task.id)126 125 result.taskId = result.entryInstance.task.id 126 def taskInstance = Task.lock(result.taskId) 127 127 128 128 if(!taskInstance) { 129 129 status.setRollbackOnly() 130 result.entryInstance.errors.rejectValue('task', " entry.task.notFound")130 result.entryInstance.errors.rejectValue('task', "task.notFound") 131 131 result.error = true 132 132 return result … … 150 150 if(!taskModification.save()) { 151 151 status.setRollbackOnly() 152 taskInstance.errors.rejectValue("task", " entry.task.failedToSaveTaskModification")152 taskInstance.errors.rejectValue("task", "task.modifications.failedToSave") 153 153 result.error = true 154 154 return result … … 160 160 if(!taskInstance.save()) { 161 161 status.setRollbackOnly() 162 result.entryInstance.errors.rejectValue("task", " entry.task.failedToSave")162 result.entryInstance.errors.rejectValue("task", "task.failedToSave") 163 163 result.error = true 164 164 return result -
trunk/grails-app/views/taskDetailed/show.gsp
r199 r203 344 344 <br /> 345 345 <g:form controller="taskProcedureDetailed" > 346 < input type="hidden"name="taskInstance.id" value="${taskInstance?.id}" />346 <g:hiddenField name="taskInstance.id" value="${taskInstance?.id}" /> 347 347 348 348 <div class="buttons"> … … 442 442 <br /> 443 443 <g:form controller="taskRecurringScheduleDetailed" > 444 < input type="hidden" name="taskInstance.id" value="${taskInstance?.id}" />444 <g:hiddenField name="task.id" value="${taskInstance.id}" /> 445 445 446 446 <div class="buttons">
Note: See TracChangeset
for help on using the changeset viewer.