Ignore:
Timestamp:
Nov 5, 2009, 4:01:35 AM (14 years ago)
Author:
gav
Message:

Change is* in Task to just 'active', 'scheduled' and 'approved'.
Regenerate non detailed controller and views.
Adjust detailed controller, views and services to suite.
Add support for task actions 'approve', 'complete', 'trash' and their counter parts.
Default task status to "not started" when creating a new task.

File:
1 edited

Legend:

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

    r180 r181  
    1111    def exportService
    1212
    13     // the delete, save and update actions only accept POST requests
    14     static allowedMethods = [delete:'POST', save:'POST', update:'POST']
     13    // these actions only accept POST requests
     14    static allowedMethods = [save:'POST', update:'POST', restore:'POST', trash:'POST', approve:'POST', renegeApproval:'POST', complete:'POST', reopen:'POST']
    1515
    1616    def index = { redirect(action:search,params:params) }
     
    223223    }
    224224
    225     def delete = {
    226         def taskInstance = Task.get( params.id )
    227         if(taskInstance) {
    228             try {
    229                 taskInstance.isActive = false
    230                 flash.message = "Task ${params.id} has been set to inactive."
    231                 redirect(action:search)
    232             }
    233             catch(org.springframework.dao.DataIntegrityViolationException e) {
    234                 flash.message = "Task ${params.id} could not be deleted"
    235                 redirect(action:show,id:params.id)
    236             }
    237         }
    238         else {
     225    def restore = {
     226
     227        if(!Task.exists(params.id)) {
    239228            flash.message = "Task not found with id ${params.id}"
    240             redirect(action:search)
    241         }
     229            redirect(action:'search')
     230        }
     231
     232        def result = taskService.restore(params)
     233
     234        if(!result.error) {
     235                flash.message = "Task ${params.id} has been restored."
     236                redirect(action:show,id:result.taskInstance.id)
     237        }
     238        else {
     239            if(result.taskInstance) {
     240                render(view:'edit',model:[taskInstance:result.taskInstance])
     241            }
     242            else {
     243                flash.message = "Task could not be updated."
     244                redirect(action:'search')
     245            }
     246        }
     247
     248    }
     249
     250    def trash = {
     251
     252        if(!Task.exists(params.id)) {
     253            flash.message = "Task not found with id ${params.id}."
     254            redirect(action:'search')
     255        }
     256
     257        def result = taskService.trash(params)
     258
     259        if(!result.error) {
     260                flash.message = "Task ${params.id} has been moved to trash."
     261                redirect(action:'search')
     262        }
     263        else {
     264            if(result.taskInstance) {
     265                render(view:'edit',model:[taskInstance:result.taskInstance])
     266            }
     267            else {
     268                flash.message = "Task could not be updated."
     269                redirect(action:'search')
     270            }
     271        }
     272
     273    }
     274
     275    def approve = {
     276
     277        if(!Task.exists(params.id)) {
     278            flash.message = "Task not found with id ${params.id}."
     279            redirect(action:'search')
     280        }
     281
     282        def result = taskService.approve(params)
     283
     284        if(!result.error) {
     285                flash.message = "Task ${params.id} has been approved."
     286                redirect(action:show,id:result.taskInstance.id)
     287        }
     288        else {
     289            if(result.taskInstance) {
     290                render(view:'edit',model:[taskInstance:result.taskInstance])
     291            }
     292            else {
     293                flash.message = "Task could not be updated."
     294                redirect(action:'search')
     295            }
     296        }
     297
     298    }
     299
     300    def renegeApproval = {
     301
     302        if(!Task.exists(params.id)) {
     303            flash.message = "Task not found with id ${params.id}."
     304            redirect(action:'search')
     305        }
     306
     307        def result = taskService.renegeApproval(params)
     308
     309        if(!result.error) {
     310                flash.message = "Task ${params.id} has had approval removed."
     311                redirect(action:show,id:result.taskInstance.id)
     312        }
     313        else {
     314            if(result.taskInstance) {
     315                render(view:'edit',model:[taskInstance:result.taskInstance])
     316            }
     317            else {
     318                flash.message = "Task could not be updated."
     319                redirect(action:'search')
     320            }
     321        }
     322
     323    }
     324
     325    def complete = {
     326
     327        if(!Task.exists(params.id)) {
     328            flash.message = "Task not found with id ${params.id}."
     329            redirect(action:'search')
     330        }
     331
     332        def result = taskService.complete(params)
     333
     334        if(!result.error) {
     335                flash.message = "Task ${params.id} has been completed."
     336                redirect(action:show,id:result.taskInstance.id)
     337        }
     338        else {
     339            if(result.taskInstance) {
     340                render(view:'edit',model:[taskInstance:result.taskInstance])
     341            }
     342            else {
     343                flash.message = "Task could not be updated."
     344                redirect(action:'search')
     345            }
     346        }
     347
     348    }
     349
     350    def reopen = {
     351
     352        if(!Task.exists(params.id)) {
     353            flash.message = "Task not found with id ${params.id}."
     354            redirect(action:'search')
     355        }
     356
     357        def result = taskService.reopen(params)
     358
     359        if(!result.error) {
     360                flash.message = "Task ${params.id} has been reopened."
     361                redirect(action:show,id:result.taskInstance.id)
     362        }
     363        else {
     364            if(result.taskInstance) {
     365                render(view:'edit',model:[taskInstance:result.taskInstance])
     366            }
     367            else {
     368                flash.message = "Task could not be updated."
     369                redirect(action:'search')
     370            }
     371        }
     372
    242373    }
    243374
     
    255386        }
    256387        else {
     388            if(taskInstance.trash) {
     389                flash.message = "You may not edit items in the trash."
     390                redirect(action:show,id:taskInstance.id)
     391            }
    257392            def criteria = taskInstance.createCriteria()
    258393            def possibleParentList = criteria {
     
    320455    def create = {
    321456        def taskInstance = new Task()
     457        // Default leadPerson to current user.
     458        taskInstance.leadPerson = Person.get(authenticateService.userDomain().id)
    322459        taskInstance.properties = params
    323460        return ['taskInstance':taskInstance]
Note: See TracChangeset for help on using the changeset viewer.