Changeset 284 for trunk/grails-app
- Timestamp:
- Jan 21, 2010, 11:25:46 AM (15 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/AssetDetailedController.groovy
r283 r284 234 234 235 235 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) 239 243 } 240 244 241 245 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) 255 253 } 256 254 257 255 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) 270 257 271 258 if(!result.error) { … … 275 262 } 276 263 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 277 277 if(result.error.code == "default.not.found") { 278 278 flash.message = g.message(code: result.error.code, args: ["Asset", params.assetToCopy?.id]) -
trunk/grails-app/i18n/messages.properties
r278 r284 9 9 asset.copy.method.help=Link creates a new asset and links it to EXISTING sub items. \ 10 10 While copy creates a new asset and new sub items. 11 asset.copy.asset.required=Please select an asset to copy. 11 12 12 13 sub.task.create.confirm=Immediately create and save a new sub task? -
trunk/grails-app/services/AssetService.groovy
r278 r284 2 2 3 3 boolean transactional = false 4 5 def create(params) { 6 def result = [:] 7 def fail = { Map m -> 8 result.error = [ code: m.code, args: ["Asset", params.id] ] 9 return result 10 } 11 12 result.assetInstance = new Asset() 13 result.assetInstance.properties = params 14 15 // success 16 return result 17 } 18 19 def copy(params) { 20 def result = [:] 21 def fail = { Map m -> 22 result.error = [ code: m.code, args: ["Asset", params.id] ] 23 return result 24 } 25 26 result.assetToCopy = Asset.get(params.assetToCopy?.id) 27 28 if(!result.assetToCopy) 29 return fail(code: "asset.copy.asset.required") 30 31 result.assetInstance = new Asset(name: result.assetToCopy.name, 32 description: result.assetToCopy.description, 33 section: result.assetToCopy.section) 34 35 result.assetInstance.properties = params 36 37 // success 38 return result 39 } 40 41 def save(params) { 42 def result = [:] 43 def fail = { Map m -> 44 if(result.assetInstance && m.field) 45 result.assetInstance.errors.rejectValue(m.field, m.code) 46 result.error = [ code: m.code, args: ["Asset", params.id] ] 47 return result 48 } 49 50 result.assetInstance = new Asset(params) 51 52 if(result.assetInstance.hasErrors() || !result.assetInstance.save(flush: true)) 53 return fail(code:"default.create.failure") 54 55 // success 56 return result 57 } 4 58 5 59 def saveCopy(params) { -
trunk/grails-app/taglib/AssetTreeTagLib.groovy
r282 r284 81 81 img(src: addImg(), alt: 'Add', title: 'Add Sub Item') 82 82 } 83 a(href: assetCopyLink(asset.id)) { 84 img(src: copyImg(), alt: 'Add', title: 'Copy Asset') 85 } 83 86 } // li 84 87 … … 240 243 } 241 244 242 def sectionCreateLink( id) {243 createLink(controller: 'sectionDetailed', action: 'create', params: [' id': id] ).toString()245 def sectionCreateLink(siteId) { 246 createLink(controller: 'sectionDetailed', action: 'create', params: ['site.id': siteId] ).toString() 244 247 } 245 248 … … 252 255 } 253 256 254 def assetCreateLink( id) {255 createLink(controller: 'assetDetailed', action: 'create', params: [' id': id] ).toString()257 def assetCreateLink(sectionId) { 258 createLink(controller: 'assetDetailed', action: 'create', params: ['section.id': sectionId] ).toString() 256 259 } 257 260 … … 265 268 266 269 def assetCopyLink(id) { 267 createLink(controller: 'assetDetailed', action: 'copy', params: ['asset .id': id] ).toString()270 createLink(controller: 'assetDetailed', action: 'copy', params: ['assetToCopy.id': id] ).toString() 268 271 } 269 272 -
trunk/grails-app/views/assetDetailed/overview.gsp
r278 r284 14 14 </div> 15 15 <div class="body"> 16 <g:if test="${flash.message}"> 17 <div class="message">${flash.message}</div> 18 </g:if> 16 <g:render template="/shared/messages" /> 19 17 20 18 <div class="dialog"> -
trunk/grails-app/views/assetDetailed/search.gsp
r271 r284 15 15 </div> 16 16 <div class="body"> 17 <g:if test="${flash.message}"> 18 <div class="message">${flash.message}</div> 19 </g:if> 17 <g:render template="/shared/messages" /> 18 20 19 <filterpane:currentCriteria domainBean="Asset" 21 20 action="search" -
trunk/grails-app/views/shared/_assetTree.gsp
r278 r284 5 5 <img src="${resource(dir:'images/skin',file:'database_add.png')}" alt="Add" title="Add Sub Item"/> 6 6 </g:link> 7 <g:link params="['asset .id':assetInstance?.id]" action="copy">7 <g:link params="['assetToCopy.id':assetInstance?.id]" action="copy"> 8 8 <img src="${resource(dir:'images/skin',file:'page_copy.png')}" alt="Copy" title="Copy Asset"/> 9 9 </g:link>
Note: See TracChangeset
for help on using the changeset viewer.