Skip to content
Snippets Groups Projects
Commit a7453a2c authored by Ide Braakman's avatar Ide Braakman Committed by João Ventura
Browse files

Issue #3459996 by idebr, deepak5423, jcnventura: Fix eslint validation

parent 545f9192
Branches
No related tags found
1 merge request!13Issue #3459996: Fix eslint validation
Pipeline #260033 passed with warnings
......@@ -16,32 +16,32 @@
* Return minutes formatted in array by allowed intervals.
*/
function SingleDatetimeAllowTimes($hours, $type) {
var times = [];
const times = [];
// Build array.
$hours.forEach(function (i) {
// Formatting hours.
if (i < 10) {
i = "0" + i;
i = `0${i}`;
}
// Default granularity is one hour.
if ($type === 60) {
times.push(i + ":00");
times.push(`${i}:00`);
}
// Custom settings, per minutes.
else {
var measure = 60 / $type;
for (var j = 0; j < measure; j++) {
var minutes = $type * j;
const measure = 60 / $type;
for (let j = 0; j < measure; j++) {
let minutes = $type * j;
if (j === 0) {
minutes = "00";
minutes = '00';
} else if (minutes < 10) {
minutes = "0" + minutes;
minutes = `0${minutes}`;
}
times.push(i + ":" + minutes);
times.push(`${i}:${minutes}`);
}
}
});
......@@ -56,101 +56,106 @@
*/
Drupal.behaviors.single_datetime = {
attach: function attach(context) {
// Setting the current language for the calendar.
var lang = drupalSettings.path.currentLanguage;
let lang = drupalSettings.path.currentLanguage;
$(once('datePicker', 'input[data-single-date-time]', context)).each(function () {
var input = $(this);
$(once('datePicker', 'input[data-single-date-time]', context)).each(
function () {
const input = $(this);
// Get widget type.
var widgetType = input.data("singleDateTime");
const widgetType = input.data('singleDateTime');
// Get hour format - 12 or 24.
var hourFormat = input.data("hourFormat");
const hourFormat = input.data('hourFormat');
// Get first day in week from Drupal.
var dayOfWeekStart = input.data("firstDay");
const dayOfWeekStart = input.data('firstDay');
// Default values (used for dates only).
var format = "Y-m-d";
var allowTimepicker = false;
let format = 'Y-m-d';
let allowTimepicker = false;
// Get disabled days.
var disabledWeekDays = input.data("disableDays");
const disabledWeekDays = input.data('disableDays');
// Get excluded dates.
var disabledDates = input.data("excludeDate");
const disabledDates = input.data('excludeDate');
// Get start date.
var startDate = input.data("startDate");
const startDate = input.data('startDate');
// Get minimum date.
var minDate = input.data("minDate");
const minDate = input.data('minDate');
// Get maximum date.
var maxDate = input.data("maxDate");
const maxDate = input.data('maxDate');
// Get start year.
var yearStart = input.data("yearStart");
const yearStart = input.data('yearStart');
// Get end year.
var yearEnd = input.data("yearEnd");
const yearEnd = input.data('yearEnd');
// Set the hour format.
var formatTime = hourFormat === "12h" ? "h:i A" : "H:i";
const formatTime = hourFormat === '12h' ? 'h:i A' : 'H:i';
var customFormat = input.data('customFormat');
const customFormat = input.data('customFormat');
var inline = input.data("inline");
const inline = input.data('inline');
var allowSeconds = Boolean(input.data("allowSeconds"));
const allowSeconds = Boolean(input.data('allowSeconds'));
var mask = Boolean(input.data("mask"));
const mask = Boolean(input.data('mask'));
var theme = input.data("datetimepickerTheme");
const theme = input.data('datetimepickerTheme');
var allowBlank = Boolean(input.data("allowBlank"));
const allowBlank = Boolean(input.data('allowBlank'));
// Default empty array. Only calculate later if field type
// includes times.
var allowTimes = [];
let allowTimes = [];
// If is date & time field.
if (widgetType === "datetime") {
var hourFormatDefault = allowSeconds === true ? "Y-m-d H:i:00" : "Y-m-d H:i:s";
var hourFormatA = allowSeconds === true ? "Y-m-d h:i:00 A" : "Y-m-d h:i:s A";
format = hourFormat === "12h" ? hourFormatA : hourFormatDefault;
if (widgetType === 'datetime') {
const hourFormatDefault =
allowSeconds === true ? 'Y-m-d H:i:00' : 'Y-m-d H:i:s';
const hourFormatA =
allowSeconds === true ? 'Y-m-d h:i:00 A' : 'Y-m-d h:i:s A';
format = hourFormat === '12h' ? hourFormatA : hourFormatDefault;
allowTimepicker = true;
// Get minute granularity, and allowed hours.
allowTimes = SingleDatetimeAllowTimes(input.data("allowedHours"), input.data("allowTimes"));
allowTimes = SingleDatetimeAllowTimes(
input.data('allowedHours'),
input.data('allowTimes'),
);
}
if (typeof customFormat !== 'undefined') {
format = customFormat;
}
$("#" + input.attr("id")).datetimepicker({
format: format,
formatTime: formatTime,
$(`#${input.attr('id')}`).datetimepicker({
format,
formatTime,
lazyInit: true,
timepicker: allowTimepicker,
todayButton: true,
dayOfWeekStart: dayOfWeekStart,
allowTimes: allowTimes,
disabledWeekDays: disabledWeekDays,
disabledDates: disabledDates,
formatDate: "d.m.Y",
inline: inline,
mask: mask,
startDate: startDate,
minDate: minDate,
maxDate: maxDate,
yearStart: yearStart,
yearEnd: yearEnd,
theme: theme,
allowBlank: allowBlank
dayOfWeekStart,
allowTimes,
disabledWeekDays,
disabledDates,
formatDate: 'd.m.Y',
inline,
mask,
startDate,
minDate,
maxDate,
yearStart,
yearEnd,
theme,
allowBlank,
});
if (lang === 'pt-br') {
......@@ -168,7 +173,8 @@
// Explicitly set locale. Does not work with passed variable
// in settings above.
$.datetimepicker.setLocale(lang);
});
}
},
);
},
};
})(jQuery, Drupal, drupalSettings, once);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment