Index: trunk/extensions/SemanticForms/includes/SF_FormInputs.php |
— | — | @@ -14,15 +14,6 @@ |
15 | 15 | */ |
16 | 16 | class SFFormInput { |
17 | 17 | /** |
18 | | - * Returns the set of input types, other than the main one, defined |
19 | | - * by this class; with the set of additional field arguments to |
20 | | - * be passed to each one. |
21 | | - */ |
22 | | - public static function getAlternateInputTypes() { |
23 | | - return array(); |
24 | | - } |
25 | | - |
26 | | - /** |
27 | 18 | * Returns the set of SMW property types for which this input is |
28 | 19 | * meant to be the default one - ideally, no more than one input |
29 | 20 | * should declare itself the default for any specific type. |
— | — | @@ -141,12 +132,6 @@ |
142 | 133 | return 'text'; |
143 | 134 | } |
144 | 135 | |
145 | | - public static function getAlternateInputTypes() { |
146 | | - return array( |
147 | | - array( 'year', array( 'size' => 4 ) ) |
148 | | - ); |
149 | | - } |
150 | | - |
151 | 136 | public static function getDefaultPropTypes() { |
152 | 137 | return array( |
153 | 138 | '_str' => array( 'field_type' => 'string' ), |
— | — | @@ -792,13 +777,13 @@ |
793 | 778 | } |
794 | 779 | } |
795 | 780 | |
796 | | -class SFTextAreaWithAutocompleteInput extends SFTextAreaInput { |
| 781 | +class SFTextAreaInput extends SFFormInput { |
797 | 782 | public static function getName() { |
798 | | - return 'textarea with autocomplete'; |
| 783 | + return 'textarea'; |
799 | 784 | } |
800 | 785 | |
801 | 786 | public static function getDefaultPropTypes() { |
802 | | - return array(); |
| 787 | + return array( '_txt' => array(), '_cod' => array() ); |
803 | 788 | } |
804 | 789 | |
805 | 790 | public static function getOtherPropTypesHandled() { |
— | — | @@ -810,22 +795,14 @@ |
811 | 796 | } |
812 | 797 | |
813 | 798 | static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
814 | | - // If 'no autocomplete' was specified, print a regular |
815 | | - // textarea instead. |
816 | | - if ( array_key_exists( 'no autocomplete', $other_args ) && |
817 | | - $other_args['no autocomplete'] == true ) { |
818 | | - unset( $other_args['autocompletion source'] ); |
819 | | - return SFTextAreaInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
820 | | - } |
821 | | - |
822 | 799 | global $sfgTabIndex, $sfgFieldNum; |
823 | 800 | |
824 | | - list( $autocompleteSettings, $remoteDataType, $delimiter ) = SFTextWithAutocompleteInput::setAutocompleteValues( $other_args ); |
825 | | - |
826 | | - $className = ( $is_mandatory ) ? "autocompleteInput mandatoryField" : "autocompleteInput createboxInput"; |
827 | | - if ( array_key_exists( 'class', $other_args ) ) |
| 801 | + $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput"; |
| 802 | + if ( array_key_exists( 'class', $other_args ) ) { |
828 | 803 | $className .= " " . $other_args['class']; |
829 | | - $input_id = "input_" . $sfgFieldNum; |
| 804 | + } |
| 805 | + // Use a special ID for the free text field, for FCK's needs. |
| 806 | + $input_id = $input_name == "free_text" ? "free_text" : "input_$sfgFieldNum"; |
830 | 807 | |
831 | 808 | if ( array_key_exists( 'rows', $other_args ) ) { |
832 | 809 | $rows = $other_args['rows']; |
— | — | @@ -837,7 +814,7 @@ |
838 | 815 | } else { |
839 | 816 | $cols = 80; |
840 | 817 | } |
841 | | - $text = ""; |
| 818 | + |
842 | 819 | if ( array_key_exists( 'autogrow', $other_args ) ) { |
843 | 820 | $className .= ' autoGrow'; |
844 | 821 | } |
— | — | @@ -849,60 +826,48 @@ |
850 | 827 | 'rows' => $rows, |
851 | 828 | 'cols' => $cols, |
852 | 829 | 'class' => $className, |
853 | | - 'autocompletesettings' => $autocompleteSettings, |
854 | 830 | ); |
855 | | - if ( !is_null( $remoteDataType ) ) { |
856 | | - $textarea_attrs['autocompletedatatype'] = $remoteDataType; |
857 | | - } |
858 | 831 | if ( $is_disabled ) { |
859 | 832 | $textarea_attrs['disabled'] = 'disabled'; |
860 | 833 | } |
861 | 834 | if ( array_key_exists( 'maxlength', $other_args ) ) { |
862 | 835 | $maxlength = $other_args['maxlength']; |
863 | 836 | // For every actual character pressed (i.e., excluding |
864 | | - // things like the Shift key), reduce the string to |
865 | | - // its allowed length if it's exceeded that. |
| 837 | + // things like the Shift key), reduce the string to its |
| 838 | + // allowed length if it's exceeded that. |
866 | 839 | // This JS code is complicated so that it'll work |
867 | 840 | // correctly in IE - IE moves the cursor to the end |
868 | | - // whenever this.value is reset, so we'll make sure |
869 | | - // to do that only when we need to. |
| 841 | + // whenever this.value is reset, so we'll make sure to |
| 842 | + // do that only when we need to. |
870 | 843 | $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); }"; |
871 | 844 | $textarea_attrs['onKeyDown'] = $maxLengthJSCheck; |
872 | 845 | $textarea_attrs['onKeyUp'] = $maxLengthJSCheck; |
873 | 846 | } |
874 | | - $textarea_input = Xml::element('textarea', $textarea_attrs, $cur_value, false); |
875 | | - $text .= $textarea_input; |
876 | | - |
877 | | - if ( array_key_exists( 'is_uploadable', $other_args ) && $other_args['is_uploadable'] == true ) { |
878 | | - if ( array_key_exists( 'default filename', $other_args ) ) { |
879 | | - $default_filename = $other_args['default filename']; |
880 | | - } else { |
881 | | - $default_filename = ""; |
882 | | - } |
883 | | - $text .= self::uploadLinkHTML( $input_id, $delimiter, $default_filename ); |
884 | | - } |
885 | | - |
| 847 | + $text = Xml::element( 'textarea', $textarea_attrs, $cur_value, false ); |
886 | 848 | $spanClass = "inputSpan"; |
887 | 849 | if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; } |
888 | | - $text = "\n" . Xml::tags( 'span', array( 'class' => $spanClass ), $text ); |
889 | | - |
| 850 | + $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text ); |
890 | 851 | return $text; |
891 | 852 | } |
892 | 853 | |
893 | 854 | public static function getParameters() { |
894 | 855 | $params = parent::getParameters(); |
895 | | - $params = array_merge( $params, SFTextWithAutocompleteInput::getAutocompletionParameters() ); |
| 856 | + $params[] = array( 'name' => 'preload', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_preload' ) ); |
| 857 | + $params[] = array( 'name' => 'rows', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_rows' ) ); |
| 858 | + $params[] = array( 'name' => 'cols', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_cols' ) ); |
| 859 | + $params[] = array( 'name' => 'maxlength', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_maxlength' ) ); |
| 860 | + $params[] = array( 'name' => 'autogrow', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_autogrow' ) ); |
896 | 861 | return $params; |
897 | 862 | } |
898 | 863 | } |
899 | 864 | |
900 | | -class SFTextAreaInput extends SFFormInput { |
| 865 | +class SFTextAreaWithAutocompleteInput extends SFTextAreaInput { |
901 | 866 | public static function getName() { |
902 | | - return 'textarea'; |
| 867 | + return 'textarea with autocomplete'; |
903 | 868 | } |
904 | 869 | |
905 | 870 | public static function getDefaultPropTypes() { |
906 | | - return array( '_txt' => array(), '_cod' => array() ); |
| 871 | + return array(); |
907 | 872 | } |
908 | 873 | |
909 | 874 | public static function getOtherPropTypesHandled() { |
— | — | @@ -914,14 +879,22 @@ |
915 | 880 | } |
916 | 881 | |
917 | 882 | static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
| 883 | + // If 'no autocomplete' was specified, print a regular |
| 884 | + // textarea instead. |
| 885 | + if ( array_key_exists( 'no autocomplete', $other_args ) && |
| 886 | + $other_args['no autocomplete'] == true ) { |
| 887 | + unset( $other_args['autocompletion source'] ); |
| 888 | + return SFTextAreaInput::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
| 889 | + } |
| 890 | + |
918 | 891 | global $sfgTabIndex, $sfgFieldNum; |
919 | 892 | |
920 | | - $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput"; |
921 | | - if ( array_key_exists( 'class', $other_args ) ) { |
| 893 | + list( $autocompleteSettings, $remoteDataType, $delimiter ) = SFTextWithAutocompleteInput::setAutocompleteValues( $other_args ); |
| 894 | + |
| 895 | + $className = ( $is_mandatory ) ? "autocompleteInput mandatoryField" : "autocompleteInput createboxInput"; |
| 896 | + if ( array_key_exists( 'class', $other_args ) ) |
922 | 897 | $className .= " " . $other_args['class']; |
923 | | - } |
924 | | - // Use a special ID for the free text field, for FCK's needs. |
925 | | - $input_id = $input_name == "free_text" ? "free_text" : "input_$sfgFieldNum"; |
| 898 | + $input_id = "input_" . $sfgFieldNum; |
926 | 899 | |
927 | 900 | if ( array_key_exists( 'rows', $other_args ) ) { |
928 | 901 | $rows = $other_args['rows']; |
— | — | @@ -933,7 +906,7 @@ |
934 | 907 | } else { |
935 | 908 | $cols = 80; |
936 | 909 | } |
937 | | - |
| 910 | + $text = ""; |
938 | 911 | if ( array_key_exists( 'autogrow', $other_args ) ) { |
939 | 912 | $className .= ' autoGrow'; |
940 | 913 | } |
— | — | @@ -945,37 +918,49 @@ |
946 | 919 | 'rows' => $rows, |
947 | 920 | 'cols' => $cols, |
948 | 921 | 'class' => $className, |
| 922 | + 'autocompletesettings' => $autocompleteSettings, |
949 | 923 | ); |
| 924 | + if ( !is_null( $remoteDataType ) ) { |
| 925 | + $textarea_attrs['autocompletedatatype'] = $remoteDataType; |
| 926 | + } |
950 | 927 | if ( $is_disabled ) { |
951 | 928 | $textarea_attrs['disabled'] = 'disabled'; |
952 | 929 | } |
953 | 930 | if ( array_key_exists( 'maxlength', $other_args ) ) { |
954 | 931 | $maxlength = $other_args['maxlength']; |
955 | 932 | // For every actual character pressed (i.e., excluding |
956 | | - // things like the Shift key), reduce the string to its |
957 | | - // allowed length if it's exceeded that. |
| 933 | + // things like the Shift key), reduce the string to |
| 934 | + // its allowed length if it's exceeded that. |
958 | 935 | // This JS code is complicated so that it'll work |
959 | 936 | // correctly in IE - IE moves the cursor to the end |
960 | | - // whenever this.value is reset, so we'll make sure to |
961 | | - // do that only when we need to. |
| 937 | + // whenever this.value is reset, so we'll make sure |
| 938 | + // to do that only when we need to. |
962 | 939 | $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); }"; |
963 | 940 | $textarea_attrs['onKeyDown'] = $maxLengthJSCheck; |
964 | 941 | $textarea_attrs['onKeyUp'] = $maxLengthJSCheck; |
965 | 942 | } |
966 | | - $text = Xml::element( 'textarea', $textarea_attrs, $cur_value, false ); |
| 943 | + $textarea_input = Xml::element('textarea', $textarea_attrs, $cur_value, false); |
| 944 | + $text .= $textarea_input; |
| 945 | + |
| 946 | + if ( array_key_exists( 'is_uploadable', $other_args ) && $other_args['is_uploadable'] == true ) { |
| 947 | + if ( array_key_exists( 'default filename', $other_args ) ) { |
| 948 | + $default_filename = $other_args['default filename']; |
| 949 | + } else { |
| 950 | + $default_filename = ""; |
| 951 | + } |
| 952 | + $text .= self::uploadLinkHTML( $input_id, $delimiter, $default_filename ); |
| 953 | + } |
| 954 | + |
967 | 955 | $spanClass = "inputSpan"; |
968 | 956 | if ( $is_mandatory ) { $spanClass .= " mandatoryFieldSpan"; } |
969 | | - $text = Xml::tags( 'span', array( 'class' => $spanClass ), $text ); |
| 957 | + $text = "\n" . Xml::tags( 'span', array( 'class' => $spanClass ), $text ); |
| 958 | + |
970 | 959 | return $text; |
971 | 960 | } |
972 | 961 | |
973 | 962 | public static function getParameters() { |
974 | 963 | $params = parent::getParameters(); |
975 | | - $params[] = array( 'name' => 'preload', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_preload' ) ); |
976 | | - $params[] = array( 'name' => 'rows', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_rows' ) ); |
977 | | - $params[] = array( 'name' => 'cols', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_cols' ) ); |
978 | | - $params[] = array( 'name' => 'maxlength', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_maxlength' ) ); |
979 | | - $params[] = array( 'name' => 'autogrow', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_autogrow' ) ); |
| 964 | + $params = array_merge( $params, SFTextWithAutocompleteInput::getAutocompletionParameters() ); |
980 | 965 | return $params; |
981 | 966 | } |
982 | 967 | } |
— | — | @@ -1083,12 +1068,6 @@ |
1084 | 1069 | return 'datetime'; |
1085 | 1070 | } |
1086 | 1071 | |
1087 | | - public static function getAlternateInputTypes() { |
1088 | | - return array( |
1089 | | - array( 'datetime with timezone', array( 'include_timezone' => true ) ) |
1090 | | - ); |
1091 | | - } |
1092 | | - |
1093 | 1072 | public static function getDefaultPropTypes() { |
1094 | 1073 | return array(); |
1095 | 1074 | } |
— | — | @@ -1100,7 +1079,7 @@ |
1101 | 1080 | static function getHTML( $datetime, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
1102 | 1081 | global $sfgTabIndex, $sfg24HourTime; |
1103 | 1082 | |
1104 | | - $include_timezone = $other_args['include_timezone']; |
| 1083 | + $include_timezone = array_key_exists( 'include timezone', $other_args ); |
1105 | 1084 | |
1106 | 1085 | if ( $datetime ) { |
1107 | 1086 | // Can show up here either as an array or a string, |
— | — | @@ -1192,6 +1171,35 @@ |
1193 | 1172 | } |
1194 | 1173 | } |
1195 | 1174 | |
| 1175 | +class SFYearInput extends SFTextInput { |
| 1176 | + public static function getName() { |
| 1177 | + return 'year'; |
| 1178 | + } |
| 1179 | + |
| 1180 | + public static function getDefaultPropTypes() { |
| 1181 | + return array(); |
| 1182 | + } |
| 1183 | + |
| 1184 | + public static function getOtherPropTypesHandled() { |
| 1185 | + return array( '_dat' ); |
| 1186 | + } |
| 1187 | + |
| 1188 | + public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
| 1189 | + $other_args['size'] = 4; |
| 1190 | + return parent::getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
| 1191 | + } |
| 1192 | + |
| 1193 | + public static function getParameters() { |
| 1194 | + $params = array(); |
| 1195 | + $params[] = array( 'name' => 'mandatory', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_mandatory' ) ); |
| 1196 | + $params[] = array( 'name' => 'restricted', 'type' => 'boolean', 'description' => wfMsg( 'sf_forminputs_restricted' ) ); |
| 1197 | + $params[] = array( 'name' => 'class', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_class' ) ); |
| 1198 | + $params[] = array( 'name' => 'default', 'type' => 'string', 'description' => wfMsg( 'sf_forminputs_default' ) ); |
| 1199 | + $params[] = array( 'name' => 'size', 'type' => 'int', 'description' => wfMsg( 'sf_forminputs_size' ) ); |
| 1200 | + return $params; |
| 1201 | + } |
| 1202 | +} |
| 1203 | + |
1196 | 1204 | class SFRadioButtonInput extends SFEnumInput { |
1197 | 1205 | public static function getName() { |
1198 | 1206 | return 'radiobutton'; |