jenkins-bot has submitted this change and it was merged.

Change subject: (bug 38201) working counters for multiple SiteLinksEditTool 
instances
......................................................................


(bug 38201) working counters for multiple SiteLinksEditTool instances

Introduced "counterSurfaces" option for PropertyEditTool. This allows to define 
counters outside of
a tools subject node and therefore allows us to get rid of the hack in the 
SiteLinksEditTool where
we were globally grabbing a counter node by its ID.

Change-Id: I70b3c06679819f1066fc8312e3a54f98689960ca
---
M lib/resources/wikibase.ui.PropertyEditTool.js
M lib/resources/wikibase.ui.SiteLinksEditTool.js
M repo/resources/wikibase.ui.entityViewInit.js
3 files changed, 20 insertions(+), 30 deletions(-)

Approvals:
  Henning Snater: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/resources/wikibase.ui.PropertyEditTool.js 
b/lib/resources/wikibase.ui.PropertyEditTool.js
index defb334..f697501 100644
--- a/lib/resources/wikibase.ui.PropertyEditTool.js
+++ b/lib/resources/wikibase.ui.PropertyEditTool.js
@@ -43,6 +43,9 @@
  *
  * @option fullListMessage {string} Message displayed when this 
PropertyEditTool may contain
  *         multiple EditableValues but the maximum number of values has been 
reached
+ *
+ * @option counterContainers {jQuery} One or more elements that will serve as 
additional nodes where
+ *         the PropertyEditTool will draw and update counters.
  */
 wb.ui.PropertyEditTool = wb.utilities.inherit( PARENT, {
        /**
@@ -81,7 +84,8 @@
                        PARENT.prototype._options, {
                                allowsMultipleValues: true,
                                allowsFullErase: false,
-                               fullListMessage: mw.message( 
'wikibase-propertyedittool-full' )
+                               fullListMessage: mw.message( 
'wikibase-propertyedittool-full' ),
+                               counterContainers: null
                        },
                        options
                );
@@ -409,6 +413,11 @@
                        this._toolbar.destroy();
                        this._toolbar = null;
                }
+
+               var $additionalCounterNodes = this.getOption( 
'counterContainers' );
+               if( $additionalCounterNodes instanceof $ ) {
+                       $additionalCounterNodes.removeClass( this.UI_CLASS + 
'-counter' );
+               }
        },
 
        /**
@@ -522,19 +531,12 @@
         * @since 0.2
         */
        refreshCounters: function() {
-               var counterElems = this._getCounterNodes();
-               if( counterElems !== null && counterElems.length > 0 ) {
-                       this._getCounterNodes().empty().append( 
this._getFormattedCounterText() );
+               var counterElems = this.getOption( 'counterContainers' );
+               if( counterElems instanceof $ ) {
+                       // Make sure all counter nodes have the UI class for 
styling.
+                       counterElems.addClass( this.UI_CLASS + '-counter' );
+                       counterElems.empty().append( 
this._getFormattedCounterText() );
                }
-       },
-
-       /**
-        * Returns nodes which should serve as counters, displaying the number 
of nodes.
-        *
-        * @return jQuery
-        */
-       _getCounterNodes: function() {
-               return this._subject.find( '.' + this.UI_CLASS + '-counter' );
        },
 
        /**
diff --git a/lib/resources/wikibase.ui.SiteLinksEditTool.js 
b/lib/resources/wikibase.ui.SiteLinksEditTool.js
index 2c14ec7..1059700 100644
--- a/lib/resources/wikibase.ui.SiteLinksEditTool.js
+++ b/lib/resources/wikibase.ui.SiteLinksEditTool.js
@@ -440,17 +440,7 @@
                        }
                }
                return unusedAllowedSiteIds;
-       },
-
-       /**
-        * @see wb.ui.PropertyEditTool._getCounterNodes
-        *
-        * @return jQuery
-        */
-       _getCounterNodes: function() {
-               return $( '#wb-item-' + mw.config.get('wbEntityId') + 
'-sitelinks-counter' );
        }
-
 } );
 
 /**
diff --git a/repo/resources/wikibase.ui.entityViewInit.js 
b/repo/resources/wikibase.ui.entityViewInit.js
index 83be1d8..8228eea 100644
--- a/repo/resources/wikibase.ui.entityViewInit.js
+++ b/repo/resources/wikibase.ui.entityViewInit.js
@@ -126,7 +126,8 @@
 
                        // removing site links heading to rebuild it with value 
counter
                        $( 'table.wb-sitelinks' ).each( function() {
-                               var group = $( this ).data( 
'wb-sitelinks-group' );
+                               var group = $( this ).data( 
'wb-sitelinks-group' ),
+                                       $sitesCounterContainer = $( '<span/>' );
 
                                // add site links section heading:
                                $( this ).before(
@@ -134,15 +135,12 @@
                                                'wb-section-heading',
                                                mw.msg( 'wikibase-sitelinks-' + 
group ),
                                                'sitelinks'
-                                       ).append(
-                                               $( '<span/>' )
-                                               .attr( 'id', 'wb-item-' + 
mw.config.get('wbEntityId') + '-sitelinks-counter' )
-                                               .addClass( 
'wb-ui-propertyedittool-counter' )
-                                       )
+                                       ).append( $sitesCounterContainer )
                                );
                                // actual initialization
                                new wb.ui.SiteLinksEditTool( $( this ), {
-                                       allowedSites: wb.getSitesOfGroup( group 
)
+                                       allowedSites: wb.getSitesOfGroup( group 
),
+                                       counterContainers: 
$sitesCounterContainer
                                } );
                        } );
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I70b3c06679819f1066fc8312e3a54f98689960ca
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to