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