Ignore:
Timestamp:
Apr 13, 2010, 11:02:59 AM (15 years ago)
Author:
gav
Message:

Refactor entry creation to provide correct error messages when trying to create a new entry on a complete task.

File:
1 edited

Legend:

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

    r394 r482  
    9393
    9494    def create = {
    95         try {
    96             def taskInstance = Task.get(params.taskInstance.id)
    97             def entryInstance = new Entry()
    98             entryInstance.task = taskInstance
    99             entryInstance.entryType = EntryType.get(params.entryType.id)
    100             return ['entryInstance':entryInstance]
     95        if(!params.taskInstance?.id || !params.entryType?.id) {
     96            flash.message = g.message(code:"entry.create.no.params")
     97            redirect(controller:"taskDetailed", action:"search")
     98            return
    10199        }
    102         catch(Exception e) {
    103             flash.message = "Please select a task, then 'Add Entry'."
     100
     101        def taskInstance = Task.read(params.taskInstance.id)
     102
     103        if(!taskInstance) {
     104            flash.message = g.message(code:"task.notFound")
    104105            redirect(controller:"taskDetailed", action:"search")
     106            return
    105107        }
    106     }
     108
     109        // Check for Complete task.
     110        if(taskInstance.taskStatus.id == 3) {
     111            flash.errorMessage = g.message(code:"task.operationNotPermittedOnCompleteTask")
     112            redirect(controller:"taskDetailed", action:"show", id: taskInstance.id)
     113            return
     114        }
     115
     116        def entryInstance = new Entry()
     117        entryInstance.task = taskInstance
     118        entryInstance.entryType = EntryType.read(params.entryType.id)
     119        return ['entryInstance': entryInstance]
     120    } // create
    107121
    108122    def save = {
     
    112126            flash.message = "Entry created."
    113127            redirect(controller: "taskDetailed", action: "show", id: result.taskId)
     128            return
    114129        }
    115         else {
    116             if(result.entryInstance) {
    117                 render(view:'create',model:[entryInstance: result.entryInstance])
    118             }
    119             else {
    120                 flash.message = "Could not create entry."
    121                 redirect(controller: "taskDetailed", action:"search")
    122             }
    123130
     131        if(result.error.code != "default.create.failure") {
     132            params.errorMessage = g.message(code: result.error.code)
    124133        }
    125     }
    126134
    127 }
     135        render(view:'create',model:[entryInstance: result.entryInstance])
     136    } // save
     137
     138} // end class
Note: See TracChangeset for help on using the changeset viewer.