=== 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);