Index: trunk/extensions/SemanticForms/includes/SF_FormInputs.php |
— | — | @@ -6,15 +6,15 @@ |
7 | 7 | * @author Jeffrey Stuckman |
8 | 8 | * @author Matt Williamson |
9 | 9 | * @author Patrick Nagel |
| 10 | + * @author Sanyam Goyal |
10 | 11 | */ |
11 | 12 | |
12 | 13 | class SFFormInputs { |
13 | | - |
14 | 14 | /** |
15 | | - * Create a comma-delimited string of values that match the specified |
16 | | - * source name and type, for use by Javascript autocompletion. |
| 15 | + * Creates an array of values that match the specified source name and type, |
| 16 | + * for use by both Javascript autocompletion and comboboxes. |
17 | 17 | */ |
18 | | - static function createAutocompleteValuesString( $source_name, $source_type ) { |
| 18 | + static function createAutocompleteValuesArray( $source_name, $source_type ) { |
19 | 19 | $names_array = array(); |
20 | 20 | // the query depends on whether this is a property, category, concept |
21 | 21 | // or namespace |
— | — | @@ -30,9 +30,19 @@ |
31 | 31 | $source_name = ""; |
32 | 32 | $names_array = SFUtils::getAllPagesForNamespace( $source_name ); |
33 | 33 | } |
| 34 | + return $names_array; |
| 35 | + } |
| 36 | + |
| 37 | + |
| 38 | + /** |
| 39 | + * Creates a comma-delimited string of values that match the specified |
| 40 | + * source name and type, for use by Javascript autocompletion. |
| 41 | + */ |
| 42 | + static function createAutocompleteValuesString( $source_name, $source_type ) { |
| 43 | + $names_array = self::createAutocompleteValuesArray( $source_name, $source_type ); |
34 | 44 | // escape quotes, to avoid Javascript errors |
35 | 45 | $names_array = array_map( 'addslashes', $names_array ); |
36 | | - $autocomplete_string = "[['" . implode( "'], ['", $names_array ) . "']]"; |
| 46 | + $autocomplete_string = "['" . implode( "', '", $names_array ) . "']"; |
37 | 47 | // replace any newlines in the string, just to avoid breaking the Javascript |
38 | 48 | $autocomplete_string = str_replace( "\n", ' ', $autocomplete_string ); |
39 | 49 | $autocomplete_string = str_replace( "\r", ' ', $autocomplete_string ); |
— | — | @@ -40,8 +50,11 @@ |
41 | 51 | } |
42 | 52 | |
43 | 53 | static function uploadLinkHTML( $input_id, $delimiter = null, $default_filename = null ) { |
| 54 | + global $wgOut, $sfgScriptPath, $sfgFancyBoxIncluded; |
| 55 | + |
44 | 56 | $upload_window_page = SpecialPage::getPage( 'UploadWindow' ); |
45 | 57 | $query_string = "sfInputID=$input_id"; |
| 58 | + $fancybox_id = "fancybox_$input_id"; |
46 | 59 | if ( $delimiter != null ) |
47 | 60 | $query_string .= "&sfDelimiter=$delimiter"; |
48 | 61 | if ( $default_filename != null ) |
— | — | @@ -53,7 +66,31 @@ |
54 | 67 | $style = "width:650 height:500"; |
55 | 68 | else |
56 | 69 | $style = ''; |
57 | | - $text = " <a href=\"$upload_window_url\" title=\"$upload_label\" rel=\"iframe\" rev=\"$style\">$upload_label</a>"; |
| 70 | + |
| 71 | + if ( !$sfgFancyBoxIncluded ) { |
| 72 | + $sfgFancyBoxIncluded = true; |
| 73 | + $wgOut->addScriptFile( "$sfgScriptPath/libs/jquery.fancybox-1.3.1.js" ); |
| 74 | + } |
| 75 | + |
| 76 | + $fancybox_js =<<<END |
| 77 | +<script type="text/javascript"> |
| 78 | +jQuery(document).ready(function() { |
| 79 | + jQuery("#$fancybox_id").fancybox({ |
| 80 | + 'width' : '75%', |
| 81 | + 'height' : '75%', |
| 82 | + 'autoScale' : false, |
| 83 | + 'transitionIn' : 'none', |
| 84 | + 'transitionOut' : 'none', |
| 85 | + 'type' : 'iframe', |
| 86 | + 'overlayColor' : '#222', |
| 87 | + 'overlayOpacity' : '0.8', |
| 88 | + }); |
| 89 | +}); |
| 90 | +</script> |
| 91 | +END; |
| 92 | + $wgOut->addScript($fancybox_js); |
| 93 | + |
| 94 | + $text = " <a id = \"$fancybox_id\" href=\"$upload_window_url\" title=\"$upload_label\" rev=\"$style\">$upload_label</a>"; |
58 | 95 | return $text; |
59 | 96 | } |
60 | 97 | |
— | — | @@ -273,9 +310,7 @@ |
274 | 311 | if ( array_key_exists( 'class', $other_args ) ) |
275 | 312 | $span_class .= " " . $other_args['class']; |
276 | 313 | $input_id = "input_$sfgFieldNum"; |
277 | | - $info_id = "info_$sfgFieldNum"; |
278 | 314 | $hidden_input_name = $input_name . "[is_list]"; |
279 | | - $disabled_text = ( $is_disabled ) ? "disabled" : ""; |
280 | 315 | // get list delimiter - default is comma |
281 | 316 | if ( array_key_exists( 'delimiter', $other_args ) ) { |
282 | 317 | $delimiter = $other_args['delimiter']; |
— | — | @@ -289,32 +324,50 @@ |
290 | 325 | $text = ""; |
291 | 326 | $return_js_text = ""; |
292 | 327 | $enum_input_ids = array(); |
293 | | - // if it's mandatory, add a span around all the checkboxes, since |
294 | | - // some browsers don't support formatting of checkboxes |
295 | | - if ( $is_mandatory ) |
296 | | - $text .= ' <span class="mandatoryFieldsSpan">' . "\n"; |
297 | 328 | foreach ( $possible_values as $key => $possible_value ) { |
298 | 329 | // create array $enum_input_ids to associate values with their input IDs, |
299 | 330 | // for use in creating the 'show on select' Javascript later |
300 | 331 | $enum_input_ids[$possible_value] = $input_id; |
301 | 332 | $cur_input_name = $input_name . "[" . $key . "]"; |
302 | | - $checked_text = ( in_array( $possible_value, $cur_values ) ) ? 'checked="checked"' : ""; |
303 | 333 | |
304 | 334 | if ( array_key_exists( 'value_labels', $other_args ) && is_array( $other_args['value_labels'] ) && array_key_exists( $possible_value, $other_args['value_labels'] ) ) |
305 | 335 | $label = htmlspecialchars( $other_args['value_labels'][$possible_value] ); |
306 | 336 | else |
307 | 337 | $label = $possible_value; |
308 | | - $text .= <<<END |
309 | | - <span class="$span_class"><input type="checkbox" id="$input_id" tabindex="$sfgTabIndex" name="$cur_input_name" value="$possible_value" class="$checkbox_class" $checked_text $disabled_text/> $label</span> |
310 | 338 | |
311 | | -END; |
| 339 | + $checkbox_attrs = array( |
| 340 | + 'type' => 'checkbox', |
| 341 | + 'id' => $input_id, |
| 342 | + 'tabindex' => $sfgTabIndex, |
| 343 | + 'name' => $cur_input_name, |
| 344 | + 'value' => $possible_value, |
| 345 | + 'class' => $checkbox_class, |
| 346 | + ); |
| 347 | + if ( in_array( $possible_value, $cur_values ) ) { |
| 348 | + $checkbox_attrs['checked'] = 'checked'; |
| 349 | + } |
| 350 | + if ( $is_disabled ) { |
| 351 | + $checkbox_attrs['disabled'] = 'disabled'; |
| 352 | + } |
| 353 | + $checkbox_input = Xml::element( 'input', $checkbox_attrs ); |
| 354 | + $text .= ' ' . Xml::tags( 'span', |
| 355 | + array( 'class' => $span_class ), |
| 356 | + $checkbox_input . ' ' . $label |
| 357 | + ) . "\n"; |
312 | 358 | $sfgTabIndex++; |
313 | 359 | $sfgFieldNum++; |
314 | 360 | $input_id = "input_$sfgFieldNum"; |
315 | 361 | } |
316 | | - // close span |
317 | | - if ( $is_mandatory ) |
318 | | - $text .= " </span>"; |
| 362 | + // if it's mandatory, add a span around all the checkboxes, since |
| 363 | + // some browsers don't support formatting of checkboxes |
| 364 | + if ( $is_mandatory ) { |
| 365 | + $text = ' ' . Xml::tags( 'span', |
| 366 | + array( |
| 367 | + 'id' => $input_id, |
| 368 | + 'class' => 'mandatoryFieldsSpan', |
| 369 | + ), $text ) . "\n"; |
| 370 | + } |
| 371 | + $info_id = "info_$sfgFieldNum"; |
319 | 372 | $text .= <<<END |
320 | 373 | <span id="$info_id" class="errorMessage"></span> |
321 | 374 | <input type="hidden" name="$hidden_input_name" value="1" /> |
— | — | @@ -358,6 +411,81 @@ |
359 | 412 | return array( $text, $return_js_text ); |
360 | 413 | } |
361 | 414 | |
| 415 | + static function comboboxHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
| 416 | + if ( array_key_exists( 'no autocomplete', $other_args ) && |
| 417 | + $other_args['no autocomplete'] == true ) { |
| 418 | + unset( $other_args['autocompletion source'] ); |
| 419 | + return SFFormInputs::textEntryHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
| 420 | + } |
| 421 | + // if a set of values was specified, print a dropdown instead |
| 422 | + if ( array_key_exists( 'possible_values', $other_args ) && $other_args['possible_values'] != null ) |
| 423 | + return SFFormInputs::dropdownHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
| 424 | + |
| 425 | + global $sfgTabIndex, $sfgFieldNum,$wgOut, $sfgScriptPath,$wgJsMimeType, $smwgScriptPath,$smwgJqUIAutoIncluded; |
| 426 | + |
| 427 | + $autocomplete_field_type = ""; |
| 428 | + $autocompletion_source = ""; |
| 429 | + |
| 430 | + $className = ( $is_mandatory ) ? "autocompleteInput mandatoryField" : "autocompleteInput createboxInput"; |
| 431 | + if ( array_key_exists( 'class', $other_args ) ) |
| 432 | + $className .= " " . $other_args['class']; |
| 433 | + $disabled_text = ( $is_disabled ) ? "disabled" : ""; |
| 434 | + if ( array_key_exists( 'autocomplete field type', $other_args ) ) { |
| 435 | + $autocomplete_field_type = $other_args['autocomplete field type']; |
| 436 | + $autocompletion_source = $other_args['autocompletion source']; |
| 437 | + if ( $autocomplete_field_type != 'external_url' ) { |
| 438 | + global $wgContLang; |
| 439 | + $autocompletion_source = $wgContLang->ucfirst( $autocompletion_source ); |
| 440 | + } |
| 441 | + } |
| 442 | + if ( array_key_exists( 'size', $other_args ) ) |
| 443 | + $size = $other_args['size']; |
| 444 | + else |
| 445 | + $size = "35"; |
| 446 | + |
| 447 | + $input_id = "input_" . $sfgFieldNum; |
| 448 | + $info_id = "info_" . $sfgFieldNum; |
| 449 | + $div_name = "div_" . $sfgFieldNum; |
| 450 | + |
| 451 | + $options_str_key = $autocompletion_source; |
| 452 | + $javascript_text = "autocompletemappings[$sfgFieldNum] = '$options_str_key';\n"; |
| 453 | + |
| 454 | + $values = array(); |
| 455 | + $values = self::createAutocompleteValuesArray($autocompletion_source, $autocomplete_field_type ); |
| 456 | + |
| 457 | + |
| 458 | + /*adding code for displaying dropdown of autocomplete values*/ |
| 459 | + |
| 460 | + $text =<<<END |
| 461 | +<div class="ui-widget"> |
| 462 | + <select id="input_$sfgFieldNum" name="$input_name"> |
| 463 | + <option value="$cur_value"></option> |
| 464 | + |
| 465 | +END; |
| 466 | + foreach ($values as $value) { |
| 467 | + $text .= " <option value=\"$value\">$value</option>\n"; |
| 468 | + } |
| 469 | + $text .= <<<END |
| 470 | + </select> |
| 471 | + <span id="$info_id" class="errorMessage"></span> |
| 472 | +</div> |
| 473 | +<script type="text/javascript" > |
| 474 | +jQuery(function() {jQuery("#input_$sfgFieldNum").combobox();}); |
| 475 | +</script> |
| 476 | +END; |
| 477 | + // there's no direct correspondence between the 'size=' attribute for |
| 478 | + // text inputs and the number of pixels, but multiplying by 6 seems to |
| 479 | + // be about right for the major browsers |
| 480 | + $pixel_width = $size * 6; |
| 481 | + $combobox_css =<<<END |
| 482 | +<style type="text/css"> |
| 483 | +input#input_$sfgFieldNum { width: {$pixel_width}px; } |
| 484 | +</style> |
| 485 | +END; |
| 486 | + $wgOut->addScript($combobox_css); |
| 487 | + return array( $text, $javascript_text ); |
| 488 | + } |
| 489 | + |
362 | 490 | static function textInputWithAutocompleteHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
363 | 491 | // if 'no autocomplete' was specified, print a regular text entry instead |
364 | 492 | if ( array_key_exists( 'no autocomplete', $other_args ) && |
— | — | @@ -369,7 +497,7 @@ |
370 | 498 | if ( array_key_exists( 'possible_values', $other_args ) && $other_args['possible_values'] != null ) |
371 | 499 | return SFFormInputs::dropdownHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
372 | 500 | |
373 | | - global $sfgTabIndex, $sfgFieldNum; |
| 501 | + global $sfgTabIndex, $sfgFieldNum, $wgOut, $sfgScriptPath,$wgJsMimeType, $smwgScriptPath,$smwgJqUIAutoIncluded; |
374 | 502 | |
375 | 503 | $className = ( $is_mandatory ) ? "autocompleteInput mandatoryField" : "autocompleteInput createboxInput"; |
376 | 504 | if ( array_key_exists( 'class', $other_args ) ) |
— | — | @@ -387,6 +515,7 @@ |
388 | 516 | $info_id = "info_" . $sfgFieldNum; |
389 | 517 | $div_name = "div_" . $sfgFieldNum; |
390 | 518 | if ( array_key_exists( 'input_type', $other_args ) && $other_args['input_type'] == "textarea" ) { |
| 519 | + |
391 | 520 | $rows = $other_args['rows']; |
392 | 521 | $cols = $other_args['cols']; |
393 | 522 | if ( array_key_exists( 'maxlength', $other_args ) ) { |
— | — | @@ -398,10 +527,23 @@ |
399 | 528 | } else { |
400 | 529 | $js_call = ""; |
401 | 530 | } |
402 | | - $text = <<<END |
403 | | - <textarea tabindex="$sfgTabIndex" id="$input_id" name="$input_name" rows="$rows" cols="$cols" class="$className" $disabled_text $js_call></textarea> |
| 531 | + $text = ""; |
| 532 | + if ( array_key_exists( 'autogrow', $other_args ) ) { |
| 533 | + $text .= <<<END |
| 534 | +<script type="text/javascript"> |
| 535 | + jQuery.noConflict(); |
| 536 | + jQuery(document).ready(function() { |
| 537 | + jQuery("#$input_id").autoGrow(); |
| 538 | + }); |
| 539 | +</script> |
404 | 540 | |
405 | 541 | END; |
| 542 | + $className .= ' autoGrow'; |
| 543 | + } |
| 544 | + |
| 545 | + $text .= <<<END |
| 546 | + <textarea tabindex="$sfgTabIndex" id="$input_id" name="$input_name" rows="$rows" cols="$cols" class="$className" $disabled_text $js_call></textarea> |
| 547 | +END; |
406 | 548 | } else { |
407 | 549 | if ( array_key_exists( 'size', $other_args ) ) |
408 | 550 | $size = $other_args['size']; |
— | — | @@ -410,6 +552,7 @@ |
411 | 553 | |
412 | 554 | $text = <<<END |
413 | 555 | <input tabindex="$sfgTabIndex" id="$input_id" name="$input_name" type="text" value="" size="$size" class="$className" |
| 556 | + |
414 | 557 | END; |
415 | 558 | if ( $is_disabled ) |
416 | 559 | $text .= " disabled"; |
— | — | @@ -442,7 +585,8 @@ |
443 | 586 | <script type="text/javascript">/* <![CDATA[ */ |
444 | 587 | |
445 | 588 | END; |
446 | | - $options_str_key = str_replace( "'", "\'", $autocompletion_source ); |
| 589 | + |
| 590 | + $options_str_key = $autocompletion_source; |
447 | 591 | if ( $is_list ) { |
448 | 592 | $options_str_key .= ",list"; |
449 | 593 | if ( $delimiter != "," ) { |
— | — | @@ -464,12 +608,13 @@ |
465 | 609 | $cur_value = str_replace( "\r", '\r', $cur_value ); |
466 | 610 | $text .= "document.getElementById('$input_id').value = \"$cur_value\"\n"; |
467 | 611 | } |
468 | | - $text .= "/* ]]> */</script>\n"; |
| 612 | + $text .= '/* ]]> */</script>'; |
469 | 613 | return array( $text, $javascript_text ); |
470 | 614 | } |
471 | 615 | |
472 | 616 | static function textAreaHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
473 | 617 | // set size values |
| 618 | + |
474 | 619 | if ( ! array_key_exists( 'rows', $other_args ) ) |
475 | 620 | $other_args['rows'] = 5; |
476 | 621 | if ( ! array_key_exists( 'cols', $other_args ) ) |
— | — | @@ -481,7 +626,7 @@ |
482 | 627 | return SFFormInputs::textInputWithAutocompleteHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
483 | 628 | } |
484 | 629 | |
485 | | - global $sfgTabIndex, $sfgFieldNum; |
| 630 | + global $sfgTabIndex, $sfgFieldNum, $smwgScriptPath, $sfgScriptPath,$wgOut; |
486 | 631 | |
487 | 632 | $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput"; |
488 | 633 | if ( array_key_exists( 'class', $other_args ) ) |
— | — | @@ -504,7 +649,23 @@ |
505 | 650 | } |
506 | 651 | |
507 | 652 | $cur_value = htmlspecialchars( $cur_value ); |
508 | | - $text = <<<END |
| 653 | + $text = ""; |
| 654 | + if ( array_key_exists( 'autogrow', $other_args ) ) { |
| 655 | + $wgOut->addScriptFile( "$sfgScriptPath/libs/SF_autogrow.js" ); |
| 656 | + $text .= <<<END |
| 657 | +<script type="text/javascript"> |
| 658 | + jQuery.noConflict(); |
| 659 | + jQuery(document).ready(function(){ |
| 660 | + jQuery("#$input_id").autoGrow(); |
| 661 | + }); |
| 662 | +</script> |
| 663 | + |
| 664 | +END; |
| 665 | + $className .= ' autoGrow'; |
| 666 | + } |
| 667 | + |
| 668 | + $text .= <<<END |
| 669 | + |
509 | 670 | <textarea tabindex="$sfgTabIndex" id="$input_id" name="$input_name" rows="$rows" cols="$cols" class="$className" $disabled_text $js_call>$cur_value</textarea> |
510 | 671 | <span id="$info_id" class="errorMessage"></span> |
511 | 672 | |
— | — | @@ -652,61 +813,132 @@ |
653 | 814 | static function radioButtonHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
654 | 815 | global $sfgTabIndex, $sfgFieldNum; |
655 | 816 | |
656 | | - $input_id = "input_$sfgFieldNum"; |
657 | | - $info_id = "info_$sfgFieldNum"; |
658 | | - $disabled_text = ( $is_disabled ) ? "disabled" : ""; |
| 817 | + $span_class = "checkboxSpan"; |
| 818 | + if ( array_key_exists( 'class', $other_args ) ) |
| 819 | + $span_class .= " " . $other_args['class']; |
| 820 | + |
659 | 821 | $check_set = false; |
660 | | - $javascript_text = ''; |
661 | | - $return_js_text = ''; |
662 | | - if ( array_key_exists( 'show on select', $other_args ) ) { |
663 | | - $javascript_text = 'onClick="'; |
664 | | - foreach ( $other_args['show on select'] as $div_id => $options ) { |
665 | | - $options_str = implode( "', '", $options ); |
666 | | - $this_js_text = "showIfSelected('$input_id', ['$options_str'], '$div_id'); "; |
667 | | - $javascript_text .= $this_js_text; |
668 | | - $return_js_text .= $this_js_text . "\n"; |
669 | | - } |
670 | | - $javascript_text .= '"'; |
671 | | - } |
672 | 822 | $text = ""; |
673 | 823 | // if it's mandatory, add a span around all the radiobuttons, since |
674 | 824 | // some browsers don't support formatting of radiobuttons |
675 | 825 | if ( $is_mandatory ) |
676 | 826 | $text .= ' <span class="mandatoryFieldsSpan">' . "\n"; |
677 | 827 | |
678 | | - // start with an initial "None" value, unless this is a mandatory field |
679 | | - // and there's a current value in place (either through a default value |
680 | | - // or because we're editing an existing page) |
| 828 | + if ( ( $possible_values = $other_args['possible_values'] ) == null ) |
| 829 | + $possible_values = array(); |
| 830 | + |
| 831 | + // Add a "None" value, unless this is a mandatory field and there's a |
| 832 | + // current value in place (either through a default value or because |
| 833 | + // we're editing an existing page). |
| 834 | + // We place it at the end of the array, instead of the beginning (even |
| 835 | + // though it gets displayed at the beginning) so that the "None" value's |
| 836 | + // ID will match that of the "error message" span, which is created at |
| 837 | + // the end of the process - the validation Javascript requires that the |
| 838 | + // two be matching |
681 | 839 | if ( ! $is_mandatory || $cur_value == '' ) { |
682 | | - $text .= ' <input type="radio" id="' . $input_id . '" tabindex="' . $sfgTabIndex . '" name="' . $input_name . '" value=""'; |
683 | | - if ( ! $cur_value ) { |
684 | | - $text .= ' checked="checked"'; |
685 | | - $check_set = true; |
686 | | - } |
687 | | - $text .= " $disabled_text $javascript_text/> " . wfMsg( 'sf_formedit_none' ) . "\n"; |
| 840 | + $possible_values[] = ''; |
688 | 841 | } |
689 | 842 | |
690 | | - if ( ( $possible_values = $other_args['possible_values'] ) == null ) |
691 | | - $possible_values = array(); |
| 843 | + // Set $cur_value to be one of the allowed options, if it isn't already - |
| 844 | + // that makes it easier to automatically have one of the radiobuttons |
| 845 | + // be checked at the beginning. |
| 846 | + if ( ! in_array( $cur_value, $possible_values ) ) { |
| 847 | + if ( in_array( '', $possible_values ) ) |
| 848 | + $cur_value = ''; |
| 849 | + else |
| 850 | + $cur_value = $possible_values[0]; |
| 851 | + } |
| 852 | + |
| 853 | + $enum_input_ids = array(); |
| 854 | + $radiobuttons_text = ''; |
| 855 | + $none_radiobutton_text = ''; |
692 | 856 | foreach ( $possible_values as $i => $possible_value ) { |
693 | | - $text .= ' <input type="radio" tabindex="' . $sfgTabIndex . '" name="' . $input_name . '" value="' . $possible_value . '"'; |
694 | | - if ( $cur_value == $possible_value || ( ! $cur_value && ! $check_set ) ) { |
695 | | - $text .= ' checked="checked"'; |
696 | | - $check_set = true; |
| 857 | + $sfgTabIndex++; |
| 858 | + $sfgFieldNum++; |
| 859 | + $input_id = "input_$sfgFieldNum"; |
| 860 | + |
| 861 | + // create array $enum_input_ids to associate values with their input IDs, |
| 862 | + // for use in creating the 'show on select' Javascript later |
| 863 | + $enum_input_ids[$possible_value] = $input_id; |
| 864 | + |
| 865 | + $radiobutton_attrs = array( |
| 866 | + 'type' => 'radio', |
| 867 | + 'id' => $input_id, |
| 868 | + 'tabindex' => $sfgTabIndex, |
| 869 | + 'name' => $input_name, |
| 870 | + 'value' => $possible_value, |
| 871 | + ); |
| 872 | + if ( $cur_value == $possible_value ) { |
| 873 | + $radiobutton_attrs['checked'] = 'checked'; |
697 | 874 | } |
698 | | - if ( array_key_exists( 'value_labels', $other_args ) && is_array( $other_args['value_labels'] ) && array_key_exists( $possible_value, $other_args['value_labels'] ) ) |
| 875 | + if ( $is_disabled ) { |
| 876 | + $radiobutton_attrs['disabled'] = 'disabled'; |
| 877 | + } |
| 878 | + if ( $possible_value == '' ) // blank/"None" value |
| 879 | + $label = wfMsg( 'sf_formedit_none' ); |
| 880 | + elseif ( array_key_exists( 'value_labels', $other_args ) && is_array( $other_args['value_labels'] ) && array_key_exists( $possible_value, $other_args['value_labels'] ) ) |
699 | 881 | $label = htmlspecialchars( $other_args['value_labels'][$possible_value] ); |
700 | 882 | else |
701 | 883 | $label = $possible_value; |
702 | | - $text .= " $disabled_text $javascript_text/> $label\n"; |
| 884 | + |
| 885 | + $radiobutton_text = ' ' . |
| 886 | + Xml::element ( 'input', $radiobutton_attrs ) . " $label\n"; |
| 887 | + |
| 888 | + // There's special handling for the "None" radiobutton, if it exists, |
| 889 | + // because it's created last but displayed first - see above. |
| 890 | + if ( $possible_value == '' ) { |
| 891 | + $none_radiobutton_text = $radiobutton_text; |
| 892 | + } else { |
| 893 | + $radiobuttons_text .= $radiobutton_text; |
| 894 | + } |
703 | 895 | } |
| 896 | + $text = $none_radiobutton_text . $radiobuttons_text; |
| 897 | + |
704 | 898 | // close span |
705 | 899 | if ( $is_mandatory ) |
706 | 900 | $text .= " </span>"; |
| 901 | + $info_id = "info_$sfgFieldNum"; |
707 | 902 | $text .= <<<END |
708 | 903 | <span id="$info_id" class="errorMessage"></span> |
709 | 904 | |
710 | 905 | END; |
| 906 | + |
| 907 | + // Finally, we do the 'show on select' handling. |
| 908 | + $return_js_text = ''; |
| 909 | + if ( array_key_exists( 'show on select', $other_args ) ) { |
| 910 | + foreach ( $other_args['show on select'] as $div_id => $options ) { |
| 911 | + $cur_input_ids = array(); |
| 912 | + foreach ( $options as $option ) { |
| 913 | + if ( array_key_exists( $option, $enum_input_ids ) ) { |
| 914 | + $cur_input_ids[] = $enum_input_ids[$option]; |
| 915 | + } |
| 916 | + } |
| 917 | + $options_str = "['" . implode( "', '", $cur_input_ids ) . "']"; |
| 918 | + $cur_js_text = "showIfChecked($options_str, '$div_id'); "; |
| 919 | + $return_js_text .= $cur_js_text . "\n"; |
| 920 | + foreach ( $possible_values as $key => $possible_value ) { |
| 921 | + // We need to add each click handler to each radiobutton, |
| 922 | + // because there doesn't seem to be any way for a radiobutton |
| 923 | + // to know that it was unchecked - rather, the newly-checked |
| 924 | + // radiobutton has to handle the change. |
| 925 | + foreach ( $enum_input_ids as $cur_input_id ) { |
| 926 | + // we use addClickHandler(), instead of adding the Javascript via |
| 927 | + // onClick="", because MediaWiki's wikibits.js does its own handling |
| 928 | + // of checkboxes, which impacts their behavior in IE |
| 929 | + if ( in_array( $possible_value, $options ) ) { |
| 930 | + $return_js_text .= <<<END |
| 931 | +addClickHandler( |
| 932 | + document.getElementById('$cur_input_id'), |
| 933 | + function() { $cur_js_text } |
| 934 | +); |
| 935 | + |
| 936 | +END; |
| 937 | + } |
| 938 | + } |
| 939 | + } |
| 940 | + } |
| 941 | + } |
| 942 | + |
711 | 943 | return array( $text, $return_js_text ); |
712 | 944 | } |
713 | 945 | |
— | — | @@ -800,7 +1032,6 @@ |
801 | 1033 | $text .= ' <input type="radio" id="' . $input_id . '" tabindex="' . $sfgTabIndex . '" name="' . $input_name . '" value=""'; |
802 | 1034 | if ( ! $cur_value ) { |
803 | 1035 | $text .= ' checked="checked"'; |
804 | | - $check_set = true; |
805 | 1036 | } |
806 | 1037 | $disabled_text = ( $is_disabled ) ? "disabled" : ""; |
807 | 1038 | $text .= " $disabled_text/> <em>" . wfMsg( 'sf_formedit_none' ) . "</em>\n"; |