r30835 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r30834‎ | r30835 | r30836 >
Date:15:42, 11 February 2008
Author:yaron
Status:old
Tags:
Comment:
Improved handling for autocompletion fields - 'list' property added, as well
as being able to set input type; bug fixes, including fix for date fields
interfering with autocompletion
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc
@@ -72,8 +72,8 @@
7373 $this->setSemanticTypeHook($date_type, false, array('SFFormPrinter', 'dateEntryHTML'), array());
7474 $this->setSemanticTypeHook($enum_type, false, array('SFFormPrinter', 'dropdownHTML'), array());
7575 $this->setSemanticTypeHook($enum_type, true, array('SFFormPrinter', 'checkboxesHTML'), array());
76 - $this->setSemanticTypeHook($page_type, false, array('SFFormPrinter', 'textEntryWithAutocompleteHTML'), array('field_type' => 'page'));
77 - $this->setSemanticTypeHook($page_type, true, array('SFFormPrinter', 'textEntryWithAutocompleteHTML'), array('field_type' => 'page', 'size' => '100', 'is_multiple' => 'true'));
 76+ $this->setSemanticTypeHook($page_type, false, array('SFFormPrinter', 'textInputWithAutocompleteHTML'), array('field_type' => 'page'));
 77+ $this->setSemanticTypeHook($page_type, true, array('SFFormPrinter', 'textInputWithAutocompleteHTML'), array('field_type' => 'page', 'size' => '100', 'is_list' => 'true'));
7878 }
7979 $this->mInputTypeHooks = array();
8080 $this->setInputTypeHook('text', array('SFFormPrinter', 'textEntryHTML'), array());
@@ -418,6 +418,7 @@
419419 $is_mandatory = false;
420420 $is_hidden = false;
421421 $is_restricted = false;
 422+ $is_list = false;
