source: trunk/grails-app/controllers/AssetDetailedController.groovy @ 149

Last change on this file since 149 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: 3.7 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class AssetDetailedController 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        [ assetInstanceList: Asset.list( params ), assetInstanceTotal: Asset.count() ]
13    }
14
15    def search = {
16        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
17        [ assetInstanceList: Asset.list( params ), assetInstanceTotal: Asset.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 assetInstance = Asset.get( params.id )
27
28        if(!assetInstance) {
29            flash.message = "Asset not found with id ${params.id}"
30            redirect(action:search)
31        }
32        else { return [ assetInstance : assetInstance ] }
33    }
34
35    def delete = {
36        def assetInstance = Asset.get( params.id )
37        if(assetInstance) {
38            try {
39                assetInstance.delete()
40                flash.message = "Asset ${params.id} deleted"
41                redirect(action:search)
42            }
43            catch(org.springframework.dao.DataIntegrityViolationException e) {
44                flash.message = "Asset ${params.id} could not be deleted"
45                redirect(action:show,id:params.id)
46            }
47        }
48        else {
49            flash.message = "Asset 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 assetInstance = Asset.get( params.id )
61
62        if(!assetInstance) {
63            flash.message = "Asset not found with id ${params.id}"
64            redirect(action:search)
65        }
66        else {
67            return [ assetInstance : assetInstance ]
68        }
69    }
70
71    def update = {
72        def assetInstance = Asset.get( params.id )
73        if(assetInstance) {
74            if(params.version) {
75                def version = params.version.toLong()
76                if(assetInstance.version > version) {
77                   
78                    assetInstance.errors.rejectValue("version", "asset.optimistic.locking.failure", "Another user has updated this Asset while you were editing.")
79                    render(view:'edit',model:[assetInstance:assetInstance])
80                    return
81                }
82            }
83            assetInstance.properties = params
84            if(!assetInstance.hasErrors() && assetInstance.save()) {
85                flash.message = "Asset ${params.id} updated"
86                redirect(action:show,id:assetInstance.id)
87            }
88            else {
89                render(view:'edit',model:[assetInstance:assetInstance])
90            }
91        }
92        else {
93            flash.message = "Asset not found with id ${params.id}"
94            redirect(action:edit,id:params.id)
95        }
96    }
97
98    def create = {
99        def assetInstance = new Asset()
100        assetInstance.properties = params
101        return ['assetInstance':assetInstance]
102    }
103
104    def save = {
105        def assetInstance = new Asset(params)
106        if(!assetInstance.hasErrors() && assetInstance.save()) {
107            flash.message = "Asset ${assetInstance.id} created"
108            redirect(action:show,id:assetInstance.id)
109        }
110        else {
111            render(view:'create',model:[assetInstance:assetInstance])
112        }
113    }
114}
Note: See TracBrowser for help on using the repository browser.