source: trunk/grails-app/controllers/InventoryItemDetailedController.groovy @ 139

Last change on this file since 139 was 139, checked in by gav, 15 years ago

Install Navigation plugin, work on navigation and hopefully fixed a few more IE vs Firefox CSS issues.
New skin for class-diagram plugin.
Adjust security config to suite.
Replace home.gsp with start.gsp, remove options.gsp and acknowledgements.gsp as they are now on start.gsp tabs.
Create search pages for Tasks, Assets and Inventory.
Change suggested login to manager.
Change all date formats to format="EEE, dd-MMM-yyyy".

File size: 4.2 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class InventoryItemDetailedController extends BaseController {
4   
5    def index = { redirect(action:search, 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)
12        [ inventoryItemInstanceList: InventoryItem.list( params ), inventoryItemInstanceTotal: InventoryItem.count() ]
13    }
14
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
20    def show = {
21       
22        // In the case of an actionSubmit button, rewrite action name from 'index'.
23        if(params._action_Show)
24        { params.action='show' }
25       
26        def inventoryItemInstance = InventoryItem.get( params.id )
27
28        if(!inventoryItemInstance) {
29            flash.message = "InventoryItem not found with id ${params.id}"
30            redirect(action:search)
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"
41                redirect(action:search)
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}"
50            redirect(action:search)
51        }
52    }
53
54    def edit = {
55       
56        // In the case of an actionSubmit button, rewrite action name from 'index'.
57        if(params._action_Edit)
58        { params.action='edit' }
59       
60        def inventoryItemInstance = InventoryItem.get( params.id )
61
62        if(!inventoryItemInstance) {
63            flash.message = "InventoryItem not found with id ${params.id}"
64            redirect(action:search)
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}
Note: See TracBrowser for help on using the repository browser.