[118] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
[268] | 3 | class AssetSubItemController extends BaseAppAdminController { |
---|
[118] | 4 | |
---|
| 5 | def index = { redirect(action:list,params:params) } |
---|
| 6 | |
---|
| 7 | // the delete, save and update actions only accept POST requests |
---|
| 8 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
| 9 | |
---|
| 10 | def list = { |
---|
| 11 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
[268] | 12 | [ assetSubItemInstanceList: AssetSubItem.list( params ), assetSubItemInstanceTotal: AssetSubItem.count() ] |
---|
[118] | 13 | } |
---|
| 14 | |
---|
| 15 | def show = { |
---|
[268] | 16 | def assetSubItemInstance = AssetSubItem.get( params.id ) |
---|
[118] | 17 | |
---|
[268] | 18 | if(!assetSubItemInstance) { |
---|
| 19 | flash.message = "AssetSubItem not found with id ${params.id}" |
---|
[118] | 20 | redirect(action:list) |
---|
| 21 | } |
---|
[268] | 22 | else { return [ assetSubItemInstance : assetSubItemInstance ] } |
---|
[118] | 23 | } |
---|
| 24 | |
---|
| 25 | def delete = { |
---|
[268] | 26 | def assetSubItemInstance = AssetSubItem.get( params.id ) |
---|
| 27 | if(assetSubItemInstance) { |
---|
[118] | 28 | try { |
---|
[268] | 29 | assetSubItemInstance.delete(flush:true) |
---|
| 30 | flash.message = "AssetSubItem ${params.id} deleted" |
---|
[118] | 31 | redirect(action:list) |
---|
| 32 | } |
---|
| 33 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
[268] | 34 | flash.message = "AssetSubItem ${params.id} could not be deleted" |
---|
[118] | 35 | redirect(action:show,id:params.id) |
---|
| 36 | } |
---|
| 37 | } |
---|
| 38 | else { |
---|
[268] | 39 | flash.message = "AssetSubItem not found with id ${params.id}" |
---|
[118] | 40 | redirect(action:list) |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | def edit = { |
---|
[268] | 45 | def assetSubItemInstance = AssetSubItem.get( params.id ) |
---|
[118] | 46 | |
---|
[268] | 47 | if(!assetSubItemInstance) { |
---|
| 48 | flash.message = "AssetSubItem not found with id ${params.id}" |
---|
[118] | 49 | redirect(action:list) |
---|
| 50 | } |
---|
| 51 | else { |
---|
[268] | 52 | return [ assetSubItemInstance : assetSubItemInstance ] |
---|
[118] | 53 | } |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | def update = { |
---|
[268] | 57 | def assetSubItemInstance = AssetSubItem.get( params.id ) |
---|
| 58 | if(assetSubItemInstance) { |
---|
[118] | 59 | if(params.version) { |
---|
| 60 | def version = params.version.toLong() |
---|
[268] | 61 | if(assetSubItemInstance.version > version) { |
---|
[118] | 62 | |
---|
[268] | 63 | assetSubItemInstance.errors.rejectValue("version", "assetSubItem.optimistic.locking.failure", "Another user has updated this AssetSubItem while you were editing.") |
---|
| 64 | render(view:'edit',model:[assetSubItemInstance:assetSubItemInstance]) |
---|
[118] | 65 | return |
---|
| 66 | } |
---|
| 67 | } |
---|
[268] | 68 | assetSubItemInstance.properties = params |
---|
| 69 | if(!assetSubItemInstance.hasErrors() && assetSubItemInstance.save(flush: true)) { |
---|
| 70 | flash.message = "AssetSubItem ${params.id} updated" |
---|
| 71 | redirect(action:show,id:assetSubItemInstance.id) |
---|
[118] | 72 | } |
---|
| 73 | else { |
---|
[268] | 74 | render(view:'edit',model:[assetSubItemInstance:assetSubItemInstance]) |
---|
[118] | 75 | } |
---|
| 76 | } |
---|
| 77 | else { |
---|
[268] | 78 | flash.message = "AssetSubItem not found with id ${params.id}" |
---|
[160] | 79 | redirect(action:list) |
---|
[118] | 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | def create = { |
---|
[268] | 84 | def assetSubItemInstance = new AssetSubItem() |
---|
| 85 | assetSubItemInstance.properties = params |
---|
| 86 | return ['assetSubItemInstance':assetSubItemInstance] |
---|
[118] | 87 | } |
---|
| 88 | |
---|
| 89 | def save = { |
---|
[268] | 90 | def assetSubItemInstance = new AssetSubItem(params) |
---|
| 91 | if(!assetSubItemInstance.hasErrors() && assetSubItemInstance.save(flush: true)) { |
---|
| 92 | flash.message = "AssetSubItem ${assetSubItemInstance.id} created" |
---|
| 93 | redirect(action:show,id:assetSubItemInstance.id) |
---|
[118] | 94 | } |
---|
| 95 | else { |
---|
[268] | 96 | render(view:'create',model:[assetSubItemInstance:assetSubItemInstance]) |
---|
[118] | 97 | } |
---|
| 98 | } |
---|
| 99 | } |
---|