http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94090
Revision: 94090 Author: salvatoreingala Date: 2011-08-08 22:04:15 +0000 (Mon, 08 Aug 2011) Log Message: ----------- Removed "intro" member, added a "label" field type instead. Modified Paths: -------------- branches/salvatoreingala/Gadgets/Gadgets_tests.php branches/salvatoreingala/Gadgets/backend/GadgetPrefs.php branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.css branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.js Modified: branches/salvatoreingala/Gadgets/Gadgets_tests.php =================================================================== --- branches/salvatoreingala/Gadgets/Gadgets_tests.php 2011-08-08 21:07:17 UTC (rev 94089) +++ branches/salvatoreingala/Gadgets/Gadgets_tests.php 2011-08-08 22:04:15 UTC (rev 94090) @@ -202,6 +202,32 @@ ) ) ); } + //Tests for 'label' type preferences + function testPrefsDescriptionsLabel() { + $correct = array( + 'fields' => array( + array( + 'type' => 'label', + 'label' => 'foo' + ) + ) + ); + + //Tests with correct values for 'label' + foreach ( array( '', '@', '@message', 'foo', '@@not message' ) as $def ) { + $correct['fields'][0]['label'] = $def; + $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correct ) ); + } + + //Tests with wrong values for 'label' + $wrong = $correct; + foreach ( array( 0, 1, true, false, null, array() ) as $label ) { + $wrong['fields'][0]['label'] = $label; + $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( $wrong ) ); + } + + } + //Tests for 'boolean' type preferences function testPrefsDescriptionsBoolean() { $correct = array( Modified: branches/salvatoreingala/Gadgets/backend/GadgetPrefs.php =================================================================== --- branches/salvatoreingala/Gadgets/backend/GadgetPrefs.php 2011-08-08 21:07:17 UTC (rev 94089) +++ branches/salvatoreingala/Gadgets/backend/GadgetPrefs.php 2011-08-08 22:04:15 UTC (rev 94090) @@ -30,6 +30,15 @@ * a list of messages referred to by it. If omitted, only the "label" field is returned (if it is a message). */ private static $prefsDescriptionSpecifications = array( + 'label' => array( + 'description' => array( + 'label' => array( + 'isMandatory' => true, + 'validator' => 'is_string' + ) + ), + 'flattener' => 'GadgetPrefs::flattenLabelDefinition' + ), 'boolean' => array( 'description' => array( 'name' => array( @@ -250,8 +259,12 @@ return $count == 0 || array_keys( $param ) === range( 0, $count - 1 ); } + private static function flattenLabelDefinition( $fieldDescription ) { + return array(); + } + //default flattener for simple fields that encode for a single preference - private static function flattenSimpleField( $fieldDescription ) { + private static function flattenSimpleFieldDefinition( $fieldDescription ) { return array( $fieldDescription['name'] => $fieldDescription ); } @@ -347,7 +360,7 @@ if ( isset( $fieldSpec['flattener'] ) ) { $flattener = $fieldSpec['flattener']; } else { - $flattener = 'GadgetPrefs::flattenSimpleField'; + $flattener = 'GadgetPrefs::flattenSimpleFieldDefinition'; } return call_user_func( $flattener, $fieldDescription ); } @@ -776,11 +789,7 @@ */ public static function getMessages( $prefsDescription ) { $msgs = array(); - - if ( isset( $prefsDescription['intro'] ) && self::isMessage( $prefsDescription['intro'] ) ) { - $msgs[] = substr( $prefsDescription['intro'], 1 ); - } - + foreach ( $prefsDescription['fields'] as $prefDesc ) { $type = $prefDesc['type']; $prefSpec = self::$prefsDescriptionSpecifications[$type]; Modified: branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.css =================================================================== --- branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.css 2011-08-08 21:07:17 UTC (rev 94089) +++ branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.css 2011-08-08 22:04:15 UTC (rev 94090) @@ -48,8 +48,16 @@ .formbuilder-slot { border: none; + padding: 3px; } +/* type-specific styles */ + +.formbuilder .formbuilder-slot-type-label label { + width: 100%; + text-align: left; +} + /* formBuilder editor */ .formbuilder-slot-nonempty { Modified: branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.js =================================================================== --- branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.js 2011-08-08 21:07:17 UTC (rev 94089) +++ branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.js 2011-08-08 22:04:15 UTC (rev 94090) @@ -129,6 +129,13 @@ //Used by preference editor to build field properties dialogs var prefsDescriptionSpecifications = { + "label": [ { + "name": "label", + "type": "string", + "label": "label", + "required": false, + "default": "" + } ], "boolean": simpleField, "string" : simpleField.concat( [ { @@ -268,7 +275,9 @@ $.error( "Missing 'type' parameter" ); } - this.$div = $( '<div/>' ).data( 'field', this ); + this.$div = $( '<div/>' ) + .addClass( 'formbuilder-slot-type-' + this.desc.type ) + .data( 'field', this ); } EmptyField.prototype.getElement = function() { @@ -286,13 +295,14 @@ $.error( "Missing or wrong 'label' parameter" ); } - var $label = $( '<label/>' ) - .text( preproc( this.options.msgPrefix, this.desc.label ) ) - .attr('for', this.options.idPrefix + this.desc.name ); + this.$label = $( '<label/>' ) + .text( preproc( this.options.msgPrefix, this.desc.label ) ); - this.$div.append( $label ); + this.$div.append( this.$label ); } + validFieldTypes["label"] = LabelField; + /* Abstract base class for all "simple" fields. Should not be instantiated. */ SimpleField.prototype = object( LabelField.prototype ); SimpleField.prototype.constructor = SimpleField; @@ -306,7 +316,9 @@ if ( typeof desc.name.length > 40 ) { $.error( 'name must be no longer than 40 characters' ); } - + + this.$label.attr('for', this.options.idPrefix + this.desc.name ); + //Use default if it is given and no value has been set if ( ( typeof options.values == 'undefined' || typeof options.values[desc.name] == 'undefined' ) && typeof desc['default'] != 'undefined' ) @@ -822,15 +834,6 @@ this.$div.attr( 'id', id ); } - //If there is an "intro", adds it to the section as a label - //TODO: kill "intro"s and make "label" fields, instead? - if ( typeof this.desc.intro == 'string' ) { - $( '<p/>' ) - .text( preproc( this.options.msgPrefix, this.desc.intro ) ) - .addClass( 'formBuilder-intro' ) - .appendTo( this.$div ); - } - for ( var i = 0; i < this.desc.fields.length; i++ ) { if ( options.editable === true ) { //add an empty slot @@ -928,34 +931,38 @@ 'options': selectOptions, 'default': selectOptions[0].value } ] - } ).formBuilder( {} ).dialog( { - width: 450, - modal: true, - resizable: false, - title: mw.msg( 'gadgets-formbuilder-editor-chose-field-title' ), - close: function() { - $( this ).remove(); - }, - buttons: [ - { - text: mw.msg( 'gadgets-formbuilder-editor-ok' ), - click: function() { - var values = $( this ).formBuilder( 'getValues' ); - $( this ).dialog( "close" ); - self._createFieldDialog( { - type: values.type, - callback: params.callback - } ); - } + } ).formBuilder( {} ) + .submit( function() { + return false; //prevent form submission + } ) + .dialog( { + width: 450, + modal: true, + resizable: false, + title: mw.msg( 'gadgets-formbuilder-editor-chose-field-title' ), + close: function() { + $( this ).remove(); }, - { - text: mw.msg( 'gadgets-formbuilder-editor-cancel' ), - click: function() { - $( this ).dialog( "close" ); + buttons: [ + { + text: mw.msg( 'gadgets-formbuilder-editor-ok' ), + click: function() { + var values = $( this ).formBuilder( 'getValues' ); + $( this ).dialog( "close" ); + self._createFieldDialog( { + type: values.type, + callback: params.callback + } ); + } + }, + { + text: mw.msg( 'gadgets-formbuilder-editor-cancel' ), + click: function() { + $( this ).dialog( "close" ); + } } - } - ] - } ); + ] + } ); return; } else { _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs