Ignore:
Timestamp:
Oct 21, 2009, 5:07:30 PM (15 years ago)
Author:
gav
Message:

Detail work on TaskRecurringSchedule? views and controller.
Regen non-detail views.
Format TaskRecurringScheduleDetailedController? to 4 spaces, no tabs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/TaskRecurringScheduleDetailedController.groovy

    r137 r157  
    44
    55class TaskRecurringScheduleDetailedController extends BaseController {
    6    
    7         def dateUtilService
    8        
     6
     7    def dateUtilService
     8
    99    def index = { redirect(action:list,params:params) }
    1010
     
    2121
    2222        if(!taskRecurringScheduleInstance) {
    23             flash.message = "TaskRecurringSchedule not found with id ${params.id}"
     23            flash.message = "Recurring Schedule not found with id ${params.id}"
    2424            redirect(action:list)
    2525        }
     
    3232            try {
    3333                taskRecurringScheduleInstance.delete()
    34                 flash.message = "TaskRecurringSchedule ${params.id} deleted"
     34                flash.message = "Recurring Schedule ${params.id} deleted"
    3535                redirect(action:list)
    3636            }
    3737            catch(org.springframework.dao.DataIntegrityViolationException e) {
    38                 flash.message = "TaskRecurringSchedule ${params.id} could not be deleted"
     38                flash.message = "Recurring Schedule ${params.id} could not be deleted"
    3939                redirect(action:show,id:params.id)
    4040            }
    4141        }
    4242        else {
    43             flash.message = "TaskRecurringSchedule not found with id ${params.id}"
     43            flash.message = "Recurring Schedule not found with id ${params.id}"
    4444            redirect(action:list)
    4545        }
     
    5050
    5151        if(!taskRecurringScheduleInstance) {
    52             flash.message = "TaskRecurringSchedule not found with id ${params.id}"
     52            flash.message = "Recurring Schedule not found with id ${params.id}"
    5353            redirect(action:list)
    5454        }
     
    5959
    6060    def update = {
    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()
    94                    
    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()
    113        
     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 Recurring Schedule 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()
     94
     95                if(!taskRecurringScheduleInstance.hasErrors() && taskRecurringScheduleInstance.save())
     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()
     113
    114114    def create = {
    115115        try {
    116116            def taskInstance = Task.get(params.taskInstance.id)
    117                         def taskRecurringScheduleInstance = new TaskRecurringSchedule()
     117            def taskRecurringScheduleInstance = new TaskRecurringSchedule()
    118118            taskRecurringScheduleInstance.task = taskInstance
    119119            return [taskRecurringScheduleInstance: taskRecurringScheduleInstance]
     
    127127    def save = {
    128128        def taskRecurringScheduleInstance = new TaskRecurringSchedule(params)
    129                 def taskInstance = Task.get(params.task.id)
    130                                
    131                 if(taskInstance.taskRecurringSchedule) {
    132                         flash.message = "This task already has a recurring schedule"
    133                         redirect(controller:"taskDetailed", action:"show", id: params.task.id)
    134                 }
    135                 else {
    136                        
    137                         if(taskRecurringScheduleInstance.startDate < dateUtilService.getToday()) {
    138                                 taskRecurringScheduleInstance.errors.rejectValue("startDate", "taskRecurring.startDate.NotInTheFuture")
    139                         }
    140                        
    141                         if(!taskRecurringScheduleInstance.hasErrors() && taskRecurringScheduleInstance.save()) {
    142                                
    143                                 taskInstance.taskRecurringSchedule = taskRecurringScheduleInstance
    144                                                
    145                                 if(taskInstance.save()) {
    146                                         flash.message = "TaskRecurringSchedule ${taskRecurringScheduleInstance.id} created"
    147                                         redirect(action:show,id:taskRecurringScheduleInstance.id)
    148                                 }
    149                                 else {
    150                                         flash.message = "Task could not be saved and therefore the Recurring Schedule has been disgarded, cause unknown."                              
    151                                         render(view:'create',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance])
    152                                 }
    153                         }
    154                         else {
    155                                 render(view:'create',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance])
    156                         }
    157                 }
     129        def taskInstance = Task.get(params.task.id)
     130
     131        if(taskInstance.taskRecurringSchedule) {
     132            flash.message = "This task already has a recurring schedule"
     133            redirect(controller:"taskDetailed", action:"show", id: params.task.id)
     134        }
     135        else {
     136
     137            if(taskRecurringScheduleInstance.startDate < dateUtilService.getToday()) {
     138                taskRecurringScheduleInstance.errors.rejectValue("startDate", "taskRecurring.startDate.NotInTheFuture")
     139            }
     140
     141            if(!taskRecurringScheduleInstance.hasErrors() && taskRecurringScheduleInstance.save()) {
     142
     143                taskInstance.taskRecurringSchedule = taskRecurringScheduleInstance
     144
     145                if(taskInstance.save()) {
     146                    flash.message = "Recurring Schedule ${taskRecurringScheduleInstance.id} created"
     147                    redirect(action:show,id:taskRecurringScheduleInstance.id)
     148                }
     149                else {
     150                    flash.message = "Task could not be saved and therefore the Recurring Schedule has been disgarded, cause unknown."   
     151                    render(view:'create',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance])
     152                }
     153            }
     154            else {
     155                render(view:'create',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance])
     156            }
     157        }
    158158
    159159    } // end save()
Note: See TracChangeset for help on using the changeset viewer.