Changeset 482 for trunk


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.

Location:
trunk/grails-app
Files:
5 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
  • trunk/grails-app/i18n/messages.properties

    r481 r482  
    9494task.targetCompletionDate.before.targetStartDate=The target completion date must be equal to or greater than \
    9595    the target start date.
     96
     97entry.create.no.params=Please select a task, then add an entry.
    9698
    9799taskRecurringSchedule.notFound=Could not complete operation, recurring schedule not found.
  • trunk/grails-app/services/TaskService.groovy

    r478 r482  
    273273            }
    274274
    275             if(result.entryInstance.hasErrors() || !result.entryInstance.save())
    276                 return fail(field:"task", code:"default.create.failure")
    277 
    278             // Success.
    279             return result
    280 
    281         } //end withTransaction
     275            // Success.
     276            return result
     277
     278        } // end withTransaction
    282279    } // end saveEntry()
    283280
  • trunk/grails-app/views/entryDetailed/create.gsp

    r432 r482  
    1414        </div>
    1515        <div class="body">
    16             <g:if test="${flash.message}">
    17             <div class="message">${flash.message}</div>
    18             </g:if>
     16            <g:render template="/shared/messages" />
    1917            <g:hasErrors bean="${entryInstance}">
    2018            <div class="errors">
  • trunk/grails-app/views/taskDetailed/create.gsp

    r433 r482  
    1212        </div>
    1313        <div class="body">
    14             <g:if test="${flash.message}">
    15             <div class="message">${flash.message}</div>
    16             </g:if>
     14            <g:render template="/shared/messages" />
    1715            <g:hasErrors bean="${taskInstance}">
    1816            <div class="errors">
Note: See TracChangeset for help on using the changeset viewer.