Tobias Gritschacher has submitted this change and it was merged.

Change subject: Fix empty references removal
......................................................................


Fix empty references removal

Change-Id: I4d4c88f07b4ae06118c7c67e56711a63b7ea15e4
---
M view/resources/jquery/wikibase/jquery.wikibase.referenceview.js
M view/resources/wikibase/view/ViewFactory.js
M view/tests/qunit/jquery/wikibase/jquery.wikibase.referenceview.tests.js
M view/tests/qunit/wikibase/view/ViewFactory.tests.js
4 files changed, 22 insertions(+), 7 deletions(-)

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



diff --git a/view/resources/jquery/wikibase/jquery.wikibase.referenceview.js 
b/view/resources/jquery/wikibase/jquery.wikibase.referenceview.js
index d407806..a6e6f2d 100644
--- a/view/resources/jquery/wikibase/jquery.wikibase.referenceview.js
+++ b/view/resources/jquery/wikibase/jquery.wikibase.referenceview.js
@@ -17,6 +17,7 @@
  * @param {Object} options
  * @param {wikibase.datamodel.Reference|null} options.value
  * @param {Function} options.getListItemAdapter
+ * @param {Function} options.removeCallback
  */
 /**
  * @event afterstartediting
@@ -72,16 +73,22 @@
         * @throws {Error} if a required option is not specified properly.
         */
        _create: function() {
-               if ( !this.options.getListItemAdapter ) {
+               if ( !this.options.getListItemAdapter || 
!this.options.removeCallback ) {
                        throw new Error( 'Required option not specified 
properly' );
                }
 
                PARENT.prototype._create.call( this );
 
+               var self = this;
                var listview;
                this.$listview.listview( {
                        listItemAdapter: this.options.getListItemAdapter( 
function( snaklistview ) {
                                listview.removeItem( snaklistview.element );
+                               if ( listview.items().length === 0 ) {
+                                       self.options.removeCallback();
+                               } else {
+                                       self._trigger( 'change' );
+                               }
                        } ),
                        value: this.options.value ? 
this.options.value.getSnaks().getGroupedSnakLists() : []
                } );
diff --git a/view/resources/wikibase/view/ViewFactory.js 
b/view/resources/wikibase/view/ViewFactory.js
index 568e1c8..5cc13c1 100644
--- a/view/resources/wikibase/view/ViewFactory.js
+++ b/view/resources/wikibase/view/ViewFactory.js
@@ -475,7 +475,11 @@
 
        SELF.prototype.getReferenceView = function( startEditingCallback, 
removeCallback, value, $dom ) {
                var structureEditorFactory = this._structureEditorFactory;
-               var view = this._getView(
+               var view;
+               var doRemove = function() {
+                       return removeCallback( view );
+               };
+               view = this._getView(
                        'referenceview',
                        $dom,
                        {
@@ -484,9 +488,10 @@
                                getListItemAdapter: 
this.getListItemAdapterForSnakListView.bind( this, startEditingCallback ),
                                getReferenceRemover: function( $dom ) {
                                        return 
structureEditorFactory.getRemover( function() {
-                                               return 
startEditingCallback().then( function() { return removeCallback( view ); } );
+                                               return 
startEditingCallback().then( doRemove );
                                        }, $dom );
-                               }
+                               },
+                               removeCallback: doRemove
                        }
                );
                return view;
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 db8c673..b385def 100644
--- a/view/tests/qunit/jquery/wikibase/jquery.wikibase.referenceview.tests.js
+++ b/view/tests/qunit/jquery/wikibase/jquery.wikibase.referenceview.tests.js
@@ -45,7 +45,8 @@
                        },
                        getListItemAdapter: function() {
                                return listItemAdapter;
-                       }
+                       },
+                       removeCallback: function() {}
                }, options );
 
                return $( '<div/>' )
diff --git a/view/tests/qunit/wikibase/view/ViewFactory.tests.js 
b/view/tests/qunit/wikibase/view/ViewFactory.tests.js
index fc4b148..e7f4b14 100644
--- a/view/tests/qunit/wikibase/view/ViewFactory.tests.js
+++ b/view/tests/qunit/wikibase/view/ViewFactory.tests.js
@@ -377,9 +377,11 @@
                sinon.assert.calledWith(
                        referenceview,
                        sinon.match( {
-                               value: value || null,
+                               getAdder: sinon.match.func,
                                getListItemAdapter: sinon.match.func,
-                               getReferenceRemover: sinon.match.func
+                               getReferenceRemover: sinon.match.func,
+                               removeCallback: sinon.match.func,
+                               value: value || null
                        } )
                );
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4d4c88f07b4ae06118c7c67e56711a63b7ea15e4
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: 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

Reply via email to