mirror of
https://github.com/ansible/awx.git
synced 2026-03-13 15:09:32 -02:30
Support moment locales in datepickere
This commit is contained in:
@@ -44,7 +44,7 @@ export default
|
||||
}, true);
|
||||
|
||||
scope.$watch('dateValue', function(newValue) {
|
||||
var newDate = moment(newValue);
|
||||
var newDate = moment(newValue, ['L'], moment.locale());
|
||||
|
||||
if (newValue && !newDate.isValid()) {
|
||||
scope.error = "That is not a valid date.";
|
||||
@@ -54,11 +54,50 @@ export default
|
||||
mustUpdateValue = true;
|
||||
});
|
||||
|
||||
var localeData =
|
||||
moment.localeData();
|
||||
var dateFormat = momentFormatToDPFormat(localeData._longDateFormat.L);
|
||||
var localeKey = momentLocaleToDPLocale(moment.locale());
|
||||
|
||||
element.find(".DatePicker").addClass("input-prepend date");
|
||||
element.find(".DatePicker").find(".DatePicker-icon").addClass("add-on");
|
||||
$(".date").systemTrackingDP({
|
||||
autoclose: true
|
||||
autoclose: true,
|
||||
language: localeKey,
|
||||
format: dateFormat
|
||||
});
|
||||
|
||||
function momentLocaleToDPLocale(localeKey) {
|
||||
var parts = localeKey.split('-');
|
||||
|
||||
if (parts.length === 2) {
|
||||
var lastPart = parts[1].toUpperCase();
|
||||
return [parts[0], lastPart].join('-');
|
||||
} else {
|
||||
return localeKey;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function momentFormatToDPFormat(momentFormat) {
|
||||
var resultFormat = momentFormat;
|
||||
|
||||
function lowerCase(str) {
|
||||
return str.toLowerCase();
|
||||
}
|
||||
|
||||
resultFormat = resultFormat.replace(/D{1,2}/, lowerCase);
|
||||
|
||||
if (/MMM/.test(resultFormat)) {
|
||||
resultFormat = resultFormat.replace('MMM', 'M');
|
||||
} else {
|
||||
resultFormat = resultFormat.replace(/M{1,2}/, 'm');
|
||||
}
|
||||
|
||||
resultFormat = resultFormat.replace(/Y{2,4}/, lowerCase);
|
||||
|
||||
return resultFormat;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user