Henning Snater has uploaded a new change for review.
https://gerrit.wikimedia.org/r/63640
Change subject: (bug 48145) TimeInput expert: Added listrotator to select
calendar
......................................................................
(bug 48145) TimeInput expert: Added listrotator to select calendar
Change-Id: I69f31e8e3de229a273dd6615abb903336679ded6
---
M ValueView/ValueView.i18n.php
M ValueView/ValueView.resources.php
M ValueView/resources/jquery.valueview/valueview.experts/experts.TimeInput.js
3 files changed, 76 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues
refs/changes/40/63640/1
diff --git a/ValueView/ValueView.i18n.php b/ValueView/ValueView.i18n.php
index 71092c1..dceba6f 100644
--- a/ValueView/ValueView.i18n.php
+++ b/ValueView/ValueView.i18n.php
@@ -45,6 +45,7 @@
// TimeInput expert:
'valueview-expert-timeinput-precision' => 'Precision:',
+ 'valueview-expert-timeinput-calendar' => 'Calendar:',
'valueview-preview-label' => 'will be displayed as:',
'valueview-preview-novalue' => 'no valid value recognized',
@@ -64,6 +65,7 @@
'valueview-expert-emptyvalue-empty' => 'Message expressing that there
is currently no value set in a jQuery valueview.
{{Identical|Empty}}',
'valueview-expert-timeinput-precision' => 'Label for the user interface
element used to set a specific precision (e.g. hour, day, month, year) when
entering a time value.',
+ 'valueview-expert-timeinput-calendar' => 'Label for the user interface
element used to select a specific calendar (e.g. Gregorian, Julian) entering a
time value.',
'valueview-preview-label' => 'Label displayed above the preview of a
value that is being entered by the user. The preview is the system\'s
interpretation of the specified value and - since there is no strict definition
for a user how to specify values - visualizes how the value will be displayed
later on after the value has been saved.',
'valueview-preview-novalue' => 'Message displayed instead of an input
value\'s preview when no value is specified yet or when the specified value
could not be interpreted by the system.',
'valueview-listrotator-auto' => 'Label of the link to have the system
automatically select the most appropriate value from a "listrotator" widget.
The "listrotator" basically is a facade for a drop-down select box allowing to
pick a value from a list of values. In addition to the defined values, an
"automatic" option may be selected that makes the system pick the most
appropriate value according to an associated input element.',
diff --git a/ValueView/ValueView.resources.php
b/ValueView/ValueView.resources.php
index 9df93af..e0fddc2 100644
--- a/ValueView/ValueView.resources.php
+++ b/ValueView/ValueView.resources.php
@@ -204,6 +204,7 @@
),
'messages' => array(
'valueview-expert-timeinput-precision',
+ 'valueview-expert-timeinput-calendar',
'valueview-preview-label',
'valueview-preview-novalue',
),
diff --git
a/ValueView/resources/jquery.valueview/valueview.experts/experts.TimeInput.js
b/ValueView/resources/jquery.valueview/valueview.experts/experts.TimeInput.js
index c2bef89..9983a77 100644
---
a/ValueView/resources/jquery.valueview/valueview.experts/experts.TimeInput.js
+++
b/ValueView/resources/jquery.valueview/valueview.experts/experts.TimeInput.js
@@ -51,10 +51,28 @@
$previewValue: null,
/**
+ * Container node for precision input and label.
+ * @type {jQuery}
+ */
+ $precisionContainer: null,
+
+ /**
* Node of the widget used to specify the precision.
* @type {jQuery}
*/
$precision: null,
+
+ /**
+ * Container node for calendar input and label.
+ * @type {jQuery}
+ */
+ $calendarContainer: null,
+
+ /**
+ * Node of the widget used to specify the calendar.
+ * @type {jQuery}
+ */
+ $calendar: null,
/**
* @see jQuery.valueview.Expert._init
@@ -76,26 +94,68 @@
.text( mw.msg( 'valueview-preview-novalue' ) )
.appendTo( this.$preview );
+ this.$precisionContainer = $( '<div/>' )
+ .addClass( this.uiBaseClass + '-precisioncontainer' )
+ .append( $( '<div/>' ).text( mw.msg(
'valueview-expert-timeinput-precision' ) ) );
+
var precisionValues = [];
$.each( timeSettings.precisiontexts, function( i, text
) {
precisionValues.push( { value: i, label: text }
);
} );
this.$precision = $( '<div/>' )
+ .addClass( this.uiBaseClass + '-precision' )
.listrotator( { values: precisionValues.reverse(),
deferInit: true } )
.on( 'listrotatorauto.' + this.uiBaseClass, function(
event ) {
- var value = new Time( self.$input.val() );
+ var value = ( self.$calendar.data(
'listrotator' ).value() )
+ ? new Time( self.$input.val(), {
calendarname: self.$calendar.data( 'listrotator' ).value() } )
+ : new Time( self.$input.val() );
$( this ).data( 'listrotator' ).rotate(
value.precision() );
self._setRawValue( value );
self._updatePreview( value );
self._viewNotifier.notify( 'change' );
} )
.on( 'listrotatorselected.' + this.uiBaseClass,
function( event, precision ) {
- var value = new Time( self.$input.val(),
precision );
+ var value = ( self.$calendar.data(
'listrotator' ).value() )
+ ? new Time( self.$input.val(), {
precision: $( this ).data( 'listrotator' ).value(), calendarname:
self.$calendar.data( 'listrotator' ).value() } )
+ : new Time( self.$input.val(), {
precision: $( this ).data( 'listrotator' ).value() } );
self._setRawValue( value );
self._updatePreview( value );
self._viewNotifier.notify( 'change' );
+ } )
+ .appendTo( this.$precisionContainer );
+
+ this.$calendarContainer = $( '<div/>' )
+ .addClass( this.uiBaseClass + '-calendarcontainer' )
+ .append( $( '<div/>' ).text( mw.msg(
'valueview-expert-timeinput-calendar' ) ) );
+
+ var calendarValues = [];
+ $.each( timeSettings.calendarnames, function( i,
calendarTerms ) {
+ calendarValues.push( { value: calendarTerms[0],
label: calendarTerms[0] } );
} );
+ this.$calendar = $( '<div/>' )
+ .listrotator( { values: calendarValues, deferInit: true
} )
+ .on( 'listrotatorauto', function( event ) {
+ var value = ( self.$precision.data(
'listrotator' ).value() )
+ ? new Time( self.$input.val(), {
precision: self.$precision.data( 'listrotator' ).value() } )
+ : new Time( self.$input.val() );
+
+ $( this ).data( 'listrotator' ).rotate(
value.calendarText() );
+ self._setRawValue( value );
+ self._updatePreview( value );
+ self._viewNotifier.notify( 'change' );
+ } )
+ .on( 'listrotatorselected', function( event ) {
+ var value = ( self.$precision.data(
'listrotator' ).value() )
+ ? new Time( self.$input.val(), {
precision: self.$precision.data( 'listrotator' ).value(), calendarname: $( this
).data( 'listrotator' ).value() } )
+ : new Time( self.$input.val(), {
calendarname: $( this ).data( 'listrotator' ).value() } );
+
+ $( this ).data( 'listrotator' ).rotate(
value.calendarText() );
+ self._setRawValue( value );
+ self._updatePreview( value );
+ self._viewNotifier.notify( 'change' );
+ } )
+ .appendTo( this.$calendarContainer );
this.$input = $( '<input/>', {
type: 'text',
@@ -112,15 +172,17 @@
// TODO: Move input extender out of here to a more
generic place since it is not
// TimeInput specific.
.inputextender( {
- content: [ this.$preview, this.$precision ],
+ content: [ this.$preview,
this.$precisionContainer, this.$calendarContainer ],
initCallback: function() {
self.$precision.data( 'listrotator'
).initWidths();
+ self.$calendar.data( 'listrotator'
).initWidths();
}
} )
.on( 'timeinputupdate.' + this.uiBasClass, function(
event, value ) {
self._updatePreview( value );
if( value && value.isValid() ) {
self.$precision.data( 'listrotator'
).rotate( value.precision() );
+ self.$calendar.data( 'listrotator'
).rotate( value.calendarText() );
}
self._viewNotifier.notify( 'change' );
} );
@@ -133,8 +195,15 @@
destroy: function() {
this.$precision.data( 'listrotator' ).destroy();
this.$precision.remove();
+ this.$precisionContainer.remove();
+
+ this.$calendar.data( 'listrotator' ).destroy();
+ this.$calendar.remove();
+ this.$calendarContainer.remove();
+
this.$previewValue.remove();
this.$preview.remove();
+
this.$input.data( 'inputextender' ).destroy();
this.$input.data( 'timeinput' ).destroy();
this.$input.remove();
@@ -232,6 +301,7 @@
this._updatePreview( this._newValue );
if( this._newValue !== null ) {
this.$precision.data( 'listrotator'
).rotate( this._newValue.precision() );
+ this.$calendar.data( 'listrotator'
).rotate( this._newValue.calendarText() );
}
this._newValue = false;
}
--
To view, visit https://gerrit.wikimedia.org/r/63640
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I69f31e8e3de229a273dd6615abb903336679ded6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits