Changeset 216 for trunk/grails-app/controllers
- Timestamp:
- Feb 26, 2010, 3:23:03 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/studycapturing/WizardController.groovy
r213 r216 52 52 [title: 'Event Descriptions'], // event descriptions 53 53 [title: 'Events'], // events 54 [title: 'Confirmation'], 54 [title: 'Confirmation'], // confirmation page 55 55 [title: 'Done'] // finish page 56 56 ] … … 271 271 272 272 // get eventDescription instance by name 273 params.eventDescription = this.getObjectByName(params.get('eventDescription'), flow.eventDescriptions)273 params.eventDescription = this.getObjectByName(params.get('eventDescription'), flow.eventDescriptions) 274 274 275 275 // instantiate Event with parameters 276 276 def event = new Event(params) 277 278 // handle event groupings 279 this.handleEventGrouping(flow, flash, params) 277 280 278 281 // validate event … … 287 290 this.appendErrors(event, flash.errors) 288 291 289 flash.startTime 290 flash.endTime 291 flash.eventDescription 292 292 flash.startTime = params.startTime 293 flash.endTime = params.endTime 294 flash.eventDescription = params.eventDescription 295 293 296 error() 294 297 } … … 296 299 on("addEventGroup") { 297 300 def increment = flow.eventGroups.size() 298 flow.eventGroups[ increment ] = new EventGroup(name: "Group "+(increment+1)) 301 def groupName = "Group " + (increment + 1) 302 303 // check if group name exists 304 def nameExists = true 305 def u = 0 306 307 // make sure a unique name is generated 308 while (nameExists) { 309 u++ 310 def count = 0 311 312 flow.eventGroups.each() { 313 if (it.name == groupName) { 314 groupName = "Group " + (increment + 1) + "," + u 315 } else { 316 count++ 317 } 318 } 319 320 nameExists = !(count == flow.eventGroups.size()) 321 } 322 323 flow.eventGroups[increment] = new EventGroup(name: groupName) 324 }.to "events" 325 on("deleteEventGroup") { 326 def delete = params.get('do') as int; 327 328 // handle event groupings 329 this.handleEventGrouping(flow, flash, params) 330 331 // remove the group with this specific id 332 if (flow.eventGroups[delete] && flow.eventGroups[delete] instanceof EventGroup) { 333 // remove this eventGroup 334 flow.eventGroups.remove(delete) 335 } 299 336 }.to "events" 300 337 on("previous") { 301 // TODO 338 // handle event groupings 339 this.handleEventGrouping(flow, flash, params) 302 340 }.to "eventDescriptions" 303 341 on("next") { 304 342 flash.errors = new LinkedHashMap() 343 344 // handle event groupings 345 this.handleEventGrouping(flow, flash, params) 305 346 306 347 // check if we have at least one subject … … 312 353 error() 313 354 } 314 }.to " confirm"355 }.to "events" 315 356 } 316 357 … … 338 379 // TODO 339 380 }.to "confirm" 381 } 382 } 383 384 /** 385 * re-usable code for handling event grouping in a web flow 386 * @param Map LocalAttributeMap (the flow scope) 387 * @param Map localAttributeMap (the flash scope) 388 * @param Map GrailsParameterMap (the flow parameters = form data) 389 * @returns boolean 390 */ 391 def handleEventGrouping(flow, flash, params) { 392 // walk through eventGroups 393 def g = 0 394 flow.eventGroups.each() { 395 def e = 0 396 def eventGroup = it 397 398 // reset events 399 eventGroup.events = new HashSet() 400 401 // walk through events 402 flow.events.each() { 403 if (params.get('event_' + e + '_group_' + g) == 'on') { 404 eventGroup.addToEvents(it) 405 //} else { 406 // eventGroup.events.minus(it) 407 } 408 e++ 409 } 410 g++ 340 411 } 341 412 } … … 396 467 397 468 flow.eventDescriptions.each() { 398 it.name 399 it.description 400 it.classification 401 it.isSamplingEvent 469 it.name = params.get('eventDescription_' + id + '_name') 470 it.description = params.get('eventDescription_' + id + '_description') 471 it.classification = Term.findByName(params.get('eventDescription_' + id + '_classification')) 472 it.isSamplingEvent = (params.containsKey('eventDescription_' + id + '_isSamplingEvent')) 402 473 403 474 // validate eventDescription … … 443 514 // yeah, also mention the first 444 515 // occurrence in the error message 445 this.appendErrorMap(name: 'The subject name needs to be unique!', flash.errors, 'subject_' +names[it.name]['firstId']+'_')516 this.appendErrorMap(name: 'The subject name needs to be unique!', flash.errors, 'subject_' + names[it.name]['firstId'] + '_') 446 517 } 447 518 448 519 // add to error map 449 this.appendErrorMap([name: 'The subject name needs to be unique!'], flash.errors, 'subject_' +id+'_')520 this.appendErrorMap([name: 'The subject name needs to be unique!'], flash.errors, 'subject_' + id + '_') 450 521 errors = true 451 522 } … … 502 573 } 503 574 504 505 575 /** 506 576 * return the object from a map of objects by searching for a name 507 * @param String 508 * @param Map 577 * @param String name 578 * @param Map map of objects 509 579 * @return Object 510 580 */ … … 545 615 this.appendErrorMap(this.getHumanReadableErrors(object), map) 546 616 } 617 547 618 def appendErrors(object, map, prepend) { 548 619 this.appendErrorMap(this.getHumanReadableErrors(object), map, prepend) … … 560 631 } 561 632 } 633 562 634 def appendErrorMap(map, mapToExtend, prepend) { 563 635 map.each() {key, value ->
Note: See TracChangeset
for help on using the changeset viewer.