Tobias Gritschacher has submitted this change and it was merged. Change subject: (bug 44683) Removing API interaction from snaklistview widget ......................................................................
(bug 44683) Removing API interaction from snaklistview widget The snaklistview widget's API interaction was specific for the references. In order to use the widget on other occasions, this API interaction needs to be performed directly in the referenceview widget. Change-Id: Iff4a60795b03029e5deaba4c656ba3ef9f7f7fcb --- M lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js M lib/resources/jquery.wikibase/jquery.wikibase.snaklistview.js 2 files changed, 52 insertions(+), 63 deletions(-) Approvals: Tobias Gritschacher: Verified; Looks good to me, approved jenkins-bot: Checked diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js b/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js index c492652..a54df92 100644 --- a/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js +++ b/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js @@ -46,6 +46,29 @@ this.options.value = this._reference.getSnaks(); } PARENT.prototype._create.call( this ); + + this.element.on( this.widgetName + 'stopediting.' + this.widgetName, function( event, dropValue ) { + if ( self.option( 'value' ) !== null && !dropValue && !self.__continueStopEditing ) { + self._saveReferenceApiCall() + .done( function( savedObject, pageInfo ) { + self.__continueStopEditing = true; + self.stopEditing( dropValue ); + } ) + .fail( function( errorCode, details ) { + var error = wb.RepoApiError.newFromApiResponse( + errorCode, details, 'save' + ); + + self.enable(); + self.element.addClass( 'wb-error' ); + + self._trigger( 'toggleError', null, [ error ] ); + + self.__continueStopEditing = false; + } ); + } + } ); + this._updateReferenceHashClass( this.value() ); }, @@ -93,17 +116,6 @@ return null; } } - }, - - /** - * Forwards to _saveReferenceApiCall implementing the abstract method of - * jquery.wikibase.snaklistview. - * @see jQuery.wikibase.snaklistview._saveSnakList - * - * @return {jQuery.promise} - */ - _saveSnakList: function() { - return this._saveReferenceApiCall(); }, /** diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.snaklistview.js b/lib/resources/jquery.wikibase/jquery.wikibase.snaklistview.js index e3312aa..aaa665d 100644 --- a/lib/resources/jquery.wikibase/jquery.wikibase.snaklistview.js +++ b/lib/resources/jquery.wikibase/jquery.wikibase.snaklistview.js @@ -187,14 +187,6 @@ }, /** - * Saves the snaks represented by this snaklistview. - * - * @params {function} Callback to be processed after saving was successful - * @return {jQuery.Promise} - */ - _saveSnakList: wb.utilities.abstractMember, - - /** * Starts the snaklistview's edit mode by starting the edit mode of all the list's snakviews. * @since 0.4 * @@ -243,70 +235,55 @@ this.element.removeClass( 'wb-error' ); }, natively: function( e, dropValue ) { - var self = this; - this.disable(); if ( dropValue ) { // If the whole item was pending, remove the whole list item. This has to be // performed in the widget using the snaklistview. - self.__continueSnakviewStopEditing = false; + this.__continueSnakviewStopEditing = false; // Re-create the list view to restore snakviews that have been removed during // editing: - self.createListView(); + this.createListView(); - self.enable(); - self.element.removeClass( 'wb-edit' ); - self._isInEditMode = false; + this.enable(); + this.element.removeClass( 'wb-edit' ); + this._isInEditMode = false; - self._trigger( 'afterstopediting', null, [ dropValue ] ); - } else if ( this.option( 'value' ) !== null ) { - // Editing an existing snak list. - self._saveSnakList() - .done( function( savedObject, pageInfo ) { - self.__continueSnakviewStopEditing = true; - $.each( self._listview.items(), function( i, item ) { - var $item = $( item ), - snakview = self._lia.liInstance( $item ); + this._trigger( 'afterstopediting', null, [ dropValue ] ); + } else if ( this.option( 'value' ) !== null && this.__continueStopEditing ) { + var self = this; - snakview.stopEditing( dropValue ); + this.__continueStopEditing = false; + this.__continueSnakviewStopEditing = true; + $.each( this._listview.items(), function( i, item ) { + var $item = $( item ), + snakview = self._lia.liInstance( $item ); - // After saving, the property should not be editable anymore. - snakview.options.locked.property = true; - } ); - self.__continueSnakviewStopEditing = false; + snakview.stopEditing( dropValue ); - self.enable(); - - self.element.removeClass( 'wb-edit' ); - self._isInEditMode = false; - - // Transform toolbar and snak view after save complete - self._trigger( 'afterstopediting', null, [ dropValue ] ); - } ) - .fail( function( errorCode, details ) { - var error = wb.RepoApiError.newFromApiResponse( - errorCode, details, 'save' - ); - - self.enable(); - self.element.addClass( 'wb-error' ); - - self._trigger( 'toggleError', null, [ error ] ); - - self.__continueStopEditing = false; + // After saving, the property should not be editable anymore. + snakview.options.locked.property = true; } ); - } else { - self.__continueStopEditing = false; + this.__continueSnakviewStopEditing = false; + + this.enable(); + + this.element.removeClass( 'wb-edit' ); + this._isInEditMode = false; + + // Transform toolbar and snak view after save complete + this._trigger( 'afterstopediting', null, [ dropValue ] ); + } else if ( !this.option( 'value' ) ) { + this.__continueStopEditing = false; // Creating a new snaklistview is managed in the object using the snaklistview (e.g. // in the statementview). Creating a snaklistview will end up in here after having // performed the API call adding the snaklistview's subject (e.g. the reference) to // the permanent part of the list (by saving the subject to the database). - self.element.removeClass( 'wb-edit' ); + this.element.removeClass( 'wb-edit' ); this._isInEditMode = false; - self._trigger( 'afterstopediting', null, [ dropValue ] ); + this._trigger( 'afterstopediting', null, [ dropValue ] ); } } } ), -- To view, visit https://gerrit.wikimedia.org/r/55543 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Iff4a60795b03029e5deaba4c656ba3ef9f7f7fcb Gerrit-PatchSet: 3 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