Fix reversing day and month. Changed date-format on write. Added hints for date format.

pull/2900/head
mhirtie 10 years ago
parent e2118ed5fd
commit 83a03b3e99
  1. 4
      frontend/app/templates/components/inplace_editor/date/date_range_picker.html
  2. 91
      frontend/app/ui_components/date/date-range-picker-directive.js
  3. 5
      frontend/app/work_packages/directives/inplace_editor/custom/editable/inplace-editor-date-directive.js

@ -1,7 +1,7 @@
<div class="inplace-edit--date-range"> <div class="inplace-edit--date-range">
<input type="text" class="inplace-edit--date-range-start-date" ng-model="startDate" /> <input type="text" class="inplace-edit--date-range-start-date" execute-on-enter="execute()" ng-model="startDate" />
<span>-</span> <span>-</span>
<input type="text" class="inplace-edit--date-range-end-date" ng-model="endDate"/> <input type="text" class="inplace-edit--date-range-end-date" execute-on-enter="execute()" ng-model="endDate"/>
<div class="inplace-edit--date-range-start-date-picker"></div> <div class="inplace-edit--date-range-start-date-picker"></div>
<div class="inplace-edit--date-range-end-date-picker"></div> <div class="inplace-edit--date-range-end-date-picker"></div>
</div> </div>

