Henning Snater has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/59422


Change subject: Triggering "afterremove" on the widget managing the remove 
process
......................................................................

Triggering "afterremove" on the widget managing the remove process

Change-Id: Ia584a60198ef599feb1613478f0203eaa6c2aac1
---
M lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js
M lib/resources/jquery.wikibase/jquery.wikibase.entityview.js
M lib/resources/jquery.wikibase/jquery.wikibase.listview.js
M lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
4 files changed, 65 insertions(+), 56 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/22/59422/1

diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js
index 8d6a6e6..a0c6583 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.claimlistview.js
@@ -13,6 +13,7 @@
 /**
  * View for displaying and editing several Wikibase Claims.
  * @since 0.3
+ * @extends jQuery.TemplatedWidget
  *
  * @option {String} entityId (required) The ID of the entity, new Claims 
should be added to.
  *
@@ -27,6 +28,9 @@
  *        (3) {jQuery} The DOM node with the widget, representing the value.
  *
  * @event canceled: Triggered after canceling the process of adding a new 
claim.
+ *        (1) {jQuery.Event}
+ *
+ * @event afterremove: Triggered after a claim(view) has been removed from the 
claimlist(view).
  *        (1) {jQuery.Event}
  */
 $.widget( 'wikibase.claimlistview', PARENT, {
@@ -60,11 +64,7 @@
         * @see jQuery.Widget._create
         */
        _create: function() {
-               var self = this,
-                       lmwAfterRemoveEvent = this._lmwEvent( 'afterremove' ),
-                       lmwErrorEvent = this._lmwEvent( 'toggleerror' ),
-                       lmwStartEditingEvent = this._lmwEvent( 'startediting' ),
-                       lmwAfterStopEditingEvent = this._lmwEvent( 
'afterstopediting' );
+               var self = this;
 
                // apply template to this.element:
                PARENT.prototype._create.call( this );
@@ -72,47 +72,15 @@
                this._createClaims(); // build this.$claims
 
                // remove Claim (and eventually section) after remove operation 
has finished
-               this.element.on( lmwAfterRemoveEvent, function( e ) {
-                       var $claim = $( e.target ),
-                               $claimsSection = $claim.parents( 
'.wb-claim-section' );
-
-                       self._lmwInstance( $claim ).destroy();
-
-                       if( $claimsSection.find( '.' + self._lmwClass() 
).length > 0 ) {
-                               // TODO: Re-implement the following focus logic:
-                               // Focus the next claim container's "edit" 
button. The user might want to alter that
-                               // claim as well. Furthermore, the browser's 
viewport will not be scrolled when
-                               // having a long claim section and directly 
focusing the section's "add" button.
-                               // Only if there are no following claim 
containers, the section's "add" button will
-                               // be focused.
-                               $claim.remove(); // other claims displayed in 
this section, leave section alone
-                       } else {
-                               $claimsSection.remove(); // remove whole 
section because last claim removed
-                               // When removing a whole section, there is no 
meaningful focus point, so no focus
-                               // is set programmatically. We could easily set 
the focus on the general "add new
-                               // claim" button; However, if the "add" button 
is not in the browser's viewport,
-                               // (probably not intended) automatic scrolling 
will occur. The only more or less
-                               // valid focus point might simply be the next 
focusable element but at this stage,
-                               // all buttons are still disabled.
-                       }
-               } )
+               this.element
                // make sure to add/remove 'wb-edit' class to sections when in 
edit mode:
                .on(
-                       [ lmwAfterStopEditingEvent, lmwStartEditingEvent, 
lmwAfterRemoveEvent ].join( ' ' ),
-                       function( e ) {
-                               if( e.type === lmwStartEditingEvent ) {
-                                       $( e.target ).parents( 
'.wb-claim-section' ).addClass( 'wb-edit' );
-                               } else {
-                                       // remove 'wb-edit' from all section 
nodes if the section itself has not child
-                                       // nodes with 'wb-edit' still set. This 
is necessary because of how we remove new
-                                       // Claims added to an existing section. 
Also required if we want multiple edit modes.
-                                       self.element.find( '.wb-claim-section' )
-                                               .not( ':has( >.wb-edit )' 
).removeClass( 'wb-edit' );
-                                       // NOTE: could be performance optimized 
with edit counter per section
-                               }
+                       this._lmwEvent( 'startediting' ) + ' ' + 
this._lmwEvent( 'afterstopediting' ),
+                       function( event ) {
+                               self._toggleEditState( event.type === 
self._lmwEvent( 'startediting' ) );
                        }
                )
-               .on( lmwErrorEvent, function( e, error ) {
+               .on( this._lmwEvent( 'toggleerror' ), function( e, error ) {
                        var $claimSection = $( e.target ).closest( 
'.wb-claim-section' );
 
                        if( error && error instanceof wb.RepoApiError ) {
@@ -123,6 +91,24 @@
                                $claimSection.removeClass( 'wb-error' );
                        }
                } );
+       },
+
+       /**
+        * Toggles edit state visually by assigning/removing wb-edit css class.
+        *
+        * @param {boolean} [on] "false" by default
+        */
+       _toggleEditState: function( on ) {
+               if( on ) {
+                       $( event.target ).parents( '.wb-claim-section' 
).addClass( 'wb-edit' );
+               } else {
+                       // remove 'wb-edit' from all section nodes if the 
section itself has not child
+                       // nodes with 'wb-edit' still set. This is necessary 
because of how we remove new
+                       // Claims added to an existing section. Also required 
if we want multiple edit modes.
+                       this.element.find( '.wb-claim-section' )
+                               .not( ':has( >.wb-edit )' ).removeClass( 
'wb-edit' );
+                       // NOTE: could be performance optimized with edit 
counter per section
+               }
        },
 
        /**
@@ -398,8 +384,32 @@
                        // NOTE: we don't update rev store here! If we want 
uniqueness for Claims, this
                        //  might be an issue at a later point and we would 
need a solution then
 
-                       // update model of represented Claim
-                       claimview._trigger( 'afterremove' );
+                       var $claim = claimview.element,
+                               $claimsSection = $claim.closest( 
'.wb-claim-section' );
+
+                       claimview.destroy();
+
+                       if( $claimsSection.find( '.' + self._lmwClass() 
).length > 0 ) {
+                               // TODO: Re-implement the following focus logic:
+                               // Focus the next claim container's "edit" 
button. The user might want to alter that
+                               // claim as well. Furthermore, the browser's 
viewport will not be scrolled when
+                               // having a long claim section and directly 
focusing the section's "add" button.
+                               // Only if there are no following claim 
containers, the section's "add" button will
+                               // be focused.
+                               $claim.remove(); // other claims displayed in 
this section, leave section alone
+                       } else {
+                               $claimsSection.remove(); // remove whole 
section because last claim removed
+                               // When removing a whole section, there is no 
meaningful focus point, so no focus
+                               // is set programmatically. We could easily set 
the focus on the general "add new
+                               // claim" button; However, if the "add" button 
is not in the browser's viewport,
+                               // (probably not intended) automatic scrolling 
will occur. The only more or less
+                               // valid focus point might simply be the next 
focusable element but at this stage,
+                               // all buttons are still disabled.
+                       }
+
+                       self._toggleEditState();
+
+                       self._trigger( 'afterremove' );
                } ).fail( function( errorCode, details ) {
                        var error = wb.RepoApiError.newFromApiResponse( 
errorCode, details, 'remove' );
 
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.entityview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.entityview.js
index 1b1ecc2..0482403 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.entityview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.entityview.js
@@ -139,8 +139,8 @@
                                $( wb ).trigger( 'stopItemPageEditMode', 
[event.target] );
                        }
                } )
-               .on( 'statementviewafterstopediting statementviewafterremove '
-                               + 'referenceviewafterstopediting 
referenceviewafterremove',
+               .on( 'statementviewafterstopediting claimlistviewafterremove '
+                               + 'referenceviewafterstopediting 
statementviewafterremove',
                        function( event ) {
                                $( wb ).trigger( 'stopItemPageEditMode', 
[event.target] );
                        }
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.listview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.listview.js
index 4ad958a..34dc634 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.listview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.listview.js
@@ -85,19 +85,12 @@
                                "listview.ListItemAdapter" );
                }
 
-               var self = this,
-                       liAfterRemoveEvent = this._lia.prefixedEvent( 
'afterremove' );
+               var self = this;
 
                // apply template to this.element:
                PARENT.prototype._create.call( this );
 
                this._createList(); // fill list with items
-
-               // remove list item after remove operation has finished
-               this.element.on( liAfterRemoveEvent, function( e ) {
-                       var $listItem = $( e.target );
-                       self.removeItem( $listItem );
-               } );
        },
 
        /**
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
index b4022b9..6e009bd 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
@@ -13,9 +13,12 @@
 
 /**
  * View for displaying and editing Wikibase Statements.
- *
  * @since 0.4
  * @extends jQuery.wikibase.claimview
+ *
+ * @event afterremove: Triggered after a reference(view) has been remove from 
the statementview's
+ *        list of references/-views.
+ *        (1) {jQuery.Event}
  */
 $.widget( 'wikibase.statementview', PARENT, {
        widgetBaseClass: 'wb-statementview',
@@ -204,11 +207,14 @@
         * @param {$.wikibase.referenceview} referenceview
         */
        remove: function( referenceview ) {
+               var self = this;
+
                referenceview.disable();
 
                this._removeReferenceApiCall( referenceview.value() )
                        .done( function( pageInfo ) {
-                               referenceview._trigger( 'afterremove' );
+                               self.$references.data( 'listview' ).removeItem( 
referenceview.element );
+                               self._trigger( 'afterremove' );
                        } ).fail( function( errorCode, details ) {
                                var error = wb.RepoApiError.newFromApiResponse( 
errorCode, details, 'remove' );
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia584a60198ef599feb1613478f0203eaa6c2aac1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>

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

Reply via email to