'use strict'; var isBookAdmin; $value) { list($table, $field_name) = explode('.', $key, 2); if (($table === 'entry') && !empty($value)) { // Prefix custom field names if (!in_array($field_name, $standard_fields['entry'])) { $field_name = VAR_PREFIX . $field_name; } $line = " $field_name: "; if (is_bool($value)) { $line .= ($value) ? 'true' : 'false'; } else { $line .= '[' . implode(', ', $value) . ']'; } $lines[] = $line; } } if (!empty($lines)) { echo "\n" . implode(",\n", $lines) . "\n"; } } echo "};\n"; ?> var conflictTimer = function conflictTimer(set) { if (set) { if (!isHidden()) { checkConflicts(true); conflictTimer.id = window.setInterval(function() { checkConflicts(true); }, ); } } else if (typeof conflictTimer.id !== 'undefined') { window.clearInterval(conflictTimer.id); } }; var changeRepTypeDetails = function changeRepTypeDetails() { var repType = parseInt($('input[name="rep_type"]:checked').val(), 10); var isRepeat = (repType !== ); $('#rep_interval').prop('required', isRepeat); $('#rep_end_date').prop('required', isRepeat).parent().toggle(isRepeat); $('#skip').parent().toggle(isRepeat); $('.rep_type_details').hide(); switch (repType) { case : $('#rep_weekly').show(); break; case : $('#rep_monthly').show(); break; default: break; } }; var changeRepIntervalUnits = function changeRepIntervalUnits() { var repType = parseInt($('input[name="rep_type"]:checked').val(), 10); var repInterval = parseInt($('input[name="rep_interval"]').val(), 10); var units = $('#interval_units'); var text; switch (repType) { case : text = (repInterval === 1) ? '' : ''; break; case : text = (repInterval === 1) ? '' : ''; break; case : text = (repInterval === 1) ? '' : ''; break; case : text = (repInterval === 1) ? '' : ''; break; default: text = units.text(); break; } units.text(text); units.parent().toggle(repType !== ); }; // areaConfig returns the properties ('enable_periods', etc.) for an area, // by default the current area var areaConfig = function areaConfig(property, areaId) { var properties = ['enable_periods', 'n_periods', 'default_duration', 'max_duration_enabled', 'max_duration_secs', 'max_duration_periods', 'max_duration_qty', 'max_duration_units', 'timezone']; var i, p, room; if ($.inArray(property, properties) < 0) { throw new Error("areaConfig(): invalid property '" + property + "' passed to areaConfig"); } if (areaId === undefined) { areaId = $('#area').val(); } if (areaConfig.data === undefined) { areaConfig.data = []; } if (areaConfig.data[areaId] === undefined) { areaConfig.data[areaId] = {}; room = $('#rooms' + areaId); for (i=0; i function checkTimeSlots(jqDate) { if (!areaConfig('enable_periods')) { var siblings = jqDate.siblings(); var select = jqDate.parent().parent().siblings('select:visible'); var slots = []; select.find('option').each(function() { slots.push($(this).val()); }); var params = {csrf_token: getCSRFToken(), id: select.attr('id'), day: parseInt(siblings.filter('input[id*="day"]').val(), 10), month: parseInt(siblings.filter('input[id*="month"]').val(), 10), year: parseInt(siblings.filter('input[id*="year"]').val(), 10), tz: areaConfig('timezone'), slots: slots}; if(args.site) { params.site = args.site; } $.post('ajax/check_slot.php', params, function(result) { $.each(result.slots, function(key, value) { $('#' + result.id).find('option[value="' + value + '"]').remove(); }); adjustWidth($('#start_seconds'), $('#end_seconds')); }, 'json'); } } function onAllDayClick() { var form = $('#main'); if (form.length === 0) { return; } var startSelect = form.find('#start_seconds'), endSelect = form.find('#end_seconds'), allDay = form.find('#all_day'); var startDatepicker = form.find('#start_date'), endDatepicker = form.find('#end_date'); var date, firstSlot, lastSlot; if (allDay.is(':checked')) // If checking the box... { firstSlot = parseInt(startSelect.find('option').first().val(), 10); lastSlot = parseInt(endSelect.find('option').last().val(), 10); onAllDayClick.oldStart = parseInt(startSelect.val(), 10); onAllDayClick.oldStartDatepicker = startDatepicker.val(); startSelect.val(firstSlot); startSelect.prop('disabled', true); onAllDayClick.oldEnd = parseInt(endSelect.val(), 10); onAllDayClick.oldEndDatepicker = endDatepicker.val(); endSelect.val(lastSlot); if ((lastSlot < firstSlot) && (onAllDayClick.oldStartDatepicker === onAllDayClick.oldEndDatepicker)) { if (onAllDayClick.oldStart < firstSlot) { date = new Date(onAllDayClick.oldStartDatepicker); date.setDate(date.getDate() - 1); startDatepicker.val(date.toISOString().split('T')[0]); } else { date = new Date(onAllDayClick.oldEndDatepicker); date.setDate(date.getDate() + 1); endDatepicker.val(date.toISOString().split('T')[0]); } } endSelect.prop('disabled', true); } else { startSelect.val(onAllDayClick.oldStart); startDatepicker.val(onAllDayClick.oldStartDatepicker); startSelect.prop('disabled', false); endSelect.val(onAllDayClick.oldEnd); endDatepicker.val(onAllDayClick.oldEndDatepicker); endSelect.prop('disabled', false); } adjustSlotSelectors(); } function validationMessages(areaId) { var field, label; validationMessages.vocab = {}; validationMessages.vocab['name'] = ''; validationMessages.vocab['rooms'] = ''; for (const [fieldName, value] of Object.entries(mandatoryFields)) { if ((value === true) || (Array.isArray(value) && value.includes(parseInt(areaId)))) { validationMessages.vocab[fieldName] = ''; } } for (var key in validationMessages.vocab) { if (validationMessages.vocab.hasOwnProperty(key)) { label = $("label[for=" + key + "]"); if (label.length > 0) { validationMessages.vocab[key] = label.text(); validationMessages.vocab[key] = '"' + validationMessages.vocab[key] + '" '; validationMessages.vocab[key] += ''; field = document.getElementById(key); if (field.setCustomValidity && field.willValidate) { $(field).on('validate', function(e) { e.target.setCustomValidity(""); if (!e.target.validity.valid) { e.target.setCustomValidity(validationMessages.vocab[$(e.target).attr('id')]); } }); $(field).on('change input', function() { $(this).trigger('validate'); }); $(field).on('invalid', function() { $(this).closest('form').removeData('submit'); }); $(field).trigger('validate'); } } 0) ?> } } } function validate(form) { var testInput = document.createElement("input"); var testSelect = document.createElement("select"); var validForm = true; if (!("pattern" in testInput) || !("required" in testInput)) { form.find('input').not('[type="checkbox"]').each(function() { var id = $(this).attr('id'); if (validationMessages.vocab[id]) { if (.test($(this).val())) { window.alert(validationMessages.vocab[id]); validForm = false; return false; } } }); if (!validForm) { return false; } } if (!("required" in testInput)) { form.find('input').filter('[type="checkbox"]').each(function() { var id = $(this).attr('id'); if (validationMessages.vocab[id]) { if (!$(this).is(':checked')) { window.alert(validationMessages.vocab[id]); validForm = false; return false; } } }); if (!validForm) { return false; } } form.find('textarea').each(function() { var id = $(this).attr('id'); if (validationMessages.vocab[id]) { if (.test($(this).val())) { window.alert(validationMessages.vocab[id]); validForm = false; return false; } } }); if (!validForm) { return false; } if (!("required" in testSelect)) { form.find('select').each(function() { var id = $(this).attr('id'); if (validationMessages.vocab[id]) { if ($(this).val() === '') { window.alert(validationMessages.vocab[id]); validForm = false; return false; } } }); if (!validForm) { return false; } } var dateDiff = getDateDifference(); if (dateDiff < 0) { window.alert(""); return false; } var repType = form.find('input:radio[name=rep_type]:checked').val(); if ((repType !== undefined) && (parseInt(repType, 10) !== )) { if ((!("min" in testInput) || !(("step" in testInput))) && (form.find('#rep_interval').val() < 1)) { window.alert(""); return false; } if ($('input[name="rep_end_date"]').val() === $('input[name="end_date"]').val()) { if (!window.confirm("")) { return false; } } if ($('input[name="rep_end_date"]').val() < $('input[name="start_date"]').val()) { window.alert(""); return false; } } form.find('input[type=submit]').prop('disabled', true); return true; } function checkConflicts(optional) { function getFormValue(formInput) { var value; if (formInput.attr('name').indexOf('[]') === -1) { if (formInput.filter(':checkbox').length > 0) { value = formInput.is(':checked') ? '1' : ''; } else if (formInput.filter(':radio').length > 0) { value = formInput.filter(':checked').val(); } else { value = formInput.val(); } } elements or else multiple ordinary inputs with a *[] name ?> else { value = []; formInput.each(function() { if ((formInput.filter(':checkbox').length === 0) || $(this).is(':checked')) { var thisValue = $(this).val(); if ($.isArray(thisValue)) { $.merge(value, thisValue); } else { value.push($(this).val()); } } }); } return value; } if (checkConflicts.nOutstanding === undefined) { checkConflicts.nOutstanding = 0; } if (optional && checkConflicts.nOutstanding) { return; } var timeout = 200; window.setTimeout(function() { var params = {}; var form = $('form#main'); if ((form.length === 0) || form.data('submit')) { return; } // Some browsers, eg Firefox, allow a 'multiple' select element to have nothing selected, // even though it has the required attribute. This won't happen when the form is submitted, // but can happen when the user is selecting options. If this happens when there is no option // selected, then don't bother checking for conflicts because the data are obviously // meaningless. An example is the rooms[] field. let requiredSelectsComplete = true; form.find('select:required').not(':disabled').each(function() { if ($(this).prop('multiple') && ($(this).val().length === 0)) { requiredSelectsComplete = false; return false; // break out of the .each loop } }); if (!requiredSelectsComplete) { return; } var relevantFields = form.find('[name]').not(':disabled, [type="submit"], [type="button"], [type="image"]'); relevantFields.each(function() { var fieldName = $(this).attr('name'); if (params[fieldName] === undefined) { params[fieldName] = getFormValue(relevantFields.filter('[name=' + fieldName.replace('[', '\\[').replace(']', '\\]') + ']')); } }); $.each(params, function(i, val) { if ((typeof(val) === 'object') && ((val === null) || (val.length === 0))) { delete params[i]; } }); if(args.site) { params.site = args.site; } checkConflicts.nOutstanding++; $.post('edit_entry_handler.php', params) .fail(function() { $('#checks').hide(); }) .done(function(result) { if (!result) { $('#checks').hide(); } else { $('#checks').show(); checkConflicts.nOutstanding--; var conflictDiv = $('#conflict_check'); var scheduleDetails = $('#schedule_details'); var policyDetails = $('#policy_details'); var titleText, detailsHTML; if (result.conflicts.length === 0) { conflictDiv.attr('class', 'good'); titleText = ''; detailsHTML = titleText; } else { conflictDiv.attr('class', 'bad'); detailsHTML = "

"; titleText = '' + "\n\n"; detailsHTML += titleText + "<\/p>"; var conflictsList = getErrorList(result.conflicts); detailsHTML += conflictsList.html; titleText += conflictsList.text; } conflictDiv.attr('title', titleText); scheduleDetails.html(detailsHTML); var policyDiv = $('#policy_check'); var rulesList; if (result.violations.errors.length === 0) { if (result.violations.notices.length === 0) { policyDiv.attr('class', 'good'); titleText = ''; detailsHTML = titleText; } else { policyDiv.attr('class', 'notice'); detailsHTML = "

"; titleText = '' + "\n\n"; detailsHTML += titleText + "<\/p>"; rulesList = getErrorList(result.violations.notices); detailsHTML += rulesList.html; titleText += rulesList.text; } } else { policyDiv.attr('class', 'bad'); detailsHTML = "

"; titleText = '' + "\n\n"; detailsHTML += titleText + "<\/p>"; rulesList = getErrorList(result.violations.errors); detailsHTML += rulesList.html; titleText += rulesList.text; } policyDiv.attr('title', titleText); policyDetails.html(detailsHTML); } }, 'json'); }, timeout); } var vocab = {}; vocab.periods = {singular: '', plural: ''}; vocab.minutes = {singular: '', plural: ''}; vocab.hours = {singular: '', plural: ''}; vocab.days = {singular: '', plural: ''}; function durFormat(r) { var lastChar; r = r.toFixed(2); r = parseFloat(r); r = r.toLocaleString(args.langPrefs); if ((r.indexOf('.') >= 0) || (r.indexOf(',') >= 0)) { while (r.slice(-1) === '0') { r = r.slice(0, -1); } lastChar = r.slice(-1); if ((lastChar === '.') || (lastChar === ',')) { r = r.slice(0, -1); } } return r; } function getDuration(from, to, days) { var duration, durUnits; var text = ''; var currentArea = $('#area').data('current'); var enablePeriods = areaConfig('enable_periods'); var durDays; var minutesPerDay = ; durUnits = (enablePeriods) ? '' : ''; duration = Math.floor((to - from) / 60); if (enablePeriods) { duration++; } durDays = Math.floor(duration/minutesPerDay); if (durDays !== 0) { days += durDays; duration -= durDays * ((enablePeriods) ? $('#start_seconds' + currentArea).find('option').length : minutesPerDay); } if (!enablePeriods && (duration >= 60)) { durUnits = "hours"; duration = durFormat(duration/60); } duration = duration.toString(); if (days !== 0) { text += days + ' '; text += (days === 1) ? vocab.days.singular : vocab.days.plural; if (duration !== '0') { text += ', '; } } if (duration !== '0') { text += duration + ' '; text += (duration === '1') ? vocab[durUnits].singular : vocab[durUnits].plural; } return text; } function getDateDifference() { var diff, secondsPerDay = , start = $('#start_date').val().split('-'), startDate = new Date(parseInt(start[0], 10), parseInt(start[1], 10) - 1, parseInt(start[2], 10), 12), endDate = $('#end_date'), end; if (endDate.length === 0) { diff = 0; } else { end = endDate.val().split('-'); endDate = new Date(parseInt(end[0], 10), parseInt(end[1], 10) - 1, parseInt(end[2], 10), 12); diff = (endDate - startDate)/(secondsPerDay * 1000); diff = Math.round(diff); } return diff; } function adjustWidth(a, b) { a.css({width: "auto"}); b.css({width: "auto"}); var aWidth = a.width(); var bWidth = b.width(); var maxWidth = Math.max(aWidth, bWidth) + 2; a.width(maxWidth); b.width(maxWidth); } var reloadSlotSelector = function reloadSlotSelector(select, area) { select.html($('#' + select.attr('id') + area).html()) .val(select.data('current')); }; var updateSelectorData = function updateSelectorData(){ var selectors = ['area', 'start_seconds', 'end_seconds']; var i, select; for (i=0; i var area = $('#area'), oldArea = area.data('previous'), currentArea = area.data('current'); var enablePeriods = areaConfig('enable_periods'), oldEnablePeriods = areaConfig('enable_periods', oldArea), defaultDuration = areaConfig('default_duration'); var startSelect = $('#start_seconds'), endSelect = $('#end_seconds'), allDay = $('#all_day'); var startKeepDisabled = startSelect.hasClass('keep_disabled'), endKeepDisabled = endSelect.hasClass('keep_disabled'), allDayKeepDisabled = allDay.hasClass('keep_disabled'); var oldStartValue = parseInt(startSelect.data('previous'), 10), oldEndValue = parseInt(endSelect.data('previous'), 10); var nbsp = '\u00A0', startValue, endValue, firstValue, lastValue, optionClone; if (startSelect.length === 0) { return; } if (allDay.is(':checked')) { startValue = parseInt(startSelect.find('option').first().val(), 10); endValue = parseInt(endSelect.find('option').last().val(), 10); if (oldArea !== currentArea) { startSelect.prop('disabled', true); endSelect.prop('disabled', true); } } else if (oldArea !== currentArea) { if (oldEnablePeriods === enablePeriods) { startSelect.find('option').reverse().each(function() { startValue = parseInt($(this).val(), 10); if (startValue <= oldStartValue) { return false; } }); endSelect.find('option').each(function() { endValue = parseInt($(this).val(), 10); if (endValue >= oldEndValue) { return false; } }); } else { startValue = parseInt(startSelect.find('option').first().val(), 10); if (enablePeriods) { endValue = startValue; } else { endValue = startValue + defaultDuration; } } } else { startValue = parseInt(startSelect.val(), 10); endValue = parseInt(endSelect.val(), 10); if (startValue !== oldStartValue) { endValue = endValue + (startValue - oldStartValue); } } var dateDifference = getDateDifference(); if (!allDay.is(':checked')) { var newState = (dateDifference < 0); if (newState || startKeepDisabled) { startSelect.prop('disabled', true); } else { startSelect.prop('disabled', false); } if (newState || endKeepDisabled) { endSelect.prop('disabled', true); } else { endSelect.prop('disabled', false); } if (newState || allDayKeepDisabled) { allDay.prop('disabled', true); } else { allDay.prop('disabled', false); } } startSelect.html($('#start_seconds' + currentArea).html()); startSelect.val(startValue); startSelect.data('current', startValue); endSelect.empty(); $('#end_time_error').text(''); $('#end_seconds' + currentArea).find('option').each(function(i) { var thisValue = parseInt($(this).val(), 10), nPeriods = areaConfig('n_periods'), maxDurationEnabled = areaConfig('max_duration_enabled'), maxDurationSecs = areaConfig('max_duration_secs'), maxDurationPeriods = areaConfig('max_duration_periods'), maxDurationQty = areaConfig('max_duration_qty'), maxDurationUnits = areaConfig('max_duration_units'), secondsPerDay = , duration, maxDuration; if (!isBookAdmin) { if (maxDurationEnabled) { duration = thisValue - startValue; if (enablePeriods) { duration = duration/60 + 1; duration += dateDifference * nPeriods; } else { duration += dateDifference * secondsPerDay; } maxDuration = (enablePeriods) ? maxDurationPeriods : maxDurationSecs; if (duration > maxDuration) { if (i === 0) { endSelect.append($(this).val(thisValue).text(nbsp)); var errorMessage = '' + nbsp; if (enablePeriods) { errorMessage += maxDurationPeriods + nbsp; errorMessage += (maxDurationPeriods > 1) ? vocab.periods.plural : vocab.periods.singular; } else { errorMessage += maxDurationQty + nbsp + maxDurationUnits; } $('#end_time_error').text(errorMessage); } else { return false; } } } } if ((thisValue > startValue) || ((thisValue === startValue) && enablePeriods) || (dateDifference !== 0)) { optionClone = $(this).clone(); if (dateDifference < 0) { optionClone.text(''); } else { optionClone.text($(this).text() + nbsp + nbsp + '(' + getDuration(startValue, thisValue, dateDifference) + ')'); } endSelect.append(optionClone); } }); firstValue = parseInt(endSelect.find('option').first().val(), 10); lastValue = parseInt(endSelect.find('option').last().val(), 10); if (isNaN(endValue)) { endValue = lastValue; } else { endValue = Math.max(endValue, firstValue); endValue = Math.min(endValue, lastValue); } endSelect.val(endValue); endSelect.data('current', endValue); adjustWidth(startSelect, endSelect); } var editEntryVisChanged = function editEntryVisChanged() { conflictTimer(false); conflictTimer(true); }; function populateFromSessionStorage(form) { var storedData = sessionStorage.getItem('form_data'); if (storedData) { var form_data = JSON.parse(storedData); $.each(form_data, function (index, field) { if (field.name === 'area') { $('#area').val(field.value).trigger('change'); return false; // We've found the area field so we can stop. } }); var selects = {}; $.each(form_data, function (index, field) { if (field.name === 'csrf_token') { return; } var el = $('[name="' + field.name + '"]'), tagName = el.prop('tagName'), type; if (tagName === undefined) { return; } if (tagName.toLowerCase() === 'select') { if (!selects[field.name]) { selects[field.name] = [] } selects[field.name].push(field.value); } else { type = el.attr('type'); switch (type) { case 'checkbox': if (field.name.match(/\[]$/)) { el.filter('[value="' + field.value + '"]').attr('checked', 'checked'); } else { el.attr('checked', 'checked'); } break; case 'radio': el.filter('[value="' + field.value + '"]').attr('checked', 'checked'); break; default: el.val(field.value); break; } } }); for (var property in selects) { $('[name="' + property + '"]').val(selects[property]).change(); } form.find('datalist').each(function() { // // // and we want to copy the value from the hidden input to the visible one ?> var prev1 = $(this).prev(); var prev2 = prev1.prev(); if ($(this).attr('id') === prev2.attr('list')) { prev2.val(prev1.val()); } else { console.warn("MRBS: something has gone wrong - maybe the MRBS datalist structure has changed.") } }); form.find('.flatpickr-input').each(function() { document.querySelector('#' + $(this).attr('id'))._flatpickr.setDate($(this).val(), true); }); } } $(document).on('page_ready', function() { isBookAdmin = args.isBookAdmin; var form = $('#main'), areaSelect = $('#area'), startAndEndDates = $('#start_date, #end_date'), startSelect, endSelect, allDay; if (areaSelect.length === 0) { areaSelect = $(''); $('#div_rooms').before(areaSelect); } $('#div_areas').show(); $('#start_seconds, #end_seconds') .each(function() { $(this).data('current', $(this).val()); $(this).data('previous', $(this).val()); }) .on('change', function() { updateSelectorData(); reloadSlotSelector($(this), $('#area').val()); adjustSlotSelectors(); updateSelectorData(); }); areaSelect .data('current', areaSelect.val()) .data('previous', areaSelect.val()) .on('change', function() { var newArea = $(this).val(); updateSelectorData(); var roomSelect = $('#rooms'); roomSelect.html($('#rooms' + newArea).html()); reloadSlotSelector($('#start_seconds'), newArea); var allDayCheckbox = $('#all_day'); allDayCheckbox.html($('#all_day' + newArea).html()); reloadSlotSelector($('#end_seconds'), newArea); for (const [fieldName, value] of Object.entries(mandatoryFields)) { if (Array.isArray(value)) { const field = $('[name="' + fieldName + '"]'); if (value.includes(parseInt(newArea))) { field.prop('required', true); } else { field.prop('required', false); field[0].setCustomValidity(''); } } } validationMessages(newArea); adjustSlotSelectors(); }); $('input[name="all_day"]').on('click', function() { onAllDayClick(); }); if (form.data('back')) { populateFromSessionStorage(form); } adjustSlotSelectors(); startSelect = form.find('#start_seconds'); endSelect = form.find('#end_seconds'); allDay = form.find('#all_day'); if (allDay.is(':visible') && (allDay.is(':disabled') === false) && (startSelect.val() === startSelect.find('option').first().val()) && (endSelect.val() === endSelect.find('option').last().val())) { allDay.attr('checked', 'checked'); startSelect.prop('disabled', true); endSelect.prop('disabled', true); onAllDayClick.oldStart = startSelect.val(); onAllDayClick.oldEnd = endSelect.val(); onAllDayClick.oldStartDatepicker = form.find('#start_date').val(); onAllDayClick.oldEndDatepicker = form.find('#end_date').val(); } if (typeof validationMessages === 'function') { validationMessages(args.area); } form.find('[type="submit"], [type="button"], [type="image"]').on('click', function() { var trigger = $(this).attr('name'); $(this).closest('form').data('submit', trigger); }); form.on('submit', function() { var result = true; if ($(this).data('submit') === 'save_button') { result = validate($(this)); if (!result) { $(this).removeData('submit'); } } if (result) { sessionStorage.setItem('form_data', JSON.stringify($(this).serializeArray())); } return result; }); $('#start_date').on('change', function() { const rep_end_date_selector = '#rep_end_date'; const start_date = $(this).val(); const old_rep_end_date = $(rep_end_date_selector).val(); const fp = document.querySelector(rep_end_date_selector)._flatpickr; fp.set('minDate', start_date); // Note that although the flatpickr documentation says this should work on mobiles, it doesn't seem to. // So we manually set the 'min' attribute for mobiles. $(rep_end_date_selector).next('.flatpickr-input.flatpickr-mobile').attr('min', start_date); if (old_rep_end_date < start_date) { fp.setDate(start_date); } }); var formFields = form.find('input.date, [name]').not(':disabled, [type="submit"], [type="button"], [type="image"]'); formFields.filter(':checkbox') .on('click', function() { checkConflicts(); }); formFields.not(':checkbox') .on('change', function() { checkConflicts(); }); var tabsHTML = '

' + '' + '
' + '
' + '
'; $('
').attr('id', 'check_results') .css('display', 'none') .html(tabsHTML) .appendTo(form); $('#conflict_check, #policy_check').on('click', function manageTabs() { var tabId, tabIndex, checkResults = $('#check_results'), checkTabs = $('#check_tabs'); switch ($(this).attr('id')) { case 'policy_check': tabId = 'policy_details'; break; case 'conflict_check': default: tabId = 'schedule_details'; break; } tabIndex = $('#details_tabs a[href="#' + tabId + '"]').parent().index(); if (manageTabs.alreadyExists) { if (!checkResults.dialog("isOpen")) { checkResults.dialog("open"); } checkTabs.tabs('option', 'active', tabIndex); return; } checkTabs.tabs(); checkTabs.tabs('option', 'active', tabIndex); checkResults.dialog({'width': 400, 'height': 200, 'minWidth': 300, 'minHeight': 150, 'draggable': true}); var detailsTabs = $('#details_tabs'); detailsTabs.append($('button.ui-dialog-titlebar-close')); $('.ui-dialog').addClass('ui-tabs') .prepend(detailsTabs) .draggable('option', 'handle', '#details_tabs'); $('.ui-dialog-titlebar').remove(); detailsTabs.addClass('ui-dialog-titlebar'); manageTabs.alreadyExists=true; }); conflictTimer(true); startAndEndDates.on('change', function() { var endDate = $('#end_date'); if ($(this).attr('id') === 'start_date') { if (endDate.css('visibility') === 'hidden') { endDate.val($(this).val()); } } if (getDateDifference() < 0) { var selector = ($(this).attr('id') === 'start_date') ? '#end_date' : '#start_date'; var fp = document.querySelector(selector)._flatpickr; fp.setDate($(this).val()); } adjustSlotSelectors(); checkConflicts(); checkTimeSlots($(this)); }); startAndEndDates.each(function() { checkTimeSlots($(this)); }); $('input[name="rep_interval"]').on('change', changeRepIntervalUnits); $('input[name="rep_type"]').on('change', function() { changeRepTypeDetails(); changeRepIntervalUnits(); }).trigger('change'); var prefix = visibilityPrefix(); if (document.addEventListener && (prefix !== null)) { document.addEventListener(prefix + "visibilitychange", editEntryVisChanged); } form.removeClass('js_hidden'); var nameInput = form.find('#name'); if (nameInput.length && !(nameInput.prop('disabled') || nameInput.val().length)) { nameInput.trigger('focus'); } var allowRegistration = $('#allow_registration'); allowRegistration.on('change', function() { var registration = $('#registration'); var allowRegistrationChecked = $(this).is(':checked'); registration.find('input, select').not($(this)).prop('disabled', !allowRegistrationChecked); if (allowRegistrationChecked) { registration.find('.enabler').trigger('change'); } }) .trigger('change'); form.on('submit', function() { $('#registration').find('input[type="checkbox"]').prop('disabled', false); }); });