Henning Snater has uploaded a new change for review.
https://gerrit.wikimedia.org/r/89004
Change subject: Keep track of reference's index in referenceview
......................................................................
Keep track of reference's index in referenceview
Keeping track of the reference's index within a statementview's list of
referenceviews
allows determining whether the referenceview's value still matches the initial
one.
Change-Id: I14d2a6ba86dcd9c8619e2eff5b60d81df287ae1b
---
M lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js
M lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
2 files changed, 55 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/04/89004/1
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js
b/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js
index 95ab7d2..fb486e7 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.referenceview.js
@@ -76,6 +76,7 @@
};
}
} ),
+ index: null,
helpMessage: mw.msg( 'wikibase-claimview-snak-new-tooltip' )
},
@@ -94,6 +95,14 @@
* @type {wikibase.SnakList}
*/
_initialSnakList: null,
+
+ /**
+ * The reference's initial index within the list of references (if it
is contained within a list
+ * of references). The initial index is stored to be able to detect
whether the index has
+ * changed and the reference does not feature its initial value.
+ * @type {number|null}
+ */
+ _initialIndex: null,
/**
* @see jQuery.wikibase.snaklistview._create
@@ -117,6 +126,8 @@
this._initialSnakList = new wb.SnakList();
}
+ this._initialIndex = this.option( 'index' );
+
PARENT.prototype._create.call( this );
// Whenever entering a new referenceview item, a single
snaklistview needs to be created
@@ -127,6 +138,21 @@
} );
this._updateReferenceHashClass( this.value() );
+ },
+
+ /**
+ * @see jQuery.Widget.option
+ *
+ * @triggers change
+ */
+ option: function( key, value ) {
+ var val = PARENT.prototype.option.apply( this, arguments );
+
+ if( key === 'index' && value !== undefined ) {
+ this._trigger( 'change' );
+ }
+
+ return val;
},
/**
@@ -426,6 +452,10 @@
* @return {boolean}
*/
isInitialValue: function() {
+ if( this.option( 'index' ) !== this._initialIndex ) {
+ return false;
+ }
+
var $snaklistviews = this.items(),
snakList = new wb.SnakList();
@@ -474,7 +504,8 @@
guid,
this.value().getSnaks(),
revStore.getClaimRevision( guid ),
- this.value().getHash() || null
+ this.value().getHash() || null,
+ this.option( 'index' )
).done( function( savedReference, pageInfo ) {
// update revision store
revStore.setClaimRevision( pageInfo.lastrevid, guid );
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
index 1c513c7..9c571ca 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
@@ -63,6 +63,11 @@
statement = this.value(),
refs = statement ? statement.getReferences() : [];
+ function indexOf( element, array ) {
+ var index = $.inArray( element, array );
+ return ( index !== -1 ) ? index : null;
+ }
+
if( this.value() ) {
var $listview = $( '<div/>' )
.prependTo( this.$references )
@@ -73,7 +78,8 @@
newItemOptionsFn: function( value ) {
return {
value: value || null,
- statementGuid:
self.value().getGuid()
+ statementGuid:
self.value().getGuid(),
+ index: indexOf( value,
refs )
};
}
} ),
@@ -85,6 +91,7 @@
$listview
.on( 'referenceviewitemadded referenceviewitemremoved',
function( event, value, $li ) {
self.drawReferencesCounter();
+ self._updateReferenceIndices();
} )
.on( 'listviewenternewitem', function( event, $newLi ) {
// Enter first item into the referenceview.
@@ -137,6 +144,8 @@
// replace heading with nice counter:
this.drawReferencesCounter();
+
+ this._updateReferenceIndices();
}
},
@@ -206,6 +215,19 @@
},
/**
+ * Updates the reference view indices.
+ * @since 0.5
+ */
+ _updateReferenceIndices: function() {
+ var $referenceviews = this.$references.data( 'listview'
).items();
+
+ for( var i = 0; i < $referenceviews.length; i++ ) {
+ var referenceview = this._referenceviewLia.liInstance(
$referenceviews.eq( i ) );
+ referenceview.option( 'index', i );
+ }
+ },
+
+ /**
* Removes a referenceview from the list of references.
* @since 0.4
*
--
To view, visit https://gerrit.wikimedia.org/r/89004
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I14d2a6ba86dcd9c8619e2eff5b60d81df287ae1b
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