Changeset 155
- Timestamp:
- Feb 2, 2010, 10:31:02 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/studycapturing/EventController.groovy
r153 r155 66 66 67 67 68 // This action is not complete yet. 69 // (1) Need to include Sampling events. 70 // (2) This probably causes orphened PrtocolPrameters that have to be delt with. 71 // (3) Parts of this might have to be moved into the Domain object's save() method. 72 // (4) The correspoding view's params are bloated and contain redundancy. 73 // (5) The whole thing should be moved to update. 74 // (6) A "create" should be added. 75 68 76 def save = { 69 println "In EventController.save: ${params}" 77 78 def event = Event.get(params["id"]) 79 80 81 if( event==null ) { // this is an entirely new event 82 render(action: "list", total:Event.count() ) 83 } 84 70 85 params["startTime"] = parseDate(params["startTime"]) // parse the date strings 71 86 params["endTime"] = parseDate(params["endTime"]) 72 87 73 def eventInstance = new Event(params) 74 75 println params.protocolInstance 76 // If a protocol instnace already exists, 77 // update this event's parameter values. 78 if(params.protocolInstance != null) { 79 params.protocolInstance.each { id, value -> 80 println id + " " + value 81 def parameter = ProtocolParameterInstance.get(id) 82 parameter.value=value 83 parameter.save() 84 } 85 } 86 87 if (eventInstance.save(flush: true)) { 88 flash.message = "${message(code: 'default.created.message', args: [message(code: 'event.label', default: 'Event'), eventInstance.id])}" 89 redirect(action: "show", id: eventInstance.id) 90 } 91 else { 92 render(view: "create", model: [eventInstance: eventInstance]) 93 } 94 render(view: "create", model: [eventInstance: eventInstance]) 95 } 88 89 // the Subject is automatically parsed 90 // update Event Description 91 def oldProtocol=event.eventDescription.protocol.id.toString() 92 def newProtocol=params["protocol.id"] 93 def protocolParameters = params["protocolParameter"] 94 95 96 if(oldProtocol<=>newProtocol) { // protocol id changed 97 event.eventDescription=EventDescription.get(newProtocol) 98 event.parameterStringValues.clear() // this does not propagate orphened parameters 99 def protocol=Protocol.get(newProtocol) 100 protocolParameters.each{ key, value -> 101 def parameter=ProtocolParameter.get(key) 102 event.parameterStringValues[key] = value 103 } 104 } 105 else // protocol is the same, values changed 106 { 107 protocolParameters.each{ key, value -> 108 def parameter=ProtocolParameter.get(key) 109 event.parameterStringValues[key]=value 110 } 111 112 } 113 114 println "parameterStringValues: " + event.parameterStringValues 115 116 println "Old Protocol: " + event.eventDescription.protocol.id 117 println "New Protocol: " + params["protocol.id"] 118 119 120 println "Old: " 121 println event.parameterStringValues.each { 122 k,v -> println "${k}: ${v}\n" 123 } 124 125 println "New:" 126 protocolParameters.each{ 127 k,v -> println "${k}: ${v}\n" 128 } 129 130 if (event.save(flush: true)) { 131 flash.message = "${message(code: 'default.created.message', args: [message(code: 'event.label', default: 'Event'), event.id])}" 132 redirect(action: "show", id: event.id) 133 } 134 135 render(action: "list", total:Event.count() ) 136 } 137 138 96 139 97 140 … … 139 182 return [eventInstance:eventInstance, testo:params.clone(), sDate:sDate, eDate:eDate, description:description ] 140 183 } 141 142 184 else 143 185 { … … 202 244 203 245 def showSample = { 246 def samples = null 204 247 def event = Event.get(params.id) 205 if( event instanceof SamplingEvent ) { render( view:"showSample", model:[samples:event.samples] ) } 206 else { render( view:"showNewSample" ) } 248 // user wants this Event to be a SamplingEvent? 249 def wantSample = params.wantSample <=>'no'?true:false 250 print wantSample 251 if( event.isSamplingEvent() ) { 252 samples=event.samples 253 println "yes ${event.id}" 254 } 255 else println "no ${event.id}" 256 257 render( view:"showSample", model:[samples:samples,wantSample:wantSample] ) 207 258 } 208 259
Note: See TracChangeset
for help on using the changeset viewer.