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

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

Resolve ticket #12 again.
Turn query cache on again since this did not resolve the problem.
Implement fix as per http://jira.codehaus.org/browse/GRAILS-5111, add flush:true to save.
Adjust templates to include above and remove home url.
Re-generate all non detailed views and controllers.
Manually add flush:true and remove home url to detailed views and controllers.

File size: 4.2 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class AssetDetailedController extends BaseController {
4
5    def filterService
6
7    def index = { redirect(action:search,params:params) }
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        [ assetInstanceList: Asset.list( params ), assetInstanceTotal: Asset.count() ]
15    }
16
17    def search = {
18        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
19
20        // Quick Search:
21        if(!params.filter) {
22           return [ assetInstanceList: Asset.list( params ), assetInstanceTotal: Asset.count() ]
23        }
24        // filterPane:
25        return[ assetInstanceList: filterService.filter( params, Asset ),
26                assetInstanceTotal: filterService.count( params, Asset ),
27                filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params),
28                params:params ]
29    }
30
31    def show = {
32       
33        // In the case of an actionSubmit button, rewrite action name from 'index'.
34        if(params._action_Show)
35        { params.action='show' }
36       
37        def assetInstance = Asset.get( params.id )
38
39        if(!assetInstance) {
40            flash.message = "Asset not found with id ${params.id}"
41            redirect(action:search)
42        }
43        else { return [ assetInstance : assetInstance ] }
44    }
45
46    def delete = {
47        def assetInstance = Asset.get( params.id )
48        if(assetInstance) {
49            try {
50                assetInstance.delete(flush:true)
51                flash.message = "Asset ${params.id} deleted"
52                redirect(action:search)
53            }
54            catch(org.springframework.dao.DataIntegrityViolationException e) {
55                flash.message = "Asset ${params.id} could not be deleted"
56                redirect(action:show,id:params.id)
57            }
58        }
59        else {
60            flash.message = "Asset not found with id ${params.id}"
61            redirect(action:search)
62        }
63    }
64
65    def edit = {
66       
67        // In the case of an actionSubmit button, rewrite action name from 'index'.
68        if(params._action_Edit)
69        { params.action='edit' }
70       
71        def assetInstance = Asset.get( params.id )
72
73        if(!assetInstance) {
74            flash.message = "Asset not found with id ${params.id}"
75            redirect(action:search)
76        }
77        else {
78            return [ assetInstance : assetInstance ]
79        }
80    }
81
82    def update = {
83        def assetInstance = Asset.get( params.id )
84        if(assetInstance) {
85            if(params.version) {
86                def version = params.version.toLong()
87                if(assetInstance.version > version) {
88                   
89                    assetInstance.errors.rejectValue("version", "asset.optimistic.locking.failure", "Another user has updated this Asset while you were editing.")
90                    render(view:'edit',model:[assetInstance:assetInstance])
91                    return
92                }
93            }
94            assetInstance.properties = params
95            if(!assetInstance.hasErrors() && assetInstance.save(flush: true)) {
96                flash.message = "Asset ${params.id} updated"
97                redirect(action:show,id:assetInstance.id)
98            }
99            else {
100                render(view:'edit',model:[assetInstance:assetInstance])
101            }
102        }
103        else {
104            flash.message = "Asset not found with id ${params.id}"
105            redirect(action:list)
106        }
107    }
108
109    def create = {
110        def assetInstance = new Asset()
111        assetInstance.properties = params
112        return ['assetInstance':assetInstance]
113    }
114
115    def save = {
116        def assetInstance = new Asset(params)
117        if(!assetInstance.hasErrors() && assetInstance.save(flush: true)) {
118            flash.message = "Asset ${assetInstance.id} created"
119            redirect(action:show,id:assetInstance.id)
120        }
121        else {
122            render(view:'create',model:[assetInstance:assetInstance])
123        }
124    }
125}
Note: See TracBrowser for help on using the repository browser.