Ignore:
Timestamp:
Nov 15, 2009, 1:50:18 AM (15 years ago)
Author:
gav
Message:

Add createEntry to TaskService, automgically updates the task to "In progress" and creates the "Started" task modification.

File:
1 edited

Legend:

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

    r185 r186  
    44
    55    def personService
     6    def taskService
    67
    78    def index = { redirect(action:list,params:params) }
     
    2021        if(!entryInstance) {
    2122            flash.message = "Entry not found with id ${params.id}"
    22             redirect(action:list)
     23            redirect(controller: 'taskDetailed', action: 'search')
    2324        }
    2425        else { return [ entryInstance : entryInstance ] }
     
    4243        else {
    4344            flash.message = "Entry not found with id ${params.id}"
    44             redirect(action:list)
     45            redirect(controller: "taskDetailed", action:"search")
    4546        }
    4647    }
     
    5051        if(!entryInstance) {
    5152                flash.message = "Entry not found with id ${params.id}"
    52                 redirect(action:list)
     53                redirect(controller: "taskDetailed", action:"search")
    5354        }
    5455        else {
     
    8687        else {
    8788            flash.message = "Entry not found with id ${params.id}"
    88             redirect(action:edit,id:params.id)
     89            redirect(controller: "taskDetailed", action:"search")
    8990        }
    9091    }
     
    9899        }
    99100        catch(Exception e) {
    100             flash.message = "Please select a task, then 'Add Entry'"
    101             redirect(controller:"taskDetailed", action:"list")
     101            flash.message = "Please select a task, then 'Add Entry'."
     102            redirect(controller:"taskDetailed", action:"search")
    102103        }
    103104    }
    104105
    105106    def save = {
    106         def entryInstance = new Entry(params)
     107        def result = taskService.createEntry(params)
    107108
    108         entryInstance.enteredBy = personService.currentUser()
    109         if(!entryInstance.hasErrors() && entryInstance.save(flush: true)) {
    110             flash.message = "Entry ${entryInstance.id} created"
    111             redirect(controller:"taskDetailed", action:"show", id: params.task.id)
     109        if(!result.error) {
     110            flash.message = "Entry created."
     111            redirect(controller: "taskDetailed", action: "show", id: result.taskId)
    112112        }
    113113        else {
    114             render(view:'create',model:[entryInstance:entryInstance])
     114            if(result.entryInstance) {
     115                render(view:'create',model:[entryInstance: result.entryInstance])
     116            }
     117            else {
     118                flash.message = "Could not create entry."
     119                redirect(controller: "taskDetailed", action:"search")
     120            }
     121
    115122        }
    116123    }
     124
    117125}
Note: See TracChangeset for help on using the changeset viewer.