Aude has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/180145

Change subject: Spin off wb.experts.Item from wb.experts.Entity
......................................................................

Spin off wb.experts.Item from wb.experts.Entity

Change-Id: I300a3abf0f10f0b3cf8048215ccd015e6e369fee
---
M repo/resources/experts/Entity.js
A repo/resources/experts/Item.js
M repo/resources/experts/getStore.js
M repo/resources/experts/resources.php
R repo/tests/qunit/experts/Item.tests.js
M repo/tests/qunit/resources.php
6 files changed, 99 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/45/180145/1

diff --git a/repo/resources/experts/Entity.js b/repo/resources/experts/Entity.js
index ceabd41..7a4a216 100644
--- a/repo/resources/experts/Entity.js
+++ b/repo/resources/experts/Entity.js
@@ -14,41 +14,64 @@
         * `valueview` `Expert` for specifying a reference to a Wikibase 
`Entity`.
         * @class wikibase.experts.Entity
         * @extends jQuery.valueview.experts.StringValue
+        * @abstract
+        * @uses jQuery.wikibase.entityselector
         * @since 0.4
         * @licence GNU GPL v2+
         * @author Daniel Werner < [email protected] >
         */
-       MODULE.Entity = vv.expert( 'wikibaseentity', PARENT, {
+       var SELF = MODULE.Entity = vv.expert( 'wikibaseentity', PARENT, {
                /**
                 * @inheritdoc
+                *
+                * @throws {Error} when called because this `Expert` is meant 
to be abstract.
                 */
                _init: function() {
+                       throw new Error( 'Abstract Entity id expert cannot be 
instantiated directly' );
+               },
+
+               /**
+                * @protected
+                */
+               _initEntityExpert: function() {
                        PARENT.prototype._init.call( this );
 
                        // FIXME: Use SuggestedStringValue
 
                        var notifier = this._viewNotifier,
-                               $input = this.$input,
                                self = this,
                                repoConfig = mw.config.get( 'wbRepo' ),
                                repoApiUrl = repoConfig.url + 
repoConfig.scriptPath + '/api.php';
 
-                       $input.entityselector( {
-                               url: repoApiUrl,
-                               selectOnAutocomplete: true
-                       } );
+                       this._initEntityselector( repoApiUrl );
 
                        var value = this.viewState().value(),
                                entityId = value && value.getPrefixedId( 
WB_ENTITIES_PREFIXMAP );
 
                        this.$input.data( 'entityselector' ).selectedEntity( 
entityId );
-                       $input
+
+                       this.$input
                        .on( 'eachchange.' + this.uiBaseClass, function( e ) {
                                $( this ).data( 'entityselector' 
).repositionMenu();
                        } )
                        .on( 'entityselectorselected.' + this.uiBaseClass, 
function( e ) {
                                self._resizeInput();
                                notifier.notify( 'change' );
+                       } );
+               },
+
+               /**
+                * Initializes a `jQuery.wikibase.entityselector` instance on 
the `Expert`'s input element.
+                * @abstract
+                * @protected
+                *
+                * @param {string} repoApiUrl
+                */
+               _initEntityselector: function( repoApiUrl ) {
+                       this.$input.entityselector( {
+                               url: repoApiUrl,
+                               type: this.constructor.TYPE,
+                               selectOnAutocomplete: true
                        } );
                },
 
@@ -81,4 +104,11 @@
                }
        } );
 
+       /**
+        * `Entity` type this `Expert` supports.
+        * @property {string} [TYPE=null]
+        * @static
+        */
+       SELF.TYPE = null;
+
 }( mediaWiki, wikibase, jQuery, jQuery.valueview ) );
diff --git a/repo/resources/experts/Item.js b/repo/resources/experts/Item.js
new file mode 100644
index 0000000..bf41a4b
--- /dev/null
+++ b/repo/resources/experts/Item.js
@@ -0,0 +1,32 @@
+( function( wb, vv ) {
+       'use strict';
+
+var MODULE = wb.experts,
+       PARENT = wb.experts.Entity;
+
+/**
+ * `valueview` `Expert` for specifying a reference to a Wikibase `Item`.
+ * @see jQuery.valueview.expert
+ * @see jQuery.valueview.Expert
+ * @class wikibase.experts.Item
+ * @extends wikibase.experts.Entity
+ * @uses jQuery.valueview
+ * @since 0.5
+ * @licence GNU GPL v2+
+ * @author H. Snater < [email protected] >
+ */
+var SELF = MODULE.Item = vv.expert( 'wikibaseitem', PARENT, {
+       /**
+        * @inheritdoc
+        */
+       _init: function() {
+               PARENT.prototype._initEntityExpert.call( this );
+       }
+} );
+
+/**
+ * @inheritdoc
+ */
+SELF.TYPE = 'item';
+
+}( wikibase, jQuery.valueview ) );
diff --git a/repo/resources/experts/getStore.js 
b/repo/resources/experts/getStore.js
index 4e45357..ef3a691 100644
--- a/repo/resources/experts/getStore.js
+++ b/repo/resources/experts/getStore.js
@@ -14,11 +14,6 @@
        var expertStore = new vv.ExpertStore( vv.experts.UnsupportedValue );
 
        expertStore.registerDataValueExpert(
-               wb.experts.Entity,
-               wb.datamodel.EntityId.TYPE
-       );
-
-       expertStore.registerDataValueExpert(
                vv.experts.GlobeCoordinateInput,
                dv.GlobeCoordinateValue.TYPE
        );
