Changeset 225 for trunk/grails-app/controllers
- Timestamp:
- Dec 8, 2009, 4:03:29 AM (15 years ago)
- Location:
- trunk/grails-app/controllers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/InventoryItemDetailedController.groovy
r178 r225 4 4 5 5 def filterService 6 def inventoryItemService 7 def inventoryMovementService 6 8 7 9 def index = { redirect(action:search, params:params) } 8 10 9 11 // the delete, save and update actions only accept POST requests 10 static allowedMethods = [delete:'POST', save:'POST', update:'POST' ]12 static allowedMethods = [delete:'POST', save:'POST', update:'POST', useInventoryItem:'POST'] 11 13 12 14 def list = { … … 29 31 } 30 32 33 /** 34 * Simply assigns a passed in task id to a session variable and redirects to search. 35 */ 36 def findInventoryItemForMovement = { 37 if(!params.task?.id) { 38 flash.message = "No task id supplied, please select a task then the inventory tab." 39 redirect(controller: "taskDetailed", action: "search") 40 return 41 } 42 43 session.inventoryMovementTaskId = params.task.id 44 flash.message = "Please find and then select the inventory item." 45 redirect(action: search) 46 } 47 31 48 def show = { 32 49 33 50 // In the case of an actionSubmit button, rewrite action name from 'index'. 34 51 if(params._action_Show) 35 52 { params.action='show' } 36 37 def inventoryItemInstance = InventoryItem.get( params.id )38 53 39 if(! inventoryItemInstance) {54 if(!InventoryItem.exists(params.id)) { 40 55 flash.message = "InventoryItem not found with id ${params.id}" 41 56 redirect(action:search) 57 return 42 58 } 43 else { return [ inventoryItemInstance : inventoryItemInstance ] } 59 60 def result = inventoryItemService.prepareShowData(params) 61 62 if(result.error) { 63 flash.message = "Could not to prepare the data to show item with id: ${params.id}." 64 redirect(action:search) 65 return 66 } 67 68 def model = [ inventoryItemInstance: result.inventoryItemInstance, 69 inventoryMovementList: result.inventoryMovementList, 70 inventoryMovementListTotal: result.inventoryMovementListTotal, 71 inventoryMovementListMax: result.inventoryMovementListMax, 72 showTab: result.showTab] 73 74 if(session.inventoryMovementTaskId) { 75 model.inventoryMovementInstance = new InventoryMovement() 76 model.inventoryMovementInstance.task = Task.get(session.inventoryMovementTaskId) 77 model.inventoryMovementInstance.quantity = 1 78 } 79 80 return model 44 81 } 45 82 … … 123 160 } 124 161 } 162 163 /** 164 * Handles the use inventory item form submit in the show view. 165 */ 166 def useInventoryItem = { 167 168 params.inventoryMovementType = InventoryMovementType.get(1) // used. 169 def result = inventoryMovementService.move(params) 170 171 if(!result.error) { 172 flash.message = "Inventory Movement for ${result.inventoryMovementInstance.inventoryItem.name.encodeAsHTML()} created." 173 redirect(controller:"taskDetailed", action:"show", id: result.taskId) 174 } 175 else { 176 if(result.inventoryMovementInstance) { 177 def p = [:] 178 p.id = result.inventoryMovementInstance.inventoryItem?.id 179 def r = inventoryItemService.prepareShowData(p) 180 181 def model = [ inventoryItemInstance: r.inventoryItemInstance, 182 inventoryMovementList: r.inventoryMovementList, 183 inventoryMovementListTotal: r.inventoryMovementListTotal, 184 inventoryMovementListMax: r.inventoryMovementListMax, 185 showTab: r.showTab] 186 187 model.inventoryMovementInstance = result.inventoryMovementInstance 188 189 render(view: 'show', model: model) 190 } 191 else { 192 flash.message = "Could not create inventory movement." 193 redirect(action:"search") 194 } 195 196 } 197 } 198 125 199 } -
trunk/grails-app/controllers/TaskDetailedController.groovy
r216 r225 154 154 { params.action='show' } 155 155 156 def showTab = [:] 157 switch (params.showTab) { 158 case "showProcedureTab": 159 showTab.procedure = new String("true") 160 break 161 case "showRecurrenceTab": 162 showTab.recurrence = new String("true") 163 break 164 case "showInventoryTab": 165 showTab.inventory = new String("true") 166 break 167 case "showSubTasksTab": 168 showTab.subTasks = new String("true") 169 break 170 default: 171 showTab.task = new String("true") 172 } 173 156 174 def taskInstance = Task.get( params.id ) 157 175 … … 177 195 def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params) 178 196 def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false) 179 def showTaskTab = new String("true")180 197 181 198 def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) … … 204 221 taskProcedureInstance: taskProcedureInstance, 205 222 taskProcedureExits: taskProcedureExits, 206 showTa skTab: showTaskTab,223 showTab: showTab, 207 224 subTaskInstanceList: subTaskInstanceList, 208 225 subTaskInstanceTotal: subTaskInstanceTotal,
Note: See TracChangeset
for help on using the changeset viewer.