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 | |
---|
50 | def protocol = ( params.protocolid) ? Protocol.get(params.protocolid) : Protocol.find("for Protocol id") |
---|
51 | def event = Event.get(params.id) |
---|
52 | def protocolInstance = event.eventDescription.protocol |
---|
53 | |
---|
54 | if( protocolInstance && protocolInstance && protocol.id==protocolInstance.id ) { |
---|
55 | def parameterStringValues = event.parameterStringValues |
---|
56 | render( view:"showMyProtocolFilled", model:["protocolInstance":protocolInstance,"event":event,"parameterStringValues":parameterStringValues] ) |
---|
57 | } |
---|
58 | else { |
---|
59 | if(protocol!=null) render( view: "showMyProtocolEmpty", model:["protocolInstance":protocol] ) |
---|
60 | else render( "NULL" ) |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | def edit = { |
---|
66 | def eventDescriptionInstance = EventDescription.get(params.id) |
---|
67 | if (!eventDescriptionInstance) { |
---|
68 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), params.id])}" |
---|
69 | redirect(action: "list") |
---|
70 | } |
---|
71 | else { |
---|
72 | return [eventDescriptionInstance: eventDescriptionInstance] |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | def update = { |
---|
77 | def eventDescriptionInstance = EventDescription.get(params.id) |
---|
78 | if (eventDescriptionInstance) { |
---|
79 | if (params.version) { |
---|
80 | def version = params.version.toLong() |
---|
81 | if (eventDescriptionInstance.version > version) { |
---|
82 | |
---|
83 | 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") |
---|
84 | render(view: "edit", model: [eventDescriptionInstance: eventDescriptionInstance]) |
---|
85 | return |
---|
86 | } |
---|
87 | } |
---|
88 | eventDescriptionInstance.properties = params |
---|
89 | if (!eventDescriptionInstance.hasErrors() && eventDescriptionInstance.save(flush: true)) { |
---|
90 | flash.message = "${message(code: 'default.updated.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), eventDescriptionInstance.id])}" |
---|
91 | redirect(action: "show", id: eventDescriptionInstance.id) |
---|
92 | } |
---|
93 | else { |
---|
94 | render(view: "edit", model: [eventDescriptionInstance: eventDescriptionInstance]) |
---|
95 | } |
---|
96 | } |
---|
97 | else { |
---|
98 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), params.id])}" |
---|
99 | redirect(action: "list") |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | def delete = { |
---|
104 | def eventDescriptionInstance = EventDescription.get(params.id) |
---|
105 | if (eventDescriptionInstance) { |
---|
106 | try { |
---|
107 | eventDescriptionInstance.delete(flush: true) |
---|
108 | flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), params.id])}" |
---|
109 | redirect(action: "list") |
---|
110 | } |
---|
111 | catch (org.springframework.dao.DataIntegrityViolationException e) { |
---|
112 | flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), params.id])}" |
---|
113 | redirect(action: "show", id: params.id) |
---|
114 | } |
---|
115 | } |
---|
116 | else { |
---|
117 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'eventDescription.label', default: 'EventDescription'), params.id])}" |
---|
118 | redirect(action: "list") |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | def test = { println "test" |
---|
124 | render("test") } |
---|
125 | } |
---|