Changeset 207 for trunk/grails-app/controllers
- Timestamp:
- Dec 1, 2009, 4:51:32 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/TaskRecurringScheduleDetailedController.groovy
r203 r207 60 60 61 61 def update = { 62 TaskRecurringSchedule.withTransaction { status ->63 62 64 def taskRecurringScheduleInstance = TaskRecurringSchedule.get( params.id ) 65 if(taskRecurringScheduleInstance) { 63 if(!TaskRecurringSchedule.exists(params.id)) { 64 flash.message = "Recurring Schedule not found with id ${params.id}" 65 redirect(action: 'list') 66 } 66 67 67 if(params.version) { 68 def version = params.version.toLong() 69 if(taskRecurringScheduleInstance.version > version) { 70 taskRecurringScheduleInstance.errors.rejectValue("version", "taskRecurringSchedule.optimistic.locking.failure", "Another user has updated this Recurring Schedule while you were editing.") 71 render(view:'edit',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance]) 72 return 73 } 74 } 68 def result = taskRecurringScheduleService.update(params) 75 69 76 Date originalDate = taskRecurringScheduleInstance.nextTargetStartDate 77 taskRecurringScheduleInstance.properties = params // Domain object is now 'dirty'. 78 Date newDate = taskRecurringScheduleInstance.nextTargetStartDate 70 if(!result.error) { 71 flash.message = "Recurring Schedule ${params.id} updated" 72 redirect(action: 'show', id: result.taskRecurringScheduleInstance.id) 73 } 74 else { 75 render(view:'edit',model:[taskRecurringScheduleInstance: result.taskRecurringScheduleInstance.attach()]) 76 } 79 77 80 // If user changes nextTargetStartDate then ensure it is in the future, otherwise it's ok to keep the original date. 81 if(originalDate.getTime() != newDate.getTime()) 82 { 83 if(newDate < dateUtilService.getToday()) 84 { 85 status.setRollbackOnly() // Only allow the transaction to Rollback, preventing flush due to 'dirty'. 86 taskRecurringScheduleInstance.errors.rejectValue("nextTargetStartDate", "taskRecurring.nextTargetStartDate.NotInTheFuture") 87 render(view:'edit',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance]) 88 return 89 } 90 } 91 92 taskRecurringScheduleInstance.setNextGenerationDate() 93 taskRecurringScheduleInstance.setNextTargetCompletionDate() 94 95 if(!taskRecurringScheduleInstance.hasErrors() && taskRecurringScheduleInstance.save(flush: true)) 96 { 97 flash.message = "Recurring Schedule ${params.id} updated" 98 redirect(action:show,id:taskRecurringScheduleInstance.id) 99 } 100 else 101 { 102 render(view:'edit',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance]) 103 } 104 } 105 else 106 { 107 flash.message = "Recurring Schedule not found with id ${params.id}" 108 redirect(action:edit,id:params.id) 109 } 110 111 } // end withTransaction 112 } // end update() 78 } 113 79 114 80 def create = {
Note: See TracChangeset
for help on using the changeset viewer.