422423 $input_type = null;
423424 $field_args = array();
424425 $default_value = "";
@@ -430,6 +431,8 @@
431432 $is_hidden = true;
432433 } elseif ($component == 'restricted') {
433434 $is_restricted = true;
 435+ } elseif ($component == 'list') {
 436+ $is_list = true;
434437 } else {
435438 $sub_components = explode('=', $component);
436439 if (count($sub_components) == 2) {
@@ -610,8 +613,8 @@
611614 // parameters in the form definition, and any information from
612615 // the template definition (contained in the $all_fields parameter)
613616 $form_field = SFFormTemplateField::createFromDefinition($field_name, $input_name,
614 - $is_mandatory, $is_hidden, $is_disabled, $input_type, $field_args,
615 - $all_fields, $strict_parsing);
 617+ $is_mandatory, $is_hidden, $is_disabled, $is_list, $input_type,
 618+ $field_args, $all_fields, $strict_parsing);
616619 // if this is not part of a 'multiple' template, incrememt the
617620 // global tab index (used for correct tabbing)
618621 if (! $field_args['part_of_multiple'])
@@ -681,9 +684,9 @@
682685 $info_id = "info_" . $sfgFieldNum;
683686 if ($is_mandatory) {
684687 if ($input_type == 'date' || $input_type == 'datetime' || $input_type == 'datetime with timezone') {
685 - $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_1', '$info_id')";
686 - $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_2', '$info_id')";
687 - $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_3', '$info_id')";
 688+ $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_month', '$info_id')";
 689+ $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_day', '$info_id')";
 690+ $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_year', '$info_id')";
688691 if ($input_type == 'datetime' || $input_type == 'datetime with timezone') {
689692 // TODO - validate the time fields
690693 if ($input_type == 'datetime with timezone') {
@@ -1057,8 +1060,8 @@
10581061 }
10591062 } else if (type == 'date') {
10601063 // validate only if day and year fields are both filled in
1061 - day_field = document.getElementById(field_id + "_2");
1062 - year_field = document.getElementById(field_id + "_3");
 1064+ day_field = document.getElementById(field_id + "_day");
 1065+ year_field = document.getElementById(field_id + "_year");
10631066 if (day_field.value == '' || year_field.value == '') {
10641067 return true;
10651068 } else if (day_field.value.match(/^\d+$/) &&
@@ -1160,16 +1163,14 @@
11611164 main_div.appendChild(new_div);
11621165 attachAutocompleteToAllFields(new_div);
11631166
1164 - if ($using_choosers)
1165 - {
 1167+ if ($using_choosers) {
11661168 hideOrShowFieldset(new_div);
11671169 }
11681170 }
11691171
11701172 function removeInstanceEventHandler(this_div_id)
11711173 {
1172 - return function()
1173 - {
 1174+ return function() {
11741175 removeInstance(this_div_id);
11751176 };
11761177 }
@@ -1190,10 +1191,8 @@
11911192 {
11921193 var forms = document.getElementsByTagName("form");
11931194 var x;
1194 - for (x=0;x<forms.length;x++)
1195 - {
1196 - if (forms[x].name == "createbox")
1197 - {
 1195+ for (x = 0; x < forms.length; x++) {
 1196+ if (forms[x].name == "createbox") {
11981197 attachAutocompleteToAllFields(forms[x]);
11991198 }
12001199 }
@@ -1204,10 +1203,14 @@
12051204 {
12061205 var inputs = base.getElementsByTagName("input");
12071206 var y;
1208 - for (y=0;y<inputs.length;y++)
1209 - {
 1207+ for (y = 0; y < inputs.length; y++) {
12101208 attachAutocompleteToField(inputs[y].id);
12111209 }
 1210+ // don't forget the textareas
 1211+ inputs = base.getElementsByTagName("textarea");
 1212+ for (y = 0; y < inputs.length; y++) {
 1213+ attachAutocompleteToField(inputs[y].id);
 1214+ }
12121215 }
12131216
12141217 //Activate autocomplete functionality for the specified field
@@ -1224,7 +1227,7 @@
12251228 var div_id = input_id.replace(/input_/g, 'div_');
12261229 var field_values = new Array();
12271230 field_values = field_string.split(',');
1228 - if (field_values[1] == 'multiple') {
 1231+ if (field_values[1] == 'list') {
12291232 var delimiter = ",";
12301233 if (field_values[2] != null) {
12311234 delimiter = field_values[2];
@@ -1259,6 +1262,7 @@
12601263
12611264 if ($form_field->is_hidden) {
12621265 $text = $this->hiddenFieldHTML($form_field->input_name, $cur_value);
 1266+ $javascript_text = "";
12631267 } elseif ($form_field->input_type != '' && $this->mInputTypeHooks[$form_field->input_type] != null) {
12641268 $funcArgs = array();
12651269 $funcArgs[] = $cur_value;
@@ -1272,6 +1276,7 @@
12731277 $default_args = $hook_values[1];
12741278 $other_args = $form_field->field_args;
12751279 $other_args['possible_values'] = $template_field->possible_values;
 1280+ $other_args['is_list'] = $template_field->is_list;
12761281 if ($template_field->is_relation) {
12771282 $other_args['is_relation'] = true;
12781283 $other_args['semantic_field_name'] = $template_field->semantic_field;
@@ -1288,7 +1293,7 @@
12891294 list($text, $javascript_text) = $this->textEntryHTML($cur_value, $form_field->input_name, $form_field->is_mandatory, $form_field->is_disabled, $field_args);
12901295 } else { // input type not defined in form, and not a relation
12911296 $field_type = $template_field->field_type;
1292 - $is_list = $template_field->is_list;
 1297+ $is_list = $form_field->is_list || $template_field->is_list;
12931298 if ($field_type != '' &&
12941299 array_key_exists($field_type, $this->mSemanticTypeHooks) &&
12951300 isset($this->mSemanticTypeHooks[$field_type][$is_list])) {
@@ -1310,6 +1315,11 @@
13111316 list($text, $javascript_text) = call_user_func_array($hook_values[0], $funcArgs);
13121317 } else { // anything else
13131318 $other_args = $form_field->field_args;
 1319+ // set field to be a list if that was specified in the form definition
 1320+ if ($form_field->is_list) {
 1321+ $other_args['is_list'] = true;
 1322+ $other_args['size'] = 100;
 1323+ }
13141324 list($text, $javascript_text) = $this->textEntryHTML($cur_value, $form_field->input_name, $form_field->is_mandatory, $form_field->is_disabled, $other_args);
13151325 }
13161326 }
@@ -1440,9 +1450,13 @@
14411451
14421452 function textEntryHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
14431453 // if it's an autocomplete, call the with-autocomplete function instead
1444 - if ((array_key_exists('autocomplete on', $other_args) && $other_args['autocomplete on'] != "") ||
1445 - array_key_exists('autocomplete on namespace', $other_args)) {
1446 - return SFFormPrinter::textEntryWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args);
 1454+ $autocompletion_disabled = array_key_exists('autocomplete on', $other_args) && $other_args['autocomplete on'] == "";
 1455+ if (! $autocompletion_disabled) {
 1456+ if ((array_key_exists('is_relation', $other_args) && $other_args['is_relation'] == true) ||
 1457+ array_key_exists('autocomplete on', $other_args) ||
 1458+ array_key_exists('autocomplete on namespace', $other_args)) {
 1459+ return SFFormPrinter::textInputWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args);
 1460+ }
14471461 }
14481462
14491463 global $sfgTabIndex, $sfgFieldNum, $sfgJSValidationCalls;
@@ -1624,7 +1638,7 @@
16251639 return array($text, null);
16261640 }
16271641
1628 - function textEntryWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
 1642+ function textInputWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
16291643 // if 'no autocomplete' was specified, call the regular text entry instead
16301644 if (array_key_exists('no_autocomplete', $other_args) &&
16311645 $other_args['no_autocomplete'] == true)
@@ -1653,23 +1667,33 @@
16541668 $input_id = "input_" . $sfgFieldNum;
16551669 $info_id = "info_" . $sfgFieldNum;
16561670 $div_name = "div_" . $sfgFieldNum;
1657 - $text =<<<END
 1671+ if (array_key_exists('input_type', $other_args) && $other_args['input_type'] == "textarea") {
 1672+ $text =<<<END
 1673+ <textarea tabindex="$sfgTabIndex" id="$input_id" name="$input_name" rows="$rows" cols="$cols" class="$className" $disabled_text></textarea>
 1674+
 1675+END;
 1676+ } else {
 1677+ $text =<<<END
16581678 <input tabindex="$sfgTabIndex" id="$input_id" name="$input_name" type="text"
16591679 value="" size="$size" class="$className" $disabled_text/>
 1680+
 1681+END;
 1682+ }
 1683+ $text .=<<<END
16601684 <span id="$info_id" class="error_message"></span>
16611685 <div class="page_name_auto_complete" id="$div_name"></div>
16621686 <script type="text/javascript">
16631687
16641688 END;
16651689 $options_str_key = str_replace("'", "\'", $semantic_field_name);
1666 - if (array_key_exists('is_multiple', $other_args)) {
1667 - $options_str_key .= ",multiple";
 1690+ if (array_key_exists('is_list', $other_args)) {
 1691+ $options_str_key .= ",list";
16681692 if (array_key_exists('delimiter', $other_args) && $other_args['delimiter'] != ",") {
16691693 $options_str_key .= "," . $other_args['delimiter'];
16701694 }
16711695 }
16721696 $autocomplete_values = $this->createAutocompleteValuesArray(str_replace(' ', '_', $semantic_field_name), $autocomplete_field_type);
1673 - if (array_key_exists('is_multiple', $other_args)) {
 1697+ if (array_key_exists('is_list', $other_args)) {
16741698 $autocomplete_string = "[['" . implode("'], ['", $autocomplete_values) . "']]";
16751699 } else {
16761700 $autocomplete_string = "['" . implode("', '", $autocomplete_values) . "']";
@@ -1687,6 +1711,17 @@
16881712 }
16891713
16901714 function textAreaHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
 1715+ // if it's an autocomplete, call the with-autocomplete function instead
 1716+ $autocompletion_disabled = array_key_exists('autocomplete on', $other_args) && $other_args['autocomplete on'] == "";
 1717+ if (! $autocompletion_disabled) {
 1718+ if ((array_key_exists('is_relation', $other_args) && $other_args['is_relation'] == true) ||
 1719+ array_key_exists('autocomplete on', $other_args) ||
 1720+ array_key_exists('autocomplete on namespace', $other_args)) {
 1721+ $other_args['input_type'] = "textarea";
 1722+ return SFFormPrinter::textInputWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args);
 1723+ }
 1724+ }
 1725+
16911726 global $sfgTabIndex, $sfgFieldNum;
16921727
16931728 $className = ($is_mandatory) ? "mandatoryField" : "createboxInput";
@@ -1711,7 +1746,7 @@
17121747 global $sfgTabIndex, $sfgFieldNum, $wgAmericanDates;
17131748
17141749 $disabled_text = ($is_disabled) ? "disabled" : "";
1715 - $text = ' <select tabindex="' . $sfgTabIndex . '" id="input_' . $sfgFieldNum . '_1" name="' . $input_name . "[month]\" $disabled_text>\n";
 1750+ $text = ' <select tabindex="' . $sfgTabIndex . '" id="input_' . $sfgFieldNum . '_month" name="' . $input_name . "[month]\" $disabled_text>\n";
17161751 $month_names = sffGetMonthNames();
17171752 foreach ($month_names as $i => $name) {
17181753 // pad out month to always be two digits
@@ -1757,8 +1792,8 @@
17581793 }
17591794 $disabled_text = ($is_disabled) ? "disabled" : "";
17601795 $text = $this->monthDropdownHTML($month, $input_name, $is_disabled);
1761 - $text .= ' <input tabindex="' . $sfgTabIndex . '" id="' . $input_id . '_2" name="' . $input_name . '[day]" type="text" value="' . $day . '" size="2" ' . $disabled_text . '/>' . "\n";
1762 - $text .= ' <input tabindex="' . $sfgTabIndex . '" id="' . $input_id . '_3" name="' . $input_name . '[year]" type="text" value="' . $year . '" size="4" ' . $disabled_text . '/>' . "\n";
 1796+ $text .= ' <input tabindex="' . $sfgTabIndex . '" id="' . $input_id . '_day" name="' . $input_name . '[day]" type="text" value="' . $day . '" size="2" ' . $disabled_text . '/>' . "\n";
 1797+ $text .= ' <input tabindex="' . $sfgTabIndex . '" id="' . $input_id . '_year" name="' . $input_name . '[year]" type="text" value="' . $year . '" size="4" ' . $disabled_text . '/>' . "\n";
17631798 $text .= " <span id=\"$info_id\" class=\"error_message\"></span>";
17641799 return array($text, null);
17651800 }

Status & tagging log