Changeset 383 for trunk/grails-app/controllers
- Timestamp:
- Apr 26, 2010, 6:36:49 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/studycapturing/WizardController.groovy
r368 r383 52 52 [title: 'Study'], // study 53 53 [title: 'Subjects'], // subjects 54 [title: 'Event Descriptions'], // event descriptions55 54 [title: 'Events'], // events and event grouping 56 55 [title: 'Confirmation'], // confirmation page … … 211 210 success() 212 211 } 213 }.to "event Descriptions"212 }.to "events" 214 213 on("delete") { 215 214 flash.errors = [:] … … 237 236 } 238 237 239 // render page three240 eventDescriptions {241 render(view: "_eventDescriptions")242 onRender {243 flow.page = 4244 245 if (!flow.eventDescriptions) {246 flow.eventDescriptions = []247 }248 }249 on("add") {250 // fetch classification by name (as posted by the form)251 //params.classification = Term.findByName(params.classification)252 253 /* TODO: rewrite to Event template254 255 // fetch protocol by name (as posted by the form)256 params.protocol = Protocol.findByName(params.protocol)257 258 // transform checkbox form value to boolean259 params.isSamplingEvent = (params.containsKey('isSamplingEvent'))260 261 262 // instantiate EventDescription with parameters263 def eventDescription = new EventDescription(params)264 265 // validate266 if (eventDescription.validate()) {267 def increment = flow.eventDescriptions.size()268 flow.eventDescriptions[increment] = eventDescription269 success()270 } else {271 // validation failed, feedback errors272 flash.errors = [:]273 flash.values = params274 this.appendErrors(eventDescription, flash.errors)275 error()276 }277 278 */279 }.to "eventDescriptions"280 on("delete") {281 def delete = params.get('do') as int;282 283 /* TODO: rewrite to Event template284 285 // handle form data286 if (!this.handleEventDescriptions(flow, flash, params)) {287 flash.values = params288 error()289 } else {290 success()291 }292 293 // remove eventDescription294 if (flow.eventDescriptions[ delete ] && flow.eventDescriptions[ delete ] instanceof EventDescription) {295 // remove all events based on this eventDescription296 for ( i in flow.events.size()..0 ) {297 if (flow.events[ i ] && flow.events[ i ].eventDescription == flow.eventDescriptions[ delete ]) {298 flow.events.remove(i)299 }300 }301 302 flow.eventDescriptions.remove(delete)303 }304 305 */306 }.to "eventDescriptions"307 on("previous") {308 flash.errors = [:]309 310 // handle form data311 if (!this.handleEventDescriptions(flow, flash, params)) {312 flash.values = params313 error()314 } else {315 success()316 }317 }.to "subjects"318 on("next") {319 flash.errors = [:]320 321 // check if we have at least one subject322 // and check form data323 if (flow.eventDescriptions.size() < 1) {324 // append error map325 flash.values = params326 this.appendErrorMap(['eventDescriptions': 'You need at least to create one eventDescription for your study'], flash.errors)327 error()328 } else if (!this.handleEventDescriptions(flow, flash, params)) {329 flash.values = params330 error()331 } else {332 success()333 }334 }.to "events"335 }336 337 238 // render events page 338 239 events { 339 240 render(view: "_events") 340 241 onRender { 341 flow.page = 5242 flow.page = 4 342 243 343 244 if (!flow.events) { … … 349 250 flow.eventGroups[0] = new EventGroup(name: 'Group 1') // 1 group by default 350 251 } 252 println flow.events 351 253 } 352 254 on("add") { 353 // create date instances from date string? 354 // @see WizardTagLibrary::timeElement{...} 355 if (params.get('startTime')) { 356 params.startTime = new Date().parse("d/M/yyyy HH:mm", params.get('startTime').toString()) 357 } 358 if (params.get('endTime')) { 359 params.get('endTime').toString() 360 params.endTime = new Date().parse("d/M/yyyy HH:mm", params.get('endTime').toString()) 361 } 362 363 // get eventDescription instance by name 364 params.eventDescription = this.getObjectByName(params.get('eventDescription'), flow.eventDescriptions) 365 366 // instantiate Event with parameters 367 def event = (params.eventDescription.isSamplingEvent) ? new SamplingEvent(params) : new Event(params) 368 369 // handle event groupings 370 this.handleEventGrouping(flow, flash, params) 371 372 // validate event 373 if (event.validate()) { 374 def increment = flow.events.size() 375 flow.events[increment] = event 376 success() 255 def startTime = (params.get('startTime')) ? params.startTime = new Date().parse("d/M/yyyy HH:mm", params.get('startTime').toString()) : null 256 def endTime = (params.get('endTime')) ? new Date().parse("d/M/yyyy HH:mm", params.get('endTime').toString()) : null 257 def template = params.get('template') 258 259 // handle template 260 if (template instanceof String && template.size() > 0) { 261 template = Template.findByName(template) 262 } else if (!template instanceof Template) { 263 template = null 264 } 265 266 // handle data 267 if (template && startTime && endTime) { 268 // add an event instance 269 def event = new Event( 270 template : template, 271 startTime : startTime, 272 endTime : endTime 273 ) 274 275 // validate event 276 if (event.validate()) { 277 // add event to event list 278 flow.events[ flow.events.size() ] = event 279 success() 280 } else { 281 // validation failed, feedback errors 282 flash.errors = [:] 283 flash.values = params 284 this.appendErrors(event, flash.errors) 285 error() 286 } 377 287 } else { 378 288 // validation failed, feedback errors 379 flash.errors = [:] 380 flash.values = params 381 this.appendErrors(event, flash.errors) 382 383 flash.startTime = params.startTime 384 flash.endTime = params.endTime 385 flash.eventDescription = params.eventDescription 386 289 flash.errors = [:] 290 flash.values = params 291 292 if (!template) this.appendErrorMap(['template': 'You need to select an event template'], flash.errors) 293 if (!startTime) this.appendErrorMap(['startTime': 'You need to define the start time of your study event'], flash.errors) 294 if (!endTime) this.appendErrorMap(['endTime': 'You need to define the end time of your study event'], flash.errors) 387 295 error() 388 296 } … … 448 356 // handle event groupings 449 357 this.handleEventGrouping(flow, flash, params) 450 }.to " eventDescriptions"358 }.to "subjects" 451 359 on("next") { 452 360 flash.values = params … … 470 378 render(view: "_confirmation") 471 379 onRender { 472 flow.page = 6380 flow.page = 5 473 381 } 474 382 on("toStudy").to "study"
Note: See TracChangeset
for help on using the changeset viewer.