Skip to content

Commit 1f57969

Browse files
author
Daniel Kinzler
committed
Merge pull request #186 from wmde/formatAgnostic
Make Experts aware of the output format
2 parents af79974 + bc38593 commit 1f57969

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ Other methods an `Expert` needs to provide:
108108
### 0.15.2 (2015-08-27)
109109

110110
#### Enhancements
111-
* `jQuery.valueview.experts.QuantityInput` explicitely asks `QuantityFormatter` to not apply rounding and units.
111+
* `jQuery.valueview.expert.valueCharacteristics` gets the output format passed in.
112+
* `jQuery.valueview.experts.QuantityInput` explicitely asks `QuantityFormatter` to not apply rounding and units in plain text format.
112113
* `jQuery.valueview.valueview` passes a `vocabularyLookupApiUrl` option to all experts.
113114
* `jQuery.valueview.experts.QuantityInput` and `jQuery.valueview.ExpertExtender.UnitSelector` now pass a `vocabularyLookupApiUrl` option to `jQuery.ui.unitsuggester`.
114115
* `jQuery.ui.unitsuggester` uses the `concepturi` from `wbsearchentities` results, if available.
@@ -291,7 +292,7 @@ Other methods an `Expert` needs to provide:
291292
* Make the minimal term length of the suggester configurable.
292293
* Add resource loader dependencies for jquery.ui.suggester, fixing bug 66268 and bug 66257.
293294

294-
### 0.6 (2014-06-04)
295+
### 0.6.0 (2014-06-04)
295296

296297
* Re-created jQuery.ui.suggester widget removing dependencies on jQuery.ui.autocomplete and jQuery.ui.menu
297298
* Implemented jQuery.util.highlightMatchingCharacters
@@ -309,7 +310,7 @@ Other methods an `Expert` needs to provide:
309310
* Change TimeInput::draw() to update the rotators' values if they are in auto mode
310311
* Change GlobeCoordinateInput::draw() to update the precision rotator value if it is in auto mode
311312

312-
### 0.5 (2014-03-28)
313+
### 0.5.0 (2014-03-28)
313314

314315
* Renamed jQuery.valueView.ExpertFactory to jQuery.valueView.ExpertStore.
315316
* Renamed jQuery.valueView option "expertProvider" to "expertStore".
@@ -332,7 +333,7 @@ Other methods an `Expert` needs to provide:
332333

333334
* Updated DataValues JavaScript dependency to version 0.4.
334335

335-
### 0.4 (2014-03-26)
336+
### 0.4.0 (2014-03-26)
336337

337338
* Remove trimming from StringValue expert
338339
* Use ViewState::getFormattedValue for GlobeCoordinate formatting
@@ -357,7 +358,7 @@ Other methods an `Expert` needs to provide:
357358
* Use ViewState::getFormattedValue for Url formatting
358359
* Use ViewState::getFormattedValue for GlobeCoordinate formatting
359360

360-
### 0.3 (2014-02-04)
361+
### 0.3.0 (2014-02-04)
361362

362363
#### Enhancements
363364

@@ -383,7 +384,7 @@ Other methods an `Expert` needs to provide:
383384
* Updated DataValues JavaScript dependency to version 0.3.
384385
* Renamed jQuery.valueview.preview to jQuery.ui.preview
385386

386-
### 0.2 (2014-01-29)
387+
### 0.2.0 (2014-01-29)
387388

388389
#### Refactorings
389390

@@ -412,7 +413,7 @@ Other methods an `Expert` needs to provide:
412413

413414
* #6 Added util.Notifier
414415

415-
### 0.1 (2013-12-23)
416+
### 0.1.0 (2013-12-23)
416417

417418
Initial release.
418419

src/experts/QuantityInput.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,17 @@
4848
/**
4949
* @inheritdoc
5050
*/
51-
valueCharacteristics: function() {
52-
return {
53-
unit: this._unitSelector && this._unitSelector.getConceptUri() || null,
54-
applyUnit: false,
55-
applyRounding: false
51+
valueCharacteristics: function( format ) {
52+
var options = {
53+
unit: this._unitSelector && this._unitSelector.getConceptUri() || null
5654
};
55+
56+
if( format === 'text/plain' ) {
57+
options.applyRounding = false;
58+
options.applyUnit = false;
59+
}
60+
61+
return options;
5762
},
5863

5964
/**

src/jquery.valueview.Expert.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,11 @@ jQuery.valueview = jQuery.valueview || {};
243243
*
244244
* This method should allow to be called statically, i. e. without a useful `this` context.
245245
*
246+
* @param {string} [format='text/html'] Typically "text/plain". Implementations should
247+
* fall back to "text/html" when the format is undefined.
246248
* @return {Object}
247249
*/
248-
valueCharacteristics: function() {
250+
valueCharacteristics: function( format ) {
249251
return {};
250252
},
251253

src/jquery.valueview.valueview.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ $.widget( 'valueview.valueview', PARENT, {
733733
clearTimeout( this._parseTimer );
734734
}
735735

736-
var valueParser = this._instantiateParser( this.valueCharacteristics() );
736+
var valueParser = this._instantiateParser( this.valueCharacteristics( 'text/plain' ) );
737737

738738
self.__lastUpdateValue = rawValue;
739739
this._parseTimer = setTimeout( function() {
@@ -860,6 +860,7 @@ $.widget( 'valueview.valueview', PARENT, {
860860
_updateTextValue: function() {
861861
var self = this,
862862
deferred = $.Deferred(),
863+
format = 'text/plain',
863864
valueFormatter,
864865
dataTypeId = this.options.dataTypeId || null,
865866
dataValue = this._value;
@@ -870,9 +871,9 @@ $.widget( 'valueview.valueview', PARENT, {
870871
return deferred.promise();
871872
}
872873

873-
valueFormatter = this._instantiateFormatter( this.valueCharacteristics() );
874+
valueFormatter = this._instantiateFormatter( this.valueCharacteristics( format ) );
874875

875-
valueFormatter.format( dataValue, dataTypeId, 'text/plain' )
876+
valueFormatter.format( dataValue, dataTypeId, format )
876877
.done( function( formattedValue, formattedDataValue ) {
877878
if( dataValue === formattedDataValue ) {
878879
self._textValue = formattedValue;
@@ -992,14 +993,15 @@ $.widget( 'valueview.valueview', PARENT, {
992993
/**
993994
* @see jQuery.valueview.Expert.valueCharacteristics
994995
*
996+
* @param {string} [format='text/html']
995997
* @return {Object}
996998
*/
997-
valueCharacteristics: function() {
999+
valueCharacteristics: function( format ) {
9981000
if( this._expert ) {
999-
return this._expert.valueCharacteristics();
1001+
return this._expert.valueCharacteristics( format );
10001002
}
10011003
if( this._expertConstructor ) {
1002-
return this._expertConstructor.prototype.valueCharacteristics();
1004+
return this._expertConstructor.prototype.valueCharacteristics( format );
10031005
}
10041006
return {};
10051007
}

0 commit comments

Comments
 (0)