Changeset 278 for trunk/grails-app/controllers
- Timestamp:
- Jan 20, 2010, 8:34:36 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/AssetDetailedController.groovy
r271 r278 7 7 def filterService 8 8 def exportService 9 10 def index = { redirect(action:search,params:params) } 9 def assetService 10 11 def index = { redirect(action:overview,params:params) } 11 12 12 13 // the delete, save and update actions only accept POST requests … … 14 15 15 16 def importAssetTree = { 17 } 18 def overview = { 16 19 } 17 20 … … 245 248 } 246 249 247 def assetInstance = new Asset(name: assetToCopy.name, section: assetToCopy.section) 250 def assetInstance = new Asset(name: assetToCopy.name, 251 description: assetToCopy.description, 252 section: assetToCopy.section) 248 253 assetInstance.properties = params 249 254 return ['assetInstance':assetInstance, assetToCopy: assetToCopy] … … 262 267 263 268 def saveCopy = { 264 def result = saveCopySrvce(params)269 def result = assetService.saveCopy(params) 265 270 266 271 if(!result.error) { … … 276 281 } 277 282 283 if(result.error.code != "default.create.failure") { 284 flash.warning = g.message(code: result.error.code, args: ["Asset"]) 285 } 286 278 287 render(view:'copy', model:[assetInstance: result.assetInstance, assetToCopy: result.assetToCopy]) 279 288 } 280 289 281 def saveCopySrvce(params) {282 Asset.withTransaction { status ->283 def result = [:]284 285 def fail = { Map m ->286 status.setRollbackOnly()287 if(result.assetInstance && m.field)288 result.assetInstance.errors.rejectValue(m.field, m.code)289 result.error = [ code: m.code, args: ["Asset", params.id] ]290 return result291 }292 293 result.assetToCopy = Asset.get(params.assetToCopy?.id)294 if(!result.assetToCopy)295 return fail(code:"default.not.found")296 297 result.assetInstance = new Asset(params)298 299 if(result.assetInstance.hasErrors() || !result.assetInstance.save())300 return fail(code:"default.create.failure")301 302 def assetSubItemInstance1303 304 // Copy subItems from level 2 and bellow.305 def copyAssetSubItem = { assetSubItemToCopy, parentItem ->306 def assetSubItemInstance = new AssetSubItem(name: assetSubItemToCopy.name,307 description: assetSubItemToCopy.description,308 parentItem: parentItem)309 310 if(assetSubItemInstance.hasErrors() || !assetSubItemInstance.save())311 return fail(field:"subItems", code:"default.create.failure")312 313 def i = 0314 for(assetSubItem in assetSubItemToCopy.subItems) {315 call(assetSubItem, assetSubItemInstance)316 // Protect against endless recurrsion.317 i++318 if(i > 100)319 fail(code:"default.create.failure")320 // Stop if an error is flagged.321 if(result.error)322 break323 }324 } //copyAssetSubItem325 326 // Copy the 1st level of subItems.327 def copyAssetSubItem1 = { assetSubItemToCopy ->328 assetSubItemInstance1 = new AssetSubItem(name: assetSubItemToCopy.name,329 description: assetSubItemToCopy.description,330 asset: result.assetInstance)331 332 if(assetSubItemInstance1.hasErrors() || !assetSubItemInstance1.save())333 return fail(field:"assetSubItems", code:"default.create.failure")334 335 def i = 0336 for(assetSubItem in assetSubItemToCopy.subItems) {337 copyAssetSubItem(assetSubItem, assetSubItemInstance1)338 // Protect against endless recurrsion.339 i++340 if(i > 100)341 fail(code:"default.create.failure")342 // Stop if an error is flagged.343 if(result.error)344 break345 }346 } //copyAssetSubItem1347 348 def i = 0349 for(assetSubItem in result.assetToCopy.assetSubItems) {350 copyAssetSubItem1(assetSubItem)351 // Protect against endless recurrsion.352 i++353 if(i > 100)354 fail(code:"default.create.failure")355 // Stop if an error is flagged.356 if(result.error)357 break358 }359 360 // Success or not.361 return result362 363 } //end withTransaction364 } // end saveCopySrvce365 366 290 } // end class
Note: See TracChangeset
for help on using the changeset viewer.