var lastPullNotification; var lastPullService; var lastKDSTimestamp; var firstTimePullNotifications = true; var isSoundActivated = true; $(document).ready(function () { if ($("#urlPullValidateNotifications").length > 0) { pullValidateNotifications(); } }); function pullRegisterValidateNotifications() { setTimeout(function () { pullValidateNotifications() }, 15000); } function pullValidateNotifications() { var url = $("#urlPullValidateNotifications").val(); if (url == null) { return; } $.ajax({ url: url, type: "POST", dataType: "json", async: false, cache: false, processData: false, contentType: false, success: function (result) { if (result.response == "ok") { var notification = result.data.notification; var service = result.data.service; var kdsTimestamp = result.data.kds.lastTimestamp; if (firstTimePullNotifications) { lastPullNotification = notification.desc; lastPullService = service.lastTimestamp; lastKDSTimestamp = kdsTimestamp; firstTimePullNotifications = false; return; } //Evaluar notificaciones if (notification.exists && notification.desc != "N/A" && (lastPullNotification == null || lastPullNotification != notification.desc)) { lastPullNotification = notification.desc; new PNotify({ title: 'Última notificación', text: '' + lastPullNotification + '', addclass: 'real-notifications', hide: true, sticker: false }); playSound(); if ($("#url-load-admin-company-booking-by-state").length > 0) { loadCompanyAdminBookings(); } } if (service.exists && (lastPullService == null || lastPullService != service.lastTimestamp)) { lastPullService = service.lastTimestamp; if ($("#url-load-admin-company-order-by-state").length > 0) { evaluateNotificationOptions(service); loadCompanyAdminOrders(); } if ($("#url-load-company-delivery-orders").length > 0) { evaluateNotificationOptions(service); loadDeliveryServices(); } if ($("#url-load-user-delivery-orders").length > 0) { evaluateNotificationOptions(service); loadDeliveryServices(); } } if(lastKDSTimestamp != kdsTimestamp) { console.log("recargar la página KDS"); loadCompanyAdminOrders(); lastKDSTimestamp = kdsTimestamp; } } } }); pullRegisterValidateNotifications(); } function evaluateNotificationOptions(service) { if (service.options.indexOf("S") != -1) { playSound(); } if (service.options.indexOf("N") != -1) { new PNotify({ title: 'Última notificación', text: 'Cambios en la orden', addclass: 'real-notifications', hide: true, sticker: false }); } } function activateSound(control, cssActivated, cssNormal) { isSoundActivated = !isSoundActivated; $(control).attr("class", isSoundActivated ? cssActivated : cssNormal); playSound(); } function playSound() { if (isSoundActivated) { $(".audio")[0].play(); } } function showMessageInApp() { setTimeout(function () { var url = $("#urlValidMessageInApp").val(); $.ajax({ url: url, type: "POST", dataType: "json", async: false, cache: false, processData: false, contentType: false, success: function (result) { _showMessageInApp(result); } }); }, 1000); } function _showMessageInApp(result) { if (result.response == "ok") { var modal = $("#modalInAppMessageDialog"); modal.find(".modal-content").prop("style", "background-color: " + result.data.themeBgColor + ";"); modal.find(".modal-title").html(result.data.companyName); modal.find(".modal-title").prop("style", "color: " + result.data.themeTextColor + ";"); modal.find(".inappmsg-title").html(result.data.title); modal.find(".inappmsg-title").prop("style", "color: " + result.data.themeTextColor + ";"); modal.find(".inappmsg-video").hide(); modal.find(".inappmsg-img").hide(); if (result.data.videoUrl != "") { modal.find(".inappmsg-video").show(); modal.find(".inappmsg-video").attr("src", result.data.videoUrl); } else if (result.data.imageUrl != "") { modal.find(".inappmsg-img").show(); modal.find(".inappmsg-img").attr("src", result.data.imageUrl); } modal.find(".inappmsg-desc").html(result.data.message); modal.find(".inappmsg-desc").prop("style", "color: " + result.data.themeTextColor + ";"); modal.find(".inappmsg-cta").prop("href", result.data.ctaUrl); modal.find(".inappmsg-btn").html(result.data.ctaTypeDesc); modal.find(".inappmsg-btn").prop("style", "background-color: " + result.data.themeTextColor + "; color: " + result.data.themeBgColor + ";"); modal.modal('show'); } } function openMessageInAppCtaUrl(ctaUrl) { var url = $("#urlCountUsedMessageInAppCtaUrl").val(); $.ajax({ url: url, type: "POST", dataType: "json", async: false, cache: false, processData: false, contentType: false, success: function (result) { if (result.response == "ok") { window.open(ctaUrl); } else { showModalDialog("Url Cta", result.data); } } }); } function openNav() { document.getElementById("mySidenav").style.left = "0"; } function closeNav() { document.getElementById("mySidenav").style.left = "-29rem"; } /* Loop through all dropdown buttons to toggle between hiding and showing its dropdown content - This allows the user to have multiple dropdowns without any conflict */ var dropdown = document.getElementsByClassName("dropdown-btn"); var i; for (i = 0; i < dropdown.length; i++) { dropdown[i].addEventListener("click", function () { this.classList.toggle("active"); var dropdownContent = this.nextElementSibling; if (dropdownContent.style.display === "block") { dropdownContent.style.display = "none"; } else { dropdownContent.style.display = "block"; } }); } $(function () { // Dropdown toggle $('.dropdown-toggle').click(function () { $(this).next('.dropdown').toggle(400); }); $(document).click(function (e) { var target = e.target; if (!$(target).is('.dropdown-toggle') && !$(target).parents().is('.dropdown-toggle')) { $('.dropdown').hide(); } }); }); function helpModal() { $("#helpVideo").modal('show'); } $(document).ready(function () { // Default initialization if ($('.select').length > 0) { $('.select').select2({ minimumResultsForSearch: Infinity }); } // Select with search if ($('.select-search').length > 0) { $('.select-search').select2(); } // Basic initialization if ($('.vigencia').length > 0) { $('.vigencia').daterangepicker({ applyClass: 'btn-success', cancelClass: 'btn-danger', locale: { format: 'YYYY-MM-DD', applyLabel: 'Aplicar', cancelLabel: 'Cancelar', startLabel: 'Fecha de Inicio', endLabel: 'Fecha Final', customRangeLabel: 'Personalizado', daysOfWeek: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Маyo', 'Junio', 'Julio', 'Аgosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], firstDay: 1 } }); } // Single picker if ($('.fecha-reserva').length > 0) { $('.fecha-reserva').daterangepicker({ singleDatePicker: true, locale: { format: 'YYYY-MM-DD', applyLabel: 'Aplicar', cancelLabel: 'Cancelar', startLabel: 'Fecha de Inicio', endLabel: 'Fecha Final', customRangeLabel: 'Personalizado', daysOfWeek: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Маyo', 'Junio', 'Julio', 'Аgosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], firstDay: 1 } }); } if ($('.fecha-evento').length > 0) { $('.fecha-evento').daterangepicker({ singleDatePicker: true, locale: { format: 'YYYY-MM-DD', applyLabel: 'Aplicar', cancelLabel: 'Cancelar', startLabel: 'Fecha de Inicio', endLabel: 'Fecha Final', customRangeLabel: 'Personalizado', daysOfWeek: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Маyo', 'Junio', 'Julio', 'Аgosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], firstDay: 1 } }); } // Simple toolbar if ($('.editor-extra').length > 0) { $('.editor-extra').wysihtml5({ parserRules: wysihtml5ParserRules, "font-styles": true, // Font styling, e.g. h1, h2, etc. Default true "emphasis": true, // Italics, bold, etc. Default true "lists": true, // (Un)ordered lists, e.g. Bullets, Numbers. Default // true "html": true, // Button which allows you to edit the generated HTML. // Default false "link": true, // Button to insert a link. Default true "image": false, // Button to insert an image. Default true, "action": true, // Undo / Redo buttons, "color": false // Button to change color of font }); } // Fechas var yesterday = new Date((new Date()).valueOf() - 1000 * 60 * 60 * 24); $('.bc-date').pickadate({ firstDay: 1, monthsFull: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], weekdaysShort: ['DO', 'LU', 'MA', 'MI', 'JU', 'VI', 'SA'], today: 'Hoy', clear: 'Borrar', close: 'Cerrar', format: 'yyyy-mm-dd', selectYears: true, selectMonths: true, disable: [ { from: [0, 0, 0], to: yesterday } ] }); $('.bc-date__unlocked').pickadate({ firstDay: 1, monthsFull: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], weekdaysShort: ['DO', 'LU', 'MA', 'MI', 'JU', 'VI', 'SA'], today: 'Hoy', clear: 'Borrar', close: 'Cerrar', format: 'yyyy-mm-dd', selectYears: true, selectMonths: true, }); $('.payment-date').pickadate({ firstDay: 1, monthsFull: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], weekdaysShort: ['DO', 'LU', 'MA', 'MI', 'JU', 'VI', 'SA'], today: 'Hoy', clear: 'Borrar', close: 'Cerrar', format: 'yyyy-mm-dd', selectYears: true, selectMonths: true, }); $('.nice__daterange').daterangepicker({ singleDatePicker: true, locale: { format: 'YYYY-MM-DD', applyLabel: 'Aplicar', cancelLabel: 'Cancelar', startLabel: 'Fecha inicial', endLabel: 'Fecha final', customRangeLabel: 'Fecha personalizada', daysOfWeek: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], firstDay: 1 } }); $.datepicker.regional['es'] = { closeText: 'Cerrar', prevText: '<', nextText: '>', currentText: 'Hoy', monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'], dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mié', 'Juv', 'Vie', 'Sáb'], dayNamesMin: ['D', 'L', 'M', 'X', 'J', 'V', 'S'], weekHeader: 'Sm', dateFormat: 'dd/mm/yy', firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: '' }; $.datepicker.setDefaults($.datepicker.regional['es']); // Horas $('.bc-time').pickatime({ format: 'HH:i', formatSubmit: 'HH:i' }); // Hora del Evento $('.event-time').pickatime({ format: 'HH:i', formatSubmit: 'HH:i' }); // Hora de la Reserva $('.booking-time').pickatime({ format: 'HH:i', formatSubmit: 'HH:i', min: [5, 0], max: [23, 30], formatLabel: 'h:i a' }); $('.pickup-time').pickatime({ format: 'HH:i', formatSubmit: 'HH:i', formatLabel: 'h:i a', interval: 15 }); $('.pickatime').pickatime({ format: 'H:i a', formatSubmit: 'H:i', min: [5, 0], max: [23, 30], }); $('.horario-restaurante_open').pickatime({ format: 'H:i a', formatLabel: 'h:i a', formatSubmit: 'h:i a' }); $('.horario-restaurante_close').pickatime({ format: 'H:i a', formatLabel: 'h:i a', formatSubmit: 'h:i a' }); $('.fecha-cupon-inicio').daterangepicker({ singleDatePicker: true, locale: { format: 'YYYY-MM-DD', applyLabel: 'Aplicar', cancelLabel: 'Cancelar', startLabel: 'Fecha de Inicio', endLabel: 'Fecha Final', customRangeLabel: 'Personalizado', daysOfWeek: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Маyo', 'Junio', 'Julio', 'Аgosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], firstDay: 1 } }); $('.fecha-cupon-final').daterangepicker({ singleDatePicker: true, locale: { format: 'YYYY-MM-DD', applyLabel: 'Aplicar', cancelLabel: 'Cancelar', startLabel: 'Fecha Final', endLabel: 'Fecha Final', customRangeLabel: 'Personalizado', daysOfWeek: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Маyo', 'Junio', 'Julio', 'Аgosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], firstDay: 1 } }); $('.fecha-nacimiento').daterangepicker({ singleDatePicker: true, locale: { format: 'YYYY-MM-DD', applyLabel: 'Aplicar', cancelLabel: 'Cancelar', startLabel: 'Fecha de Inicio', endLabel: 'Fecha Final', customRangeLabel: 'Personalizado', daysOfWeek: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'], monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Маyo', 'Junio', 'Julio', 'Аgosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], firstDay: 1 } }); if ($('.tags-input').length > 0) { $('.tags-input').tagsinput(); } // Table setup // Setting datatable defaults if ($.fn.dataTable != null) { $.extend($.fn.dataTable.defaults, { autoWidth: false, dom: '<"datatable-header"fBl><"datatable-scroll-wrap"t><"datatable-footer"ip>', language: { search: 'Filtro: _INPUT_', searchPlaceholder: 'Escribe para filtrar...', lengthMenu: 'Mostrando: _MENU_', paginate: { 'first': 'Primero', 'last': 'Último', 'next': '→', 'previous': '←' } } }); } // Basic initialization if ($('.app-table').length > 0) { $('.app-table').DataTable({ responsive: true, }); } // Checkboxes, radios if ($('.styled').length > 0) { $(".styled").uniform({ radioClass: 'choice' }); // Style form components $('.styled').uniform(); } // Initialize if ($(".validar").length > 0) { var validator = $(".validar").validate( { ignore: 'input[type=hidden], .select2-search__field', // ignore // hidden // fields errorClass: 'validation-error-label', successClass: 'validation-valid-label', highlight: function (element, errorClass) { $(element).removeClass(errorClass); }, unhighlight: function (element, errorClass) { $(element).removeClass(errorClass); }, // Different components require proper error label placement errorPlacement: function (error, element) { // Styled checkboxes, radios, bootstrap switch if (element.parents('div').hasClass("checker") || element.parents('div').hasClass("choice") || element.parent().hasClass('bootstrap-switch-container')) { if (element.parents('label').hasClass('checkbox-inline') || element.parents('label').hasClass('radio-inline')) { error.appendTo(element.parent().parent().parent().parent()); } else { error.appendTo(element.parent().parent().parent().parent().parent()); } } // Unstyled checkboxes, radios else if (element.parents('div').hasClass('checkbox') || element.parents('div').hasClass('radio')) { error.appendTo(element.parent().parent().parent()); } // Input with icons and Select2 else if (element.parents('div').hasClass('has-feedback') || element.hasClass('select2-hidden-accessible')) { error.appendTo(element.parent()); } // Inline checkboxes, radios else if (element.parents('label').hasClass('checkbox-inline') || element.parents('label').hasClass('radio-inline')) { error.appendTo(element.parent().parent()); } // Input group, styled file input else if (element.parent().hasClass('uploader') || element.parents().hasClass('input-group')) { error.appendTo(element.parent().parent()); } else if (element.parents().hasClass('form-editor')) { error.appendTo(element.parent().parent()); } else { error.insertAfter(element); } }, validClass: "validation-valid-label", success: function (label) { label.addClass("validation-valid-label").text("Correcto.") }, rules: { password: { minlength: 5 }, repeat_password: { equalTo: "#password" }, email: { email: true }, repeat_email: { equalTo: "#email" }, minimum_characters: { minlength: 10 }, maximum_characters: { maxlength: 10 }, minimum_number: { min: 10 }, maximum_number: { max: 10 }, number_range: { range: [10, 20] }, url: { url: true }, date: { date: true }, date_iso: { dateISO: true }, numbers: { number: true }, digits: { digits: true }, creditcard: { creditcard: true }, basic_checkbox: { minlength: 2 }, styled_checkbox: { minlength: 2 }, switchery_group: { minlength: 2 }, switch_group: { minlength: 2 } }, messages: { custom: { required: "This is a custom error message", }, agree: "Please accept our policy" } }); } // Initialize if ($(".validar-edit").length > 0) { var validator = $(".validar-edit").validate( { ignore: 'input[type=hidden], .select2-search__field', // ignore // hidden // fields errorClass: 'validation-error-label', successClass: 'validation-valid-label', highlight: function (element, errorClass) { $(element).removeClass(errorClass); }, unhighlight: function (element, errorClass) { $(element).removeClass(errorClass); }, // Different components require proper error label placement errorPlacement: function (error, element) { // Styled checkboxes, radios, bootstrap switch if (element.parents('div').hasClass("checker") || element.parents('div').hasClass("choice") || element.parent().hasClass('bootstrap-switch-container')) { if (element.parents('label').hasClass('checkbox-inline') || element.parents('label').hasClass('radio-inline')) { error.appendTo(element.parent().parent().parent().parent()); } else { error.appendTo(element.parent().parent().parent().parent().parent()); } } // Unstyled checkboxes, radios else if (element.parents('div').hasClass('checkbox') || element.parents('div').hasClass('radio')) { error.appendTo(element.parent().parent().parent()); } // Input with icons and Select2 else if (element.parents('div').hasClass('has-feedback') || element.hasClass('select2-hidden-accessible')) { error.appendTo(element.parent()); } // Inline checkboxes, radios else if (element.parents('label').hasClass('checkbox-inline') || element.parents('label').hasClass('radio-inline')) { error.appendTo(element.parent().parent()); } // Input group, styled file input else if (element.parent().hasClass('uploader') || element.parents().hasClass('input-group')) { error.appendTo(element.parent().parent()); } else { error.insertAfter(element); } }, validClass: "validation-valid-label", success: function (label) { label.addClass("validation-valid-label").text("Correcto.") }, rules: { password: { minlength: 5 }, repeat_password: { equalTo: "#password" }, email: { email: true }, repeat_email: { equalTo: "#email" }, minimum_characters: { minlength: 10 }, maximum_characters: { maxlength: 10 }, minimum_number: { min: 10 }, maximum_number: { max: 10 }, number_range: { range: [10, 20] }, url: { url: true }, date: { date: true }, date_iso: { dateISO: true }, numbers: { number: true }, digits: { digits: true }, creditcard: { creditcard: true }, basic_checkbox: { minlength: 2 }, styled_checkbox: { minlength: 2 }, switchery_group: { minlength: 2 }, switch_group: { minlength: 2 } }, messages: { custom: { required: "This is a custom error message", }, agree: "Please accept our policy" } }); } // Reset form $('#reset').on('click', function () { validator.resetForm(); }); // Alert combination $('#cambio-clave').on('click', function () { swal({ title: "¿Estás seguro?", text: "¿Desea notificar la clave de acceso del usuario niceeat ?", type: "warning", showCancelButton: true, confirmButtonColor: "#EF5350", confirmButtonText: "Si, enviar!", cancelButtonText: "No, cancelar!", closeOnConfirm: false, closeOnCancel: false }, function (isConfirm) { if (isConfirm) { swal({ title: "Enviada!", text: "Tu nueva contraseña ha sido generada.", confirmButtonColor: "#66BB6A", type: "success" }); } else { swal({ title: "Cancelado", text: "Tu contraseña sigue siendo la misma :)", confirmButtonColor: "#2196F3", type: "error" }); } }); }); // Override defaults if ($.fn.stepy != null) { $.fn.stepy.defaults.legend = false; $.fn.stepy.defaults.transition = 'fade'; $.fn.stepy.defaults.duration = 150; $.fn.stepy.defaults.backLabel = ''; $.fn.stepy.defaults.nextLabel = ''; // Clickable titles $(".stepy-clickable").stepy({ titleClick: true }); } // Modal template var modalTemplate = '