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

Change subject: Turn views into EditableTemplatedWidgets
......................................................................


Turn views into EditableTemplatedWidgets

Change-Id: I3f484bdb2d3ee7827e58c2034a05753478e389c3
---
M view/resources/jquery/wikibase/jquery.wikibase.badgeselector.js
M 
view/resources/jquery/wikibase/jquery.wikibase.entitytermsforlanguagelistview.js
M view/resources/jquery/wikibase/jquery.wikibase.referenceview.js
M view/resources/jquery/wikibase/jquery.wikibase.sitelinkview.js
M view/resources/jquery/wikibase/jquery.wikibase.snaklistview.js
M view/resources/jquery/wikibase/jquery.wikibase.statementlistview.js
M view/resources/jquery/wikibase/resources.php
M view/resources/jquery/wikibase/snakview/resources.php
M view/resources/jquery/wikibase/snakview/snakview.js
M view/tests/qunit/jquery/wikibase/jquery.wikibase.referenceview.tests.js
M view/tests/qunit/jquery/wikibase/jquery.wikibase.sitelinklistview.tests.js
M view/tests/qunit/jquery/wikibase/jquery.wikibase.snaklistview.tests.js
M view/tests/qunit/jquery/wikibase/jquery.wikibase.statementlistview.tests.js
M view/tests/qunit/wikibase/view/ToolbarViewController.tests.js
14 files changed, 66 insertions(+), 427 deletions(-)

Approvals:
  Jonas Kress (WMDE): Looks good to me, approved
  jenkins-bot: Verified



