r94090 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94089‎ | r94090 | r94091 >
Date:22:04, 8 August 2011
Author:salvatoreingala
Status:deferred
Tags:
Comment:
Removed "intro" member, added a "label" field type instead.
Modified paths:
  • /branches/salvatoreingala/Gadgets/Gadgets_tests.php (modified) (history)
  • /branches/salvatoreingala/Gadgets/backend/GadgetPrefs.php (modified) (history)
  • /branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.css (modified) (history)
  • /branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.js (modified) (history)

Diff [purge]

Index: branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.css
@@ -48,8 +48,16 @@
4949
5050 .formbuilder-slot {
5151 border: none;
 52+ padding: 3px;
5253 }
5354
 55+/* type-specific styles */
 56+
 57+.formbuilder .formbuilder-slot-type-label label {
 58+ width: 100%;
 59+ text-align: left;
 60+}
 61+
5462 /* formBuilder editor */
5563
5664 .formbuilder-slot-nonempty {
Index: branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.js
@@ -129,6 +129,13 @@
130130
131131 //Used by preference editor to build field properties dialogs
132132 var prefsDescriptionSpecifications = {
 133+ "label": [ {
 134+ "name": "label",
 135+ "type": "string",
 136+ "label": "label",
 137+ "required": false,
 138+ "default": ""
 139+ } ],
133140 "boolean": simpleField,
134141 "string" : simpleField.concat( [
135142 {
@@ -268,7 +275,9 @@
269276 $.error( "Missing 'type' parameter" );
270277 }
271278
272 - this.$div = $( '<div/>' ).data( 'field', this );
 279+ this.$div = $( '<div/>' )
 280+ .addClass( 'formbuilder-slot-type-' + this.desc.type )
 281+ .data( 'field', this );
273282 }
274283
275284 EmptyField.prototype.getElement = function() {
@@ -286,13 +295,14 @@
287296 $.error( "Missing or wrong 'label' parameter" );
288297 }
289298
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 ) );
293301
294 - this.$div.append( $label );
 302+ this.$div.append( this.$label );
295303 }
296304
 305+ validFieldTypes["label"] = LabelField;
 306+
297307 /* Abstract base class for all "simple" fields. Should not be instantiated. */
298308 SimpleField.prototype = object( LabelField.prototype );
299309 SimpleField.prototype.constructor = SimpleField;
@@ -306,7 +316,9 @@
307317 if ( typeof desc.name.length > 40 ) {
308318 $.error( 'name must be no longer than 40 characters' );
309319 }
310 -
 320+
 321+ this.$label.attr('for', this.options.idPrefix + this.desc.name );
 322+
311323 //Use default if it is given and no value has been set
312324 if ( ( typeof options.values == 'undefined' || typeof options.values[desc.name] == 'undefined' )
313325 && typeof desc['default'] != 'undefined' )
@@ -822,15 +834,6 @@
823835 this.$div.attr( 'id', id );
824836 }
825837
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 -
835838 for ( var i = 0; i < this.desc.fields.length; i++ ) {
836839 if ( options.editable === true ) {
837840 //add an empty slot
@@ -928,34 +931,38 @@
929932 'options': selectOptions,
930933 'default': selectOptions[0].value
931934 } ]
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();
951946 },
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+ }
956964 }
957 - }
958 - ]
959 - } );
 965+ ]
 966+ } );
960967
961968 return;
962969 } else {
Index: branches/salvatoreingala/Gadgets/Gadgets_tests.php
@@ -202,6 +202,32 @@
203203 ) ) );
204204 }
205205
 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+
206232 //Tests for 'boolean' type preferences
207233 function testPrefsDescriptionsBoolean() {
208234 $correct = array(
Index: branches/salvatoreingala/Gadgets/backend/GadgetPrefs.php
@@ -30,6 +30,15 @@
3131 * a list of messages referred to by it. If omitted, only the "label" field is returned (if it is a message).
3232 */
3333 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+ ),
3443 'boolean' => array(
3544 'description' => array(
3645 'name' => array(
@@ -250,8 +259,12 @@
251260 return $count == 0 || array_keys( $param ) === range( 0, $count - 1 );
252261 }
253262
 263+ private static function flattenLabelDefinition( $fieldDescription ) {
 264+ return array();
 265+ }
 266+
254267 //default flattener for simple fields that encode for a single preference
255 - private static function flattenSimpleField( $fieldDescription ) {
 268+ private static function flattenSimpleFieldDefinition( $fieldDescription ) {
256269 return array( $fieldDescription['name'] => $fieldDescription );
257270 }
258271
@@ -347,7 +360,7 @@
348361 if ( isset( $fieldSpec['flattener'] ) ) {
349362 $flattener = $fieldSpec['flattener'];
350363 } else {
351 - $flattener = 'GadgetPrefs::flattenSimpleField';
 364+ $flattener = 'GadgetPrefs::flattenSimpleFieldDefinition';
352365 }
353366 return call_user_func( $flattener, $fieldDescription );
354367 }
@@ -776,11 +789,7 @@
777790 */
778791 public static function getMessages( $prefsDescription ) {
779792 $msgs = array();
780 -
781 - if ( isset( $prefsDescription['intro'] ) && self::isMessage( $prefsDescription['intro'] ) ) {
782 - $msgs[] = substr( $prefsDescription['intro'], 1 );
783 - }
784 -
 793+
785794 foreach ( $prefsDescription['fields'] as $prefDesc ) {
786795 $type = $prefDesc['type'];
787796 $prefSpec = self::$prefsDescriptionSpecifications[$type];

Status & tagging log