Ignore:
Timestamp:
Mar 31, 2009, 5:43:09 AM (16 years ago)
Author:
gav
Message:

Implemented the bulk of AssignedPerson? domain

Location:
trunk/src/grails-app/controllers
Files:
3 added
2 edited

Legend:

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

    r85 r96  
    11import org.codehaus.groovy.grails.plugins.springsecurity.Secured
    22
    3 @Secured(['ROLE_AppAdmin'])
    4 class TaskController extends BaseController {
     3class TaskController extends BaseAppAdminController {
    54   
    65    def index = { redirect(action:list,params:params) }
     
    109
    1110    def list = {
    12         if(!params.max) params.max = 10
    13         [ taskInstanceList: Task.list( params ) ]
     11        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
     12        [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ]
    1413    }
     14
    1515    def show = {
    1616        def taskInstance = Task.get( params.id )
     
    2222        else { return [ taskInstance : taskInstance ] }
    2323    }
    24  
     24
    2525    def delete = {
    2626        def taskInstance = Task.get( params.id )
    2727        if(taskInstance) {
    28             taskInstance.delete()
    29             flash.message = "Task ${params.id} deleted"
    30             redirect(action:list)
     28            try {
     29                taskInstance.delete()
     30                flash.message = "Task ${params.id} deleted"
     31                redirect(action:list)
     32            }
     33            catch(org.springframework.dao.DataIntegrityViolationException e) {
     34                flash.message = "Task ${params.id} could not be deleted"
     35                redirect(action:show,id:params.id)
     36            }
    3137        }
    3238        else {
     
    5157        def taskInstance = Task.get( params.id )
    5258        if(taskInstance) {
     59            if(params.version) {
     60                def version = params.version.toLong()
     61                if(taskInstance.version > version) {
     62                   
     63                    taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.")
     64                    render(view:'edit',model:[taskInstance:taskInstance])
     65                    return
     66                }
     67            }
    5368            taskInstance.properties = params
    5469            if(!taskInstance.hasErrors() && taskInstance.save()) {
     
    8297        }
    8398    }
    84 
    8599}
  • trunk/src/grails-app/controllers/TaskDetailedController.groovy

    r85 r96  
    99
    1010    def list = {
    11         if(!params.max) params.max = 10
    12         [ taskInstanceList: Task.list( params ) ]
     11        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
     12        [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ]
    1313    }
    1414
     
    2626        def taskInstance = Task.get( params.id )
    2727        if(taskInstance) {
    28             taskInstance.delete()
    29             flash.message = "Task ${params.id} deleted"
    30             redirect(action:list)
     28            try {
     29                taskInstance.delete()
     30                flash.message = "Task ${params.id} deleted"
     31                redirect(action:list)
     32            }
     33            catch(org.springframework.dao.DataIntegrityViolationException e) {
     34                flash.message = "Task ${params.id} could not be deleted"
     35                redirect(action:show,id:params.id)
     36            }
    3137        }
    3238        else {
     
    5763        def taskInstance = Task.get( params.id )
    5864        if(taskInstance) {
     65            if(params.version) {
     66                def version = params.version.toLong()
     67                if(taskInstance.version > version) {
     68                   
     69                    taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.")
     70                    render(view:'edit',model:[taskInstance:taskInstance])
     71                    return
     72                }
     73            }
    5974            taskInstance.properties = params
    6075            if(!taskInstance.hasErrors() && taskInstance.save()) {
Note: See TracChangeset for help on using the changeset viewer.