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

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

Add filterPane to Asset and Inventory search views.

File size: 4.6 KB
RevLine 
[116]1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class InventoryItemDetailedController extends BaseController {
[156]4
5    def filterService
6
[139]7    def index = { redirect(action:search, params:params) }
[116]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        [ inventoryItemInstanceList: InventoryItem.list( params ), inventoryItemInstanceTotal: InventoryItem.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[ inventoryItemInstanceList: InventoryItem.list( params ), inventoryItemInstanceTotal: InventoryItem.count() ]
23        }
24        // filterPane:
25        return[ inventoryItemInstanceList: filterService.filter( params, InventoryItem ),
26                inventoryItemInstanceTotal: filterService.count( params, InventoryItem ),
27                filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params),
28                params:params ]
[139]29    }
30
[116]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       
[116]37        def inventoryItemInstance = InventoryItem.get( params.id )
38
39        if(!inventoryItemInstance) {
40            flash.message = "InventoryItem not found with id ${params.id}"
[139]41            redirect(action:search)
[116]42        }
43        else { return [ inventoryItemInstance : inventoryItemInstance ] }
44    }
45
46    def delete = {
47        def inventoryItemInstance = InventoryItem.get( params.id )
48        if(inventoryItemInstance) {
49            try {
50                inventoryItemInstance.delete()
51                flash.message = "InventoryItem ${params.id} deleted"
[139]52                redirect(action:search)
[116]53            }
54            catch(org.springframework.dao.DataIntegrityViolationException e) {
55                flash.message = "InventoryItem ${params.id} could not be deleted"
56                redirect(action:show,id:params.id)
57            }
58        }
59        else {
60            flash.message = "InventoryItem not found with id ${params.id}"
[139]61            redirect(action:search)
[116]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       
[116]71        def inventoryItemInstance = InventoryItem.get( params.id )
72
73        if(!inventoryItemInstance) {
74            flash.message = "InventoryItem not found with id ${params.id}"
[139]75            redirect(action:search)
[116]76        }
77        else {
78            return [ inventoryItemInstance : inventoryItemInstance ]
79        }
80    }
81
82    def update = {
83        def inventoryItemInstance = InventoryItem.get( params.id )
84        if(inventoryItemInstance) {
85            if(params.version) {
86                def version = params.version.toLong()
87                if(inventoryItemInstance.version > version) {
88                   
89                    inventoryItemInstance.errors.rejectValue("version", "inventoryItem.optimistic.locking.failure", "Another user has updated this InventoryItem while you were editing.")
90                    render(view:'edit',model:[inventoryItemInstance:inventoryItemInstance])
91                    return
92                }
93            }
94            inventoryItemInstance.properties = params
95            if(!inventoryItemInstance.hasErrors() && inventoryItemInstance.save()) {
96                flash.message = "InventoryItem ${params.id} updated"
97                redirect(action:show,id:inventoryItemInstance.id)
98            }
99            else {
100                render(view:'edit',model:[inventoryItemInstance:inventoryItemInstance])
101            }
102        }
103        else {
104            flash.message = "InventoryItem not found with id ${params.id}"
105            redirect(action:edit,id:params.id)
106        }
107    }
108
109    def create = {
110        def inventoryItemInstance = new InventoryItem()
111        inventoryItemInstance.properties = params
112        return ['inventoryItemInstance':inventoryItemInstance]
113    }
114
115    def save = {
116        def inventoryItemInstance = new InventoryItem(params)
117        if(!inventoryItemInstance.hasErrors() && inventoryItemInstance.save()) {
118            flash.message = "InventoryItem ${inventoryItemInstance.id} created"
119            redirect(action:show,id:inventoryItemInstance.id)
120        }
121        else {
122            render(view:'create',model:[inventoryItemInstance:inventoryItemInstance])
123        }
124    }
125}
Note: See TracBrowser for help on using the repository browser.