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

Change subject: referenceview: Using listview.value()
......................................................................


referenceview: Using listview.value()

Change-Id: Iccef189bbd450add404d9717394dee9be0bd7199
---
M lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js
1 file changed, 23 insertions(+), 45 deletions(-)

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



diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js
index 490f2c1..0b44434 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js
@@ -228,17 +228,14 @@
                        this._reference = reference;
                        return this._reference;
                } else {
-                       var listview = this.$listview.data( 'listview' ),
-                               lia = listview.listItemAdapter(),
-                               snaklistviews = this.$listview.data( 'listview' 
).items(),
-                               snakList = new wb.datamodel.SnakList();
+                       var snakList = new wb.datamodel.SnakList();
 
-                       for( var i = 0; i < snaklistviews.length; i++ ) {
-                               var curSnakList = lia.liInstance( 
snaklistviews.eq( i ) ).value();
-                               if( curSnakList ) {
-                                       snakList.merge( curSnakList );
+                       $.each( this.$listview.data( 'listview' ).value(), 
function() {
+                               var snakListForProperty = this.value();
+                               if( snakListForProperty ) {
+                                       snakList.merge( snakListForProperty );
                                }
-                       }
+                       } );
 
                        if ( this._reference ) {
                                return new wb.datamodel.Reference( snakList || 
[], this._reference.getHash() );
@@ -259,13 +256,9 @@
                        return;
                }
 
-               var listview = this.$listview.data( 'listview' ),
-                       lia = listview.listItemAdapter(),
-                       $snaklistviews = listview.items();
-
-               for( var i = 0; i < $snaklistviews.length; i++ ) {
-                       lia.liInstance( $snaklistviews.eq( [i] ) 
).startEditing();
-               }
+               $.each( this.$listview.data( 'listview' ).value(), function() {
+                       this.startEditing();
+               } );
 
                this._attachEditModeEventHandlers();
 
@@ -404,44 +397,29 @@
         * @return {boolean}
         */
        isValid: function() {
-               var listview = this.$listview.data( 'listview' ),
-                       lia = listview.listItemAdapter(),
-                       $snaklistviews = listview.items();
-
-               for( var i = 0; i < $snaklistviews.length; i++ ) {
-                       if( !lia.liInstance( $snaklistviews.eq( i ) ).isValid() 
) {
-                               return false;
+               var isValid = true;
+               $.each( this.$listview.data( 'listview' ).value(), function() {
+                       if( !this.isValid() ) {
+                               isValid = false;
                        }
-               }
-
-               return true;
+                       return isValid;
+               } );
+               return isValid;
        },
 
        /**
-        * Returns whether the referenceview's current value matches the value 
it has been initialized
-        * with.
+        * Returns whether the `referenceview`'s current value matches the 
value it has been initialized
+        * with by checking the `Reference`'s `Snak`s.
         * @since 0.5
         *
         * @return {boolean}
         */
        isInitialValue: function() {
-               var listview = this.$listview.data( 'listview' ),
-                       lia = listview.listItemAdapter(),
-                       $snaklistviews = listview.items(),
-                       snakList = new wb.datamodel.SnakList();
-
-               // Generate a SnakList object featuring all current reference 
snaks to be able to compare it
-               // to the SnakList object the referenceview has been 
initialized with:
-               if( $snaklistviews.length ) {
-                       for( var i = 0; i < $snaklistviews.length; i++ ) {
-                               var snakview = lia.liInstance( 
$snaklistviews.eq( i ) );
-                               if( snakview.value() ) {
-                                       snakList.merge( snakview.value() );
-                               }
-                       }
-               }
-
-               return snakList.equals( this._initialSnakList );
+               var currentReference = this.value(),
+                       currentSnakList = currentReference
+                               ? currentReference.getSnaks()
+                               : new wb.datamodel.SnakList();
+               return currentSnakList.equals( this._initialSnakList );
        },
 
        /**

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iccef189bbd450add404d9717394dee9be0bd7199
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: jenkins-bot <>

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

Reply via email to