Changeset 137 for trunk/grails-app/controllers
- Timestamp:
- Sep 1, 2009, 10:10:43 PM (15 years ago)
- Location:
- trunk/grails-app/controllers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/TaskDetailedController.groovy
r134 r137 31 31 params.order = "desc" 32 32 params.sort = "id" 33 34 def entryWorkDoneList = Entry.withCriteria { 35 def entryType = EntryType.findByName("WorkDone") 36 eq("entryType", entryType) 37 eq("task", taskInstance) 38 } 39 40 def entryFaultList = Entry.withCriteria { 41 def entryType = EntryType.findByName("Fault") 42 eq("entryType", entryType) 43 eq("task", taskInstance) 44 } 33 45 34 46 def subTaskInstanceList = Task.findAllByParentTask(taskInstance, params) … … 53 65 } 54 66 55 return [ taskInstance : taskInstance, 67 return [ taskInstance: taskInstance, 68 entryWorkDoneList: entryWorkDoneList, 69 entryFaultList: entryFaultList, 56 70 taskProcedureInstance: taskProcedureInstance, 57 71 taskProcedureExits: taskProcedureExits, -
trunk/grails-app/controllers/TaskRecurringScheduleDetailedController.groovy
r136 r137 1 1 import org.codehaus.groovy.grails.plugins.springsecurity.Secured 2 2 import org.codehaus.groovy.runtime.TimeCategory 3 import java.text.SimpleDateFormat 3 4 4 5 class TaskRecurringScheduleDetailedController extends BaseController { 5 6 7 def dateUtilService 8 6 9 def index = { redirect(action:list,params:params) } 7 10 … … 51 54 } 52 55 else { 53 return [ taskRecurringScheduleInstance : taskRecurringScheduleInstance 56 return [ taskRecurringScheduleInstance : taskRecurringScheduleInstance] 54 57 } 55 58 } 56 59 57 60 def update = { 58 def taskRecurringScheduleInstance = TaskRecurringSchedule.get( params.id ) 59 if(taskRecurringScheduleInstance) { 60 if(params.version) { 61 def version = params.version.toLong() 62 if(taskRecurringScheduleInstance.version > version) { 61 TaskRecurringSchedule.withTransaction { status -> 62 63 def taskRecurringScheduleInstance = TaskRecurringSchedule.get( params.id ) 64 if(taskRecurringScheduleInstance) { 65 66 if(params.version) { 67 def version = params.version.toLong() 68 if(taskRecurringScheduleInstance.version > version) { 69 taskRecurringScheduleInstance.errors.rejectValue("version", "taskRecurringSchedule.optimistic.locking.failure", "Another user has updated this TaskRecurringSchedule while you were editing.") 70 render(view:'edit',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance]) 71 return 72 } 73 } 74 75 Date originalDate = taskRecurringScheduleInstance.startDate 76 taskRecurringScheduleInstance.properties = params // Domain object is now 'dirty'. 77 Date newDate = taskRecurringScheduleInstance.startDate 78 79 // If user changes startDate then ensure it is in the future, otherwise it's ok to keep the original date. 80 if(originalDate.getTime() != newDate.getTime()) 81 { 82 if(newDate < dateUtilService.getToday()) 83 { 84 status.setRollbackOnly() // Only allow the transaction to Rollback, preventing flush due to 'dirty'. 85 taskRecurringScheduleInstance.errors.rejectValue("startDate", "taskRecurring.startDate.NotInTheFuture") 86 render(view:'edit',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance]) 87 return 88 } 89 } 90 91 taskRecurringScheduleInstance.nextTargetStartDate = taskRecurringScheduleInstance.startDate 92 taskRecurringScheduleInstance.setNextGenerationDate() 93 taskRecurringScheduleInstance.setNextTargetCompletionDate() 63 94 64 taskRecurringScheduleInstance.errors.rejectValue("version", "taskRecurringSchedule.optimistic.locking.failure", "Another user has updated this TaskRecurringSchedule while you were editing.") 65 render(view:'edit',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance]) 66 return 67 } 68 } 69 // taskRecurringScheduleInstance.properties = params 70 setUpdateProperties() 71 72 if(!taskRecurringScheduleInstance.hasErrors() && taskRecurringScheduleInstance.save()) { 73 flash.message = "TaskRecurringSchedule ${params.id} updated" 74 redirect(action:show,id:taskRecurringScheduleInstance.id) 75 } 76 else { 77 render(view:'edit',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance]) 78 } 79 } 80 else { 81 flash.message = "TaskRecurringSchedule not found with id ${params.id}" 82 redirect(action:edit,id:params.id) 83 } 84 } 95 if(!taskRecurringScheduleInstance.hasErrors() && taskRecurringScheduleInstance.save()) 96 { 97 flash.message = "TaskRecurringSchedule ${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 = "TaskRecurringSchedule not found with id ${params.id}" 108 redirect(action:edit,id:params.id) 109 } 110 111 } // end withTransaction 112 } // end update() 85 113 86 114 def create = { … … 95 123 redirect(controller:"taskDetailed", action:"list") 96 124 } 97 } 125 } // end create() 98 126 99 127 def save = { … … 106 134 } 107 135 else { 136 137 if(taskRecurringScheduleInstance.startDate < dateUtilService.getToday()) { 138 taskRecurringScheduleInstance.errors.rejectValue("startDate", "taskRecurring.startDate.NotInTheFuture") 139 } 108 140 109 141 if(!taskRecurringScheduleInstance.hasErrors() && taskRecurringScheduleInstance.save()) { … … 125 157 } 126 158 127 } 128 129 private setUpdateProperties() { 130 def originalStartDate = taskRecurringScheduleInstance.startDate 131 132 if(taskRecurringScheduleInstance.startDate == params.startDate) { 133 taskRecurringScheduleInstance.properties = params 134 } 135 else { 136 taskRecurringScheduleInstance.properties = params 137 taskRecurringScheduleInstance.nextTargetStartDate = params.startDate 138 } 139 140 } 159 } // end save() 141 160 142 /*143 private Date calculateNextDueDate(recurEvery, period, startDate) {144 def nextDue = new Date()145 146 switch (period) {147 case "Day(s)":148 use(TimeCategory) {149 nextDue = startDate + recurEvery.days150 }151 return nextDue152 case "Week(s)":153 use(TimeCategory) {154 nextDue = startDate + recurEvery.weeks155 }156 return nextDue157 case "Month(s)":158 use(TimeCategory) {159 nextDue = startDate + recurEvery.months160 }161 return nextDue162 case "Year(s)":163 use(TimeCategory) {164 nextDue = startDate + recurEvery.years165 }166 return nextDue167 default:168 return nextDue169 }170 171 }*/172 161 }
Note: See TracChangeset
for help on using the changeset viewer.