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