@ -29,10 +29,16 @@
module.exports = function(TimezoneService, ConfigurationService, module.exports = function(TimezoneService, ConfigurationService,
I18n, $timeout) { I18n, $timeout) {
var parseDate = TimezoneService.parseDate, var parseDate = TimezoneService.parseDate,
parseISODate = TimezoneService.parseISODate,
formattedDate = function(date) { formattedDate = function(date) {
return TimezoneService.parseDate(date).format('L'); return TimezoneService.parseDate(date).format('L');
}, },
formattedISODate = TimezoneService.formattedISODate, formattedISODate = TimezoneService.formattedISODate,
customDateFormat = 'YYYY-MM-DD',
datepickerFormat = 'yy-mm-dd',
customFormattedDate = function(date) {
return parseISODate(date).format(customDateFormat);
},
noStartDate = I18n.t('js.label_no_start_date'), noStartDate = I18n.t('js.label_no_start_date'),
noEndDate = I18n.t('js.label_no_due_date'); noEndDate = I18n.t('js.label_no_due_date');
return { return {
@ -46,13 +52,14 @@ module.exports = function(TimezoneService, ConfigurationService,
link: function(scope, element) { link: function(scope, element) {
var startTimerId = 0, var startTimerId = 0,
endTimerId = 0, endTimerId = 0,
form = element.parents('.inplace-edit--form'),
inputStart = element.find('.inplace-edit--date-range-start-date'), inputStart = element.find('.inplace-edit--date-range-start-date'),
inputEnd = element.find('.inplace-edit--date-range-end-date'), inputEnd = element.find('.inplace-edit--date-range-end-date'),
divStart = element.find('.inplace-edit--date-range-start-date-picker'), divStart = element.find('.inplace-edit--date-range-start-date-picker'),
divEnd = element.find('.inplace-edit--date-range-end-date-picker'), divEnd = element.find('.inplace-edit--date-range-end-date-picker'),
prevStartDate = '', prevStartDate = '',
prevEndDate = '', prevEndDate = '',
addClearButton = function (div, inp) { addClearButton = function (inp) {
setTimeout(function() { setTimeout(function() {
var buttonPane = div.find('.ui-datepicker-buttonpane'); var buttonPane = div.find('.ui-datepicker-buttonpane');
@ -76,65 +83,89 @@ module.exports = function(TimezoneService, ConfigurationService,
if(date) { if(date) {
div.datepicker('option', 'defaultDate', formattedDate(date)); div.datepicker('option', 'defaultDate', formattedDate(date));
div.datepicker('option', 'setDate', formattedDate(date)); div.datepicker('option', 'setDate', formattedDate(date));
input.val(formattedDate(date)); input.val(customFormattedDate(date));
input.attr('title', customFormattedDate(date));
} else { } else {
div.datepicker('option', 'defaultDate', null); div.datepicker('option', 'defaultDate', null);
div.datepicker('option', 'setDate', null); div.datepicker('option', 'setDate', null);
input.val(''); input.val('');
input.change();
input.attr('title', noDate);
date = null; date = null;
} }
}; };
inputStart.attr('placeholder', noStartDate); scope.execute = function() {
inputEnd.attr('placeholder', noEndDate); form.scope().editPaneController.submit(false);
};
inputStart.attr({
'placeholder': customDateFormat,
'aria-label': customDateFormat,
'title': noStartDate
});
inputEnd.attr({
'placeholder': customDateFormat,
'aria-label': customDateFormat,
'title': noEndDate
});
inputStart.on('change', function() { inputStart.on('change', function() {
if(inputStart.val().replace(/^\s+|\s+$/g, '') === '') { if(inputStart.val().trim() === '') {
$timeout(function() { $timeout(function() {
scope.startDate = null; scope.startDate = null;
}); });
inputStart.val(''); inputStart.val('');
inputStart.attr('title', noStartDate);
inputEnd.datepicker('option', 'minDate', null);
$timeout.cancel(startTimerId); $timeout.cancel(startTimerId);
return; return;
} }
$timeout.cancel(startTimerId); $timeout.cancel(startTimerId);
startTimerId = $timeout(function() { startTimerId = $timeout(function() {
var date = inputStart.val(), var date = inputStart.val(),
isValid = TimezoneService.isValid(date, 'DD/MM/YYYY'); isValid = TimezoneService.isValid(date, customDateFormat);
if(isValid){ if(isValid){
scope.startDate = formattedISODate(date); scope.startDate = formattedISODate(parseDate(date, customDateFormat));
inputStart.attr('title', customFormattedDate(date));
} }
}, 1000); }, 1000);
}).on('click', function() {
inputStart.datepicker('show');
}); });
inputEnd.on('change', function() { inputEnd.on('change', function() {
if(inputEnd.val().replace(/^\s+|\s+$/g, '') === '') { if(inputEnd.val().trim() === '') {
$timeout(function() { $timeout(function() {
scope.endDate = null; scope.endDate = null;
}); });
inputEnd.val(''); inputEnd.val('');
inputEnd.attr('title', noEndDate);
inputStart.datepicker('option', 'maxDate', null);
$timeout.cancel(endTimerId); $timeout.cancel(endTimerId);
return; return;
} }
$timeout.cancel(startTimerId); $timeout.cancel(endTimerId);
startTimerId = $timeout(function() { endTimerId = $timeout(function() {
var date = inputEnd.val(), var date = inputEnd.val(),
isValid = TimezoneService.isValid(date, 'DD/MM/YYYY'); isValid = TimezoneService.isValid(date, customDateFormat);
if(isValid){ if(isValid){
scope.endDate = formattedISODate(date); scope.endDate = formattedISODate(parseDate(date, customDateFormat));
inputEnd.attr('title', customFormattedDate(date));
} }
}, 1000); }, 1000);
}).on('click', function(){
inputEnd.datepicker('show');
}); });
divStart.datepicker({ divStart.datepicker({
firstDay: ConfigurationService.startOfWeek(), firstDay: ConfigurationService.startOfWeek(),
showWeeks: true, showWeeks: true,
changeMonth: true, changeMonth: true,
numberOfMonths: 2,
showButtonPanel: true, showButtonPanel: true,
dateFormat: 'dd/mm/yy', dateFormat: datepickerFormat,
inline: true, inline: true,
alterOffset: function(offset) { alterOffset: function(offset) {
var wHeight = angular.element(window).height(), var wHeight = angular.element(window).height(),
@ -148,19 +179,18 @@ module.exports = function(TimezoneService, ConfigurationService,
return offset; return offset;
}, },
beforeShow: function() { beforeShow: function() {
addClearButton(divStart, inputStart); addClearButton(inputStart);
}, },
onChangeMonthYear: function() { onChangeMonthYear: function() {
addClearButton(divStart, inputStart); addClearButton(inputStart);
}, },
onSelect: function(selectedDate) { onSelect: function(selectedDate) {
if(!selectedDate || selectedDate === '' || selectedDate === prevStartDate) { if(!selectedDate || selectedDate === '' || selectedDate === prevStartDate) {
return; return;
} }
var parsedDate = parseDate(selectedDate, 'DD/MM/YYYY'); prevStartDate = parseDate(selectedDate, customDateFormat);
prevStartDate = parsedDate;
$timeout(function() { $timeout(function() {
scope.startDate = formattedISODate(parsedDate); scope.startDate = formattedISODate(prevStartDate);
}); });
divEnd.datepicker('option', 'minDate', selectedDate ? selectedDate : null); divEnd.datepicker('option', 'minDate', selectedDate ? selectedDate : null);
divStart.hide(); divStart.hide();
@ -170,8 +200,7 @@ module.exports = function(TimezoneService, ConfigurationService,
firstDay: ConfigurationService.startOfWeek(), firstDay: ConfigurationService.startOfWeek(),
showWeeks: true, showWeeks: true,
changeMonth: true, changeMonth: true,
numberOfMonths: 2, dateFormat: datepickerFormat,
dateFormat: 'dd/mm/yy',
inline: true, inline: true,
alterOffset: function(offset) { alterOffset: function(offset) {
var wHeight = angular.element(window).height(), var wHeight = angular.element(window).height(),
@ -185,19 +214,18 @@ module.exports = function(TimezoneService, ConfigurationService,
return offset; return offset;
}, },
beforeShow: function() { beforeShow: function() {
addClearButton(divEnd, inputEnd); addClearButton(inputEnd);
}, },
onChangeMonthYear: function() { onChangeMonthYear: function() {
addClearButton(divEnd, inputEnd); addClearButton(inputEnd);
}, },
onSelect: function(selectedDate) { onSelect: function(selectedDate) {
if(!selectedDate || selectedDate === '' || selectedDate === prevEndDate) { if(!selectedDate || selectedDate === '' || selectedDate === prevEndDate) {
return; return;
} }
var parsedDate = parseDate(selectedDate, 'DD/MM/YYYY'); prevEndDate = parseDate(selectedDate, customDateFormat);
prevEndDate = parsedDate;
$timeout(function() { $timeout(function() {
scope.endDate = formattedISODate(parsedDate); scope.endDate = formattedISODate(prevEndDate);
}); });
divStart.datepicker('option', 'maxDate', selectedDate ? selectedDate : null); divStart.datepicker('option', 'maxDate', selectedDate ? selectedDate : null);
divEnd.hide(); divEnd.hide();
@ -206,15 +234,18 @@ module.exports = function(TimezoneService, ConfigurationService,
if(scope.endDate) { if(scope.endDate) {
prevEndDate = formattedDate(scope.endDate); prevEndDate = formattedDate(scope.endDate);
divStart.datepicker('option', 'maxDate', formattedDate(scope.endDate)); inputStart.datepicker('option', 'maxDate', formattedDate(scope.endDate));
} }
if(scope.startDate) { if(scope.startDate) {
prevStartDate = formattedDate(scope.startDate); prevStartDate = formattedDate(scope.startDate);
divEnd.datepicker('option', 'minDate', formattedDate(scope.startDate)); inputEnd.datepicker('option', 'minDate', formattedDate(scope.startDate));
} }
setDate(divStart, inputStart, scope.startDate); setDate(inputStart, scope.startDate);
setDate(divEnd, inputEnd, scope.endDate); setDate(inputEnd, scope.endDate);
$timeout(function() {
inputStart.click();
});
inputStart.on('click', function() { inputStart.on('click', function() {
if(divStart.is(':hidden') || divEnd.is(':visible')) { if(divStart.is(':hidden') || divEnd.is(':visible')) {

@ -35,8 +35,8 @@ module.exports = function(WorkPackageFieldService, EditableFieldsState,
return TimezoneService.parseDate(date).format('L'); return TimezoneService.parseDate(date).format('L');
}, },
formattedISODate = TimezoneService.formattedISODate, formattedISODate = TimezoneService.formattedISODate,
customDateFormat = 'DD/MM/YYYY', customDateFormat = 'YYYY-MM-DD',
datepickerFormat = 'dd/mm/yy', datepickerFormat = 'yy-mm-dd',
customFormattedDate = function(date) { customFormattedDate = function(date) {
return parseISODate(date).format(customDateFormat); return parseISODate(date).format(customDateFormat);
}; };
@ -66,6 +66,7 @@ module.exports = function(WorkPackageFieldService, EditableFieldsState,
angular.element( '<button>', { angular.element( '<button>', {
text: 'Clear', text: 'Clear',
click: function() { click: function() {
inp.focus();
setDate(inp, null); setDate(inp, null);
} }
}) })

Loading…
Cancel
Save