- Timestamp:
- Mar 8, 2010, 6:25:07 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy
r240 r246 46 46 * @param Closure body 47 47 */ 48 def ajaxButton = { 48 def ajaxButton = {attrs, body -> 49 49 // get the jQuery version 50 50 def jQueryVersion = grailsApplication.getMetadata()['plugins.jquery'] … … 87 87 button = button.replaceFirst(/data\:jQuery/, "data:\'_eventId_${elementName}=1&\'+jQuery") 88 88 } 89 89 90 90 // add an after success function call? 91 91 // usefull for performing actions on success data (hence on refreshed … … 106 106 // replace double semi colons 107 107 button = button.replaceAll(/;{2,}/, ';') 108 108 109 109 // render button 110 110 out << button … … 116 116 * @see WizardTagLib::baseElement (ajaxSubmitOnChange) 117 117 */ 118 def ajaxSubmitJs = { 118 def ajaxSubmitJs = {attrs, body -> 119 119 // define AJAX provider 120 120 setProvider([library: ajaxProvider]) … … 130 130 131 131 // strip the button part to only leave the Ajax call 132 button = button.replaceFirst(/<[^\"]*\"jQuery.ajax/, 'jQuery.ajax')133 button = button.replaceFirst(/return false.*/, '')132 button = button.replaceFirst(/<[^\"]*\"jQuery.ajax/, 'jQuery.ajax') 133 button = button.replaceFirst(/return false.*/, '') 134 134 135 135 // change form if a form attribute is present … … 166 166 * Example initial webflow action to work with this javascript: 167 167 * ... 168 * mainPage { 169 * render(view: "/wizard/index") 170 * onRender { 171 * flow.page = 1 172 * } 173 * on("next").to "pageOne" 174 * } 175 * ... 168 * mainPage {* render(view: "/wizard/index") 169 * onRender {* flow.page = 1 170 *}* on("next").to "pageOne" 171 *}* ... 176 172 * 177 173 * @param Map attributes 178 174 * @param Closure body 179 175 */ 180 def ajaxFlowRedirect = { 176 def ajaxFlowRedirect = {attrs, body -> 181 177 // generate javascript 182 178 out << '<script type="text/javascript">' … … 207 203 /** 208 204 * generate a base form element 209 * @param String 210 * @param Map 211 * @param Closure 212 */ 213 def baseElement = { 205 * @param String inputElement name 206 * @param Map attributes 207 * @param Closure help content 208 */ 209 def baseElement = {inputElement, attrs, help -> 214 210 // work variables 215 211 def description = attrs.remove('description') 216 212 def addExampleElement = attrs.remove('addExampleElement') 217 def addExample2Element 213 def addExample2Element = attrs.remove('addExample2Element') 218 214 219 215 // got an ajax onchange action? … … 247 243 out << ' <div class="input">' 248 244 out << renderedElement 249 if (help()) {245 if (help()) { 250 246 out << ' <div class="helpIcon"></div>' 251 247 } … … 255 251 if (addExampleElement) { 256 252 def exampleAttrs = new LinkedHashMap() 257 exampleAttrs.name = attrs.get('name') +'Example'258 exampleAttrs.class 253 exampleAttrs.name = attrs.get('name') + 'Example' 254 exampleAttrs.class = 'isExample' 259 255 exampleAttrs.disabled = 'disabled' 260 256 exampleAttrs.size = 30 … … 266 262 if (addExample2Element) { 267 263 def exampleAttrs = new LinkedHashMap() 268 exampleAttrs.name = attrs.get('name') +'Example2'269 exampleAttrs.class 264 exampleAttrs.name = attrs.get('name') + 'Example2' 265 exampleAttrs.class = 'isExample' 270 266 exampleAttrs.disabled = 'disabled' 271 267 exampleAttrs.size = 30 … … 290 286 * @param Closure body (help text) 291 287 */ 292 def textFieldElement = { 288 def textFieldElement = {attrs, body -> 293 289 // set default size, or scale to max length if it is less than the default size 294 290 if (!attrs.get("size")) { … … 308 304 } 309 305 310 311 306 /** 312 307 * render a select form element … … 314 309 * @param Closure body (help text) 315 310 */ 316 def selectElement = { 311 def selectElement = {attrs, body -> 317 312 baseElement.call( 318 313 'select', … … 327 322 * @param Closure body (help text) 328 323 */ 329 def checkBoxElement = { 324 def checkBoxElement = {attrs, body -> 330 325 baseElement.call( 331 326 'checkBox', … … 341 336 * @param Closure body (help text) 342 337 */ 343 def dateElement = { 338 def dateElement = {attrs, body -> 344 339 // transform value? 345 340 if (attrs.value instanceof Date) { … … 347 342 attrs.value = String.format('%td/%<tm/%<tY', attrs.value) 348 343 } 349 344 350 345 // set some textfield values 351 346 attrs.maxlength = (attrs.maxlength) ? attrs.maxlength : 10 352 347 attrs.addExampleElement = true 353 348 354 349 // render a normal text field 355 350 //out << textFieldElement(attrs,body) … … 366 361 * @param Closure body (help text) 367 362 */ 368 def timeElement = { 363 def timeElement = {attrs, body -> 369 364 // transform value? 370 365 if (attrs.value instanceof Date) { … … 384 379 ) 385 380 } 386 381 387 382 /** 388 383 * Template form element 389 * @param Map 390 * @param Closure 391 */ 392 def speciesElement = { 384 * @param Map attributes 385 * @param Closure help content 386 */ 387 def speciesElement = {attrs, body -> 393 388 // render template element 394 389 baseElement.call( … … 401 396 /** 402 397 * Button form element 403 * @param Map 404 * @param Closure 405 */ 406 def buttonElement = { 398 * @param Map attributes 399 * @param Closure help content 400 */ 401 def buttonElement = {attrs, body -> 407 402 // render template element 408 403 baseElement.call( … … 417 412 * @param Map attrs 418 413 */ 419 def speciesSelect = { 414 def speciesSelect = {attrs -> 420 415 // fetch the speciesOntology 421 416 // note that this is a bit nasty, probably the ontologyName should … … 437 432 /** 438 433 * Template form element 439 * @param Map 440 * @param Closure 441 */ 442 def templateElement = { 434 * @param Map attributes 435 * @param Closure help content 436 */ 437 def templateElement = {attrs, body -> 443 438 // render template element 444 439 baseElement.call( … … 448 443 ) 449 444 } 450 445 451 446 /** 452 447 * render a template select element 453 448 * @param Map attrs 454 449 */ 455 def templateSelect = { 450 def templateSelect = {attrs -> 456 451 def entity = attrs.remove('entity') 457 452 458 453 // fetch templates 459 attrs.from = (entity) ? Template.findAllByEntity(entity) : Template.findAll() 454 if (attrs.remove('addDummy')) { 455 attrs.from = [''] 456 if (entity && entity instanceof Class) { 457 Template.findAllByEntity(entity).each() { 458 attrs.from[attrs.from.size()] = it 459 } 460 } 461 } else { 462 attrs.from = (entity) ? Template.findAllByEntity(entity) : Template.findAll() 463 } 460 464 461 465 // got a name? … … 465 469 466 470 // got result? 467 if (attrs.from.size() > 0) {471 if (attrs.from.size() > 0) { 468 472 out << select(attrs) 469 473 } else { … … 476 480 /** 477 481 * Term form element 478 * @param Map 479 * @param Closure 480 */ 481 def termElement = { 482 * @param Map attributes 483 * @param Closure help content 484 */ 485 def termElement = {attrs, body -> 482 486 // render term element 483 487 baseElement.call( … … 492 496 * @param Map attrs 493 497 */ 494 def termSelect = { 498 def termSelect = {attrs -> 495 499 // fetch all terms 496 500 attrs.from = Term.findAll() // for now, all terms as we cannot identify terms as being treatment terms... … … 504 508 } 505 509 506 def show = { attrs -> 510 /** 511 * Protocol form element 512 * @param Map attributes 513 * @param Closure help content 514 */ 515 def protocolElement = {attrs, body -> 516 // render protocol element 517 baseElement.call( 518 'protocolSelect', 519 attrs, 520 body 521 ) 522 } 523 524 /** 525 * render a protocol select element 526 * @param Map attrs 527 */ 528 def protocolSelect = {attrs -> 529 // fetch all protocold 530 attrs.from = Protocol.findAll() // for now, all protocols 531 532 // got a name? 533 if (!attrs.name) { 534 attrs.name = 'protocol' 535 } 536 537 out << select(attrs) 538 } 539 540 def show = {attrs -> 507 541 // is object parameter set? 508 542 def o = attrs.object … … 520 554 * @param Map attributes 521 555 */ 522 def templateColumnHeaders = { 556 def templateColumnHeaders = {attrs -> 523 557 def template = attrs.remove('template') 524 558 … … 533 567 * @param Map attributes 534 568 */ 535 def templateColumns = { 536 def subject 537 def subjectId 538 def template 539 def intFields 540 def stringFields 541 def floatFields 542 def termFields 569 def templateColumns = {attrs, body -> 570 def subject = attrs.remove('subject') 571 def subjectId = attrs.remove('id') 572 def template = attrs.remove('template') 573 def intFields = subject.templateIntegerFields 574 def stringFields = subject.templateStringFields 575 def floatFields = subject.templateFloatFields 576 def termFields = subject.templateTermFields 543 577 544 578 // output columns for these subjectFields … … 555 589 from: it.listEntries, 556 590 value: (stringFields) ? stringFields.get(it.name) : '' 557 ) 591 ) 558 592 } else { 559 593 out << '<span class="warning">no values!!</span>' … … 576 610 default: 577 611 // unsupported field type 578 out << '<span class="warning">!' +it.type+'</span>'612 out << '<span class="warning">!' + it.type + '</span>' 579 613 //out << subject.getFieldValue(it.name) 580 614 break; … … 584 618 } 585 619 } 620 621 /** 622 * render form elements based on an entity's template 623 * @param Map attributes 624 * @param String body 625 */ 626 def templateElements = {attrs -> 627 def entity = (attrs.get('entity')) 628 def template = (entity && entity instanceof TemplateEntity) ? entity.template : null 629 630 // got a template? 631 if (template) { 632 // render template fields 633 template.fields.each() { 634 switch (it.type) { 635 case 'STRINGLIST': 636 if (!it.listEntries.isEmpty()) { 637 out << selectElement( 638 description: it.name, 639 name: it.name, 640 from: it.listEntries, 641 value: attrs 642 ) 643 } else { 644 out << '<span class="warning">no values!!</span>' 645 } 646 break 647 case 'STRING': 648 out << textFieldElement( 649 description: it.name, 650 name: it.name 651 ) 652 break 653 case 'DATE': 654 out << dateElement( 655 description: it.name, 656 name: it.name 657 ) 658 break 659 case 'INTEGER': 660 out << textFieldElement( 661 description: it.name, 662 name: it.name 663 ) 664 break 665 case 'DOUBLE': 666 out << textFieldElement( 667 description: it.name, 668 name: it.name 669 ) 670 break 671 default: 672 out << "unkown field type '" + it.type + "'<br/>" 673 break 674 } 675 } 676 } 677 } 586 678 }
Note: See TracChangeset
for help on using the changeset viewer.