Ignore:
Timestamp:
Mar 29, 2009, 11:56:11 PM (16 years ago)
Author:
gav
Message:

Rename Modification and ModificationType? domains to TaskModification? and TaskModificationType? respectively. Re-generate controller and views. Update ERD. It's an evil but a necessary mouthful as we may want to track other modifications later.

File:
1 moved

Legend:

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

    r92 r93  
    11import org.codehaus.groovy.grails.plugins.springsecurity.Secured
    22
    3 class ModificationController extends BaseController {
     3class TaskModificationController extends BaseController {
    44   
    55    def index = { redirect(action:list,params:params) }
     
    99
    1010    def list = {
    11         if(!params.max) params.max = 10
    12         [ modificationInstanceList: Modification.list( params ) ]
     11        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
     12        [ taskModificationInstanceList: TaskModification.list( params ), taskModificationInstanceTotal: TaskModification.count() ]
    1313    }
    1414
    1515    def show = {
    16         def modificationInstance = Modification.get( params.id )
     16        def taskModificationInstance = TaskModification.get( params.id )
    1717
    18         if(!modificationInstance) {
    19             flash.message = "Modification not found with id ${params.id}"
     18        if(!taskModificationInstance) {
     19            flash.message = "TaskModification not found with id ${params.id}"
    2020            redirect(action:list)
    2121        }
    22         else { return [ modificationInstance : modificationInstance ] }
     22        else { return [ taskModificationInstance : taskModificationInstance ] }
    2323    }
    2424
    2525    def delete = {
    26         def modificationInstance = Modification.get( params.id )
    27         if(modificationInstance) {
    28             modificationInstance.delete()
    29             flash.message = "Modification ${params.id} deleted"
    30             redirect(action:list)
     26        def taskModificationInstance = TaskModification.get( params.id )
     27        if(taskModificationInstance) {
     28            try {
     29                taskModificationInstance.delete()
     30                flash.message = "TaskModification ${params.id} deleted"
     31                redirect(action:list)
     32            }
     33            catch(org.springframework.dao.DataIntegrityViolationException e) {
     34                flash.message = "TaskModification ${params.id} could not be deleted"
     35                redirect(action:show,id:params.id)
     36            }
    3137        }
    3238        else {
    33             flash.message = "Modification not found with id ${params.id}"
     39            flash.message = "TaskModification not found with id ${params.id}"
    3440            redirect(action:list)
    3541        }
     
    3743
    3844    def edit = {
    39         def modificationInstance = Modification.get( params.id )
     45        def taskModificationInstance = TaskModification.get( params.id )
    4046
    41         if(!modificationInstance) {
    42             flash.message = "Modification not found with id ${params.id}"
     47        if(!taskModificationInstance) {
     48            flash.message = "TaskModification not found with id ${params.id}"
    4349            redirect(action:list)
    4450        }
    4551        else {
    46             return [ modificationInstance : modificationInstance ]
     52            return [ taskModificationInstance : taskModificationInstance ]
    4753        }
    4854    }
    4955
    5056    def update = {
    51         def modificationInstance = Modification.get( params.id )
    52         if(modificationInstance) {
    53             modificationInstance.properties = params
    54             if(!modificationInstance.hasErrors() && modificationInstance.save()) {
    55                 flash.message = "Modification ${params.id} updated"
    56                 redirect(action:show,id:modificationInstance.id)
     57        def taskModificationInstance = TaskModification.get( params.id )
     58        if(taskModificationInstance) {
     59            if(params.version) {
     60                def version = params.version.toLong()
     61                if(taskModificationInstance.version > version) {
     62                   
     63                    taskModificationInstance.errors.rejectValue("version", "taskModification.optimistic.locking.failure", "Another user has updated this TaskModification while you were editing.")
     64                    render(view:'edit',model:[taskModificationInstance:taskModificationInstance])
     65                    return
     66                }
     67            }
     68            taskModificationInstance.properties = params
     69            if(!taskModificationInstance.hasErrors() && taskModificationInstance.save()) {
     70                flash.message = "TaskModification ${params.id} updated"
     71                redirect(action:show,id:taskModificationInstance.id)
    5772            }
    5873            else {
    59                 render(view:'edit',model:[modificationInstance:modificationInstance])
     74                render(view:'edit',model:[taskModificationInstance:taskModificationInstance])
    6075            }
    6176        }
    6277        else {
    63             flash.message = "Modification not found with id ${params.id}"
     78            flash.message = "TaskModification not found with id ${params.id}"
    6479            redirect(action:edit,id:params.id)
    6580        }
     
    6782
    6883    def create = {
    69         def modificationInstance = new Modification()
    70         modificationInstance.properties = params
    71         return ['modificationInstance':modificationInstance]
     84        def taskModificationInstance = new TaskModification()
     85        taskModificationInstance.properties = params
     86        return ['taskModificationInstance':taskModificationInstance]
    7287    }
    7388
    7489    def save = {
    75         def modificationInstance = new Modification(params)
    76         if(!modificationInstance.hasErrors() && modificationInstance.save()) {
    77             flash.message = "Modification ${modificationInstance.id} created"
    78             redirect(action:show,id:modificationInstance.id)
     90        def taskModificationInstance = new TaskModification(params)
     91        if(!taskModificationInstance.hasErrors() && taskModificationInstance.save()) {
     92            flash.message = "TaskModification ${taskModificationInstance.id} created"
     93            redirect(action:show,id:taskModificationInstance.id)
    7994        }
    8095        else {
    81             render(view:'create',model:[modificationInstance:modificationInstance])
     96            render(view:'create',model:[taskModificationInstance:taskModificationInstance])
    8297        }
    8398    }
Note: See TracChangeset for help on using the changeset viewer.