Tobias Gritschacher has submitted this change and it was merged. Change subject: Removing toolbar definition from listview widget ......................................................................
Removing toolbar definition from listview widget The toolbar definition in the listview widget actually belongs to the list of references initialized in the statementview widget. The listview widget shall not be aware of editing interaction. Change-Id: I4d4e363f659af62042ab6dcaeaccbb14f3656737 --- M lib/resources/jquery.wikibase/jquery.wikibase.listview.js M lib/resources/jquery.wikibase/jquery.wikibase.statementview.js M lib/resources/jquery.wikibase/jquery.wikibase.toolbarcontroller/toolbarcontroller.js M repo/resources/wikibase.ui.entityViewInit.js 4 files changed, 35 insertions(+), 24 deletions(-) Approvals: Tobias Gritschacher: Verified; Looks good to me, approved diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.listview.js b/lib/resources/jquery.wikibase/jquery.wikibase.listview.js index 6e1cce4..24513e1 100644 --- a/lib/resources/jquery.wikibase/jquery.wikibase.listview.js +++ b/lib/resources/jquery.wikibase/jquery.wikibase.listview.js @@ -327,17 +327,4 @@ } ); -// Register toolbar: -$.wikibase.toolbarcontroller.definition( 'addtoolbar', { - widget: { - name: 'wikibase.listview', - prototype: $.wikibase.listview.prototype - }, - options: { - interactionWidgetName: $.wikibase.listview.prototype.widgetName, - toolbarParentSelector: '.wb-listview-toolbar', - addButtonLabel: mw.msg( 'wikibase-addreference' ) - } -} ); - }( mediaWiki, wikibase, jQuery ) ); diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js index 30db435..4424a4b 100644 --- a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js +++ b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js @@ -164,7 +164,7 @@ } } ); -// Register toolbar: +// Register toolbars: $.wikibase.toolbarcontroller.definition( 'edittoolbar', { widget: { name: 'wikibase.statementview', @@ -176,4 +176,20 @@ } } ); +$.wikibase.toolbarcontroller.definition( 'addtoolbar', { + id: 'references', + selector: '.wb-statement-references-container', + eventPrefix: 'referenceview', + baseClass: 'wb-referenceview', + options: { + toolbarParentSelector: '.wb-statement-references > .wb-listview-toolbar', + customAction: function( event, $parent ) { + var statementView = $parent.closest( '.wb-statementview' ).data( 'statementview' ); + statementView.$references.data( 'listview' ).enterNewItem(); + }, + eventPrefix: $.wikibase.statementview.prototype.widgetEventPrefix, + addButtonLabel: mw.msg( 'wikibase-addreference' ) + } +} ); + }( mediaWiki, wikibase, jQuery ) ); diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.toolbarcontroller/toolbarcontroller.js b/lib/resources/jquery.wikibase/jquery.wikibase.toolbarcontroller/toolbarcontroller.js index 4eefe60..1799464 100644 --- a/lib/resources/jquery.wikibase/jquery.wikibase.toolbarcontroller/toolbarcontroller.js +++ b/lib/resources/jquery.wikibase/jquery.wikibase.toolbarcontroller/toolbarcontroller.js @@ -54,16 +54,23 @@ /** * Initializes the toolbars for the nodes that are descendants of the node the toolbar * controller is initialized on. + * * @since 0.4 + * @param {boolean} [isPending] Whether element that triggered the toolbar + * (re-)initialization is in a pending state. */ - initToolbars: function() { + initToolbars: function( isPending ) { var self = this; $.each( TOOLBAR_TYPES, function( i, type ) { $.each( self.options[type], function( j, id ) { - var def = $.wikibase.toolbarcontroller.definition( type, id ); + var def = $.wikibase.toolbarcontroller.definition( type, id ), + options = ( type === 'edittoolbar' && isPending ) ? + $.extend( {}, def.options, { enableRemove: !isPending } ) + : def.options; + self.element - .find( def.selector || ':' + def.widget.fullName )[type]( def.options ); + .find( def.selector || ':' + def.widget.fullName )[type]( options ); } ); } ); @@ -90,13 +97,14 @@ // Listen to widget's native "create" event in order to initialize toolbars // corresponding to the widget just instantiated. self.element.on( eventPrefix + 'create.' + self.widgetName, function( event ) { - if ( type === 'addtoolbar' ) { - self.initToolbars(); - } else if ( type === 'edittoolbar' ) { - var $target = $( event.target ), - isPending = $target.hasClass( baseClass + '-new' ) - || $target.find( baseClass + '-new' ).length > 0; + var $target = $( event.target ), + isPending = $target.hasClass( baseClass + '-new' ) + || $target.find( baseClass + '-new' ).length > 0; + if ( type === 'addtoolbar' ) { + // Initialize toolbars that are not initialized already: + self.initToolbars( isPending ); + } else if ( type === 'edittoolbar' ) { $( event.target ).edittoolbar( $.extend( {}, def.options, { enableRemove: !isPending } ) ); diff --git a/repo/resources/wikibase.ui.entityViewInit.js b/repo/resources/wikibase.ui.entityViewInit.js index 43c0b4e..f00c9af 100644 --- a/repo/resources/wikibase.ui.entityViewInit.js +++ b/repo/resources/wikibase.ui.entityViewInit.js @@ -128,7 +128,7 @@ // BUILD TOOLBARS $( '.wb-entity' ).toolbarcontroller( { - addtoolbar: ['claimlistview', 'listview', 'claimsection'], + addtoolbar: ['claimlistview', 'claimsection', 'references'], edittoolbar: ['statementview', 'referenceview'] } ); } -- To view, visit https://gerrit.wikimedia.org/r/52361 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I4d4e363f659af62042ab6dcaeaccbb14f3656737 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Henning Snater <henning.sna...@wikimedia.de> Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits