| [118] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured | 
|---|
 | 2 |  | 
|---|
| [124] | 3 | class AssetDetailedController extends BaseController { | 
|---|
| [156] | 4 |  | 
|---|
 | 5 |     def filterService | 
|---|
 | 6 |  | 
|---|
| [139] | 7 |     def index = { redirect(action:search,params:params) } | 
|---|
| [118] | 8 |  | 
|---|
 | 9 |     // the delete, save and update actions only accept POST requests | 
|---|
 | 10 |     static allowedMethods = [delete:'POST', save:'POST', update:'POST'] | 
|---|
 | 11 |  | 
|---|
 | 12 |     def list = { | 
|---|
 | 13 |         params.max = Math.min( params.max ? params.max.toInteger() : 10,  100) | 
|---|
 | 14 |         [ assetInstanceList: Asset.list( params ), assetInstanceTotal: Asset.count() ] | 
|---|
 | 15 |     } | 
|---|
 | 16 |  | 
|---|
| [139] | 17 |     def search = { | 
|---|
 | 18 |         params.max = Math.min( params.max ? params.max.toInteger() : 10,  100) | 
|---|
| [156] | 19 |  | 
|---|
 | 20 |         // Quick Search: | 
|---|
 | 21 |         if(!params.filter) { | 
|---|
 | 22 |            return [ assetInstanceList: Asset.list( params ), assetInstanceTotal: Asset.count() ] | 
|---|
 | 23 |         } | 
|---|
 | 24 |         // filterPane: | 
|---|
 | 25 |         return[ assetInstanceList: filterService.filter( params, Asset ), | 
|---|
 | 26 |                 assetInstanceTotal: filterService.count( params, Asset ), | 
|---|
 | 27 |                 filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), | 
|---|
 | 28 |                 params:params ] | 
|---|
| [139] | 29 |     } | 
|---|
 | 30 |  | 
|---|
| [118] | 31 |     def show = { | 
|---|
| [139] | 32 |          | 
|---|
 | 33 |         // In the case of an actionSubmit button, rewrite action name from 'index'. | 
|---|
 | 34 |         if(params._action_Show) | 
|---|
 | 35 |         { params.action='show' } | 
|---|
 | 36 |          | 
|---|
| [118] | 37 |         def assetInstance = Asset.get( params.id ) | 
|---|
 | 38 |  | 
|---|
 | 39 |         if(!assetInstance) { | 
|---|
 | 40 |             flash.message = "Asset not found with id ${params.id}" | 
|---|
| [139] | 41 |             redirect(action:search) | 
|---|
| [118] | 42 |         } | 
|---|
 | 43 |         else { return [ assetInstance : assetInstance ] } | 
|---|
 | 44 |     } | 
|---|
 | 45 |  | 
|---|
 | 46 |     def delete = { | 
|---|
 | 47 |         def assetInstance = Asset.get( params.id ) | 
|---|
 | 48 |         if(assetInstance) { | 
|---|
 | 49 |             try { | 
|---|
| [161] | 50 |                 assetInstance.delete(flush:true) | 
|---|
| [118] | 51 |                 flash.message = "Asset ${params.id} deleted" | 
|---|
| [139] | 52 |                 redirect(action:search) | 
|---|
| [118] | 53 |             } | 
|---|
 | 54 |             catch(org.springframework.dao.DataIntegrityViolationException e) { | 
|---|
 | 55 |                 flash.message = "Asset ${params.id} could not be deleted" | 
|---|
 | 56 |                 redirect(action:show,id:params.id) | 
|---|
 | 57 |             } | 
|---|
 | 58 |         } | 
|---|
 | 59 |         else { | 
|---|
 | 60 |             flash.message = "Asset not found with id ${params.id}" | 
|---|
| [139] | 61 |             redirect(action:search) | 
|---|
| [118] | 62 |         } | 
|---|
 | 63 |     } | 
|---|
 | 64 |  | 
|---|
 | 65 |     def edit = { | 
|---|
| [139] | 66 |          | 
|---|
 | 67 |         // In the case of an actionSubmit button, rewrite action name from 'index'. | 
|---|
 | 68 |         if(params._action_Edit) | 
|---|
 | 69 |         { params.action='edit' } | 
|---|
 | 70 |          | 
|---|
| [118] | 71 |         def assetInstance = Asset.get( params.id ) | 
|---|
 | 72 |  | 
|---|
 | 73 |         if(!assetInstance) { | 
|---|
 | 74 |             flash.message = "Asset not found with id ${params.id}" | 
|---|
| [139] | 75 |             redirect(action:search) | 
|---|
| [118] | 76 |         } | 
|---|
 | 77 |         else { | 
|---|
 | 78 |             return [ assetInstance : assetInstance ] | 
|---|
 | 79 |         } | 
|---|
 | 80 |     } | 
|---|
 | 81 |  | 
|---|
 | 82 |     def update = { | 
|---|
 | 83 |         def assetInstance = Asset.get( params.id ) | 
|---|
 | 84 |         if(assetInstance) { | 
|---|
 | 85 |             if(params.version) { | 
|---|
 | 86 |                 def version = params.version.toLong() | 
|---|
 | 87 |                 if(assetInstance.version > version) { | 
|---|
 | 88 |                      | 
|---|
 | 89 |                     assetInstance.errors.rejectValue("version", "asset.optimistic.locking.failure", "Another user has updated this Asset while you were editing.") | 
|---|
 | 90 |                     render(view:'edit',model:[assetInstance:assetInstance]) | 
|---|
 | 91 |                     return | 
|---|
 | 92 |                 } | 
|---|
 | 93 |             } | 
|---|
 | 94 |             assetInstance.properties = params | 
|---|
 | 95 |             if(!assetInstance.hasErrors() && assetInstance.save()) { | 
|---|
 | 96 |                 flash.message = "Asset ${params.id} updated" | 
|---|
 | 97 |                 redirect(action:show,id:assetInstance.id) | 
|---|
 | 98 |             } | 
|---|
 | 99 |             else { | 
|---|
 | 100 |                 render(view:'edit',model:[assetInstance:assetInstance]) | 
|---|
 | 101 |             } | 
|---|
 | 102 |         } | 
|---|
 | 103 |         else { | 
|---|
 | 104 |             flash.message = "Asset not found with id ${params.id}" | 
|---|
| [161] | 105 |             redirect(action:list) | 
|---|
| [118] | 106 |         } | 
|---|
 | 107 |     } | 
|---|
 | 108 |  | 
|---|
 | 109 |     def create = { | 
|---|
 | 110 |         def assetInstance = new Asset() | 
|---|
 | 111 |         assetInstance.properties = params | 
|---|
 | 112 |         return ['assetInstance':assetInstance] | 
|---|
 | 113 |     } | 
|---|
 | 114 |  | 
|---|
 | 115 |     def save = { | 
|---|
 | 116 |         def assetInstance = new Asset(params) | 
|---|
 | 117 |         if(!assetInstance.hasErrors() && assetInstance.save()) { | 
|---|
 | 118 |             flash.message = "Asset ${assetInstance.id} created" | 
|---|
 | 119 |             redirect(action:show,id:assetInstance.id) | 
|---|
 | 120 |         } | 
|---|
 | 121 |         else { | 
|---|
 | 122 |             render(view:'create',model:[assetInstance:assetInstance]) | 
|---|
 | 123 |         } | 
|---|
 | 124 |     } | 
|---|
 | 125 | } | 
|---|