dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29840
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15148: add new option to picker.createInstance, fromIso, allows to convert field from ISO 8601 to local ...
------------------------------------------------------------
revno: 15148
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-05-05 15:32:13 +0700
message:
add new option to picker.createInstance, fromIso, allows to convert field from ISO 8601 to local calendar, useful if date is coming directly from db
modified:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.period.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.period.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.period.js 2014-05-05 04:19:56 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.period.js 2014-05-05 08:32:13 +0000
@@ -62,10 +62,20 @@
* Creates a date picker.
*
* @param el Element to select on, can be any kind of jQuery selector, or a jqEl
+ * @param fromIso Convert field from ISO 8601 to local calendar
* @param options Additional options, will be merged with the defaults
*/
-dhis2.period.DatePicker.prototype.createInstance = function( el, options ) {
- $(el).calendarsPicker($.extend({}, this.defaults, options));
+dhis2.period.DatePicker.prototype.createInstance = function( el, fromIso, options ) {
+ var $el = $(el);
+
+ if( fromIso ) {
+ var iso8601 = $.calendars.instance('gregorian');
+ var isoDate = iso8601.parseDate(this.format, $el.val());
+ var cDateIsoDate = this.calendar.fromJD(isoDate.toJD());
+ $el.val(this.calendar.formatDate(this.format, cDateIsoDate));
+ }
+
+ $el.calendarsPicker($.extend({}, this.defaults, options));
};
/**
@@ -73,14 +83,27 @@
*
* @param fromEl From element to select on, can be any kind of jQuery selector, or a jqEl
* @param toEl To element to select on, can be any kind of jQuery selector, or a jqEl
+ * @param fromIso Convert fields from ISO 8601 to local calendar
* @param options Additional options, will be merged with the defaults
*/
-dhis2.period.DatePicker.prototype.createRangedInstance = function( fromEl, toEl, options ) {
+dhis2.period.DatePicker.prototype.createRangedInstance = function( fromEl, toEl, fromIso, options ) {
var mergedOptions = $.extend({}, this.defaults, options);
var $fromEl = $(fromEl);
var $toEl = $(toEl);
+ if( fromIso ) {
+ var iso8601 = $.calendars.instance('gregorian');
+ var from = iso8601.parseDate(this.format, $fromEl.val());
+ var to = iso8601.parseDate(this.format, $toEl.val());
+
+ var cDateFrom = this.calendar.fromJD(from.toJD());
+ var cDateTo = this.calendar.fromJD(to.toJD());
+
+ $fromEl.val(this.calendar.formatDate(this.format, cDateFrom));
+ $toEl.val(this.calendar.formatDate(this.format, cDateTo));
+ }
+
mergedOptions.onSelect = function( dates ) {
if( this.id === $fromEl.attr('id') ) {
$toEl.calendarsPicker("option", "minDate", dates[0] || null);