- Timestamp:
- Nov 15, 2009, 1:50:18 AM (15 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/EntryDetailedController.groovy
r185 r186 4 4 5 5 def personService 6 def taskService 6 7 7 8 def index = { redirect(action:list,params:params) } … … 20 21 if(!entryInstance) { 21 22 flash.message = "Entry not found with id ${params.id}" 22 redirect( action:list)23 redirect(controller: 'taskDetailed', action: 'search') 23 24 } 24 25 else { return [ entryInstance : entryInstance ] } … … 42 43 else { 43 44 flash.message = "Entry not found with id ${params.id}" 44 redirect( action:list)45 redirect(controller: "taskDetailed", action:"search") 45 46 } 46 47 } … … 50 51 if(!entryInstance) { 51 52 flash.message = "Entry not found with id ${params.id}" 52 redirect( action:list)53 redirect(controller: "taskDetailed", action:"search") 53 54 } 54 55 else { … … 86 87 else { 87 88 flash.message = "Entry not found with id ${params.id}" 88 redirect( action:edit,id:params.id)89 redirect(controller: "taskDetailed", action:"search") 89 90 } 90 91 } … … 98 99 } 99 100 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") 102 103 } 103 104 } 104 105 105 106 def save = { 106 def entryInstance = newEntry(params)107 def result = taskService.createEntry(params) 107 108 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) 112 112 } 113 113 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 115 122 } 116 123 } 124 117 125 } -
trunk/grails-app/i18n/messages.properties
r181 r186 51 51 inventoryMovement.quantity.insufficientItemsInStock=Could not complete operation, insufficient items in stock. 52 52 inventoryMovement.inventoryItem.notFound=Inventory Item not found. 53 54 entry.task.notFound=Could not complete operation, task not found. 55 entry.task.failedToSave=Could not complete operation, task failed to save. 56 entry.task.failedToSaveTaskModification=Could not complete operation, task modification failed to save. 57 entry.task.taskIsComplete=This operation is not permitted on a complete task. 53 58 54 59 default.doesnt.match.message=Property [{0}] of class [{1}] with value [{2}] does not match the required pattern [{3}] -
trunk/grails-app/services/TaskService.groovy
r182 r186 36 36 } // end create() 37 37 38 def start() { 39 //TaskModificationType.get(2) 40 } // end start() 38 def createEntry(params) { 39 Task.withTransaction { status -> 40 def result = [:] 41 result.entryInstance = new Entry(params) 42 result.entryInstance.enteredBy = personService.currentUser() 43 44 if(result.entryInstance.validate()) { 45 def taskInstance = Task.lock(result.entryInstance.task.id) 46 result.taskId = result.entryInstance.task.id 47 48 if(!taskInstance) { 49 status.setRollbackOnly() 50 result.entryInstance.errors.rejectValue('task', "entry.task.notFound") 51 result.error = true 52 return result 53 } 54 55 if(taskInstance.taskStatus.id == 3) { 56 status.setRollbackOnly() 57 result.entryInstance.errors.rejectValue('task', "entry.task.taskIsComplete") 58 result.error = true 59 return result 60 } 61 62 // If task status is "Not Started" and entry type is "Work Done" then we create the started modification and set the status. 63 if(taskInstance.taskStatus.id == 1 && result.entryInstance.entryType.id == 2) { 64 65 // Create the "Started" task modification, this provides the "Actual started date". 66 def taskModification = new TaskModification(person: personService.currentUser(), 67 taskModificationType: TaskModificationType.get(2), 68 task: taskInstance) 69 70 if(!taskModification.save()) { 71 status.setRollbackOnly() 72 taskInstance.errors.rejectValue("task", "entry.task.failedToSaveTaskModification") 73 result.error = true 74 return result 75 } 76 77 // Set task status to "In progress". 78 taskInstance.taskStatus = TaskStatus.get(2) 79 80 if(!taskInstance.save()) { 81 status.setRollbackOnly() 82 result.entryInstance.errors.rejectValue("task", "entry.task.failedToSave") 83 result.error = true 84 return result 85 } 86 } 87 88 if(!result.entryInstance.save()) { 89 status.setRollbackOnly() 90 result.error = true 91 return result 92 } 93 94 // All went well if we get to here. 95 return result 96 } 97 else { 98 result.error = true 99 return result 100 } 101 102 } //end withTransaction 103 } // end create() 41 104 42 105 def update(params) { -
trunk/grails-app/views/entryDetailed/create.gsp
r147 r186 33 33 </td> 34 34 <td valign="top" class="name"> 35 ${entryInstance?.task ?.description}35 ${entryInstance?.task} 36 36 </td> 37 37 </tr>
Note: See TracChangeset
for help on using the changeset viewer.