Skip to content

Commit a5b94b9

Browse files
committed
Merge pull request #162 from wmde/datavalues070
Adapt to DataValuesJavaScript 0.7.0
2 parents 0804c12 + 23be0b8 commit a5b94b9

File tree

9 files changed

+47
-60
lines changed

9 files changed

+47
-60
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ Other methods an `Expert` needs to provide:
105105

106106
## Release notes
107107

108-
### 0.14.4 (2015-06-08)
108+
### 0.14.4 (2015-06-10)
109109
* Added expert for `UnDeserializableValue`s.
110+
* Updated DataValues JavaScript dependency to version 0.7.
110111

111112
### 0.14.3 (2015-04-02)
112113
* Fix premature afterparse handling (e.g. save) of parsed values.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"require": {
2323
"php": ">=5.3.0",
24-
"data-values/javascript": "~0.6.0"
24+
"data-values/javascript": "~0.7.0"
2525
},
2626
"autoload": {
2727
"files": [

src/ExpertExtender/ExpertExtender.CalendarHint.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
( function( $, ExpertExtender, Time ) {
1+
( function( $, ExpertExtender, TimeValue ) {
22
'use strict';
33

44
/**
@@ -94,28 +94,30 @@
9494
return;
9595
}
9696

97-
// Are we in the interesting range
98-
if( !( value.year() > 1581 && value.year() < 1930 && value.precision() > 10 ) ) {
97+
var assumeCalendar = value.getYear() <= 1581 || value.getYear() >= 1930;
98+
99+
if( assumeCalendar || value.getOption( 'precision' ) <= 10 ) {
99100
this.$calendarhint.hide();
100101
return;
101102
}
102103

103-
var msg = this._messageProvider.getMessage(
104-
this._prefix + '-' + value.calendar().toLowerCase()
105-
);
104+
var calendarModel = value.getOption( 'calendarModel' ),
105+
msg = this._messageProvider.getMessage(
106+
this._prefix + '-' + TimeValue.getCalendarModelKeyByUri( calendarModel )
107+
);
106108

107109
if( !msg ) {
108110
return;
109111
}
110112

111113
this.$calendarhint.children( '.' + this._prefix + '-message' ).text( msg );
112114

113-
this._otherCalendar = ( value.calendar() === Time.CALENDAR.GREGORIAN )
114-
? Time.CALENDAR.JULIAN
115-
: Time.CALENDAR.GREGORIAN;
115+
this._otherCalendar = calendarModel === TimeValue.CALENDARS.GREGORIAN
116+
? TimeValue.CALENDARS.JULIAN
117+
: TimeValue.CALENDARS.GREGORIAN;
116118

117119
msg = this._messageProvider.getMessage(
118-
this._prefix + '-switch-' + this._otherCalendar.toLowerCase()
120+
this._prefix + '-switch-' + TimeValue.getCalendarModelKeyByUri( this._otherCalendar )
119121
);
120122
if( msg ) {
121123
this.$calendarhint.children( '.' + this._prefix + '-switch' ).html( msg );
@@ -138,4 +140,4 @@
138140
this._otherCalendar = null;
139141
}
140142
} );
141-
}( jQuery, jQuery.valueview.ExpertExtender, time.Time ) );
143+
}( jQuery, jQuery.valueview.ExpertExtender, dataValues.TimeValue ) );

src/ExpertExtender/resources.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
'ExpertExtender.CalendarHint.css',
3434
),
3535
'dependencies' => array(
36+
'dataValues.TimeValue',
3637
'jquery.valueview.ExpertExtender',
37-
'time.js'
3838
),
3939
'messages' => array(
4040
'valueview-expertextender-calendarhint-gregorian',

src/experts/TimeInput.js

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
( function( $, vv, time ) {
1+
( function( $, vv, TimeValue ) {
22
'use strict';
33

4-
var Time = time.Time,
5-
timeSettings = time.settings;
6-
74
var PARENT = vv.experts.StringValue;
85

96
/**
@@ -38,7 +35,7 @@
3835
$.proxy( this._onRotatorChange, this ),
3936
function() {
4037
var value = self.viewState().value();
41-
return value && value.getValue().precision();
38+
return value && value.getOption( 'precision' );
4239
}
4340
);
4441

@@ -53,7 +50,7 @@
5350
$.proxy( this._onRotatorChange, this ),
5451
function() {
5552
var value = self.viewState().value();
56-
return value && value.getValue().calendar();
53+
return value && value.getOption( 'calendarModel' );
5754
}
5855
);
5956

@@ -64,8 +61,7 @@
6461
new vv.ExpertExtender.CalendarHint(
6562
this._messageProvider,
6663
function() {
67-
var value = self.viewState().value();
68-
return value && value.getValue();
64+
return self.viewState().value();
6965
},
7066
function( value ) {
7167
// FIXME: Do not use private function:
@@ -143,13 +139,13 @@
143139
valueCharacteristics: function() {
144140
var options = {},
145141
precision = this.precisionRotator && this.precisionRotator.getValue() || null,
146-
calendarname = this.calendarRotator && this.calendarRotator.getValue() || null;
142+
calendarUri = this.calendarRotator && this.calendarRotator.getValue() || null;
147143

148144
if( precision !== null ) {
149145
options.precision = precision;
150146
}
151-
if( calendarname !== null ) {
152-
options.calendar = calendarNameToUri( calendarname );
147+
if( calendarUri !== null ) {
148+
options.calendar = calendarUri;
153149
}
154150

155151
return options;
@@ -162,11 +158,12 @@
162158
* @return {Object[]} [{ value: <{number}>, label: <{string}>}, ...]
163159
*/
164160
function getPrecisionValues() {
165-
var precisionValues = [];
166-
$.each( timeSettings.precisiontexts, function( i, text ) {
167-
if( i <= Time.PRECISION.DAY ) {
161+
var precisionValues = [],
162+
dayPrecision = TimeValue.getPrecisionById( 'DAY' );
163+
$.each( TimeValue.PRECISIONS, function( precisionValue, precision ) {
164+
if( precisionValue <= dayPrecision ) {
168165
// TODO: Remove this check as soon as time values are supported.
169-
precisionValues.unshift( { value: i, label: text } );
166+
precisionValues.unshift( { value: precisionValue, label: precision.text } );
170167
}
171168
} );
172169
return precisionValues;
@@ -180,23 +177,13 @@
180177
*/
181178
function getCalendarValues( messageProvider ) {
182179
var calendarValues = [];
183-
$.each( timeSettings.calendarnames, function( calendarKey, calendarTerms ) {
180+
$.each( TimeValue.CALENDARS, function( key, uri ) {
184181
var label = messageProvider.getMessage(
185-
'valueview-expert-timevalue-calendar-' + calendarTerms[0].toLowerCase()
186-
) || calendarTerms[0];
187-
calendarValues.push( { value: calendarTerms[0], label: label } );
182+
'valueview-expert-timevalue-calendar-' + key.toLowerCase()
183+
) || key.toLowerCase();
184+
calendarValues.push( { value: uri, label: label } );
188185
} );
189186
return calendarValues;
190187
}
191188

192-
/**
193-
* @ignore
194-
*
195-
* @param {string} calendarname
196-
* @return {string}
197-
*/
198-
function calendarNameToUri( calendarname ) {
199-
return new Time( { calendarname: calendarname, precision: 0, year: 0 } ).calendarURI();
200-
}
201-
202-
}( jQuery, jQuery.valueview, time ) );
189+
}( jQuery, jQuery.valueview, dataValues.TimeValue ) );

src/experts/resources.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
'TimeInput.css',
120120
),
121121
'dependencies' => array(
122+
'dataValues.TimeValue',
122123
'jquery.valueview.ExpertExtender',
123124
'jquery.valueview.ExpertExtender.CalendarHint',
124125
'jquery.valueview.ExpertExtender.Container',
@@ -127,7 +128,6 @@
127128
'jquery.valueview.ExpertExtender.Toggler',
128129
'jquery.valueview.experts',
129130
'jquery.valueview.Expert',
130-
'time.js',
131131
'util.MessageProvider',
132132
),
133133
'messages' => array(

tests/src/ExpertExtender/ExpertExtender.CalendarHint.tests.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
$,
88
ExpertExtender,
99
testExpertExtenderExtension,
10-
Time,
10+
TimeValue,
1111
HashMessageProvider,
1212
sinon,
1313
QUnit,
@@ -37,11 +37,11 @@
3737
'valueview-expertextender-calendarhint-switch-julian': 'MSG2'
3838
} ),
3939
function() {
40-
return new time.Time( '2014-01-01' );
40+
return new TimeValue( '2014-01-01T00:00:00Z' );
4141
},
4242
null
4343
);
44-
var $extender = $( '<div />' ).appendTo( 'body' ) ;
44+
var $extender = $( '<div />' ).appendTo( 'body' );
4545

4646
calendarHint.init( $extender );
4747
calendarHint.draw();
@@ -58,7 +58,7 @@
5858
'valueview-expertextender-calendarhint-switch-julian': 'MSG2'
5959
} ),
6060
function() {
61-
return new Time( '1901-01-01' );
61+
return new TimeValue( '1901-01-01T00:00:00Z' );
6262
},
6363
null
6464
);
@@ -74,7 +74,7 @@
7474

7575
QUnit.test( 'switch switches the calendar model', function( assert ) {
7676
var setSpy = sinon.spy();
77-
var timeValue = new Time( '1901-01-01' );
77+
var timeValue = new TimeValue( '1901-01-01T00:00:00Z' );
7878
var calendarHint = new ExpertExtender.CalendarHint(
7979
new HashMessageProvider( {
8080
'valueview-expertextender-calendarhint-gregorian': 'MSG1',
@@ -102,7 +102,7 @@
102102

103103
QUnit.test( 'switch twice switches the calendar model back', function( assert ) {
104104
var setSpy = sinon.spy();
105-
var timeValue = new Time( '1901-01-01' );
105+
var timeValue = new TimeValue( '1901-01-01T00:00:00Z' );
106106
var calendarHint = new ExpertExtender.CalendarHint(
107107
new HashMessageProvider( {
108108
'valueview-expertextender-calendarhint-gregorian': 'MSG1',
@@ -125,12 +125,9 @@
125125
sinon.assert.calledOnce( setSpy );
126126
assert.equal( setSpy.firstCall.args[0], 'Julian' );
127127

128-
timeValue = new Time( {
129-
year: timeValue.year(),
130-
month: timeValue.month(),
131-
day: timeValue.day(),
132-
calendarname: Time.CALENDAR.JULIAN,
133-
precision: timeValue.precision()
128+
timeValue = new TimeValue( timeValue.toJSON().time, {
129+
calendarModel: TimeValue.CALENDARS.JULIAN,
130+
precision: timeValue.getOption( 'precision' )
134131
} );
135132
calendarHint.draw();
136133

@@ -146,7 +143,7 @@
146143
jQuery,
147144
jQuery.valueview.ExpertExtender,
148145
jQuery.valueview.tests.testExpertExtenderExtension,
149-
time.Time,
146+
dataValues.TimeValue,
150147
util.HashMessageProvider,
151148
sinon,
152149
QUnit,

tests/src/ExpertExtender/resources.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
'ExpertExtender.CalendarHint.tests.js',
3333
),
3434
'dependencies' => array(
35+
'dataValues.TimeValue',
3536
'jquery.valueview.ExpertExtender.CalendarHint',
3637
'jquery.valueview.test.testExpertExtenderExtension',
3738
'util.HashMessageProvider',
38-
'time.js'
3939
),
4040
),
4141

tests/src/experts/resources.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
'TimeInput.tests.js',
5454
),
5555
'dependencies' => array(
56+
'dataValues.TimeValue',
5657
'jquery.valueview.experts.TimeInput',
5758
'jquery.valueview.tests.testExpert',
58-
'time.js',
5959
),
6060
),
6161

0 commit comments

Comments
 (0)