Changeset 425
- Timestamp:
- Mar 3, 2010, 3:50:21 PM (15 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/InventoryItemDetailedController.groovy
r423 r425 238 238 def result = inventoryItemService.edit(params) 239 239 240 if(!result.error) 241 return [ inventoryItemInstance : result.inventoryItemInstance ] 240 if(!result.error) { 241 def possibleAlternateItems = inventoryItemService.getPossibleAlternateItems(result.inventoryItemInstance) 242 return [ inventoryItemInstance : result.inventoryItemInstance, possibleAlternateItems: possibleAlternateItems] 243 } 242 244 243 245 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) … … 260 262 } 261 263 262 render(view:'edit', model:[inventoryItemInstance: result.inventoryItemInstance.attach()]) 264 def possibleAlternateItems = inventoryItemService.getPossibleAlternateItems(result.inventoryItemInstance) 265 render(view:'edit', model:[inventoryItemInstance: result.inventoryItemInstance.attach(), possibleAlternateItems: possibleAlternateItems]) 263 266 } 264 267 -
trunk/grails-app/domain/InventoryItem.groovy
r422 r425 56 56 57 57 String toString() {"${this.name}"} 58 59 def afterInsert = { 60 addReverseAlternateItems() 61 } 62 63 // Add reverse alternateItem references. 64 def addReverseAlternateItems() { 65 this.alternateItems.each() { 66 if( !it.alternateItems?.contains(this) ) 67 it.addToAlternateItems(this) 68 } 69 } 70 71 /** 72 * Remove all reverse alternateItem references. 73 * Update: reverse alternateItem handling must be done in the 74 * service class since the before assignment alternateItems are required. 75 */ 76 def removeReverseAlternateItems(alternateItems = this.alternateItems) { 77 alternateItems.each() { 78 it.removeFromAlternateItems(this) 79 } 80 } 81 58 82 } -
trunk/grails-app/i18n/messages.properties
r421 r425 123 123 inventoryMovement.quantity.insufficientItemsInStock=Could not complete operation, insufficient items in stock. 124 124 inventoryMovement.inventoryItem.notFound=Inventory Item not found. 125 inventoryMovement.still.associated=Could not complete operation as inventory movements are still associated with this item. 125 126 126 127 assignedGroup.task.not.found=Please select a task and then ''Add Assigned Group''. -
trunk/grails-app/services/InventoryItemService.groovy
r405 r425 5 5 6 6 boolean transactional = false 7 8 /** 9 * Prepare a sorted list of possible alternateItems. 10 */ 11 def getPossibleAlternateItems(inventoryItemInstance) { 12 def criteria = inventoryItemInstance.createCriteria() 13 def possibleAlternateItems = criteria { 14 and { 15 eq('isActive', true) 16 notEqual('id', inventoryItemInstance.id) 17 } 18 }.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } 19 } 7 20 8 21 /** … … 50 63 51 64 def delete(params) { 52 def result = [:] 53 def fail = { Map m -> 54 result.error = [ code: m.code, args: ["InventoryItem", params.id] ] 55 return result 56 } 65 InventoryItem.withTransaction { status -> 66 def result = [:] 57 67 58 result.inventoryItemInstance = InventoryItem.get(params.id) 68 def fail = { Map m -> 69 status.setRollbackOnly() 70 if(result.inventoryItemInstance && m.field) 71 result.inventoryItemInstance.errors.rejectValue(m.field, m.code) 72 result.error = [ code: m.code, args: ["InventoryItem", params.id] ] 73 return result 74 } 59 75 60 if(!result.inventoryItemInstance) 61 return fail(code:"default.not.found") 76 result.inventoryItemInstance = InventoryItem.get(params.id) 62 77 63 try { 64 result.inventoryItemInstance.delete(flush:true) 65 return result //Success. 66 } 67 catch(org.springframework.dao.DataIntegrityViolationException e) { 68 return fail(code:"default.delete.failure") 69 } 78 if(!result.inventoryItemInstance) 79 return fail(code:"default.not.found") 70 80 71 } 81 if(result.inventoryItemInstance.inventoryMovements) 82 return fail(code:"inventoryMovement.still.associated") 83 84 result.inventoryItemInstance.removeReverseAlternateItems() 85 86 try { 87 result.inventoryItemInstance.delete(flush:true) 88 return result //Success. 89 } 90 catch(org.springframework.dao.DataIntegrityViolationException e) { 91 return fail(code:"default.delete.failure") 92 } 93 94 } //end withTransaction 95 } // end delete() 72 96 73 97 def edit(params) { … … 110 134 } 111 135 136 def previousAlternateItems = new ArrayList(result.inventoryItemInstance.alternateItems) 137 112 138 result.inventoryItemInstance.properties = params 113 139 114 140 if(result.inventoryItemInstance.hasErrors() || !result.inventoryItemInstance.save()) 115 141 return fail(code:"default.update.failure") 142 143 result.inventoryItemInstance.removeReverseAlternateItems(previousAlternateItems) 144 result.inventoryItemInstance.addReverseAlternateItems() 116 145 117 146 // Success. … … 158 187 } 159 188 160 161 189 } // end class -
trunk/grails-app/views/inventoryItemDetailed/edit.gsp
r422 r425 238 238 <td valign="top" class="value ${hasErrors(bean:inventoryItemInstance,field:'alternateItems','errors')}"> 239 239 <g:select name="alternateItems" 240 from="${ InventoryItem.list().sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }}"240 from="${possibleAlternateItems}" 241 241 size="5" multiple="yes" optionKey="id" 242 242 value="${inventoryItemInstance?.alternateItems.id}" noSelection="['':'--None--']"/> -
trunk/grails-app/views/inventoryItemDetailed/show.gsp
r422 r425 149 149 <td valign="top" style="text-align:left;" class="value"> 150 150 <ul> 151 <g:each var="a" in="${ inventoryItemInstance.alternateItems}">151 <g:each var="a" in="${ inventoryItemInstance.alternateItems.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } }"> 152 152 <li><g:link controller="inventoryItemDetailed" action="show" id="${a.id}">${a?.encodeAsHTML()}</g:link></li> 153 153 </g:each>
Note: See TracChangeset
for help on using the changeset viewer.