@@ -49,6 +44,14 @@
                );
        }
 
+       var monoTextType = dataTypeStore.getDataType( 'monolingualtext' );
+       if( monoTextType ) {
+               expertStore.registerDataTypeExpert(
+                       vv.experts.MonolingualText,
+                       monoTextType.getId()
+               );
+       }
+
        var urlType = dataTypeStore.getDataType( 'url' );
        if( urlType ) {
                expertStore.registerDataTypeExpert(
@@ -57,11 +60,11 @@
                );
        }
 
-       var monoTextType = dataTypeStore.getDataType( 'monolingualtext' );
-       if( monoTextType ) {
+       var wikibaseItemType = dataTypeStore.getDataType( 'wikibase-item' );
+       if( wikibaseItemType ) {
                expertStore.registerDataTypeExpert(
-                       vv.experts.MonolingualText,
-                       monoTextType.getId()
+                       wb.experts.Item,
+                       wikibaseItemType.getId()
                );
        }
 
diff --git a/repo/resources/experts/resources.php 
b/repo/resources/experts/resources.php
index d9d6871..67bae85 100644
--- a/repo/resources/experts/resources.php
+++ b/repo/resources/experts/resources.php
@@ -40,7 +40,7 @@
                                'jquery.valueview.experts.UnsupportedValue',
                                'wikibase.datamodel.EntityId',
                                'wikibase.experts.__namespace',
-                               'wikibase.experts.Entity',
+                               'wikibase.experts.Item',
                        ),
                ),
 
@@ -54,9 +54,21 @@
                                'jquery.valueview.experts.StringValue',
                                'jquery.wikibase.entityselector',
                                'mw.config.values.wbRepo',
+                               'util.inherit',
                                'wikibase.experts.__namespace',
                        ),
                ),
+
+               'wikibase.experts.Item' => $moduleTemplate + array(
+                       'scripts' => array(
+                               'Item.js',
+                       ),
+                       'dependencies' => array(
+                               'jquery.valueview.Expert',
+                               'wikibase.experts.__namespace',
+                               'wikibase.experts.Entity',
+                       ),
+               ),
        );
 
 } );
diff --git a/repo/tests/qunit/experts/Entity.tests.js 
b/repo/tests/qunit/experts/Item.tests.js
similarity index 74%
rename from repo/tests/qunit/experts/Entity.tests.js
rename to repo/tests/qunit/experts/Item.tests.js
index 1903f68..eab8b7c 100644
--- a/repo/tests/qunit/experts/Entity.tests.js
+++ b/repo/tests/qunit/experts/Item.tests.js
@@ -7,10 +7,10 @@
 
        var testExpert = valueview.tests.testExpert;
 
-       QUnit.module( 'wikibase.experts.Entity' );
+       QUnit.module( 'wikibase.experts.Item' );
 
        testExpert( {
-               expertConstructor: wb.experts.Entity
+               expertConstructor: wb.experts.Item
        } );
 
 }( QUnit, jQuery.valueview, wikibase ) );
diff --git a/repo/tests/qunit/resources.php b/repo/tests/qunit/resources.php
index 48bda24..8334384 100644
--- a/repo/tests/qunit/resources.php
+++ b/repo/tests/qunit/resources.php
@@ -101,12 +101,12 @@
                        ),
                ),
 
-               'wikibase.experts.Entity.tests' => $moduleBase + array(
+               'wikibase.experts.Item.tests' => $moduleBase + array(
                        'scripts' => array(
-                               'experts/Entity.tests.js',
+                               'experts/Item.tests.js',
                        ),
                        'dependencies' => array(
-                               'wikibase.experts.Entity',
+                               'wikibase.experts.Item',
                                'wikibase.tests.qunit.testrunner',
                        ),
                ),

-- 
To view, visit https://gerrit.wikimedia.org/r/180145
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I300a3abf0f10f0b3cf8048215ccd015e6e369fee
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: wmf/1.25wmf12c
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to