introduce "Now" button

Throught the plugin: https://github.com/jcsmorais/shortcut-buttons-flatpickr
import js library via yarn
This commit is contained in:
Jean-Baptiste Bellet
2021-01-27 18:04:28 +01:00
parent 329ec3455f
commit 079008d99b
3 changed files with 49 additions and 7 deletions

View File

@@ -1,7 +1,24 @@
$(document).ready(function(){
window.FLATPICKR_DATE_DEFAULT = {
dateFormat: Spree.translations.flatpickr_date_format,
locale: I18n.locale
locale: I18n.locale,
plugins: [
ShortcutButtonsPlugin({
button: [{
label: "Today"
}],
label: "or",
onClick: (index, fp) => {
let date;
switch (index) {
case 0:
date = new Date();
break;
}
fp.setDate(date);
}
})
]
}
window.FLATPICKR_DATETIME_DEFAULT = Object.assign(
{},
@@ -9,6 +26,23 @@ $(document).ready(function(){
{
enableTime: true,
time_24hr: true,
plugins: [
ShortcutButtonsPlugin({
button: [{
label: "Now"
}],
label: "or",
onClick: (index, fp) => {
let date;
switch (index) {
case 0:
date = new Date();
break;
}
fp.setDate(date);
}
})
]
}
);
flatpickr(".datetimepicker", window.FLATPICKR_DATETIME_DEFAULT);

View File

@@ -1,8 +1,11 @@
angular.module("admin.utils").directive "datepicker", ->
angular.module("admin.utils").directive "datepicker", ($window, $timeout) ->
require: "ngModel"
link: (scope, element, attrs, ngModel) ->
flatpickr(element, Object.assign({},
window.FLATPICKR_DATE_DEFAULT, {
onOpen: (selectedDates, dateStr, instance) ->
instance.setDate(ngModel.$modelValue)
}));
$timeout ->
flatpickr(element, Object.assign(
{},
$window.FLATPICKR_DATE_DEFAULT, {
onOpen: (selectedDates, dateStr, instance) ->
instance.setDate(ngModel.$modelValue)
}
));