Ignore:
Timestamp:
Jan 21, 2010, 11:25:46 AM (15 years ago)
Author:
gav
Message:

Move asset copy and create functions into AssetService.
Repair create links in AssetTreeTagLib.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/AssetDetailedController.groovy

    r283 r284  
    234234
    235235    def create = {
    236         def assetInstance = new Asset()
    237         assetInstance.properties = params
    238         return ['assetInstance':assetInstance]
     236        def result = assetService.create(params)
     237
     238        if(!result.error)
     239            return [assetInstance: result.assetInstance]
     240
     241        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     242        redirect(action: search)
    239243    }
    240244
    241245    def copy = {
    242         def assetToCopy = Asset.get(params.asset.id)
    243 
    244         if(!assetToCopy) {
    245             flash.message = "Please select an asset to copy."
    246             redirect(action: list)
    247             return
    248         }
    249 
    250         def assetInstance = new Asset(name: assetToCopy.name,
    251                                                             description: assetToCopy.description,
    252                                                             section: assetToCopy.section)
    253         assetInstance.properties = params
    254         return ['assetInstance':assetInstance, assetToCopy: assetToCopy]
     246        def result = assetService.copy(params)
     247
     248        if(!result.error)
     249            return [assetInstance: result.assetInstance, assetToCopy: result.assetToCopy]
     250
     251        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     252        redirect(action: search)
    255253    }
    256254
    257255    def save = {
    258         def assetInstance = new Asset(params)
    259         if(!assetInstance.hasErrors() && assetInstance.save(flush: true)) {
    260             flash.message = "Asset ${assetInstance.id} created"
    261             redirect(action:show,id:assetInstance.id)
    262         }
    263         else {
    264             render(view:'create',model:[assetInstance:assetInstance])
    265         }
    266     }
    267 
    268     def saveCopy = {
    269         def result = assetService.saveCopy(params)
     256        def result = assetService.save(params)
    270257
    271258        if(!result.error) {
     
    275262        }
    276263
     264        render(view:'create', model:[assetInstance: result.assetInstance])
     265    }
     266
     267
     268    def saveCopy = {
     269        def result = assetService.saveCopy(params)
     270
     271        if(!result.error) {
     272            flash.message = g.message(code: "default.create.success", args: ["Asset", result.assetInstance.id])
     273            redirect(action:show, id: result.assetInstance.id)
     274            return
     275        }
     276
    277277        if(result.error.code == "default.not.found") {
    278278            flash.message = g.message(code: result.error.code, args: ["Asset", params.assetToCopy?.id])
Note: See TracChangeset for help on using the changeset viewer.