Changeset 285 for trunk/grails-app/controllers
- Timestamp:
- Jan 21, 2010, 1:38:57 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/AssetSubItemDetailedController.groovy
r276 r285 2 2 3 3 class AssetSubItemDetailedController extends BaseController { 4 4 5 def assetSubItemService 6 5 7 def index = { redirect(controller: "assetDetailed", params:params) } 6 8 … … 27 29 } 28 30 catch(org.springframework.dao.DataIntegrityViolationException e) { 29 flash. message = "AssetSubItem ${params.id} could not be deleted"31 flash.errorMessage = "AssetSubItem ${params.id} could not be deleted" 30 32 redirect(action:show,id:params.id) 31 33 } … … 110 112 111 113 def create = { 112 def assetSubItemInstance = new AssetSubItem() 113 assetSubItemInstance.properties = params 114 return ['assetSubItemInstance':assetSubItemInstance] 114 def result = assetSubItemService.create(params) 115 116 if(!result.error) 117 return [assetSubItemInstance: result.assetSubItemInstance, assetInstance: result.assetInstance] 118 119 flash.message = g.message(code: result.error.code, args: result.error.args) 120 redirect(controller: 'assetDetailed', action: 'search') 115 121 } 116 122 117 123 def save = { 118 def assetSubItemInstance = new AssetSubItem(params)124 def result = assetSubItemService.save(params) 119 125 120 // if(!assetSubItemInstance.asset && !assetSubItemInstance.parentItem) { 121 // flash.message = "Either an asset or parentItem is required." 122 // render(view:'create',model:[assetSubItemInstance:assetSubItemInstance]) 123 // return 124 // } 125 // 126 // if(assetSubItemInstance.asset && assetSubItemInstance.parentItem) { 127 // flash.message = "Both an asset and parentItem may not be specified at the same time." 128 // render(view:'create',model:[assetSubItemInstance:assetSubItemInstance]) 129 // return 130 // } 126 if(!result.error) { 127 // Success. 128 flash.message = g.message(code: "default.create.success", args: ["AssetSubItem", result.assetSubItemInstance.name]) 131 129 132 if(!assetSubItemInstance.hasErrors() && assetSubItemInstance.save(flush: true)) { 133 flash.message = "AssetSubItem ${assetSubItemInstance.id} created" 134 135 if(assetSubItemInstance.assets) 136 redirect(controller: "assetDetailed", action:"show", id: assetSubItemInstance.assets.toArray()[0].id) 130 /// @todo: This just grabs the first parent in an unsorted list and needs improving. 131 if(result.assetSubItemInstance.assets) 132 redirect(controller: "assetDetailed", action:"show", id: result.assetSubItemInstance.assets.toArray()[0].id) 137 133 else { 138 134 //Get the top parentItem. 139 def parentItem = assetSubItemInstance.parentItem135 def parentItem = result.assetSubItemInstance.parentItem 140 136 def i = 0 141 137 while(parentItem?.parentItem) { … … 150 146 redirect(controller: "assetDetailed", action:"show", id: parentItem.assets.toArray()[0].id) 151 147 else 152 redirect(action:"show", id: assetSubItemInstance.id) // End stop if all else fails.148 redirect(action:"show", id: result.assetSubItemInstance.id) // End stop if all else fails. 153 149 } 150 return 151 } 154 152 155 }156 else {157 render(view:'create',model:[assetSubItemInstance:assetSubItemInstance]) 158 }159 } // end save()153 if(result.error.code == "assetSubItem.asset.not.found") 154 flash.errorMessage = g.message(code: "default.create.success") 155 156 render(view:'create', model:[assetSubItemInstance: result.assetSubItemInstance, assetInstance: result.assetInstance]) 157 } 160 158 161 159 } // end class
Note: See TracChangeset
for help on using the changeset viewer.