1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
2 | |
---|
3 | class 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 | entryInstance.delete() |
---|
31 | flash.message = "Entry ${params.id} deleted" |
---|
32 | redirect(action:list) |
---|
33 | } |
---|
34 | else { |
---|
35 | flash.message = "Entry not found with id ${params.id}" |
---|
36 | redirect(action:list) |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | def edit = { |
---|
41 | def entryInstance = Entry.get( params.id ) |
---|
42 | |
---|
43 | if(!entryInstance) { |
---|
44 | flash.message = "Entry not found with id ${params.id}" |
---|
45 | redirect(action:list) |
---|
46 | } |
---|
47 | else { |
---|
48 | return [ entryInstance : entryInstance ] |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | def update = { |
---|
53 | def entryInstance = Entry.get( params.id ) |
---|
54 | if(entryInstance) { |
---|
55 | entryInstance.properties = params |
---|
56 | if(!entryInstance.hasErrors() && entryInstance.save()) { |
---|
57 | flash.message = "Entry ${params.id} updated" |
---|
58 | redirect(action:show,id:entryInstance.id) |
---|
59 | } |
---|
60 | else { |
---|
61 | render(view:'edit',model:[entryInstance:entryInstance]) |
---|
62 | } |
---|
63 | } |
---|
64 | else { |
---|
65 | flash.message = "Entry not found with id ${params.id}" |
---|
66 | redirect(action:edit,id:params.id) |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | def create = { |
---|
71 | def entryInstance = new Entry() |
---|
72 | entryInstance.properties = params |
---|
73 | return ['entryInstance':entryInstance] |
---|
74 | } |
---|
75 | |
---|
76 | def save = { |
---|
77 | def entryInstance = new Entry(params) |
---|
78 | |
---|
79 | entryInstance.enteredBy = Person.get(authenticateService.userDomain().id) |
---|
80 | if(!entryInstance.hasErrors() && entryInstance.save()) { |
---|
81 | flash.message = "Entry ${entryInstance.id} created" |
---|
82 | redirect(controller:"taskDetailed", action:"show", id: params.task.id) |
---|
83 | } |
---|
84 | else { |
---|
85 | render(view:'create',model:[entryInstance:entryInstance]) |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|