source: trunk/src/grails-app/controllers/EntryController.groovy @ 56

Last change on this file since 56 was 49, checked in by gav, 16 years ago

Work on Task logic and entry creation

File size: 2.5 KB
RevLine 
[40]1class EntryController extends BaseController {
2
3    def beforeInterceptor = [action:this.&auth]
4
[21]5    def index = { redirect(action:list,params:params) }
[16]6
[21]7    // the delete, save and update actions only accept POST requests
8    def allowedMethods = [delete:'POST', save:'POST', update:'POST']
9
10    def list = {
11        if(!params.max) params.max = 10
12        [ entryInstanceList: Entry.list( params ) ]
13    }
14
15    def show = {
16        def entryInstance = Entry.get( params.id )
17
18        if(!entryInstance) {
19            flash.message = "Entry not found with id ${params.id}"
20            redirect(action:list)
21        }
22        else { return [ entryInstance : entryInstance ] }
23    }
24
25    def delete = {
26        def entryInstance = Entry.get( params.id )
27        if(entryInstance) {
28            entryInstance.delete()
29            flash.message = "Entry ${params.id} deleted"
30            redirect(action:list)
31        }
32        else {
33            flash.message = "Entry not found with id ${params.id}"
34            redirect(action:list)
35        }
36    }
37
38    def edit = {
39        def entryInstance = Entry.get( params.id )
40
41        if(!entryInstance) {
42            flash.message = "Entry not found with id ${params.id}"
43            redirect(action:list)
44        }
45        else {
46            return [ entryInstance : entryInstance ]
47        }
48    }
49
50    def update = {
51        def entryInstance = Entry.get( params.id )
52        if(entryInstance) {
53            entryInstance.properties = params
54            if(!entryInstance.hasErrors() && entryInstance.save()) {
55                flash.message = "Entry ${params.id} updated"
56                redirect(action:show,id:entryInstance.id)
57            }
58            else {
59                render(view:'edit',model:[entryInstance:entryInstance])
60            }
61        }
62        else {
63            flash.message = "Entry not found with id ${params.id}"
64            redirect(action:edit,id:params.id)
65        }
66    }
67
68    def create = {
69        def entryInstance = new Entry()
70        entryInstance.properties = params
71        return ['entryInstance':entryInstance]
72    }
73
74    def save = {
75        def entryInstance = new Entry(params)
[49]76            entryInstance.person = Person.findByUserId(session.userId)
77
[21]78        if(!entryInstance.hasErrors() && entryInstance.save()) {
79            flash.message = "Entry ${entryInstance.id} created"
80            redirect(action:show,id:entryInstance.id)
81        }
82        else {
83            render(view:'create',model:[entryInstance:entryInstance])
84        }
85    }
[16]86}
Note: See TracBrowser for help on using the repository browser.