Henning Snater has submitted this change and it was merged.
Change subject: EntityIdInput expert keeps track of raw value when set to
deleted entity
......................................................................
EntityIdInput expert keeps track of raw value when set to deleted entity
When the value of the expert is set to an ID of an entity which is deleted,
then the input field is
empty. Because of this, when asking for the value (via rawValue()), the expert
did return null
instead of the ID of the deleted/missing entity.
This was wrong behavior since displaying an empty string for missing entities
is just an decision
of how to visualize the value. rawValue() should still return the same value as
set before. Only
after the user changes the input's value, the value should be set to null
(empty) or another value.
One case not clearly defined still is what happens when the value is set to a
missing entity, so
an empty string will be displayed in the box, but then the user types
something, then removes the
typed string again so the text in the box is an empty string again. Should
rawValue() could now
either return null (current behavior) since the user changed the value in the
meanwhile, or it
could be reset to the missing entity ID which was set before.
Effect in the UI: When clicking edit on a Snak using a deleted item, then
pressing cancel, the view
did not display "<id> (Deleted item)" anymore as it did
before clicking edit.
This change fixes this, so the label will be displayed
correctly after cancel.
Change-Id: I678b7b2724857c2a950c06e3d9ec72afb79170e9
---
M
lib/resources/jquery.valueview.experts.wikibase/experts.wikibase.EntityIdInput.js
1 file changed, 43 insertions(+), 15 deletions(-)
Approvals:
Henning Snater: Verified; Looks good to me, approved
diff --git
a/lib/resources/jquery.valueview.experts.wikibase/experts.wikibase.EntityIdInput.js
b/lib/resources/jquery.valueview.experts.wikibase/experts.wikibase.EntityIdInput.js
index f946bc2..95d736c 100644
---
a/lib/resources/jquery.valueview.experts.wikibase/experts.wikibase.EntityIdInput.js
+++
b/lib/resources/jquery.valueview.experts.wikibase/experts.wikibase.EntityIdInput.js
@@ -26,6 +26,14 @@
*/
vv.experts.wikibase.EntityIdInput = vv.expert( 'wikibaseentityidinput',
PARENT, {
/**
+ * Field used to remember a value as current value while the
value can't be displayed by
+ * the entity selector as current value. Used if an Entity not
in the system is set as
+ * current value. false implies that the current value is the
one of the entity selector.
+ * @type {false|string}
+ */
+ _actualValue: false,
+
+ /**
* @see Query.valueview.experts.StringValue._init
*/
_init: function() {
@@ -35,20 +43,16 @@
$input = this.$input,
self = this;
- $input
- .entityselector( {
+ $input.entityselector( {
url: mw.util.wikiScript( 'api' ),
selectOnAutocomplete: true
} )
- .eachchange( function( event, oldValue ) {
- $( this ).data( 'entityselector'
).repositionMenu();
- } )
.on( 'entityselectorselect', function( e, ui ) {
- var itemData = {
+ var entityData = {
id: ui.item.id,
label: {}
};
- itemData.label[ mw.config.get( 'wgUserLanguage'
) ] = ui.item.label;
+ entityData.label[ mw.config.get(
'wgUserLanguage' ) ] = ui.item.label;
// update local store with newest information
about selected item
// TODO: create more sophisticated local store
interface rather than accessing
@@ -56,7 +60,7 @@
wb.fetchedEntities[ ui.item.id ] = new
wb.store.FetchedContent( {
// TODO: *terrible* solution to use
regex, entityselector should provide title
title: new mw.Title( ui.item.url.match(
/[^\/]+$/ )[0] ),
- content: new wb.Item( itemData )
+ content: new wb.Item( entityData ) //
TODO: make this work for all Entity types!
} );
self._resizeInput();
@@ -66,17 +70,25 @@
// Snak).
// "response": Each time an API query returns
(the input value gets auto-completed).
// "close": After having selected an entity by
clicking on a suggestion list item.
- 'entityselectoraftersetentity
entityselectorresponse entityselectorclose',
+ 'entityselectoraftersetentity
entityselectorresponse entityselectorclose'
+ + ' eachchange',
function( e ) {
- var expand = $( this ).data(
'AutoExpandInput' );
- expand && expand.expand();
+ self._resizeInput();
$( this ).data( 'entityselector'
).repositionMenu();
}
- );
+ )
+ .on(
+ 'eachchange entityselectorselect
entityselectoraftersetentity',
+ function( e ) {
+ // Entity selector's value is actual
value after change.
+ self._actualValue = false;
- $input.on( 'entityselectorselect', function( event,
response ) {
- notifier.notify( 'change' ); // here in
addition to 'eachchange' from StringValue expert
- } );
+ if( e.type !== 'eachchange' ) {
+ // Already registered to
'eachchange' in StringValue expert.
+ notifier.notify( 'change' );
+ }
+ }
+ );
},
/**
@@ -88,6 +100,11 @@
* the other returns a string!
*/
_getRawValue: function() {
+ if( this._actualValue !== false ) {
+ // Empty input field is displayed because some
entity, not in the system, is set as
+ // current value.
+ return this._actualValue;
+ }
var entitySelector = this.$input.data( 'entityselector'
),
selectedEntity =
entitySelector.selectedEntity();
@@ -120,6 +137,17 @@
this.$input.data( 'entityselector' ).selectedEntity(
simpleEntity );
this._resizeInput();
+
+ if( !fetchedEntity && entityId ) {
+ // Entity not in the system, can be considered
deleted. In this case we display an
+ // empty input box while the "real" value is
still that reference to the entity not
+ // in the system. _getValue() has to return
that one until the user types something.
+ // NOTE: This is *not* a hack!
+ this._actualValue = entityId;
+ // NOTE: this has to be done after entity
selector change because there is a event
+ // registered to
"entityselectoraftersetentity" which will set the actual value
+ // back to false.
+ }
// TODO: entityselector should just be able to handle
wb.Entity without making it a
// dependency there.
},
--
To view, visit https://gerrit.wikimedia.org/r/58675
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I678b7b2724857c2a950c06e3d9ec72afb79170e9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits