1 | package dbnp.studycapturing |
---|
2 | import dbnp.data.Term |
---|
3 | |
---|
4 | class EventDescriptionController { |
---|
5 | |
---|
6 | static allowedMethods = [save: "POST", update: "POST", delete: "POST"] |
---|
7 | |
---|
8 | def index = { |
---|
9 | redirect(action: "list", params: params) |
---|
10 | } |
---|
11 | |
---|
12 | def list = { |
---|
13 | params.max = Math.min(params.max ? params.int('max') : 10, 100) |
---|
14 | [eventDescriptionInstanceList: EventDescription.list(params), eventDescriptionInstanceTotal: EventDescription.count()] |
---|
15 | } |
---|
16 | |
---|
17 | def create = { |
---|
18 | def eventDescriptionInstance = new EventDescription() |
---|
19 | eventDescriptionInstance.properties = params |
---|
20 | return [eventDescriptionInstance: eventDescriptionInstance] |
---|
21 | } |
---|
22 | |
---|
23 | def save = { |
---|
24 | def eventDescriptionInstance = new EventDescription(params) |
---|
25 | if (eventDescriptionInstance.save(flush: true)) { |
---|
26 | flash.message = "${message(code: 'default.created.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), eventDescriptionInstance.id])}" |
---|
27 | redirect(action: "show", id: eventDescriptionInstance.id) |
---|
28 | } |
---|
29 | else { |
---|
30 | render(view: "create", model: [eventDescriptionInstance: eventDescriptionInstance]) |
---|
31 | } |
---|
32 | } |
---|
33 | |
---|
34 | def show = { |
---|
35 | |
---|
36 | def eventDescriptionInstance = EventDescription.get(params.id) |
---|
37 | if (!eventDescriptionInstance) { |
---|
38 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), params.id])}" |
---|
39 | redirect(action: "list") |
---|
40 | } |
---|
41 | |
---|
42 | else { |
---|
43 | [eventDescriptionInstance: eventDescriptionInstance, params:params] |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | def showMyProtocol = { |
---|
49 | def description = EventDescription.get(params.id) |
---|
50 | if( description.protocol==null ) { |
---|
51 | protocol = new Protocol() |
---|
52 | render( view:"showMyProtocolEmpty", model:[protocol:protocol,description:description] ) |
---|
53 | } |
---|
54 | else { |
---|
55 | render( view: "showMyProtocolFilled", model:[protocol:description.protocol,description:description] ) |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | def showMyProtocolEmpty = { |
---|
61 | println "in showMyProtocolEmpty" |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | def showMyProtocolFilled = { |
---|
66 | println "in showMyProtocolFilled" |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | def edit = { |
---|
74 | def eventDescriptionInstance = EventDescription.get(params.id) |
---|
75 | if (!eventDescriptionInstance) { |
---|
76 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), params.id])}" |
---|
77 | redirect(action: "list") |
---|
78 | } |
---|
79 | else { |
---|
80 | return [eventDescriptionInstance: eventDescriptionInstance] |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | def update = { |
---|
85 | def eventDescriptionInstance = EventDescription.get(params.id) |
---|
86 | if (eventDescriptionInstance) { |
---|
87 | if (params.version) { |
---|
88 | def version = params.version.toLong() |
---|
89 | if (eventDescriptionInstance.version > version) { |
---|
90 | |
---|
91 | eventDescriptionInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'eventDescription.label', default: 'EventDescription')] as Object[], "Another user has updated this EventDescription while you were editing") |
---|
92 | render(view: "edit", model: [eventDescriptionInstance: eventDescriptionInstance]) |
---|
93 | return |
---|
94 | } |
---|
95 | } |
---|
96 | eventDescriptionInstance.properties = params |
---|
97 | if (!eventDescriptionInstance.hasErrors() && eventDescriptionInstance.save(flush: true)) { |
---|
98 | flash.message = "${message(code: 'default.updated.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), eventDescriptionInstance.id])}" |
---|
99 | redirect(action: "show", id: eventDescriptionInstance.id) |
---|
100 | } |
---|
101 | else { |
---|
102 | render(view: "edit", model: [eventDescriptionInstance: eventDescriptionInstance]) |
---|
103 | } |
---|
104 | } |
---|
105 | else { |
---|
106 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), params.id])}" |
---|
107 | redirect(action: "list") |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | def delete = { |
---|
112 | def eventDescriptionInstance = EventDescription.get(params.id) |
---|
113 | if (eventDescriptionInstance) { |
---|
114 | try { |
---|
115 | eventDescriptionInstance.delete(flush: true) |
---|
116 | flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), params.id])}" |
---|
117 | redirect(action: "list") |
---|
118 | } |
---|
119 | catch (org.springframework.dao.DataIntegrityViolationException e) { |
---|
120 | flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), params.id])}" |
---|
121 | redirect(action: "show", id: params.id) |
---|
122 | } |
---|
123 | } |
---|
124 | else { |
---|
125 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), params.id])}" |
---|
126 | redirect(action: "list") |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | def test = { render(params) } |
---|
132 | |
---|
133 | def test2 = { |
---|
134 | def eventDescriptionInstance = EventDescription.get(params.id) |
---|
135 | if (!eventDescriptionInstance) { |
---|
136 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), params.id])}" |
---|
137 | redirect(action: "list") |
---|
138 | } |
---|
139 | else { |
---|
140 | return [eventDescriptionInstance: eventDescriptionInstance] |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | |
---|
145 | def addProtocolParameter = { |
---|
146 | render( action:"showProtocolParameters", model:['addNew':true] ) |
---|
147 | } |
---|
148 | |
---|
149 | |
---|
150 | def showProtocolParameters = { |
---|
151 | println params |
---|
152 | |
---|
153 | def description = EventDescription.get(params.id) |
---|
154 | def protocol = description.protocol==null ? new Protocol() : description.protocol |
---|
155 | |
---|
156 | if( params['addOneParameter']=='true') { // add a new parameter |
---|
157 | println "adding" |
---|
158 | def parameter = new ProtocolParameter() |
---|
159 | protocol.addToParameters(parameter) |
---|
160 | } |
---|
161 | |
---|
162 | def list = [] |
---|
163 | protocol.parameters.each { |
---|
164 | list.add(it) |
---|
165 | list.sort{ a,b -> a.name <=> b.name } |
---|
166 | } |
---|
167 | |
---|
168 | render( view:"showProtocolParameters", model:[protocol:protocol,description:description,list:list] ) |
---|
169 | } |
---|
170 | |
---|
171 | } |
---|