Changeset 216 for trunk/grails-app
- Timestamp:
- Feb 26, 2010, 3:23:03 PM (13 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 4 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 -> -
trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy
r213 r216 55 55 // javascript function to call after success 56 56 def afterSuccess = attrs['afterSuccess'] 57 58 // src parameter? 59 def src = attrs['src'] 60 def alt = attrs['alt'] 57 61 58 62 // generate a normal submitToRemote button … … 89 93 if (afterSuccess) { 90 94 button = button.replaceFirst(/\.html\(data\)\;/, '.html(data);' + afterSuccess + ';') 95 } 96 97 // got an src parameter? 98 if (src) { 99 def replace = 'type="image" src="' + src + '"' 100 101 if (alt) replace = replace + ' alt="' + alt + '"' 102 103 button = button.replaceFirst(/type="button"/, replace) 91 104 } 92 105 -
trunk/grails-app/views/wizard/common/_wizard.gsp
r145 r216 18 18 <h1>Create a new study</h1> 19 19 <g:form action="pages" name="wizardForm" id="wizardForm"> 20 <g:hiddenField name="do" value="" /> 20 21 <div id="wizardPage"> 21 22 <wizard:ajaxFlowRedirect form="form#wizardForm" name="next" url="[controller:'wizard',action:'pages']" update="[success:'wizardPage',failure:'wizardError']" afterSuccess="onWizardPage()" /> -
trunk/grails-app/views/wizard/pages/_events.gsp
r213 r216 45 45 <div class="column">duration</div> 46 46 <g:if test="${eventGroups}"><g:each var="eventGroup" status="i" in="${eventGroups}"> 47 <div class="column"><g:textField name="eventGroup_${i}_name" value="${eventGroup.name}" /></div> 47 <div class="column"> 48 <g:textField name="eventGroup_${i}_name" value="${eventGroup.name}" /> 49 <wizard:ajaxButton name="deleteEventGroup" src="../images/icons/famfamfam/delete.png" alt="delete this eventgroup" class="famfamfam" value="-" url="[controller:'wizard',action:'pages']" update="[success:'wizardPage',failure:'wizardError']" before="\$(\'input[name=do]\').val(${i});" afterSuccess="onWizardPage()" /> 50 </div> 48 51 </g:each></g:if> 49 <div class="column"><wizard:ajaxButton name="addEventGroup" value="+" url="[controller:'wizard',action:'pages']" update="[success:'wizardPage',failure:'wizardError']" afterSuccess="onWizardPage()" /></div> 52 <div class="column"> 53 <wizard:ajaxButton name="addEventGroup" src="../images/icons/famfamfam/add.png" alt="add a new eventgroup" class="famfamfam" value="+" url="[controller:'wizard',action:'pages']" update="[success:'wizardPage',failure:'wizardError']" afterSuccess="onWizardPage()" /> 54 </div> 50 55 </div> 51 56 <g:each var="event" status="i" in="${events}"> … … 57 62 <div class="column">${event.getShortDuration()}</div> 58 63 <g:if test="${eventGroups}"><g:each var="eventGroup" status="j" in="${eventGroups}"> 59 <div class="column"><input type="checkbox" name="event_${i}_group_${j}"/></div> 64 <div class="column"> 65 <g:if test="${eventGroup.events.find{ it == event} }"> 66 <input type="checkbox" name="event_${i}_group_${j}" checked="checked" /> 67 </g:if><g:else> 68 <input type="checkbox" name="event_${i}_group_${j}"/> 69 </g:else> 70 </div> 60 71 </g:each></g:if> 61 72 <div class="column"></div> … … 63 74 </g:each> 64 75 </div> 76 <div class="sliderContainer"> 77 <div class="slider"/> 78 </div> 65 79 </g:if> 66 80 </wizard:pageContent>
Note: See TracChangeset
for help on using the changeset viewer.