/** * Copyright since 2007 PrestaShop SA and Contributors * PrestaShop is an International Registered Trademark & Property of PrestaShop SA * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.md. * It is also available through the world-wide-web at this URL: * https://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@prestashop.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to https://devdocs.prestashop.com/ for more information. * * @author PrestaShop SA and Contributors * @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ $(document).ready(function () { if (youEditFieldFor) { $('.translatable span.hint').append(`
${youEditFieldFor}`); } $('.notification.dropdown-toggle').on('click', function () { $(this).parent().toggleClass('open'); updateEmployeeNotifications(); }); $(document).on('click', function (e) { if (!$(e.target).closest('#notification').length && $('#notification').hasClass('open')) { $('#notification').removeClass('open'); getPush(); } }); $('.notifications .nav-link').on('shown.bs.tab', function () { updateEmployeeNotifications(); }); // call it once immediately, then use setTimeout if (parseInt(show_new_orders) || parseInt(show_new_customers) || parseInt(show_new_messages)) { getPush(); } }); function updateEmployeeNotifications() { $.post( admin_notification_push_link, { type: $('.notifications .nav-item.active a').data('type') } ); } function renderOrderNotification(value) { const carrier = value.carrier !== '' ? ` - ${value.carrier}` : ''; return ` #${value.id_order} - ${from_msg} ${value.customer_name} (${value.iso_code}) ${value.total_paid}${carrier} `; } function renderCustomerNotification(value) { const company = value.company !== '' ? ` (${value.company})` : ''; return ` #${value.id_customer} - ${value.customer_name}${company} - ${customer_name_msg} ${value.date_add}; `; } function renderMessageNotification(value) { const company = value.company !== '' ? ` (${value.company})` : ''; return ` fiber_manual_record ${value.status} - ${value.customer_name} ${company} - access_time ${value.date_add} `; } function renderNotifications(panelId, data, renderFn) { var panel = $('#' + panelId); var tabCounter = panel.closest('#notification').find(`a[href="#${panelId}"] .notif-counter`); if (data.total > 0) { var html = data.results.map(renderFn).join('') panel.removeClass('empty').children('.notification-elements').html(html); tabCounter.text(` (${data.total})`).data('nb', data.total); } else { panel.addClass('empty').children('.notification-elements').empty(); tabCounter.text(''); } } function getPush() { $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: `${admin_notification_get_link}&rand=${new Date().getTime()}`, cache: false, dataType: 'json', success: function (json) { setTimeout(getPush, 120000); if (!json) { return; } // Add orders notifications to the list renderNotifications('orders-notifications', json.order, renderOrderNotification); // Add customers notifications to the list renderNotifications('customers-notifications', json.customer, renderCustomerNotification); // Add messages notifications to the list renderNotifications('messages-notifications', json.customer_message, renderMessageNotification); var notifCount = parseInt(json.order.total) + parseInt(json.customer.total) + parseInt(json.customer_message.total); if (notifCount > 0) { $("#total_notif_number_wrapper").removeClass('hide'); $('#total_notif_value').text(notifCount); } else { $("#total_notif_number_wrapper").addClass('hide'); } } }); }