diff --git a/view/resources/jquery/wikibase/jquery.wikibase.badgeselector.js 
b/view/resources/jquery/wikibase/jquery.wikibase.badgeselector.js
index 51dc2f5..a3425b8 100644
--- a/view/resources/jquery/wikibase/jquery.wikibase.badgeselector.js
+++ b/view/resources/jquery/wikibase/jquery.wikibase.badgeselector.js
@@ -5,7 +5,7 @@
 ( function( $, mw ) {
        'use strict';
 
-var PARENT = $.ui.TemplatedWidget;
+var PARENT = $.ui.EditableTemplatedWidget;
 
 /**
  * References one single $menu instance that is reused for all badgeselector 
instances.
@@ -16,7 +16,7 @@
 /**
  * Selector for toggling badges.
  * @since 0.5
- * @extends jQuery.ui.TemplatedWidget
+ * @extends jQuery.ui.EditableTemplatedWidget
  *
  * @option {string[]} [value]
  *         Item ids of badges currently assigned.
@@ -361,31 +361,18 @@
                }
        },
 
-       startEditing: function() {
-               if ( this.isInEditMode() ) {
-                       return;
-               }
-
-               this.element.addClass( 'wb-edit' );
-
+       _startEditing: function() {
                this._updateEmptyBadge();
-
-               this._trigger( 'afterstartediting' );
+               return $.Deferred().resolve().promise();
        },
 
        /**
         * @param {boolean} dropValue
         */
-       stopEditing: function( dropValue ) {
-               if ( !this.isInEditMode() ) {
-                       return;
-               }
-
+       _stopEditing: function( dropValue ) {
                if ( $menu ) {
                        $menu.hide();
                }
-
-               this.element.removeClass( 'wb-edit' );
 
                if ( !dropValue ) {
                        this._updateEmptyBadge();
@@ -396,14 +383,7 @@
                        // Reinitialize badges based on this.options.value
                        this._addBadges();
                }
-               this._trigger( 'afterstopediting', null, [dropValue] );
-       },
-
-       /**
-        * @return {boolean}
-        */
-       isInEditMode: function() {
-               return this.element.hasClass( 'wb-edit' );
+               return $.Deferred().resolve().promise();
        },
 
        /**
diff --git 
a/view/resources/jquery/wikibase/jquery.wikibase.entitytermsforlanguagelistview.js
 
b/view/resources/jquery/wikibase/jquery.wikibase.entitytermsforlanguagelistview.js
index 41cd29e..fa3fd5d 100644
--- 
a/view/resources/jquery/wikibase/jquery.wikibase.entitytermsforlanguagelistview.js
+++ 
b/view/resources/jquery/wikibase/jquery.wikibase.entitytermsforlanguagelistview.js
@@ -6,12 +6,12 @@
 ( function( mw, wb, $ ) {
        'use strict';
 
-       var PARENT = $.ui.TemplatedWidget;
+       var PARENT = $.ui.EditableTemplatedWidget;
 
 /**
  * Displays multiple fingerprints (see 
jQuery.wikibase.entitytermsforlanguageview).
  * @since 0.5
- * @extends jQuery.ui.TemplatedWidget
+ * @extends jQuery.ui.EditableTemplatedWidget
  *
  * @option {Fingerprint} value
  *
@@ -60,11 +60,6 @@
         * @type {jQuery}
         */
        $entitytermsforlanguagelistviewMore: null,
-
-       /**
-        * @type {boolean}
-        */
-       _isInEditMode: false,
 
        /**
         * @type {Object} Map of language codes pointing to list items (in the 
form of jQuery nodes).
@@ -287,7 +282,7 @@
 
                Object.keys( this._getMoreLanguages() ).sort().forEach( 
function( languageCode ) {
                        var $item = listview.addItem( 
self._getValueForLanguage( languageCode ) );
-                       if ( self._isInEditMode ) {
+                       if ( self.isInEditMode() ) {
                                lia.liInstance( $item ).startEditing();
                        }
                        self._moreLanguagesItems[languageCode] = $item;
@@ -364,67 +359,23 @@
                };
        },
 
-       /**
-        * @return {boolean}
-        */
-       isEmpty: function() {
-               return !!this.$listview.data( 'listview' ).items().length;
-       },
-
-       startEditing: function() {
-               if ( this._isInEditMode ) {
-                       return;
-               }
-
-               this._isInEditMode = true;
-               this.element.addClass( 'wb-edit' );
-
+       _startEditing: function() {
+               var self = this;
                var listview = this.$listview.data( 'listview' );
-               listview.startEditing();
-
-               this.updateInputSize();
-
-               this._trigger( 'afterstartediting' );
+               return listview.startEditing().done( function() {
+                       self.updateInputSize();
+               } );
        },
 
        /**
         * @param {boolean} [dropValue]
         */
-       stopEditing: function( dropValue ) {
-               var deferred = $.Deferred();
-
-               if ( !this._isInEditMode ) {
-                       return deferred.resolve().promise();
-               }
-
-               this.disable();
-
+       _stopEditing: function( dropValue ) {
                var listview = this.$listview.data( 'listview' );
 
-               listview.value().forEach( function( entitytermsforlanguageview 
) {
-                       entitytermsforlanguageview.stopEditing( dropValue );
-               } );
-
-               this._afterStopEditing( dropValue );
-               deferred.resolve();
-               return deferred.promise();
-       },
-
-       /**
-        * @param {boolean} dropValue
-        */
-       _afterStopEditing: function( dropValue ) {
-               if ( !dropValue ) {
-                       this.options.value = this.value();
-               }
-               this._isInEditMode = false;
-               this.enable();
-               this.element.removeClass( 'wb-edit' );
-               this._trigger( 'afterstopediting', null, [dropValue] );
-       },
-
-       cancelEditing: function() {
-               this.stopEditing( true );
+               return $.when.apply( $, listview.value().map( function( 
entitytermsforlanguageview ) {
+                       return entitytermsforlanguageview.stopEditing( 
dropValue );
+               } ) );
        },
 
        /**
@@ -466,23 +417,8 @@
                }
        },
 
-       /**
-        * Applies/Removes error state.
-        *
-        * @param {Error} [error]
-        */
-       setError: function( error ) {
-               if ( error ) {
-                       this.element.addClass( 'wb-error' );
-                       this._trigger( 'toggleerror', null, [error] );
-               } else {
-                       this.removeError();
-                       this._trigger( 'toggleerror' );
-               }
-       },
-
        removeError: function() {
-               this.element.removeClass( 'wb-error' );
+               PARENT.prototype.removeError.call( this );
 
                var listview = this.$listview.data( 'listview' ),
                        lia = listview.listItemAdapter();
diff --git a/view/resources/jquery/wikibase/jquery.wikibase.referenceview.js 
b/view/resources/jquery/wikibase/jquery.wikibase.referenceview.js
index a6e6f2d..162862e 100644
--- a/view/resources/jquery/wikibase/jquery.wikibase.referenceview.js
+++ b/view/resources/jquery/wikibase/jquery.wikibase.referenceview.js
@@ -1,13 +1,13 @@
 ( function( wb, $ ) {
        'use strict';
 
-       var PARENT = $.ui.TemplatedWidget;
+       var PARENT = $.ui.EditableTemplatedWidget;
 
 /**
  * View for displaying and editing `wikibase.datamodel.Reference` objects.
  * @see wikibase.datamodel.Reference
  * @class jQuery.wikibase.referenceview
- * @extends jQuery.ui.TemplatedWidget
+ * @extends jQuery.ui.EditableTemplatedWidget
  * @since 0.4
  * @license GPL-2.0+
  * @author H. Snater < mediaw...@snater.com >
@@ -58,13 +58,6 @@
                value: null,
                getListItemAdapter: null
        },
-
-       /**
-        * Whether the widget is currently in edit mode.
-        * @property {boolean} [_isInEditMode=false]
-        * @private
-        */
-       _isInEditMode: false,
 
        /**
         * @inheritdoc
@@ -197,21 +190,12 @@
         *
         * @since 0.5
         */
-       startEditing: function() {
-               if ( this.isInEditMode() ) {
-                       return;
-               }
-
-               this.$listview.data( 'listview' ).startEditing();
-
+       _startEditing: function() {
                this._attachEditModeEventHandlers();
-
-               this.element.addClass( 'wb-edit' );
-               this._isInEditMode = true;
 
                this._snakListAdder = this.options.getAdder( 
this.enterNewItem.bind( this ), this.element );
 
-               this._trigger( 'afterstartediting' );
+               return this.$listview.data( 'listview' ).startEditing();
        },
 
        /**
@@ -219,23 +203,15 @@
         *
         * @since 0.5
         */
-       stopEditing: function() {
-               if ( !this.isInEditMode() ) {
-                       return;
-               }
+       _stopEditing: function() {
+               this._detachEditModeEventHandlers();
 
                this._snakListAdder.destroy();
                this._snakListAdder = null;
 
-               this._isInEditMode = false;
-               this.element.removeClass( 'wb-edit' );
-
-               this._detachEditModeEventHandlers();
-
                // FIXME: There should be a listview::stopEditing method
                this._stopEditingReferenceSnaks();
-
-               this._trigger( 'afterstopediting' );
+               return $.Deferred().resolve().promise();
        },
 
        /**
@@ -244,17 +220,6 @@
        _stopEditingReferenceSnaks: function() {
                var listview = this.$listview.data( 'listview' );
                listview.value( this.options.value ? 
this.options.value.getSnaks().getGroupedSnakLists() : [] );
-       },
-
-       /**
-        * Returns whether the widget is currently in edit mode.
-        *
-        * @since 0.5
-        *
-        * @return {boolean}
-        */
-       isInEditMode: function() {
-               return this._isInEditMode;
        },
 
        /**
@@ -284,16 +249,6 @@
                                $snakview.data( 'snakview' ).focus();
                        } );
                } );
-       },
-
-       /**
-        * Sets/removes error state from the widget.
-        *
-        * @param {boolean} error
-        */
-       setError: function( error ) {
-               this.element.toggleClass( 'wb-error', error );
-               this._trigger( 'toggleerror', null, [ error ] );
        },
 
        /**
diff --git a/view/resources/jquery/wikibase/jquery.wikibase.sitelinkview.js 
b/view/resources/jquery/wikibase/jquery.wikibase.sitelinkview.js
index bbe80a8..e739c3a 100644
--- a/view/resources/jquery/wikibase/jquery.wikibase.sitelinkview.js
+++ b/view/resources/jquery/wikibase/jquery.wikibase.sitelinkview.js
@@ -5,12 +5,12 @@
 ( function( mw, wb, $ ) {
        'use strict';
 
-       var PARENT = $.ui.TemplatedWidget;
+       var PARENT = $.ui.EditableTemplatedWidget;
 
 /**
  * Displays and allows editing a site link.
  * @since 0.5
- * @extends jQuery.ui.TemplatedWidget
+ * @extends jQuery.ui.EditableTemplatedWidget
  *
  * @option {wikibase.datamodel.SiteLink} [value]
  *         Default: null
@@ -72,11 +72,6 @@
        },
 
        /**
-        * @type {boolean}
-        */
-       _isInEditMode: false,
-
-       /**
         * @type {jQuery.wikibase.badgeselector|null}
         */
        _badgeselector: null,
@@ -133,7 +128,7 @@
                        this._siteLinkRemover = null;
                }
 
-               if ( this._isInEditMode ) {
+               if ( this.isInEditMode() ) {
                        var self = this;
 
                        this.element.one( this.widgetEventPrefix + 
'afterstopediting', function( event ) {
@@ -201,9 +196,7 @@
                        this._createBadgeSelector();
                }
 
-               this.element.toggleClass( 'wb-edit', this._isInEditMode );
-
-               if ( this._isInEditMode ) {
+               if ( this.isInEditMode() ) {
                        this._drawEditMode();
                }
        },
@@ -358,7 +351,7 @@
         * @return {boolean}
         */
        isEmpty: function() {
-               if ( !this._isInEditMode ) {
+               if ( !this.isInEditMode() ) {
                        return !this.options.value;
                }
 
@@ -370,19 +363,14 @@
        /**
         * Puts the widget into edit mode.
         */
-       startEditing: function() {
-               if ( this._isInEditMode ) {
-                       return;
-               }
-
-               this._isInEditMode = true;
+       _startEditing: function() {
                this._draw();
 
                if ( this.option( 'disabled' ) ) {
                        this._setState( 'disable' );
                }
 
-               this._trigger( 'afterstartediting' );
+               return $.Deferred().resolve().promise();
        },
 
        /**
@@ -395,35 +383,12 @@
         *         Rejected parameters:
         *         - {Error}
         */
-       stopEditing: function( dropValue ) {
-               var deferred = $.Deferred();
-
-               if ( !this._isInEditMode ) {
-                       return deferred.resolve().promise();
-               }
-
+       _stopEditing: function( dropValue ) {
                if ( this._badgeselector ) {
                        this._badgeselector.stopEditing( dropValue );
                }
-               this._afterStopEditing( dropValue );
 
-               return deferred.resolve().promise();
-       },
-
-       /**
-        * Callback tearing down edit mode.
-        *
-        * @param {boolean} dropValue
-        */
-       _afterStopEditing: function( dropValue ) {
-               if ( !dropValue ) {
-                       this.options.value = this.value();
-               }
-
-               this._isInEditMode = false;
-               this._draw();
-
-               this._trigger( 'afterstopediting', null, [dropValue] );
+               return $.Deferred().resolve().promise();
        },
 
        /**
@@ -442,7 +407,7 @@
         */
        value: function( siteLink ) {
                if ( siteLink === undefined ) {
-                       if ( !this._isInEditMode ) {
+                       if ( !this.isInEditMode() ) {
                                return this.options.value;
                        }
 
@@ -502,7 +467,7 @@
         * @param {string} state
         */
        _setState: function( state ) {
-               if ( this._isInEditMode ) {
+               if ( this.isInEditMode() ) {
                        var $siteInput = this.$siteId.find( 'input' ),
                                hasSiteId = !!( this.options.value && 
this.options.value.getSiteId() );
 
@@ -541,21 +506,6 @@
                        $siteselector.focus();
                } else {
                        this.element.focus();
-               }
-       },
-
-       /**
-        * Applies/Removes error state.
-        *
-        * @param {Error} [error]
-        */
-       setError: function( error ) {
-               if ( error ) {
-                       this.element.addClass( 'wb-error' );
-                       this._trigger( 'toggleerror', null, [error] );
-               } else if ( this.element.hasClass( 'wb-error' ) ) {
-                       this.element.removeClass( 'wb-error' );
-                       this._trigger( 'toggleerror' );
                }
        }
 
diff --git a/view/resources/jquery/wikibase/jquery.wikibase.snaklistview.js 
b/view/resources/jquery/wikibase/jquery.wikibase.snaklistview.js
index adb0a50..01eebf0 100644
--- a/view/resources/jquery/wikibase/jquery.wikibase.snaklistview.js
+++ b/view/resources/jquery/wikibase/jquery.wikibase.snaklistview.js
@@ -1,13 +1,13 @@
 ( function( wb, $ ) {
        'use strict';
 
-       var PARENT = $.ui.TemplatedWidget;
+       var PARENT = $.ui.EditableTemplatedWidget;
 
 /**
  * View for displaying and editing a `wikibase.datamodel.SnakList` object.
  * @see wikibase.datamodel.SnakList
  * @class jQuery.wikibase.snaklistview
- * @extends jQuery.ui.TemplatedWidget
+ * @extends jQuery.ui.EditableTemplatedWidget
  * @uses jQuery.wikibase.listview
  * @since 0.4
  * @license GPL-2.0+
@@ -76,12 +76,6 @@
         * @private
         */
        _lia: null,
-
-       /**
-        * Whether the `snaklistview` currently is in edit mode.
-        * @property {boolean} [_isInEditMode=false]
-        */
-       _isInEditMode: false,
 
        /**
         * @inheritdoc
@@ -174,17 +168,8 @@
        /**
         * Starts the widget's edit mode.
         */
-       startEditing: function() {
-               if ( this._isInEditMode ) {
-                       return;
-               }
-
-               this._listview.startEditing();
-
-               this.element.addClass( 'wb-edit' );
-               this._isInEditMode = true;
-
-               this._trigger( 'afterstartediting' );
+       _startEditing: function() {
+               return this._listview.startEditing();
        },
 
        /**
@@ -193,14 +178,7 @@
         * @param {boolean} [dropValue=false] If `true`, the widget's value 
will be reset to the one from
         *        before edit mode was started
         */
-       stopEditing: function( dropValue ) {
-               if ( !this._isInEditMode ) {
-                       return;
-               }
-
-               this.element.removeClass( 'wb-error' );
-               this.disable();
-
+       _stopEditing: function( dropValue ) {
                if ( dropValue ) {
                        // If the whole item was pending, remove the whole list 
item. This has to be
                        // performed in the widget using the snaklistview.
@@ -216,20 +194,7 @@
                                snakview.options.locked.property = true;
                        } );
                }
-
-               this.enable();
-
-               this.element.removeClass( 'wb-edit' );
-               this._isInEditMode = false;
-
-               this._trigger( 'afterstopediting', null, [ dropValue ] );
-       },
-
-       /**
-        * Cancels editing. (Short-cut for `stopEditing( true )`.)
-        */
-       cancelEditing: function() {
-               return this.stopEditing( true ); // stop editing and drop value
+               return $.Deferred().resolve().promise();
        },
 
        /**
@@ -271,13 +236,6 @@
                return this._listview.enterNewItem().done( function() {
                        self.startEditing();
                } );
-       },
-
-       /**
-        * @return {boolean}
-        */
-       isInEditMode: function() {
-               return this._isInEditMode;
        },
 
        /**
diff --git 
a/view/resources/jquery/wikibase/jquery.wikibase.statementlistview.js 
b/view/resources/jquery/wikibase/jquery.wikibase.statementlistview.js
index 1c01894..2464492 100644
--- a/view/resources/jquery/wikibase/jquery.wikibase.statementlistview.js
+++ b/view/resources/jquery/wikibase/jquery.wikibase.statementlistview.js
@@ -181,15 +181,6 @@
        },
 
        /**
-        * Returns whether the widget currently features any `statementview` 
widgets.
-        *
-        * @return {boolean}
-        */
-       isEmpty: function() {
-               return !this._listview.items().length;
-       },
-
-       /**
         * Adds a new, pending `statementview` to the `statementlistview`.
         *
         * @see jQuery.wikibase.listview.enterNewItem
diff --git a/view/resources/jquery/wikibase/resources.php 
b/view/resources/jquery/wikibase/resources.php
index 4b58509..d3c1a46 100644
--- a/view/resources/jquery/wikibase/resources.php
+++ b/view/resources/jquery/wikibase/resources.php
@@ -45,7 +45,7 @@
                        ),
                        'dependencies' => array(
                                'jquery.ui.menu',
-                               'jquery.ui.TemplatedWidget',
+                               'jquery.ui.EditableTemplatedWidget',
                                'wikibase.templates',
                        ),
                ),
@@ -184,7 +184,7 @@
                                
'themes/default/jquery.wikibase.entitytermsforlanguagelistview.css',
                        ),
                        'dependencies' => array(
-                               'jquery.ui.TemplatedWidget',
+                               'jquery.ui.EditableTemplatedWidget',
                                'jquery.wikibase.entitytermsforlanguageview',
                                'wikibase.getLanguageNameByCode',
                        ),
@@ -206,7 +206,7 @@
                                
'themes/default/jquery.wikibase.entitytermsforlanguageview.css',
                        ),
                        'dependencies' => array(
-                               'jquery.ui.TemplatedWidget',
+                               'jquery.ui.EditableTemplatedWidget',
                                'jquery.wikibase.aliasesview',
                                'jquery.wikibase.descriptionview',
                                'jquery.wikibase.labelview',
@@ -286,6 +286,7 @@
                        ),
                        'dependencies' => array(
                                'jquery.removeClassByRegex',
+                               'jquery.ui.EditableTemplatedWidget',
                                'jquery.wikibase.listview',
                                'wikibase.datamodel',
                        ),
@@ -315,7 +316,7 @@
                        'dependencies' => array(
                                'jquery.makeCollapsible',
                                'jquery.sticknode',
-                               'jquery.ui.TemplatedWidget',
+                               'jquery.ui.EditableTemplatedWidget',
                                'jquery.util.EventSingletonManager',
                                'mediawiki.jqueryMsg', // for {{plural}} and 
{{gender}} support in messages
                                'wikibase.buildErrorOutput',
@@ -358,7 +359,7 @@
                                
'themes/default/jquery.wikibase.sitelinkview.css',
                        ),
                        'dependencies' => array(
-                               'jquery.ui.TemplatedWidget',
+                               'jquery.ui.EditableTemplatedWidget',
                                'jquery.util.EventSingletonManager',
                                'jquery.wikibase.badgeselector',
                                'jquery.wikibase.pagesuggester',
@@ -382,7 +383,7 @@
                                'jquery.wikibase.snaklistview.js',
                        ),
                        'dependencies' => array(
-                               'jquery.ui.TemplatedWidget',
+                               'jquery.ui.EditableTemplatedWidget',
                                'jquery.wikibase.listview',
                                'wikibase.datamodel.Snak',
                                'wikibase.datamodel.SnakList',
diff --git a/view/resources/jquery/wikibase/snakview/resources.php 
b/view/resources/jquery/wikibase/snakview/resources.php
index 37dd29b..d560ddb 100644
--- a/view/resources/jquery/wikibase/snakview/resources.php
+++ b/view/resources/jquery/wikibase/snakview/resources.php
@@ -27,8 +27,8 @@
                        'dependencies' => array(
                                'dataValues.DataValue',
                                'jquery.event.special.eachchange',
+                               'jquery.ui.EditableTemplatedWidget',
                                'jquery.ui.position',
-                               'jquery.ui.TemplatedWidget',
                                'jquery.wikibase.entityselector',
                                'jquery.wikibase.snakview.variations',
                                'jquery.wikibase.snakview.ViewState',
diff --git a/view/resources/jquery/wikibase/snakview/snakview.js 
b/view/resources/jquery/wikibase/snakview/snakview.js
index 6e4ecf1..79754b7 100644
--- a/view/resources/jquery/wikibase/snakview/snakview.js
+++ b/view/resources/jquery/wikibase/snakview/snakview.js
@@ -9,13 +9,13 @@
        // Erase existing object to prevent jQuery.Widget detecting an existing 
constructor:
        delete $.wikibase.snakview;
 
-       var PARENT = $.ui.TemplatedWidget;
+       var PARENT = $.ui.EditableTemplatedWidget;
 
 /**
  * View for displaying and editing `wikibase.datamodel.Snak` objects.
  * @see wikibase.datamodel.Snak
  * @class jQuery.wikibase.snakview
- * @extends jQuery.ui.TemplatedWidget
+ * @extends jQuery.ui.EditableTemplatedWidget
  * @since 0.3
  * @author Daniel Werner < daniel.wer...@wikimedia.de >
  * @author H. Snater < mediaw...@snater.com >
@@ -112,12 +112,6 @@
         * @private
         */
        _cachedValues: null,
-
-       /**
-        * @property {boolean}
-        * @private
-        */
-       _isInEditMode: false,
 
        /**
         * Whether then `snakview`'s value is regarded "valid" at the moment.
@@ -295,38 +289,20 @@
                $.Widget.prototype.destroy.call( this );
        },
 
-       /**
-        * Starts the widget's edit mode.
-        *
-        * @return {Object} jQuery.Promise
-        * @return {Function} return.done
-        * @return {Function} return.fail
-        */
-       startEditing: function() {
+       _startEditing: function() {
                var deferred = $.Deferred();
-
-               if ( this.isInEditMode() ) {
-                       return deferred.resolve().promise();
-               }
-
-               var self = this;
-
-               this._isInEditMode = true;
-
                if ( this.options.getSnakRemover ) {
                        this._snakRemover = this.options.getSnakRemover( 
this.element );
                }
 
                if ( this._variation ) {
                        $( this._variation ).one( 'afterstartediting', 
function() {
-                               self._trigger( 'afterstartediting' );
                                deferred.resolve();
                        } );
                        this.draw();
                        this._variation.startEditing();
                } else {
                        this.draw();
-                       this._trigger( 'afterstartediting' );
                        deferred.resolve();
                }
                return deferred.promise();
@@ -354,47 +330,20 @@
         * @param {boolean} [dropValue=false] If `true`, the widget's value 
will be reset to the one
         *        from before edit mode was started.
         */
-       stopEditing: function( dropValue ) {
-               if ( !this.isInEditMode() ) {
-                       return;
-               }
-
+       _stopEditing: function( dropValue ) {
                if ( this._snakRemover ) {
                        this._snakRemover.destroy();
                        this._snakRemover = null;
                }
 
-               var snak = this.snak();
-
-               this._isInEditMode = false;
-
                if ( this._variation ) {
                        this._variation.stopEditing( dropValue );
-
-                       if ( !dropValue ) {
-                               // TODO: "this.snak( this.snak() )" is supposed 
to work to update the Snak. However,
-                               // the Variation asking the ValueView returns 
null as soon as edit mode is left.
-                               this.snak( snak );
-                       }
                }
-
-               if ( !this._variation || dropValue ) {
-                       this.value( this.options.value );
-               }
-
-               // TODO: Should throw an error somewhere when trying to leave 
edit mode while this.snak()
-               //  still returns null.
+               this.drawSnakTypeSelector();
 
                this.element.off( 'keydown.' + this.widgetName );
 
-               this._trigger( 'afterstopediting', null, [dropValue] );
-       },
-
-       /**
-        * Cancels editing. (Short-cut for `stopEditing( true )`.)
-        */
-       cancelEditing: function() {
-               return this.stopEditing( true );
+               return $.Deferred().resolve().promise();
        },
 
        /**
@@ -413,13 +362,6 @@
                if ( this._variation ) {
                        this._trigger( 'change' );
                }
-       },
-
-       /**
-        * @return {boolean}
-        */
-       isInEditMode: function() {
-               return this._isInEditMode;
        },
 
        /**
diff --git 
a/view/tests/qunit/jquery/wikibase/jquery.wikibase.referenceview.tests.js 
b/view/tests/qunit/jquery/wikibase/jquery.wikibase.referenceview.tests.js
index b385def..58f5e69 100644
--- a/view/tests/qunit/jquery/wikibase/jquery.wikibase.referenceview.tests.js
+++ b/view/tests/qunit/jquery/wikibase/jquery.wikibase.referenceview.tests.js
@@ -15,9 +15,6 @@
                                        }
                                } ).promise();
                        };
-                       this.isValid = function() {
-                               return false;
-                       };
                        this.stopEditing = function() {};
                        this.value = function() {
                                return this.options.value;
@@ -40,7 +37,9 @@
                        },
                        getReferenceRemover: function() {
                                return {
-                                       destroy: function() {}
+                                       destroy: function() {},
+                                       disable: function() {},
+                                       enable: function() {}
                                };
                        },
                        getListItemAdapter: function() {
diff --git 
a/view/tests/qunit/jquery/wikibase/jquery.wikibase.sitelinklistview.tests.js 
b/view/tests/qunit/jquery/wikibase/jquery.wikibase.sitelinklistview.tests.js
index efd4929..8a9398b 100644
--- a/view/tests/qunit/jquery/wikibase/jquery.wikibase.sitelinklistview.tests.js
+++ b/view/tests/qunit/jquery/wikibase/jquery.wikibase.sitelinklistview.tests.js
@@ -177,17 +177,6 @@
 
        sitelinklistview.enterNewItem();
 
-       var listview = sitelinklistview.$listview.data( 'listview' ),
-               lia = listview.listItemAdapter(),
-               sitelinkview = lia.liInstance( listview.items().first() );
-
-       sitelinkview.isEmpty = function() {
-               return false;
-       };
-       sitelinkview.isValid = function() {
-               return false;
-       };
-
        assert.strictEqual(
                sitelinklistview.value().length,
                0,
@@ -371,12 +360,16 @@
        sitelinklistview.enterNewItem();
 
        var listview = sitelinklistview.$listview.data( 'listview' ),
-               $sitelinkview = listview.items().first();
+               sitelinkview = listview.value()[0];
+
+       sitelinkview.isEmpty = function() {
+               return true;
+       };
 
        assert.equal( listview.items().length, 2 );
        var e = $.Event( 'keydown' );
        e.which = e.keyCode = $.ui.keyCode.BACKSPACE;
-       $sitelinkview.trigger( e );
+       sitelinkview.element.trigger( e );
 
        assert.equal( listview.items().length, 1 );
 } );
diff --git 
a/view/tests/qunit/jquery/wikibase/jquery.wikibase.snaklistview.tests.js 
b/view/tests/qunit/jquery/wikibase/jquery.wikibase.snaklistview.tests.js
index 8137212..0662731 100644
--- a/view/tests/qunit/jquery/wikibase/jquery.wikibase.snaklistview.tests.js
+++ b/view/tests/qunit/jquery/wikibase/jquery.wikibase.snaklistview.tests.js
@@ -25,7 +25,6 @@
                        }
                        return _value;
                };
-               this.isValid = function() {};
                this.startEditing = function() {
                        this._trigger( 'change' );
                        this._trigger( 'afterstartediting' );
@@ -383,25 +382,6 @@
                        null,
                        'Snaklistview is not valid due to pending value.'
                );
-       } );
-
-       QUnit.test( 'cancelEditing()', function( assert ) {
-               assert.expect( 1 );
-               var $node = createSnaklistview(),
-                       snaklistview = $node.data( 'snaklistview' );
-
-               // Since cancelEditing is just a short-cut, there is no need 
for particular testing expect
-               // for verifying the actual short-cut behaviour.
-               snaklistview.stopEditing = function( dropValue ) {
-                       assert.strictEqual(
-                               dropValue,
-                               true,
-                               'Called stopEditing with dropValue flag set to 
TRUE.'
-                       );
-               };
-
-               snaklistview.startEditing();
-               snaklistview.cancelEditing();
        } );
 
        QUnit.test( 'Stopping edit mode dropping value', function( assert ) {
diff --git 
a/view/tests/qunit/jquery/wikibase/jquery.wikibase.statementlistview.tests.js 
b/view/tests/qunit/jquery/wikibase/jquery.wikibase.statementlistview.tests.js
index 607db28..ba3a7a7 100644
--- 
a/view/tests/qunit/jquery/wikibase/jquery.wikibase.statementlistview.tests.js
+++ 
b/view/tests/qunit/jquery/wikibase/jquery.wikibase.statementlistview.tests.js
@@ -140,51 +140,6 @@
        );
 } );
 
-QUnit.test( 'isEmpty()', function( assert ) {
-       assert.expect( 4 );
-       var $statementlistview = createStatementlistview(),
-               statementlistview = $statementlistview.data( 
'statementlistview' );
-
-       assert.ok(
-               statementlistview.isEmpty(),
-               'Verified isEmpty() returning TRUE when widget has been 
initialized with an empty '
-                       + 'StatementList.'
-       );
-
-       $statementlistview = createStatementlistview( {
-               value: new wb.datamodel.StatementList( [
-                       new wb.datamodel.Statement( new wb.datamodel.Claim(
-                                       new wb.datamodel.PropertyNoValueSnak( 
'P1' )
-                       ) )
-               ] )
-       } );
-       statementlistview = $statementlistview.data( 'statementlistview' );
-
-       assert.ok(
-               !statementlistview.isEmpty(),
-               'Verified isEmpty() returning FALSE when widget has been 
initialized with a filled '
-                       + 'StatmentList.'
-       );
-
-       statementlistview.value( new wb.datamodel.StatementList() );
-
-       assert.ok(
-               statementlistview.isEmpty(),
-               'Verified isEmpty() returning TRUE after setting an empty 
StatementList.'
-       );
-
-       statementlistview.value( new wb.datamodel.StatementList( [
-               new wb.datamodel.Statement( new wb.datamodel.Claim(
-                       new wb.datamodel.PropertyNoValueSnak( 'P2' )
-               ) )
-       ] ) );
-
-       assert.ok(
-               !statementlistview.isEmpty(),
-               'Verified isEmpty() returning FALSE after setting an filled 
StatementList.'
-       );
-} );
-
 QUnit.test( 'enterNewItem', function( assert ) {
        assert.expect( 2 );
        var $statementlistview = createStatementlistview(),
diff --git a/view/tests/qunit/wikibase/view/ToolbarViewController.tests.js 
b/view/tests/qunit/wikibase/view/ToolbarViewController.tests.js
index f94ceb3..22aac99 100644
--- a/view/tests/qunit/wikibase/view/ToolbarViewController.tests.js
+++ b/view/tests/qunit/wikibase/view/ToolbarViewController.tests.js
@@ -32,7 +32,6 @@
                                on: function() {}
                        },
                        enable: function() {},
-                       isValid: function() {},
                        setError: function() {},
                        startEditing: function() {
                                return $.Deferred();

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3f484bdb2d3ee7827e58c2034a05753478e389c3
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Heine <m...@adrianheine.de>
Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de>
Gerrit-Reviewer: Thiemo M├Ąttig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to