Файловый менеджер - Редактировать - /home/clickysoft/public_html/travel-guru.clickysoft.net/public/js/load-message-rate-agent.js
Назад
$(document).ready(function () { // Function to load messages from preloaded data function loadMessagesForUser(userId) { $.ajax({ url: "/get-messages/" + userId, method: "GET", success: function (response) { $("#chat-full-name").text(response.full_name); $(".seen-cont-tm").text("Last seen " + response.last_seen); $(".messages").html(response.html); }, error: function (xhr, status, error) { console.error("Error loading messages:", error); $(".messages").empty().append("<p>Error loading messages.</p>"); }, }); } function rateAgentModal(userId) { $.ajax({ url: "/review/rating/modal/" + userId, method: "GET", success: function (response) { $("#exampleModal1-rate").html(response.html); // Load the modal content $("#exampleModal1-rate").modal("show"); // Show the modal // Attach the event listener for star ratings once modal content is loaded $(document).on("click", ".rating-stars i", function () { let selectedRating = $(this).data("value"); // Get the star's value // Reset all stars to empty (fa-star-o) $(".rating-stars i") .removeClass("fa-star") .addClass("fa-star-o"); // Fill the stars up to the selected star $(".rating-stars i").each(function (index) { if (index < selectedRating) { $(this) .removeClass("fa-star-o") .addClass("fa-star"); } }); }); // Attach the event listener for the submit review button $(document).on("click", "#submitReview", function () { let receiverId = $("#receiver-id").val(); let message = $("#review_message").val(); let selectedRating = $(".rating-stars i.fa-star").length; // Get the number of filled stars let hasError = false; // Flag to track errors // Clear previous error messages $(".error-message").remove(); // Client-side validation if (selectedRating === 0) { $("#ratingError").html( '<div class="error-message" style="color: red;">Please select a rating.</div>' ); hasError = true; } if (message.trim() === "") { $("#messageError").html( '<div class="error-message" style="color: red;">Please write a review message.</div>' ); hasError = true; } // Prevent submission if there are validation errors if (hasError) { return; } // If validation passed, proceed with AJAX submission $.ajax({ url: routes.submitReview, method: "POST", data: { agent_id: receiverId, message: message, rating: selectedRating, _token: "{{ csrf_token() }}", }, success: function (response) { if (response.status === "error") { toastr.error(response.message); // Show error message } else { toastr.success("Review submitted successfully"); $("#exampleModal1-rate").modal("hide"); // Hide the modal after success } }, error: function (xhr, status, error) { if (xhr.status === 422) { // Laravel validation error status let errors = xhr.responseJSON.errors; // Display validation errors in the form if (errors.rating) { $("#ratingError").html( '<div class="error-message" style="color: red;">' + errors.rating[0] + "</div>" ); } if (errors.message) { $("#messageError").html( '<div class="error-message" style="color: red;">' + errors.message[0] + "</div>" ); } } else if (xhr.status === 400) { // Handle custom error (already reviewed) toastr.error(xhr.responseJSON.message); } else { // Fallback for unexpected errors toastr.error( "Something went wrong. Please try again." ); } }, }); }); }, error: function (xhr, status, error) { console.error("Error loading modal:", error); }, }); } $("body #rate-agent").on("click", function () { rateAgentModal($("#receiver-id").val()); }); $("#user-list").on("click", ".user-item", function () { var userId = $(this).data("id"); // Get the user ID from the button's data attribute $("#receiver-id").val(userId); loadMessagesForUser(userId); // Load messages for the clicked user }); // Search functionality $("#search-chat-input").on("input", function () { var searchValue = $(this).val().toLowerCase(); var foundUserId = null; $("#user-list .user-item").filter(function () { var isVisible = $(this).data("fullname").toLowerCase().indexOf(searchValue) > -1; $(this).toggle(isVisible); // Get the first matching user's ID if (isVisible && foundUserId === null) { foundUserId = $(this).data("id"); } }); // if (foundUserId) { // loadMessagesForUser(foundUserId); // } else { // $('.messages').empty(); // Clear messages if no user is found // } }); }); $(document).ready(function () { // Handle form submission $("#submitReview").on("click", function () { let receiverId = $("#agent_id").val(); let message = $("#review_message").val(); let hasError = false; // Flag to track errors // Clear previous error messages $(".error-message").remove(); // Client-side validation if (selectedRating === 0) { $("#ratingError").html( '<div class="error-message" style="color: red;">Please select a rating.</div>' ); hasError = true; } if (message.trim() === "") { $("#messageError").html( '<div class="error-message" style="color: red;">Please write a review message.</div>' ); hasError = true; } // Prevent submission if there are validation errors if (hasError) { return; } // If validation passed, proceed with AJAX submission $.ajax({ url: "{{ route('submit.review') }}", // Update the route if needed method: "POST", data: { agent_id: receiverId, message: message, rating: selectedRating, _token: "{{ csrf_token() }}", }, success: function (response) { if (response.status === "error") { // Show error if the user has already reviewed toastr.error(response.message); } else { toastr.info("Review submitted successfully"); } }, error: function (xhr, status, error) { if (xhr.status === 422) { // Laravel validation error status let errors = xhr.responseJSON.errors; // Display validation errors in the form if (errors.rating) { $("#ratingError").html( '<div class="error-message" style="color: red;">' + errors.rating[0] + "</div>" ); } if (errors.message) { $("#messageError").html( '<div class="error-message" style="color: red;">' + errors.message[0] + "</div>" ); } } else if (xhr.status === 400) { // Handle custom error (already reviewed) toastr.error(xhr.responseJSON.message); } else { // Fallback for unexpected errors toastr.error("Something went wrong. Please try again."); } }, }); }); }); document.addEventListener("DOMContentLoaded", function () { // Function to scroll to the first unread message function scrollToFirstUnread() { var unreadMessage = document.querySelector(".unread-message"); if (unreadMessage) { // Scroll to the first unread message unreadMessage.scrollIntoView({ behavior: "smooth", block: "start", }); } else { // If no unread messages, scroll to the bottom of the chat scrollToBottom(); } } // Function to scroll to the bottom of the chat function scrollToBottom() { var messageContainer = document.querySelector( "#style-4 .force-overflow" ); // Ensure you're targeting the correct container if (messageContainer) { // Scroll to the bottom of the container messageContainer.scrollTop = messageContainer.scrollHeight; console.log( "Scrolled to bottom:", messageContainer.scrollTop, messageContainer.scrollHeight ); // Debugging log } } // Call this function when the page loads scrollToFirstUnread(); // Observe the chat for dynamically added messages var messageContainer = document.querySelector("#style-4 .force-overflow"); var observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { if (mutation.addedNodes.length > 0) { scrollToBottom(); // Always scroll to bottom on new messages } }); }); // Start observing the message container for added messages if (messageContainer) { observer.observe(messageContainer, { childList: true, }); } });
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка