/* global I18n */ /* eslint-disable no-underscore-dangle */ var DasboardCalendarWidget = (function() { function calendarTemplate() { return ``; } function getMonthEventsList(date, clndrInstance) { var getUrl = $('.dashboard-calendar').data('month-events-url'); $.get(getUrl, { date: date }, function(result) { clndrInstance.setEvents(result.events); }); } function initCalendar() { var dayOfWeek = [ I18n.t('dashboard.calendar.dow.su'), I18n.t('dashboard.calendar.dow.mo'), I18n.t('dashboard.calendar.dow.tu'), I18n.t('dashboard.calendar.dow.we'), I18n.t('dashboard.calendar.dow.th'), I18n.t('dashboard.calendar.dow.fr'), I18n.t('dashboard.calendar.dow.sa') ]; var clndrInstance = $('.dashboard-calendar').clndr({ template: $(calendarTemplate()).html(), daysOfTheWeek: dayOfWeek, forceSixRows: true, clickEvents: { click: function(target) { var getDayUrl = $('.dashboard-calendar').data('day-events-url'); if ($(target.element).hasClass('event')) { $.get(getDayUrl, { date: target.date._i }, function(result) { $(target.element).find('.tasks').html(result.html); }); } }, onMonthChange: function(month) { getMonthEventsList(month._d, clndrInstance); } } }); getMonthEventsList((new Date()), clndrInstance); } return { init: () => { if ($('.current-tasks-widget').length) { initCalendar(); } } }; }()); var formatJS; $(document).on('turbolinks:load', function() { DasboardCalendarWidget.init(); formatJS = $('body').data('datetime-picker-format'); });