jenkins-bot has submitted this change and it was merged.

Change subject: Added snakview.variations.Value.start/stopEditing()
......................................................................


Added snakview.variations.Value.start/stopEditing()

startEditing() and stopEditing() should be triggered immediately instead of 
deferring those calls
to inside the draw() function. In draw(), there is no way to determine the 
dropValue parameter to
be submitted to $.valueview.stopEditing()

Bug: 70337
Change-Id: I066a53910ff899e535478a6ab1713eaf39151971
---
M lib/resources/jquery.wikibase/snakview/snakview.js
M lib/resources/jquery.wikibase/snakview/snakview.variations.Value.js
M lib/resources/jquery.wikibase/snakview/snakview.variations.Variation.js
3 files changed, 52 insertions(+), 10 deletions(-)

Approvals:
  Adrian Lang: Looks good to me, approved
  Henning Snater: Checked
  jenkins-bot: Verified



diff --git a/lib/resources/jquery.wikibase/snakview/snakview.js 
b/lib/resources/jquery.wikibase/snakview/snakview.js
index 180db6c..0c5e0ae 100644
--- a/lib/resources/jquery.wikibase/snakview/snakview.js
+++ b/lib/resources/jquery.wikibase/snakview/snakview.js
@@ -304,6 +304,10 @@
                        this._isInEditMode = true;
                        this.draw();
 
+                       if( this._variation ) {
+                               this._variation.startEditing();
+                       }
+
                        // attach keyboard input events
                        this.element.on( 'keydown.' + this.widgetName, 
function( event ) {
                                if ( self.options.disabled ) {
@@ -382,6 +386,10 @@
                natively: function( e, dropValue, newSnak ) {
                        this._isInEditMode = false;
                        this._initialSnak = null;
+
+                       if( this._variation ) {
+                               this._variation.stopEditing( dropValue );
+                       }
 
                        // update view; will remove edit interfaces and 
represent value statically
                        this._setValue( newSnak !== null ? newSnak.toMap() : {} 
); // triggers this.draw()
@@ -833,9 +841,15 @@
        drawVariation: function() {
                // property ID will be null if not in edit mode and no Snak set 
or if in edit mode and user
                // didn't choose property yet.
-               var propertyId = this._propertyId;
+               var propertyId = this._propertyId,
+                       self = this;
 
                if( propertyId && this._variation ) {
+                       $( this._variation ).one( 'afterdraw', function() {
+                               if( self.isInEditMode() ) {
+                                       self.variation().startEditing();
+                               }
+                       } );
                        this.variation().draw();
                } else {
                        // remove any remains from previous rendering or 
initial template (e.g. '$4')
diff --git 
a/lib/resources/jquery.wikibase/snakview/snakview.variations.Value.js 
b/lib/resources/jquery.wikibase/snakview/snakview.variations.Value.js
index 631e3d4..2279b44 100644
--- a/lib/resources/jquery.wikibase/snakview/snakview.variations.Value.js
+++ b/lib/resources/jquery.wikibase/snakview/snakview.variations.Value.js
@@ -87,16 +87,8 @@
                                        // _setValue().
                                        self._newDataValue = false;
 
-                                       // Switch to edit/non-edit view 
depending on snakview:
-                                       self._valueView[
-                                               ( 
self._viewState.isInEditMode() ? 'start' : 'stop' ) + 'Editing'
-                                       ]();
-
-                                       if( self._viewState.isInEditMode() ) {
-                                               self._attachEventHandlers();
-                                       } else {
+                                       if( !self._viewState.isInEditMode() ) {
                                                self.$viewPort.css( 'height', 
'auto' );
-                                               self._removeEventHandlers();
                                        }
 
                                        // Set state
@@ -216,6 +208,30 @@
                },
 
                /**
+                * @see 
jQuery.wikibase.snakview.variations.Variation.startEditing
+                */
+               startEditing: function() {
+                       if( !this._valueView || this._valueView.isInEditMode() 
) {
+                               return;
+                       }
+                       this._valueView.startEditing();
+                       this._attachEventHandlers();
+                       this.draw();
+               },
+
+               /**
+                * @see 
jQuery.wikibase.snakview.variations.Variation.stopEditing
+                */
+               stopEditing: function( dropValue ) {
+                       if( !this._valueView || !this._valueView.isInEditMode() 
) {
+                               return;
+                       }
+                       this._valueView.stopEditing( dropValue );
+                       this._removeEventHandlers();
+                       this.draw();
+               },
+
+               /**
                 * Attaches event handlers to the value view widget's element.
                 */
                _attachEventHandlers: function() {
diff --git 
a/lib/resources/jquery.wikibase/snakview/snakview.variations.Variation.js 
b/lib/resources/jquery.wikibase/snakview/snakview.variations.Variation.js
index 8932990..0a021f8 100644
--- a/lib/resources/jquery.wikibase/snakview/snakview.variations.Variation.js
+++ b/lib/resources/jquery.wikibase/snakview/snakview.variations.Variation.js
@@ -179,6 +179,18 @@
                draw: util.abstractMember,
 
                /**
+                * Start the variation's edit mode.
+                */
+               startEditing: function() {},
+
+               /**
+                * Stops the variation's edit mode.
+                *
+                * @param {boolean} dropValue
+                */
+               stopEditing: function( dropValue ) {},
+
+               /**
                 * Will set the focus if there is some focusable input object.
                 *
                 * @since 0.4

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I066a53910ff899e535478a6ab1713eaf39151971
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to