Index: branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.css |
— | — | @@ -48,8 +48,16 @@ |
49 | 49 | |
50 | 50 | .formbuilder-slot { |
51 | 51 | border: none; |
| 52 | + padding: 3px; |
52 | 53 | } |
53 | 54 | |
| 55 | +/* type-specific styles */ |
| 56 | + |
| 57 | +.formbuilder .formbuilder-slot-type-label label { |
| 58 | + width: 100%; |
| 59 | + text-align: left; |
| 60 | +} |
| 61 | + |
54 | 62 | /* formBuilder editor */ |
55 | 63 | |
56 | 64 | .formbuilder-slot-nonempty { |
Index: branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.js |
— | — | @@ -129,6 +129,13 @@ |
130 | 130 | |
131 | 131 | //Used by preference editor to build field properties dialogs |
132 | 132 | var prefsDescriptionSpecifications = { |
| 133 | + "label": [ { |
| 134 | + "name": "label", |
| 135 | + "type": "string", |
| 136 | + "label": "label", |
| 137 | + "required": false, |
| 138 | + "default": "" |
| 139 | + } ], |
133 | 140 | "boolean": simpleField, |
134 | 141 | "string" : simpleField.concat( [ |
135 | 142 | { |
— | — | @@ -268,7 +275,9 @@ |
269 | 276 | $.error( "Missing 'type' parameter" ); |
270 | 277 | } |
271 | 278 | |
272 | | - this.$div = $( '<div/>' ).data( 'field', this ); |
| 279 | + this.$div = $( '<div/>' ) |
| 280 | + .addClass( 'formbuilder-slot-type-' + this.desc.type ) |
| 281 | + .data( 'field', this ); |
273 | 282 | } |
274 | 283 | |
275 | 284 | EmptyField.prototype.getElement = function() { |
— | — | @@ -286,13 +295,14 @@ |
287 | 296 | $.error( "Missing or wrong 'label' parameter" ); |
288 | 297 | } |
289 | 298 | |
290 | | - var $label = $( '<label/>' ) |
291 | | - .text( preproc( this.options.msgPrefix, this.desc.label ) ) |
292 | | - .attr('for', this.options.idPrefix + this.desc.name ); |
| 299 | + this.$label = $( '<label/>' ) |
| 300 | + .text( preproc( this.options.msgPrefix, this.desc.label ) ); |
293 | 301 | |
294 | | - this.$div.append( $label ); |
| 302 | + this.$div.append( this.$label ); |
295 | 303 | } |
296 | 304 | |
| 305 | + validFieldTypes["label"] = LabelField; |
| 306 | + |
297 | 307 | /* Abstract base class for all "simple" fields. Should not be instantiated. */ |
298 | 308 | SimpleField.prototype = object( LabelField.prototype ); |
299 | 309 | SimpleField.prototype.constructor = SimpleField; |
— | — | @@ -306,7 +316,9 @@ |
307 | 317 | if ( typeof desc.name.length > 40 ) { |
308 | 318 | $.error( 'name must be no longer than 40 characters' ); |
309 | 319 | } |
310 | | - |
| 320 | + |
| 321 | + this.$label.attr('for', this.options.idPrefix + this.desc.name ); |
| 322 | + |
311 | 323 | //Use default if it is given and no value has been set |
312 | 324 | if ( ( typeof options.values == 'undefined' || typeof options.values[desc.name] == 'undefined' ) |
313 | 325 | && typeof desc['default'] != 'undefined' ) |
— | — | @@ -822,15 +834,6 @@ |
823 | 835 | this.$div.attr( 'id', id ); |
824 | 836 | } |
825 | 837 | |
826 | | - //If there is an "intro", adds it to the section as a label |
827 | | - //TODO: kill "intro"s and make "label" fields, instead? |
828 | | - if ( typeof this.desc.intro == 'string' ) { |
829 | | - $( '<p/>' ) |
830 | | - .text( preproc( this.options.msgPrefix, this.desc.intro ) ) |
831 | | - .addClass( 'formBuilder-intro' ) |
832 | | - .appendTo( this.$div ); |
833 | | - } |
834 | | - |
835 | 838 | for ( var i = 0; i < this.desc.fields.length; i++ ) { |
836 | 839 | if ( options.editable === true ) { |
837 | 840 | //add an empty slot |
— | — | @@ -928,34 +931,38 @@ |
929 | 932 | 'options': selectOptions, |
930 | 933 | 'default': selectOptions[0].value |
931 | 934 | } ] |
932 | | - } ).formBuilder( {} ).dialog( { |
933 | | - width: 450, |
934 | | - modal: true, |
935 | | - resizable: false, |
936 | | - title: mw.msg( 'gadgets-formbuilder-editor-chose-field-title' ), |
937 | | - close: function() { |
938 | | - $( this ).remove(); |
939 | | - }, |
940 | | - buttons: [ |
941 | | - { |
942 | | - text: mw.msg( 'gadgets-formbuilder-editor-ok' ), |
943 | | - click: function() { |
944 | | - var values = $( this ).formBuilder( 'getValues' ); |
945 | | - $( this ).dialog( "close" ); |
946 | | - self._createFieldDialog( { |
947 | | - type: values.type, |
948 | | - callback: params.callback |
949 | | - } ); |
950 | | - } |
| 935 | + } ).formBuilder( {} ) |
| 936 | + .submit( function() { |
| 937 | + return false; //prevent form submission |
| 938 | + } ) |
| 939 | + .dialog( { |
| 940 | + width: 450, |
| 941 | + modal: true, |
| 942 | + resizable: false, |
| 943 | + title: mw.msg( 'gadgets-formbuilder-editor-chose-field-title' ), |
| 944 | + close: function() { |
| 945 | + $( this ).remove(); |
951 | 946 | }, |
952 | | - { |
953 | | - text: mw.msg( 'gadgets-formbuilder-editor-cancel' ), |
954 | | - click: function() { |
955 | | - $( this ).dialog( "close" ); |
| 947 | + buttons: [ |
| 948 | + { |
| 949 | + text: mw.msg( 'gadgets-formbuilder-editor-ok' ), |
| 950 | + click: function() { |
| 951 | + var values = $( this ).formBuilder( 'getValues' ); |
| 952 | + $( this ).dialog( "close" ); |
| 953 | + self._createFieldDialog( { |
| 954 | + type: values.type, |
| 955 | + callback: params.callback |
| 956 | + } ); |
| 957 | + } |
| 958 | + }, |
| 959 | + { |
| 960 | + text: mw.msg( 'gadgets-formbuilder-editor-cancel' ), |
| 961 | + click: function() { |
| 962 | + $( this ).dialog( "close" ); |
| 963 | + } |
956 | 964 | } |
957 | | - } |
958 | | - ] |
959 | | - } ); |
| 965 | + ] |
| 966 | + } ); |
960 | 967 | |
961 | 968 | return; |
962 | 969 | } else { |
Index: branches/salvatoreingala/Gadgets/Gadgets_tests.php |
— | — | @@ -202,6 +202,32 @@ |
203 | 203 | ) ) ); |
204 | 204 | } |
205 | 205 | |
| 206 | + //Tests for 'label' type preferences |
| 207 | + function testPrefsDescriptionsLabel() { |
| 208 | + $correct = array( |
| 209 | + 'fields' => array( |
| 210 | + array( |
| 211 | + 'type' => 'label', |
| 212 | + 'label' => 'foo' |
| 213 | + ) |
| 214 | + ) |
| 215 | + ); |
| 216 | + |
| 217 | + //Tests with correct values for 'label' |
| 218 | + foreach ( array( '', '@', '@message', 'foo', '@@not message' ) as $def ) { |
| 219 | + $correct['fields'][0]['label'] = $def; |
| 220 | + $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correct ) ); |
| 221 | + } |
| 222 | + |
| 223 | + //Tests with wrong values for 'label' |
| 224 | + $wrong = $correct; |
| 225 | + foreach ( array( 0, 1, true, false, null, array() ) as $label ) { |
| 226 | + $wrong['fields'][0]['label'] = $label; |
| 227 | + $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( $wrong ) ); |
| 228 | + } |
| 229 | + |
| 230 | + } |
| 231 | + |
206 | 232 | //Tests for 'boolean' type preferences |
207 | 233 | function testPrefsDescriptionsBoolean() { |
208 | 234 | $correct = array( |
Index: branches/salvatoreingala/Gadgets/backend/GadgetPrefs.php |
— | — | @@ -30,6 +30,15 @@ |
31 | 31 | * a list of messages referred to by it. If omitted, only the "label" field is returned (if it is a message). |
32 | 32 | */ |
33 | 33 | private static $prefsDescriptionSpecifications = array( |
| 34 | + 'label' => array( |
| 35 | + 'description' => array( |
| 36 | + 'label' => array( |
| 37 | + 'isMandatory' => true, |
| 38 | + 'validator' => 'is_string' |
| 39 | + ) |
| 40 | + ), |
| 41 | + 'flattener' => 'GadgetPrefs::flattenLabelDefinition' |
| 42 | + ), |
34 | 43 | 'boolean' => array( |
35 | 44 | 'description' => array( |
36 | 45 | 'name' => array( |
— | — | @@ -250,8 +259,12 @@ |
251 | 260 | return $count == 0 || array_keys( $param ) === range( 0, $count - 1 ); |
252 | 261 | } |
253 | 262 | |
| 263 | + private static function flattenLabelDefinition( $fieldDescription ) { |
| 264 | + return array(); |
| 265 | + } |
| 266 | + |
254 | 267 | //default flattener for simple fields that encode for a single preference |
255 | | - private static function flattenSimpleField( $fieldDescription ) { |
| 268 | + private static function flattenSimpleFieldDefinition( $fieldDescription ) { |
256 | 269 | return array( $fieldDescription['name'] => $fieldDescription ); |
257 | 270 | } |
258 | 271 | |
— | — | @@ -347,7 +360,7 @@ |
348 | 361 | if ( isset( $fieldSpec['flattener'] ) ) { |
349 | 362 | $flattener = $fieldSpec['flattener']; |
350 | 363 | } else { |
351 | | - $flattener = 'GadgetPrefs::flattenSimpleField'; |
| 364 | + $flattener = 'GadgetPrefs::flattenSimpleFieldDefinition'; |
352 | 365 | } |
353 | 366 | return call_user_func( $flattener, $fieldDescription ); |
354 | 367 | } |
— | — | @@ -776,11 +789,7 @@ |
777 | 790 | */ |
778 | 791 | public static function getMessages( $prefsDescription ) { |
779 | 792 | $msgs = array(); |
780 | | - |
781 | | - if ( isset( $prefsDescription['intro'] ) && self::isMessage( $prefsDescription['intro'] ) ) { |
782 | | - $msgs[] = substr( $prefsDescription['intro'], 1 ); |
783 | | - } |
784 | | - |
| 793 | + |
785 | 794 | foreach ( $prefsDescription['fields'] as $prefDesc ) { |
786 | 795 | $type = $prefDesc['type']; |
787 | 796 | $prefSpec = self::$prefsDescriptionSpecifications[$type]; |