Changeset 350 for trunk/grails-app
- Timestamp:
- Feb 10, 2010, 5:09:22 AM (15 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/AssetDetailedController.groovy
r334 r350 232 232 */ 233 233 def delete = { 234 def assetInstance = Asset.get( params.id)235 if(assetInstance) { 236 try{237 assetInstance.delete(flush:true)238 flash.message = "Asset ${params.id} deleted"239 redirect(action:search)240 241 catch(org.springframework.dao.DataIntegrityViolationException e) { 242 flash.message = "Asset ${params.id} could not be deleted"243 redirect(action:show,id:params.id) 244 }245 }246 else {247 flash.message = "Asset not found with id ${params.id}"248 redirect(action:search) 249 }234 def result = assetService.delete(params) 235 236 if(!result.error) { 237 flash.message = g.message(code: "default.delete.success", args: ["Asset", params.id]) 238 redirect(action:search) 239 return 240 } 241 242 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 243 244 if(result.error.code == "default.not.found") { 245 redirect(action:search) 246 return 247 } 248 249 redirect(action:show, id: params.id) 250 250 } 251 251 -
trunk/grails-app/i18n/messages.properties
r347 r350 11 11 asset.copy.asset.required=Please select an asset to copy. 12 12 13 maintenanceActions.still.associated=Could not complete operation as maintenance actions are still associated with this item. 14 15 asset.subItems.delete.failure=Could not complete operation as orphan sub items failed to delete. 16 13 17 assetSubItem.asset.not.found=Could not complete operation as an asset was supplied but not found. 14 18 assetSubItem.assets.associated=Could not complete operation as assets are still associated with this sub item. 15 assetSubItem.maintenanceActions.associated=Could not complete operation as maintenance actions are still associated with this sub item.16 19 17 20 sub.task.create.confirm=Immediately create and save a new sub task? -
trunk/grails-app/services/AssetService.groovy
r329 r350 2 2 3 3 boolean transactional = false 4 5 def assetSubItemService 4 6 5 7 /** … … 13 15 } 14 16 } 17 18 def delete(params) { 19 Asset.withTransaction { status -> 20 def result = [:] 21 22 def fail = { Map m -> 23 status.setRollbackOnly() 24 if(result.assetInstance && m.field) 25 result.assetInstance.errors.rejectValue(m.field, m.code) 26 result.error = [ code: m.code, args: ["Asset", params.id] ] 27 return result 28 } 29 30 result.assetInstance = Asset.get(params.id) 31 32 if(!result.assetInstance) 33 return fail(code:"default.not.found") 34 35 if(result.assetInstance.maintenanceActions) 36 return fail(code:"maintenanceActions.still.associated") 37 38 // Remove orphan assetSubItems. 39 def assetSubItems = new ArrayList(result.assetInstance.assetSubItems) // avoid ConcurrentModificationException. 40 def r 41 for(assetSubItem in assetSubItems) { 42 result.assetInstance.removeFromAssetSubItems(assetSubItem) 43 if(!assetSubItem.assets && !assetSubItem.parentItem) { 44 r = assetSubItemService.delete(id: assetSubItem.id) 45 if(r.error) { 46 fail(code:"asset.subItems.delete.failure") 47 break 48 } 49 } 50 } 51 52 if(result.error) 53 return result 54 55 try { 56 result.assetInstance.delete(flush:true) 57 return result //Success. 58 } 59 catch(org.springframework.dao.DataIntegrityViolationException e) { 60 return fail(code:"default.delete.failure") 61 } 62 63 } // end withTransaction 64 } // end delete() 15 65 16 66 def create(params) { … … 164 214 return result 165 215 166 } // end withTransaction216 } // end withTransaction 167 217 } // end saveCopySrvce 168 218 -
trunk/grails-app/services/AssetSubItemService.groovy
r347 r350 19 19 20 20 if(result.assetSubItemInstance.maintenanceActions) 21 return fail(code:" assetSubItem.maintenanceActions.associated")21 return fail(code:"maintenanceActions.still.associated") 22 22 23 23 try {
Note: See TracChangeset
for help on using the changeset viewer.