Henning Snater has uploaded a new change for review.
https://gerrit.wikimedia.org/r/169997
Change subject: snakview: Re-set previous snak value when toggling the snak type
......................................................................
snakview: Re-set previous snak value when toggling the snak type
Change-Id: Id7e4c60c0a3cf2f13823d4c2322b32295ddbe672
---
M lib/resources/jquery.wikibase/snakview/snakview.js
1 file changed, 28 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/97/169997/1
diff --git a/lib/resources/jquery.wikibase/snakview/snakview.js
b/lib/resources/jquery.wikibase/snakview/snakview.js
index bb7450d..180db6c 100644
--- a/lib/resources/jquery.wikibase/snakview/snakview.js
+++ b/lib/resources/jquery.wikibase/snakview/snakview.js
@@ -112,6 +112,13 @@
_variation: null,
/**
+ * Cache for the values of specific wikibase.snakview.variations in
order to have those restored
+ * when toggling he snak type.
+ * @type {Object}
+ */
+ _cachedValues: null,
+
+ /**
* The property of the Snak currently represented by the view.
* @type {String}
*/
@@ -165,6 +172,8 @@
this._entityStore = this.option( 'entityStore' );
this._valueViewBuilder = this.option( 'valueViewBuilder' );
+
+ this._cachedValues = {};
// set value, can be a wb.datamodel.Snak or plain Object as
wb.datamodel.Snak.toMap() or just pieces of it
this.value( this.option( 'value' ) || {} );
@@ -554,6 +563,10 @@
* @param {Object|null} value
*/
_setValue: function( value ) {
+ if( this._snakType && this._variation ) {
+ this._cachedValues[this._snakType] =
this._variation.value();
+ }
+
value = value || {};
this._propertyId = value.property || null;
@@ -575,6 +588,11 @@
this.draw();
},
+ /**
+ * Updates specifics of the value.
+ *
+ * @param {Object} changes
+ */
_updateValue: function( changes ) {
this._setValue( $.extend( this._getValue(), changes ) );
},
@@ -585,8 +603,8 @@
*
* @since 0.4
*
- * @param {wb.datamodel.Snak|null} [snak]
- * @return wb.datamodel.Snak|null
+ * @param {wikibase.datamodel.Snak|null} [snak]
+ * @return {wikibase.datamodel.Snak|null}
*/
snak: function( snak ) {
if( snak === undefined ) {
@@ -647,9 +665,15 @@
}
if( snakType !== this._snakType ) {
// TODO: check whether given snak type is actually
valid!
- this._updateValue( {
+ var changes = {
snaktype: snakType
- } );
+ };
+
+ if( this._cachedValues[snakType] ) {
+ $.extend( changes, this._cachedValues[snakType]
);
+ }
+
+ this._updateValue( changes );
}
},
--
To view, visit https://gerrit.wikimedia.org/r/169997
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id7e4c60c0a3cf2f13823d4c2322b32295ddbe672
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