File manager - Edit - /home/autoph/public_html/projects/tickets-autohub/public/js/main.js
Back
$(document).ready(function () { // function updateNotificationsTray() { // var notifications = JSON.parse(localStorage.getItem('notifications')) || []; // var notificationBadge = $('.notification-badge'); // var notificationsContainer = $('.notifications-container'); // // Clear the existing notifications // notificationsContainer.empty(); // // Initialize the totalNotifications count // var totalNotifications = 0; // // Add the notifications to the tray // $.each(notifications, function(index, notification) { // var notificationElement = $('<i class="notification p-1 mr-1 text-left">' + notification.name + ' has submitted a ticket' + '</i>'); // // Set the CSS class based on whether the notification is clicked // if (notification.clicked) { // notificationElement.addClass('clicked'); // } // // Handle click event to toggle the "clicked" status // notificationElement.on('click', function() { // // Toggle the "clicked" status // notification.clicked = !notification.clicked; // // Update the notifications array in localStorage // localStorage.setItem('notifications', JSON.stringify(notifications)); // // Re-render the notifications tray // updateNotificationsTray(); // }); // notificationsContainer.append(notificationElement); // // Increment totalNotifications for each notification (clicked or not) // totalNotifications += 1; // }); // // Update the notification badge with the total number of notifications // updateNotificationBadge(totalNotifications); // // Function to update the notification badge // function updateNotificationBadge(count) { // if (count > 0) { // notificationBadge.text(count).removeClass('visually-hidden'); // } else { // notificationBadge.text('').addClass('visually-hidden'); // } // } // } // Call the function to initialize and display notifications // updateNotificationsTray(); // function checkForTickets(){ // if(AuthUserid && !(AuthUserRole.includes("carplus-admin-access"))){ // $.ajax({ // type: "GET", // url: "/ticket/ticketCreated", // dataType: 'json', // data: null, // processData: false, // contentType: false, // headers: { // 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') // }, // success: function(result){ // let storedIds = JSON.parse(localStorage.getItem('storedIds')) || []; // if(result['check'] !== null){ // // Check if the new id is different from the one stored // if (result['check'].tix_id && !storedIds.includes(result['check'].tix_id)) { // if(!(result['check'].usr_id == parseInt(AuthUserid)) && !(AuthUserRole.includes("user"))){ // toastRWithTime(result['sender'].f_name + " " + result['sender'].l_name + " submitted a ticket", 'success'); // if ('Notification' in window && Notification.permission === 'granted') { // var notification = new Notification('New Ticket Created', { // body: result['sender'].f_name + " " + result['sender'].l_name + " submitted a ticket" // }); // // Handle click event on the notification (e.g., redirect to the ticket) // notification.onclick = function () { // window.location.href = '/ticket/department/tickets'; // Adjust the URL as needed // }; // } // } // // Replace the stored id with the new one // storedIds = [result['check'].tix_id]; // // Save the updated ids array to localStorage // localStorage.setItem('storedIds', JSON.stringify(storedIds)); // } // } // var notifications = JSON.parse(localStorage.getItem('notifications')) || []; // // Check if a new notification with the same full name doesn't exist // var isDuplicate = notifications.some(function(existingNotification) { // return existingNotification.name === result['sender'].f_name + ' ' + result['sender'].l_name; // }); // if (!isDuplicate) { // // Add the new notification (concatenated name) to the notifications array // notifications.push({ // name: result['sender'].f_name + ' ' + result['sender'].l_name, // clicked: false // Add the "clicked" field and set it to false // }); // // Store the updated notifications array in localStorage // localStorage.setItem('notifications', JSON.stringify(notifications)); // // Update the notifications tray with the new notifications // updateNotificationsTray(); // } // }, // complete: function(){ // // Retrieve existing notifications from localStorage // checkForTickets(); // }, // error: function(error){ // // toastRWithTime(error.statusText,"error"); // } // }); // } // } // Define the notifications array (you can initialize it as an empty array) var notifications = []; var AuthUserRole =[]; var AuthUserid =''; // Function to add a new notification to the notifications array function addNotification(id, name) { // Create a new notification object var notification = { id: id, // Unique identifier for the notification name: name, // Notification message or name clicked: false // Initial click state (set to false) }; // Add the new notification to the array notifications.push(notification); } // Function to check if a notification has been clicked based on cookies function isNotificationClicked(notificationId) { // Get the corresponding cookie const cookieName = `notification_${notificationId}`; const value = getCookie(cookieName); // Check if the cookie exists and has a 'clicked' value return value === 'clicked'; } // Function to get the value of a cookie by its name function getCookie(cookieName) { const cookies = document.cookie.split(';'); for (const cookie of cookies) { const [key, value] = cookie.trim().split('='); if (key === cookieName) { return value; } } return null; } // Function to set a cookie when a notification is clicked function setNotificationClickedCookie(notificationId) { // Set a cookie with the notification ID as the key and 'clicked' as the value document.cookie = `notification_${notificationId}=clicked; expires=Thu, 01 Jan 2099 00:00:00 UTC; path=/`; } function addNotificationIfNotExists(notificationId, notificationText) { // Check if a notification with the same ID exists in the array const notificationExists = notifications.some((notification) => notification.id === notificationId); if (!notificationExists) { // Add the new notification to the array notifications.push({ id: notificationId, text: notificationText, }); // Update the notifications tray with the new notifications updateNotificationsTray(); } } // Function to update the notifications tray function updateNotificationsTray() { var notificationBadge = $('.notification-badge'); var notificationsContainer = $('.notifications-container'); // Clear the existing notifications notificationsContainer.empty(); // Initialize the totalNotifications count var totalNotifications = 0; // Initialize a variable to count clicked notifications var clickedNotifications = 0; // Loop through notifications and add them to the tray $.each(notifications, function (index, notification) { var notificationElement = $('<div class="notification p-3 ml-n-2"></div>'); // Check if the notification has been clicked based on cookies if (isNotificationClicked(notification.id)) { notificationElement.addClass('clicked'); clickedNotifications++; // Increment clicked notifications } // Add the notification message to the element var message = notification.text + ' has submitted a ticket'; notificationElement.text(message); // Handle click event to toggle the "clicked" status notificationElement.on('click', function () { // Toggle the "clicked" status notification.clicked = !notification.clicked; // Update the notifications array in localStorage localStorage.setItem('notifications', JSON.stringify(notifications)); // Toggle the "clicked" class based on the updated status notificationElement.toggleClass('clicked', notification.clicked); // Handle any additional actions when a notification is clicked handleNotificationClick(notification); // If the notification is clicked, decrease the totalNotifications count if (notification.clicked) { totalNotifications--; clickedNotifications++; // Increment clicked notifications } // Update the notification badge count updateNotificationBadge(totalNotifications); }); notificationsContainer.append(notificationElement); // Increment totalNotifications for each notification (clicked or not) totalNotifications++; }); // Update the notification badge count updateNotificationBadge(totalNotifications); // Function to update the notification badge function updateNotificationBadge(count) { if (count > 0) { notificationBadge.text(count).removeClass('visually-hidden'); } else { notificationBadge.text('').addClass('visually-hidden'); } } // Return the total and clicked notifications counts return { totalNotifications, clickedNotifications }; } // Function to handle any additional actions when a notification is clicked function handleNotificationClick(notification) { // Add your custom code here to handle what happens when a notification is clicked // For example, you can redirect the user to a specific page or perform other actions. // You can access the notification object for any necessary data. } // Your existing checkForTickets function function checkForTickets() { if (AuthUserid && !(AuthUserRole.includes("carplus-admin-access"))) { $.ajax({ type: "GET", url: "/ticket/ticketCreated", dataType: 'json', data: null, processData: false, contentType: false, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function (result) { // Check if a new notification has been received if (result['check'] !== null) { // Check if the new id is different from the one stored if (result['check'].tix_id && !isNotificationClicked(result['check'].tix_id)) { if (!(result['check'].usr_id == parseInt(AuthUserid)) && !(AuthUserRole.includes("user"))) { toastRWithTime(result['sender'].f_name + " " + result['sender'].l_name + " submitted a ticket", 'success'); if ('Notification' in window && Notification.permission === 'granted') { var notification = new Notification('New Ticket Created', { body: result['sender'].f_name + " " + result['sender'].l_name + " submitted a ticket" }); // Handle click event on the notification (e.g., redirect to the ticket) notification.onclick = function () { window.location.href = '/ticket/department/tickets'; // Adjust the URL as needed }; } // Set a cookie to track the clicked notification setNotificationClickedCookie(result['check'].tix_id); // setNotificationShownCookie(result['check'].tix_id); // Add the notification to the array if it doesn't already exist addNotificationIfNotExists(result['check'].tix_id, result['sender'].f_name + " " + result['sender'].l_name); } } } // Continue checking for tickets setTimeout(() => { checkForTickets(); }, 600000); //10mins // checkForTickets(); }, error: function (error) { // Handle error // toastRWithTime(error.statusText,"error"); // Continue checking for tickets even on error setTimeout(() => { checkForTickets(); }, 600000); //10mins } }); } } // Start checking for tickets and update the notifications tray function checkCarplusTickets(){ if(AuthUserRole.includes("carplus-admin-access")){ $.ajax({ type: "GET", url: "/ticket/carplus/CarplusTicketCreated", dataType: 'json', data: null, processData: false, contentType: false, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function(result){ let storedCarplusIds = JSON.parse(localStorage.getItem('storedCarplusIds')) || []; // Check if the new id is different from the one stored if (result.id && !storedCarplusIds.includes(result.id)) { if(!(result.ticket_creator_id == parseInt(AuthUserid)) && !(AuthUserRole.includes("user"))){ toastRWithTime("New Carplus Ticket has been submitted", 'success'); if ('Notification' in window && Notification.permission === 'granted') { var notification = new Notification('New Ticket Created', { body: 'A new carplus ticket has been created.' }); // Handle click event on the notification (e.g., redirect to the ticket) notification.onclick = function () { window.location.href = '/ticket/carplus'; // Adjust the URL as needed }; } } // Replace the stored id with the new one storedCarplusIds = [result.id]; // Save the updated ids array to localStorage localStorage.setItem('storedCarplusIds', JSON.stringify(storedCarplusIds)); } }, complete: function(){ // // Retrieve existing notifications from localStorage // var notifications = JSON.parse(localStorage.getItem('notifications')) || []; // // Add new notifications to the existing array (avoiding duplicates) // $.each(result, function(index, newNotification) { // var exists = false; // $.each(notifications, function(index, existingNotification) { // if (JSON.stringify(existingNotification) === JSON.stringify(newNotification)) { // exists = true; // return false; // Exit the loop if a duplicate is found // } // }); // if (!exists) { // notifications.push(newNotification); // } // }); // // Remove notifications that are no longer present in the result // notifications = notifications.filter(function(notification) { // return result.some(function(newNotification) { // return JSON.stringify(notification) === JSON.stringify(newNotification); // }); // }); // // Store the updated notifications array in localStorage // localStorage.setItem('notifications', JSON.stringify(notifications)); // // Update the notifications tray with the new notifications // updateNotificationsTray(); checkCarplusTickets(); }, error: function(error){ // toastRWithTime(error.statusText,"error"); } }); } } $('.fa-bell').on('click', function() { // alert(); $('.notifications-container').toggleClass('show'); }); $('#multiCollapseConfig1').on('show.bs.collapse hide.bs.collapse', function () { $('.caret1').toggleClass("caret-up", $(this).hasClass("show")); $('.caret1').toggleClass("caret-down", !$(this).hasClass("show")); }); $('#multiCollapseExample1').on('show.bs.collapse hide.bs.collapse', function () { $('.caret2').toggleClass("caret-up", $(this).hasClass("show")); $('.caret2').toggleClass("caret-down", !$(this).hasClass("show")); }); $('#_logoutBtn').on('click', (e)=>{ $.ajax({ type: "POST", url: "/logout", data:null, processData: false, contentType: false, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function(result){ window.location.href = "/login"; }, error: function(error){ } }); }); if ('Notification' in window) { Notification.requestPermission() .then(function (permission) { if (permission === 'granted') { // User has granted permission to show notifications if (!(AuthUserRole.includes("user") || AuthUserRole.includes("carplus-admin-access"))) { console.log(AuthUserRole); checkForTickets(); } else { checkCarplusTickets(); } // Start checking for tickets } else { if (!(AuthUserRole.includes("user") || AuthUserRole.includes("carplus-admin-access"))) { checkForTickets(); } else { checkCarplusTickets(); } } }); } updateNotificationsTray(); });
| ver. 1.4 |
.
| PHP 8.1.32 | Generation time: 0 |
proxy
|
phpinfo
|
Settings