- Timestamp:
- Feb 23, 2010, 10:14:19 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/InventoryItemDetailedController.groovy
r403 r405 126 126 params.action='show' 127 127 128 if(!InventoryItem.exists(params.id)) { 129 flash.message = "InventoryItem not found with id ${params.id}" 128 def result = inventoryItemService.show(params) 129 130 if(!result.error) { 131 132 def model = [ inventoryItemInstance: result.inventoryItemInstance, 133 inventoryMovementList: result.inventoryMovementList, 134 inventoryMovementListTotal: result.inventoryMovementListTotal, 135 inventoryMovementListMax: result.inventoryMovementListMax, 136 showTab: result.showTab] 137 138 if(session.inventoryMovementTaskId) { 139 model.inventoryMovementInstance = new InventoryMovement() 140 model.inventoryMovementInstance.task = Task.get(session.inventoryMovementTaskId) 141 model.inventoryMovementInstance.quantity = 1 142 } 143 144 // Success. 145 return model 146 } 147 148 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 149 redirect(action:search) 150 return 151 } 152 153 def delete = { 154 def result = inventoryItemService.delete(params) 155 156 if(!result.error) { 157 flash.message = g.message(code: "default.delete.success", args: ["InventoryItem", params.id]) 158 redirect(action:list) 159 return 160 } 161 162 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 163 164 if(result.error.code == "default.not.found") { 130 165 redirect(action:search) 131 166 return 132 167 } 133 168 134 def result = inventoryItemService.prepareShowData(params) 135 136 if(result.error) { 137 flash.message = "Could not to prepare the data to show item with id: ${params.id}." 138 redirect(action:search) 139 return 140 } 141 142 def model = [ inventoryItemInstance: result.inventoryItemInstance, 143 inventoryMovementList: result.inventoryMovementList, 144 inventoryMovementListTotal: result.inventoryMovementListTotal, 145 inventoryMovementListMax: result.inventoryMovementListMax, 146 showTab: result.showTab] 147 148 if(session.inventoryMovementTaskId) { 149 model.inventoryMovementInstance = new InventoryMovement() 150 model.inventoryMovementInstance.task = Task.get(session.inventoryMovementTaskId) 151 model.inventoryMovementInstance.quantity = 1 152 } 153 154 return model 155 } 156 157 def delete = { 158 def inventoryItemInstance = InventoryItem.get( params.id ) 159 if(inventoryItemInstance) { 160 try { 161 inventoryItemInstance.delete(flush:true) 162 flash.message = "InventoryItem ${params.id} deleted" 163 redirect(action:search) 164 } 165 catch(org.springframework.dao.DataIntegrityViolationException e) { 166 flash.message = "InventoryItem ${params.id} could not be deleted" 167 redirect(action:show,id:params.id) 168 } 169 } 170 else { 171 flash.message = "InventoryItem not found with id ${params.id}" 172 redirect(action:search) 173 } 169 redirect(action:show, id: params.id) 174 170 } 175 171 … … 180 176 params.action='edit' 181 177 182 def inventoryItemInstance = InventoryItem.get( params.id ) 183 184 if(!inventoryItemInstance) { 185 flash.message = "InventoryItem not found with id ${params.id}" 178 def result = inventoryItemService.edit(params) 179 180 if(!result.error) 181 return [ inventoryItemInstance : result.inventoryItemInstance ] 182 183 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 184 redirect(action:search) 185 } 186 187 def update = { 188 def result = inventoryItemService.update(params) 189 190 if(!result.error) { 191 flash.message = g.message(code: "default.update.success", args: ["InventoryItem", params.id]) 192 redirect(action:show, id: params.id) 193 return 194 } 195 196 if(result.error.code == "default.not.found") { 197 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 186 198 redirect(action:search) 187 } 188 else { 189 return [ inventoryItemInstance : inventoryItemInstance ] 190 } 191 } 192 193 def update = { 194 def inventoryItemInstance = InventoryItem.get( params.id ) 195 if(inventoryItemInstance) { 196 if(params.version) { 197 def version = params.version.toLong() 198 if(inventoryItemInstance.version > version) { 199 200 inventoryItemInstance.errors.rejectValue("version", "default.optimistic.locking.failure") 201 render(view:'edit',model:[inventoryItemInstance:inventoryItemInstance]) 202 return 203 } 204 } 205 inventoryItemInstance.properties = params 206 if(!inventoryItemInstance.hasErrors() && inventoryItemInstance.save(flush: true)) { 207 flash.message = "InventoryItem ${params.id} updated" 208 redirect(action:show,id:inventoryItemInstance.id) 209 } 210 else { 211 render(view:'edit',model:[inventoryItemInstance:inventoryItemInstance]) 212 } 213 } 214 else { 215 flash.message = "InventoryItem not found with id ${params.id}" 216 redirect(action:search) 217 } 199 return 200 } 201 202 render(view:'edit', model:[inventoryItemInstance: result.inventoryItemInstance.attach()]) 218 203 } 219 204 220 205 def create = { 221 def inventoryItemInstance = new InventoryItem() 222 inventoryItemInstance.properties = params 223 return ['inventoryItemInstance':inventoryItemInstance] 206 def result = inventoryItemService.create(params) 207 208 if(!result.error) 209 return [inventoryItemInstance: result.inventoryItemInstance] 210 211 //flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 212 redirect(action: search) 224 213 } 225 214 226 215 def save = { 227 def inventoryItemInstance = new InventoryItem(params) 228 if(!inventoryItemInstance.hasErrors() && inventoryItemInstance.save(flush: true)) { 229 flash.message = "InventoryItem ${inventoryItemInstance.id} created" 230 redirect(action:show,id:inventoryItemInstance.id) 231 } 232 else { 233 render(view:'create',model:[inventoryItemInstance:inventoryItemInstance]) 234 } 216 def result = inventoryItemService.save(params) 217 218 if(!result.error) { 219 flash.message = g.message(code: "default.create.success", args: ["InventoryItem", result.inventoryItemInstance.id]) 220 redirect(action:show, id: result.inventoryItemInstance.id) 221 return 222 } 223 224 //flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 225 render(view:'create', model:[inventoryItemInstance: result.inventoryItemInstance]) 235 226 } 236 227 … … 252 243 def p = [:] 253 244 p.id = result.inventoryMovementInstance.inventoryItem?.id 254 def r = inventoryItemService. prepareShowData(p)245 def r = inventoryItemService.show(p) 255 246 256 247 def model = [ inventoryItemInstance: r.inventoryItemInstance,
Note: See TracChangeset
for help on using the changeset viewer.