Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc |
— | — | @@ -72,8 +72,8 @@ |
73 | 73 | $this->setSemanticTypeHook($date_type, false, array('SFFormPrinter', 'dateEntryHTML'), array()); |
74 | 74 | $this->setSemanticTypeHook($enum_type, false, array('SFFormPrinter', 'dropdownHTML'), array()); |
75 | 75 | $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')); |
78 | 78 | } |
79 | 79 | $this->mInputTypeHooks = array(); |
80 | 80 | $this->setInputTypeHook('text', array('SFFormPrinter', 'textEntryHTML'), array()); |
— | — | @@ -418,6 +418,7 @@ |
419 | 419 | $is_mandatory = false; |
420 | 420 | $is_hidden = false; |
421 | 421 | $is_restricted = false; |
| 422 | + $is_list = false; |
422 | 423 | $input_type = null; |
423 | 424 | $field_args = array(); |
424 | 425 | $default_value = ""; |
— | — | @@ -430,6 +431,8 @@ |
431 | 432 | $is_hidden = true; |
432 | 433 | } elseif ($component == 'restricted') { |
433 | 434 | $is_restricted = true; |
| 435 | + } elseif ($component == 'list') { |
| 436 | + $is_list = true; |
434 | 437 | } else { |
435 | 438 | $sub_components = explode('=', $component); |
436 | 439 | if (count($sub_components) == 2) { |
— | — | @@ -610,8 +613,8 @@ |
611 | 614 | // parameters in the form definition, and any information from |
612 | 615 | // the template definition (contained in the $all_fields parameter) |
613 | 616 | $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); |
616 | 619 | // if this is not part of a 'multiple' template, incrememt the |
617 | 620 | // global tab index (used for correct tabbing) |
618 | 621 | if (! $field_args['part_of_multiple']) |
— | — | @@ -681,9 +684,9 @@ |
682 | 685 | $info_id = "info_" . $sfgFieldNum; |
683 | 686 | if ($is_mandatory) { |
684 | 687 | 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')"; |
688 | 691 | if ($input_type == 'datetime' || $input_type == 'datetime with timezone') { |
689 | 692 | // TODO - validate the time fields |
690 | 693 | if ($input_type == 'datetime with timezone') { |
— | — | @@ -1057,8 +1060,8 @@ |
1058 | 1061 | } |
1059 | 1062 | } else if (type == 'date') { |
1060 | 1063 | // 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"); |
1063 | 1066 | if (day_field.value == '' || year_field.value == '') { |
1064 | 1067 | return true; |
1065 | 1068 | } else if (day_field.value.match(/^\d+$/) && |
— | — | @@ -1160,16 +1163,14 @@ |
1161 | 1164 | main_div.appendChild(new_div); |
1162 | 1165 | attachAutocompleteToAllFields(new_div); |
1163 | 1166 | |
1164 | | - if ($using_choosers) |
1165 | | - { |
| 1167 | + if ($using_choosers) { |
1166 | 1168 | hideOrShowFieldset(new_div); |
1167 | 1169 | } |
1168 | 1170 | } |
1169 | 1171 | |
1170 | 1172 | function removeInstanceEventHandler(this_div_id) |
1171 | 1173 | { |
1172 | | - return function() |
1173 | | - { |
| 1174 | + return function() { |
1174 | 1175 | removeInstance(this_div_id); |
1175 | 1176 | }; |
1176 | 1177 | } |
— | — | @@ -1190,10 +1191,8 @@ |
1191 | 1192 | { |
1192 | 1193 | var forms = document.getElementsByTagName("form"); |
1193 | 1194 | 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") { |
1198 | 1197 | attachAutocompleteToAllFields(forms[x]); |
1199 | 1198 | } |
1200 | 1199 | } |
— | — | @@ -1204,10 +1203,14 @@ |
1205 | 1204 | { |
1206 | 1205 | var inputs = base.getElementsByTagName("input"); |
1207 | 1206 | var y; |
1208 | | - for (y=0;y<inputs.length;y++) |
1209 | | - { |
| 1207 | + for (y = 0; y < inputs.length; y++) { |
1210 | 1208 | attachAutocompleteToField(inputs[y].id); |
1211 | 1209 | } |
| 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 | + } |
1212 | 1215 | } |
1213 | 1216 | |
1214 | 1217 | //Activate autocomplete functionality for the specified field |
— | — | @@ -1224,7 +1227,7 @@ |
1225 | 1228 | var div_id = input_id.replace(/input_/g, 'div_'); |
1226 | 1229 | var field_values = new Array(); |
1227 | 1230 | field_values = field_string.split(','); |
1228 | | - if (field_values[1] == 'multiple') { |
| 1231 | + if (field_values[1] == 'list') { |
1229 | 1232 | var delimiter = ","; |
1230 | 1233 | if (field_values[2] != null) { |
1231 | 1234 | delimiter = field_values[2]; |
— | — | @@ -1259,6 +1262,7 @@ |
1260 | 1263 | |
1261 | 1264 | if ($form_field->is_hidden) { |
1262 | 1265 | $text = $this->hiddenFieldHTML($form_field->input_name, $cur_value); |
| 1266 | + $javascript_text = ""; |
1263 | 1267 | } elseif ($form_field->input_type != '' && $this->mInputTypeHooks[$form_field->input_type] != null) { |
1264 | 1268 | $funcArgs = array(); |
1265 | 1269 | $funcArgs[] = $cur_value; |
— | — | @@ -1272,6 +1276,7 @@ |
1273 | 1277 | $default_args = $hook_values[1]; |
1274 | 1278 | $other_args = $form_field->field_args; |
1275 | 1279 | $other_args['possible_values'] = $template_field->possible_values; |
| 1280 | + $other_args['is_list'] = $template_field->is_list; |
1276 | 1281 | if ($template_field->is_relation) { |
1277 | 1282 | $other_args['is_relation'] = true; |
1278 | 1283 | $other_args['semantic_field_name'] = $template_field->semantic_field; |
— | — | @@ -1288,7 +1293,7 @@ |
1289 | 1294 | list($text, $javascript_text) = $this->textEntryHTML($cur_value, $form_field->input_name, $form_field->is_mandatory, $form_field->is_disabled, $field_args); |
1290 | 1295 | } else { // input type not defined in form, and not a relation |
1291 | 1296 | $field_type = $template_field->field_type; |
1292 | | - $is_list = $template_field->is_list; |
| 1297 | + $is_list = $form_field->is_list || $template_field->is_list; |
1293 | 1298 | if ($field_type != '' && |
1294 | 1299 | array_key_exists($field_type, $this->mSemanticTypeHooks) && |
1295 | 1300 | isset($this->mSemanticTypeHooks[$field_type][$is_list])) { |
— | — | @@ -1310,6 +1315,11 @@ |
1311 | 1316 | list($text, $javascript_text) = call_user_func_array($hook_values[0], $funcArgs); |
1312 | 1317 | } else { // anything else |
1313 | 1318 | $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 | + } |
1314 | 1324 | list($text, $javascript_text) = $this->textEntryHTML($cur_value, $form_field->input_name, $form_field->is_mandatory, $form_field->is_disabled, $other_args); |
1315 | 1325 | } |
1316 | 1326 | } |
— | — | @@ -1440,9 +1450,13 @@ |
1441 | 1451 | |
1442 | 1452 | function textEntryHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) { |
1443 | 1453 | // 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 | + } |
1447 | 1461 | } |
1448 | 1462 | |
1449 | 1463 | global $sfgTabIndex, $sfgFieldNum, $sfgJSValidationCalls; |
— | — | @@ -1624,7 +1638,7 @@ |
1625 | 1639 | return array($text, null); |
1626 | 1640 | } |
1627 | 1641 | |
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) { |
1629 | 1643 | // if 'no autocomplete' was specified, call the regular text entry instead |
1630 | 1644 | if (array_key_exists('no_autocomplete', $other_args) && |
1631 | 1645 | $other_args['no_autocomplete'] == true) |
— | — | @@ -1653,23 +1667,33 @@ |
1654 | 1668 | $input_id = "input_" . $sfgFieldNum; |
1655 | 1669 | $info_id = "info_" . $sfgFieldNum; |
1656 | 1670 | $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 |
1658 | 1678 | <input tabindex="$sfgTabIndex" id="$input_id" name="$input_name" type="text" |
1659 | 1679 | value="" size="$size" class="$className" $disabled_text/> |
| 1680 | + |
| 1681 | +END; |
| 1682 | + } |
| 1683 | + $text .=<<<END |
1660 | 1684 | <span id="$info_id" class="error_message"></span> |
1661 | 1685 | <div class="page_name_auto_complete" id="$div_name"></div> |
1662 | 1686 | <script type="text/javascript"> |
1663 | 1687 | |
1664 | 1688 | END; |
1665 | 1689 | $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"; |
1668 | 1692 | if (array_key_exists('delimiter', $other_args) && $other_args['delimiter'] != ",") { |
1669 | 1693 | $options_str_key .= "," . $other_args['delimiter']; |
1670 | 1694 | } |
1671 | 1695 | } |
1672 | 1696 | $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)) { |
1674 | 1698 | $autocomplete_string = "[['" . implode("'], ['", $autocomplete_values) . "']]"; |
1675 | 1699 | } else { |
1676 | 1700 | $autocomplete_string = "['" . implode("', '", $autocomplete_values) . "']"; |
— | — | @@ -1687,6 +1711,17 @@ |
1688 | 1712 | } |
1689 | 1713 | |
1690 | 1714 | 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 | + |
1691 | 1726 | global $sfgTabIndex, $sfgFieldNum; |
1692 | 1727 | |
1693 | 1728 | $className = ($is_mandatory) ? "mandatoryField" : "createboxInput"; |
— | — | @@ -1711,7 +1746,7 @@ |
1712 | 1747 | global $sfgTabIndex, $sfgFieldNum, $wgAmericanDates; |
1713 | 1748 | |
1714 | 1749 | $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"; |
1716 | 1751 | $month_names = sffGetMonthNames(); |
1717 | 1752 | foreach ($month_names as $i => $name) { |
1718 | 1753 | // pad out month to always be two digits |
— | — | @@ -1757,8 +1792,8 @@ |
1758 | 1793 | } |
1759 | 1794 | $disabled_text = ($is_disabled) ? "disabled" : ""; |
1760 | 1795 | $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"; |
1763 | 1798 | $text .= " <span id=\"$info_id\" class=\"error_message\"></span>"; |
1764 | 1799 | return array($text, null); |
1765 | 1800 | } |