Daniel Werner has uploaded a new change for review.
https://gerrit.wikimedia.org/r/67572
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, 29 insertions(+), 23 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/72/67572/1
diff --git a/lib/resources/wikibase.ui.PropertyEditTool.js
b/lib/resources/wikibase.ui.PropertyEditTool.js
index d87095f..6a9cfba 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 counterSurfaces {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' ),
+ counterSurfaces: null
},
options
);
@@ -409,6 +413,11 @@
this._toolbar.destroy();
this._toolbar = null;
}
+
+ var $additionalCounterNodes = this.getOption( 'counterSurfaces'
);
+ if( $additionalCounterNodes instanceof $ ) {
+ $additionalCounterNodes.removeClass( this.UI_CLASS +
'-counter' );
+ }
},
/**
@@ -523,18 +532,27 @@
*/
refreshCounters: function() {
var counterElems = this._getCounterNodes();
- if( counterElems !== null && counterElems.length > 0 ) {
- this._getCounterNodes().empty().append(
this._getFormattedCounterText() );
- }
+
+ // 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
+ * @since 0.4
+ *
+ * @returns {jQuery}
*/
_getCounterNodes: function() {
- return this._subject.find( '.' + this.UI_CLASS + '-counter' );
+ var $nodes = this._subject.find( '.' + this.UI_CLASS +
'-counter' ),
+ $optionalNodes = this.getOption( 'counterSurfaces' );
+
+ if( $optionalNodes instanceof $ ) {
+ $nodes = $nodes.add( $optionalNodes );
+ }
+ return $nodes;
},
/**
diff --git a/lib/resources/wikibase.ui.SiteLinksEditTool.js
b/lib/resources/wikibase.ui.SiteLinksEditTool.js
index a8929dd..4b70aa6 100644
--- a/lib/resources/wikibase.ui.SiteLinksEditTool.js
+++ b/lib/resources/wikibase.ui.SiteLinksEditTool.js
@@ -442,17 +442,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..36a0aeb 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' ),
+ $sitesCounterSurface = $( '<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( $sitesCounterSurface )
);
// actual initialization
new wb.ui.SiteLinksEditTool( $( this ), {
- allowedSites: wb.getSitesOfGroup( group
)
+ allowedSites: wb.getSitesOfGroup( group
),
+ counterSurfaces: $sitesCounterSurface
} );
} );
--
To view, visit https://gerrit.wikimedia.org/r/67572
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I70b3c06679819f1066fc8312e3a54f98689960ca
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits