NamespaceMultiselectWidget: Allow filtering by namespace ID or label
authorMoriel Schottlender <moriel@gmail.com>
Thu, 28 Feb 2019 19:21:02 +0000 (11:21 -0800)
committerMoriel Schottlender <moriel@gmail.com>
Thu, 7 Mar 2019 21:19:25 +0000 (13:19 -0800)
If the user types in a namespace ID, the menu should display the
corresponding namespace value, and allow its addition.

Depends on I9bc411e844d16034d8 being available in the OOUI release.

Bug: T216078
Depends-On: I9bc411e844d16034d86e0f8ed28fa20356a78bdf
Change-Id: Ifa113241b391a32ce64c0c2b1a6d55d1ef64de97

resources/Resources.php
resources/src/mediawiki.widgets/mw.widgets.NamespacesMenuOptionWidget.js [new file with mode: 0644]
resources/src/mediawiki.widgets/mw.widgets.NamespacesMultiselectWidget.js

index 65e6855..167d591 100644 (file)
@@ -2800,6 +2800,7 @@ return [
        'mediawiki.widgets.NamespacesMultiselectWidget' => [
                'scripts' => [
                        'resources/src/mediawiki.widgets/mw.widgets.NamespacesMultiselectWidget.js',
+                       'resources/src/mediawiki.widgets/mw.widgets.NamespacesMenuOptionWidget.js',
                ],
                'dependencies' => [
                        'oojs-ui-widgets',
diff --git a/resources/src/mediawiki.widgets/mw.widgets.NamespacesMenuOptionWidget.js b/resources/src/mediawiki.widgets/mw.widgets.NamespacesMenuOptionWidget.js
new file mode 100644 (file)
index 0000000..24f52af
--- /dev/null
@@ -0,0 +1,37 @@
+/*!
+ * MediaWiki Widgets - NamespacesMenuOptionWidget class.
+ *
+ * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+( function () {
+
+       /**
+        * Creates an mw.widgets.NamespacesMenuOptionWidget object
+        *
+        * This MenuOptionWidget widget returns an item match text that includes
+        * both the label and the data, so the menu can filter on either.
+        *
+        * @class
+        * @extends OO.ui.MenuOptionWidget
+        *
+        * @constructor
+        * @param {Object} [config] Configuration options
+        */
+       mw.widgets.NamespacesMenuOptionWidget = function MwWidgetsNamespacesMenuOptionWidget( config ) {
+               // Parent
+               mw.widgets.NamespacesMenuOptionWidget.parent.call( this, config );
+       };
+
+       /* Setup */
+
+       OO.inheritClass( mw.widgets.NamespacesMenuOptionWidget, OO.ui.MenuOptionWidget );
+
+       /**
+        * @inheritdoc
+        */
+       mw.widgets.NamespacesMenuOptionWidget.prototype.getMatchText = function () {
+               return this.getData() + ' ' + this.getLabel();
+       };
+
+}() );
index e5adc29..d4e9b1c 100644 (file)
                        {
                                clearInputOnChoose: true,
                                inputPosition: 'inline',
-                               allowEditTags: false
+                               allowEditTags: false,
+                               menu: {
+                                       filterMode: 'substring'
+                               }
                        },
                        config,
                        {
        OO.inheritClass( mw.widgets.NamespacesMultiselectWidget, OO.ui.MenuTagMultiselectWidget );
        OO.mixinClass( mw.widgets.NamespacesMultiselectWidget, OO.ui.mixin.PendingElement );
 
+       /* Methods */
+
+       /**
+        * @inheritdoc
+        */
+       mw.widgets.NamespacesMultiselectWidget.prototype.createMenuOptionWidget = function ( data, label, icon ) {
+               return new mw.widgets.NamespacesMenuOptionWidget( {
+                       data: data,
+                       label: label || data,
+                       icon: icon
+               } );
+       };
+
 }() );