source: trunk/grails-app/controllers/EntryDetailedController.groovy @ 127

Last change on this file since 127 was 98, checked in by gav, 16 years ago

Installed help-balloons plugin.
Adjust security config to allow javascript and help-balloons folders.
Add "Repeat password" to change password.
Detailed Entry views, including only allow user to edit their own entries.
Adjust Entry constraints.
Add comments to layouts/main.gsp.
Work on TaskDetailed? view to show entry durations and allow editing.
Entry duration formatting to CSS and increased base font size to 14px.

File size: 3.4 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class EntryDetailedController extends BaseController {
4
5    def authenticateService
6   
7    def index = { redirect(action:list,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        if(!params.max) params.max = 10
14        [ entryInstanceList: Entry.list( params ) ]
15    }
16
17    def show = {
18        def entryInstance = Entry.get( params.id )
19
20        if(!entryInstance) {
21            flash.message = "Entry not found with id ${params.id}"
22            redirect(action:list)
23        }
24        else { return [ entryInstance : entryInstance ] }
25    }
26
27    def delete = {
28        def entryInstance = Entry.get( params.id )
29        if(entryInstance) {
30            if(entryInstance.enteredBy.loginName == authenticateService.userDomain().loginName) {
31                entryInstance.delete()
32                flash.message = "Entry ${params.id} deleted"
33                redirect(action:list)
34            }
35            else {
36                flash.message = "You may only delete your own entries."
37                redirect(action:show,id:entryInstance.id)
38            }
39
40        }
41        else {
42            flash.message = "Entry not found with id ${params.id}"
43            redirect(action:list)
44        }
45    }
46
47    def edit = {
48        def entryInstance = Entry.get( params.id )
49        if(!entryInstance) {
50                flash.message = "Entry not found with id ${params.id}"
51                redirect(action:list)
52        }
53        else {
54
55            if(entryInstance.enteredBy.loginName == authenticateService.userDomain().loginName) {
56                return [ entryInstance : entryInstance ]
57            }
58            else {
59                flash.message = "You may only edit your own entries."
60                redirect(action:show,id:entryInstance.id)
61            }
62
63        }
64    }
65
66    def update = {
67        def entryInstance = Entry.get( params.id )
68        if(entryInstance) {
69            entryInstance.properties = params
70            if(!entryInstance.hasErrors() && entryInstance.save()) {
71                flash.message = "Entry ${params.id} updated"
72                redirect(action:show,id:entryInstance.id)
73            }
74            else {
75                render(view:'edit',model:[entryInstance:entryInstance])
76            }
77        }
78        else {
79            flash.message = "Entry not found with id ${params.id}"
80            redirect(action:edit,id:params.id)
81        }
82    }
83
84    def create = {
85        try {
86            def taskInstance = Task.get(params.taskInstance.id)
87            def entryInstance = new Entry()
88            entryInstance.task = taskInstance
89            return ['entryInstance':entryInstance]
90        }
91        catch(Exception e) {
92            flash.message = "Please select a task, then 'Add Entry'"
93            redirect(controller:"taskDetailed", action:"list")
94        }
95    }
96
97    def save = {
98        def entryInstance = new Entry(params)
99
100        entryInstance.enteredBy = Person.get(authenticateService.userDomain().id)
101        if(!entryInstance.hasErrors() && entryInstance.save()) {
102            flash.message = "Entry ${entryInstance.id} created"
103            redirect(controller:"taskDetailed", action:"show", id: params.task.id)
104        }
105        else {
106            render(view:'create',model:[entryInstance:entryInstance])
107        }
108    }
109}
Note: See TracBrowser for help on using the repository browser.