Tobias Gritschacher has submitted this change and it was merged.
Change subject: Disabling "remove" link when there is just one reference snak
......................................................................
Disabling "remove" link when there is just one reference snak
Change-Id: I2d94a4e39b950419d8c187a3390584ad93592cea
---
M lib/resources/jquery.wikibase/jquery.wikibase.snaklistview.js
1 file changed, 22 insertions(+), 0 deletions(-)
Approvals:
Tobias Gritschacher: Verified; Looks good to me, approved
jenkins-bot: Checked
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.snaklistview.js
b/lib/resources/jquery.wikibase/jquery.wikibase.snaklistview.js
index d7d4eef..4a33a22 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.snaklistview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.snaklistview.js
@@ -152,6 +152,8 @@
this.$listview
.on( 'listviewitemadded', function( event, value, $newLi ) {
+ self._updateRemoveToolbarState();
+
// Listen to all the snakview "change" events to be
able to determine whether the
// snaklistview itself is valid.
$newLi.on( self._lia.prefixedEvent( 'change' ),
function( event ) {
@@ -160,6 +162,9 @@
} );
} )
.on( self._lia.prefixedEvent( 'change' ) + '
listviewitemremoved', function( event ) {
+ if ( event.type === 'listviewitemremoved' ) {
+ self._updateRemoveToolbarState();
+ }
// Forward the "change" event to external components
(e.g. the edit toolbar).
self._trigger( 'change' );
} )
@@ -210,6 +215,8 @@
self._createRemoveToolbar( $( item ) );
} );
+
+ self._updateRemoveToolbarState();
this.element.addClass( 'wb-edit' );
this._isInEditMode = true;
@@ -333,6 +340,7 @@
* @param {jQuery} $item List item node
*/
_createRemoveToolbar: function( $item ) {
+ // TODO: Use toolbar controller.
if ( $item.data( 'removetoolbar' ) ) {
return;
}
@@ -357,6 +365,20 @@
},
/**
+ * Updates the state (dis-/enabled) of the first list item's "remove"
toolbar. If there is only
+ * one item left in the list, the remove button will get disabled.
+ */
+ _updateRemoveToolbarState: function() {
+ if ( !this._listview.items() ) {
+ return;
+ }
+ var firstItemToolbar = $( this._listview.items()[0] ).data(
'removetoolbar' );
+ if ( firstItemToolbar ) {
+ firstItemToolbar[ ( this._listview.items().length === 1
) ? 'disable' : 'enable' ]();
+ }
+ },
+
+ /**
* Sets/Returns the current list of snaks represented by the view. If
there are no snaks, null
* will be returned.
* @since 0.4
--
To view, visit https://gerrit.wikimedia.org/r/53562
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2d94a4e39b950419d8c187a3390584ad93592cea
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits