Index: trunk/extensions/SemanticForms/includes/SF_FormInputs.php |
— | — | @@ -434,41 +434,26 @@ |
435 | 435 | } |
436 | 436 | |
437 | 437 | class SFTextWithAutocompleteInput extends SFTextInput { |
438 | | - static function getText( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
439 | | - // If 'no autocomplete' was specified, print a regular text |
440 | | - // entry instead. |
441 | | - if ( array_key_exists( 'no autocomplete', $other_args ) && |
442 | | - $other_args['no autocomplete'] == true ) { |
443 | | - unset( $other_args['autocompletion source'] ); |
444 | | - return SFTextInput::getText( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
445 | | - } |
446 | | - // if a set of values was specified, print a dropdown instead |
447 | | - if ( array_key_exists( 'possible_values', $other_args ) && $other_args['possible_values'] != null ) |
448 | | - return SFDropdownInput::getText( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
449 | | - |
450 | | - global $sfgTabIndex, $sfgFieldNum, $sfgAutocompleteValues; |
451 | | - |
452 | | - $className = ( $is_mandatory ) ? "autocompleteInput mandatoryField" : "autocompleteInput createboxInput"; |
453 | | - if ( array_key_exists( 'class', $other_args ) ) |
454 | | - $className .= " " . $other_args['class']; |
455 | | - if ( array_key_exists( 'autocomplete field type', $other_args ) ) { |
456 | | - $autocomplete_field_type = $other_args['autocomplete field type']; |
457 | | - $autocompletion_source = $other_args['autocompletion source']; |
| 438 | + static function setAutocompleteValues( $field_args ) { |
| 439 | + global $sfgAutocompleteValues; |
| 440 | + |
| 441 | + if ( array_key_exists( 'autocomplete field type', $field_args ) ) { |
| 442 | + $autocomplete_field_type = $field_args['autocomplete field type']; |
| 443 | + $autocompletion_source = $field_args['autocompletion source']; |
458 | 444 | if ( $autocomplete_field_type != 'external_url' ) { |
459 | 445 | global $wgContLang; |
460 | 446 | $autocompletion_source = $wgContLang->ucfirst( $autocompletion_source ); |
461 | 447 | } |
462 | 448 | } |
463 | | - $input_id = "input_" . $sfgFieldNum; |
464 | 449 | |
465 | 450 | // Get all autocomplete-related values, plus delimiter value |
466 | 451 | // (it's needed also for the 'uploadable' link, if there is one). |
467 | 452 | $autocompleteSettings = $autocompletion_source; |
468 | | - $is_list = ( array_key_exists( 'is_list', $other_args ) && $other_args['is_list'] == true ); |
| 453 | + $is_list = ( array_key_exists( 'is_list', $field_args ) && $field_args['is_list'] == true ); |
469 | 454 | if ( $is_list ) { |
470 | 455 | $autocompleteSettings .= ",list"; |
471 | | - if ( array_key_exists( 'delimiter', $other_args ) ) { |
472 | | - $delimiter = $other_args['delimiter']; |
| 456 | + if ( array_key_exists( 'delimiter', $field_args ) ) { |
| 457 | + $delimiter = $field_args['delimiter']; |
473 | 458 | $autocompleteSettings .= "," . $delimiter; |
474 | 459 | } else { |
475 | 460 | $delimiter = ","; |
— | — | @@ -478,82 +463,148 @@ |
479 | 464 | } |
480 | 465 | |
481 | 466 | $remoteDataType = null; |
482 | | - if ( array_key_exists( 'remote autocompletion', $other_args ) && |
483 | | - $other_args['remote autocompletion'] == true ) { |
| 467 | + if ( array_key_exists( 'remote autocompletion', $field_args ) && |
| 468 | + $field_args['remote autocompletion'] == true ) { |
484 | 469 | $remoteDataType = $autocomplete_field_type; |
485 | 470 | } elseif ( $autocompletion_source != '' ) { |
486 | 471 | $autocomplete_values = SFUtils::getAutocompleteValues( $autocompletion_source, $autocomplete_field_type ); |
487 | 472 | $sfgAutocompleteValues[$autocompleteSettings] = $autocomplete_values; |
488 | 473 | } |
| 474 | + return array( $autocompleteSettings, $remoteDataType, $delimiter ); |
| 475 | + } |
489 | 476 | |
490 | | - if ( array_key_exists( 'input_type', $other_args ) && $other_args['input_type'] == "textarea" ) { |
491 | | - |
492 | | - $rows = $other_args['rows']; |
493 | | - $cols = $other_args['cols']; |
494 | | - $text = ""; |
495 | | - if ( array_key_exists( 'autogrow', $other_args ) ) { |
496 | | - $className .= ' autoGrow'; |
497 | | - } |
| 477 | + static function getText( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
| 478 | + // If 'no autocomplete' was specified, print a regular text |
| 479 | + // entry instead. |
| 480 | + if ( array_key_exists( 'no autocomplete', $other_args ) && |
| 481 | + $other_args['no autocomplete'] == true ) { |
| 482 | + unset( $other_args['autocompletion source'] ); |
| 483 | + return SFTextInput::getText( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
| 484 | + } |
| 485 | + // if a set of values was specified, print a dropdown instead |
| 486 | + if ( array_key_exists( 'possible_values', $other_args ) && $other_args['possible_values'] != null ) |
| 487 | + return SFDropdownInput::getText( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
498 | 488 | |
499 | | - $textarea_attrs = array( |
500 | | - 'tabindex' => $sfgTabIndex, |
501 | | - 'id' => $input_id, |
502 | | - 'name' => $input_name, |
503 | | - 'rows' => $rows, |
504 | | - 'cols' => $cols, |
505 | | - 'class' => $className, |
506 | | - 'autocompletesettings' => $autocompleteSettings, |
507 | | - ); |
508 | | - if ( !is_null( $remoteDataType ) ) { |
509 | | - $textarea_attrs['autocompletedatatype'] = $remoteDataType; |
510 | | - } |
511 | | - if ( $is_disabled ) { |
512 | | - $textarea_attrs['disabled'] = 'disabled'; |
513 | | - } |
514 | | - if ( array_key_exists( 'maxlength', $other_args ) ) { |
515 | | - $maxlength = $other_args['maxlength']; |
516 | | - // For every actual character pressed (i.e., |
517 | | - // excluding things like the Shift key), |
518 | | - // reduce the string to its allowed length if |
519 | | - // it's exceeded that. |
520 | | - // This JS code is complicated so that it'll |
521 | | - // work correctly in IE - IE moves the cursor |
522 | | - // to the end whenever this.value is reset, |
523 | | - // so we'll make sure to do that only when |
524 | | - // we need to. |
525 | | - $maxLengthJSCheck = "if (window.event && window.event.keyCode < 48 && window.event.keyCode != 13) return; if (this.value.length > $maxlength) { this.value = this.value.substring(0, $maxlength); }"; |
526 | | - $textarea_attrs['onKeyDown'] = $maxLengthJSCheck; |
527 | | - $textarea_attrs['onKeyUp'] = $maxLengthJSCheck; |
528 | | - } |
529 | | - $textarea_input = Xml::element('textarea', $textarea_attrs, $cur_value, false); |
530 | | - $text .= $textarea_input; |
531 | | - } else { |
532 | | - if ( array_key_exists( 'size', $other_args ) ) |
533 | | - $size = $other_args['size']; |
534 | | - else |
535 | | - $size = "35"; |
| 489 | + global $sfgTabIndex, $sfgFieldNum; |
536 | 490 | |
537 | | - $inputAttrs = array( |
538 | | - 'type' => 'text', |
539 | | - 'id' => $input_id, |
540 | | - 'name' => $input_name, |
541 | | - 'value' => $cur_value, |
542 | | - 'size' => $size, |
543 | | - 'class' => $className, |
544 | | - 'tabindex' => $sfgTabIndex, |
545 | | - 'autocompletesettings' => $autocompleteSettings, |
546 | | - ); |
547 | | - if ( !is_null( $remoteDataType ) ) { |
548 | | - $inputAttrs['autocompletedatatype'] = $remoteDataType; |
| 491 | + list( $autocompleteSettings, $remoteDataType, $delimiter ) = self::setAutocompleteValues( $other_args ); |
| 492 | + |
| 493 | + $className = ( $is_mandatory ) ? "autocompleteInput mandatoryField" : "autocompleteInput createboxInput"; |
| 494 | + if ( array_key_exists( 'class', $other_args ) ) |
| 495 | + $className .= " " . $other_args['class']; |
| 496 | + $input_id = "input_" . $sfgFieldNum; |
| 497 | + |
| 498 | + |
| 499 | + if ( array_key_exists( 'size', $other_args ) ) |
| 500 | + $size = $other_args['size']; |
| 501 | + else |
| 502 | + $size = "35"; |
| 503 | + |
| 504 | + $inputAttrs = array( |
| 505 | + 'type' => 'text', |
| 506 | + 'id' => $input_id, |
| 507 | + 'name' => $input_name, |
| 508 | + 'value' => $cur_value, |
| 509 | + 'size' => $size, |
| 510 | + 'class' => $className, |
| 511 | + 'tabindex' => $sfgTabIndex, |
| 512 | + 'autocompletesettings' => $autocompleteSettings, |
| 513 | + ); |
| 514 | + if ( !is_null( $remoteDataType ) ) { |
| 515 | + $inputAttrs['autocompletedatatype'] = $remoteDataType; |
| 516 | + } |
| 517 | + if ( $is_disabled ) { |
| 518 | + $inputAttrs['disabled'] = 'disabled'; |
| 519 | + } |
| 520 | + if ( array_key_exists( 'maxlength', $other_args ) ) { |
| 521 | + $text .= ' maxlength="' . $other_args['maxlength'] . '"'; |
| 522 | + } |
| 523 | + $text = "\n\t" . Xml::element( 'input', $inputAttrs ) . "\n"; |
| 524 | + |
| 525 | + if ( array_key_exists( 'is_uploadable', $other_args ) && $other_args['is_uploadable'] == true ) { |
| 526 | + if ( array_key_exists( 'default filename', $other_args ) ) { |
| 527 | + $default_filename = $other_args['default filename']; |
| 528 | + } else { |
| 529 | + $default_filename = ""; |
549 | 530 | } |
550 | | - if ( $is_disabled ) { |
551 | | - $inputAttrs['disabled'] = 'disabled'; |
552 | | - } |
553 | | - if ( array_key_exists( 'maxlength', $other_args ) ) { |
554 | | - $text .= ' maxlength="' . $other_args['maxlength'] . '"'; |
555 | | - } |
556 | | - $text = "\n\t" . Xml::element( 'input', $inputAttrs ) . "\n"; |
| 531 | + $text .= self::uploadLinkHTML( $input_id, $delimiter, $default_filename ); |
557 | 532 | } |
| 533 | + |
| 534 | + $spanClass = "inputSpan"; |
| 535 | + if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; } |
| 536 | + $text = "\n" . Xml::tags( 'span', array( 'class' => $spanClass ), $text ); |
| 537 | + |
| 538 | + return $text; |
| 539 | + } |
| 540 | + |
| 541 | + public static function getParameters() { |
| 542 | + $params = array(); |
| 543 | + $params[] = array( 'name' => 'maxlength', 'type' => 'int' ); |
| 544 | + $params[] = array( 'name' => 'list', 'type' => 'boolean' ); |
| 545 | + $params[] = array( 'name' => 'remote autocompletion', 'type' => 'boolean' ); |
| 546 | + return array(); |
| 547 | + } |
| 548 | +} |
| 549 | + |
| 550 | +class SFTextAreaWithAutocompleteInput extends SFTextWithAutocompleteInput { |
| 551 | + static function getText( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
| 552 | + // If 'no autocomplete' was specified, print a regular |
| 553 | + // textarea instead. |
| 554 | + if ( array_key_exists( 'no autocomplete', $other_args ) && |
| 555 | + $other_args['no autocomplete'] == true ) { |
| 556 | + unset( $other_args['autocompletion source'] ); |
| 557 | + return SFTextAreaInput::getText( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
| 558 | + } |
| 559 | + |
| 560 | + global $sfgTabIndex, $sfgFieldNum; |
| 561 | + |
| 562 | + list( $autocompleteSettings, $remoteDataType, $delimiter ) = self::setAutocompleteValues( $other_args ); |
| 563 | + |
| 564 | + $className = ( $is_mandatory ) ? "autocompleteInput mandatoryField" : "autocompleteInput createboxInput"; |
| 565 | + if ( array_key_exists( 'class', $other_args ) ) |
| 566 | + $className .= " " . $other_args['class']; |
| 567 | + $input_id = "input_" . $sfgFieldNum; |
| 568 | + |
| 569 | + $rows = $other_args['rows']; |
| 570 | + $cols = $other_args['cols']; |
| 571 | + $text = ""; |
| 572 | + if ( array_key_exists( 'autogrow', $other_args ) ) { |
| 573 | + $className .= ' autoGrow'; |
| 574 | + } |
| 575 | + |
| 576 | + $textarea_attrs = array( |
| 577 | + 'tabindex' => $sfgTabIndex, |
| 578 | + 'id' => $input_id, |
| 579 | + 'name' => $input_name, |
| 580 | + 'rows' => $rows, |
| 581 | + 'cols' => $cols, |
| 582 | + 'class' => $className, |
| 583 | + 'autocompletesettings' => $autocompleteSettings, |
| 584 | + ); |
| 585 | + if ( !is_null( $remoteDataType ) ) { |
| 586 | + $textarea_attrs['autocompletedatatype'] = $remoteDataType; |
| 587 | + } |
| 588 | + if ( $is_disabled ) { |
| 589 | + $textarea_attrs['disabled'] = 'disabled'; |
| 590 | + } |
| 591 | + if ( array_key_exists( 'maxlength', $other_args ) ) { |
| 592 | + $maxlength = $other_args['maxlength']; |
| 593 | + // For every actual character pressed (i.e., |
| 594 | + // excluding things like the Shift key), |
| 595 | + // reduce the string to its allowed length if |
| 596 | + // it's exceeded that. |
| 597 | + // This JS code is complicated so that it'll |
| 598 | + // work correctly in IE - IE moves the cursor |
| 599 | + // to the end whenever this.value is reset, |
| 600 | + // so we'll make sure to do that only when |
| 601 | + // we need to. |
| 602 | + $maxLengthJSCheck = "if (window.event && window.event.keyCode < 48 && window.event.keyCode != 13) return; if (this.value.length > $maxlength) { this.value = this.value.substring(0, $maxlength); }"; |
| 603 | + $textarea_attrs['onKeyDown'] = $maxLengthJSCheck; |
| 604 | + $textarea_attrs['onKeyUp'] = $maxLengthJSCheck; |
| 605 | + } |
| 606 | + $textarea_input = Xml::element('textarea', $textarea_attrs, $cur_value, false); |
| 607 | + $text .= $textarea_input; |
| 608 | + |
558 | 609 | if ( array_key_exists( 'is_uploadable', $other_args ) && $other_args['is_uploadable'] == true ) { |
559 | 610 | if ( array_key_exists( 'default filename', $other_args ) ) { |
560 | 611 | $default_filename = $other_args['default filename']; |
— | — | @@ -575,6 +626,7 @@ |
576 | 627 | $params[] = array( 'name' => 'maxlength', 'type' => 'int' ); |
577 | 628 | $params[] = array( 'name' => 'list', 'type' => 'boolean' ); |
578 | 629 | $params[] = array( 'name' => 'remote autocompletion', 'type' => 'boolean' ); |
| 630 | + $params[] = array( 'name' => 'autogrow', 'type' => 'boolean' ); |
579 | 631 | return array(); |
580 | 632 | } |
581 | 633 | } |
— | — | @@ -593,8 +645,7 @@ |
594 | 646 | // If it's an autocomplete, call the with-autocomplete |
595 | 647 | // function instead. |
596 | 648 | if ( array_key_exists( 'autocompletion source', $other_args ) ) { |
597 | | - $other_args['input_type'] = "textarea"; |
598 | | - return SFTextWithAutocompleteInput::getText( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
| 649 | + return SFTextAreaWithAutocompleteInput::getText( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
599 | 650 | } |
600 | 651 | |
601 | 652 | global $sfgTabIndex, $sfgFieldNum; |