"use strict"; /** confirm modal start */ $.ajaxSetup({ headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), }, }); $(document).on("click", ".confirm-action", function (event) { event.preventDefault(); let url = $(this).data("action") ?? $(this).attr("href"); let method = $(this).data("method") ?? "POST"; let icon = $(this).data("icon") ?? "fas fa-warning"; $.confirm({ title: "Are you sure?", icon: icon, theme: "modern", closeIcon: true, animation: "scale", type: "red", scrollToPreviousElement: false, scrollToPreviousElementAnimate: false, buttons: { confirm: { btnClass: "btn-red", action: function () { event.preventDefault(); $.ajax({ type: method, url: url, success: function (response) { if (response.redirect) { window.sessionStorage.hasPreviousMessage = true; window.sessionStorage.previousMessage = response.message ?? null; location.href = response.redirect; } else { Notify("success", response); } }, error: function (xhr, status, error) { Notify("error", xhr); }, }); }, }, close: { action: function () { this.buttons.close.hide(); }, }, }, }); }); /**confirm modal end */ $('.filter-form').on('input', function (e) { e.preventDefault(); let $form = $(this); let table = $form.attr('table'); let method = $form.attr('method') || "GET"; let url = $form.attr('action') + '?' + $form.serialize(); $.ajax({ type: method, url: url, dataType: "json", success: function (res) { $(table).html(res.data); } }); }); /** filter all from end */ /** DELETE ACTION */ $(document).on("click", ".delete-confirm", function (e) { e.preventDefault(); let t = $(this), o = t.attr("href") ?? t.data("action"), i = t.html(); // Create modal dynamically let confirmationModal = `
`; $("body").append(confirmationModal); // Append modal to the body $("#delete-confirmation-modal").modal("show"); // handle dynamic modal $(".delete-confirmation-button").on("click", function () { $.ajax({ url: o, data: { _token: CSRF_TOKEN }, type: "DELETE", beforeSend: function () { t.html($savingLoader).attr("disabled", true); }, success: function (e) { t.html(i).removeClass("disabled").attr("disabled", false); ajaxSuccess(e, t); }, error: function (e) { t.html(i).removeClass("disabled").attr("disabled", false); Notify(e); }, }); // Hide and remove modal $("#delete-confirmation-modal").modal("hide"); $("#delete-confirmation-modal").remove(); }); }); // Listen for input changes and update feature values accordingly $("#words_limit").on("input", function () { $("#word_feature").val($("#words_limit").val() + " Word Limit"); }); $("#images_limit").on("input", function () { $("#image_feature").val($("#images_limit").val() + " images Limit"); }); $(".exit-branch-btn").on("click", function () { $(".exit-title").text($(this).data("title")); $(".exit-branch").attr("href", $(this).data("exit-url")); $("#exitModal").modal("show"); }); $(document).ready(function () { $(".logoutButton").on("click", function () { document.getElementById("logoutForm").submit(); }); $(document).on('change', '.custom-reports-checkbox', function() { if ($('.custom-reports-checkbox:checked').length === $('.custom-reports-checkbox').length) { $('#selectAll').prop('checked', true); } else { $('#selectAll').prop('checked', false); } }); var reportType = $("#reportType").val(); var reportFields = JSON.parse($("#reportFields").val() || "[]"); var prevFields = JSON.parse($("#prevFields").val() || "[]"); $("#type").on("change", function () { var type = $(this).val(); generateCheckboxes(type); }); if (reportType) { generateCheckboxes(reportType); } // Recursive function to flatten nested fields function flattenFields(obj, prefix = "") { var flat = {}; $.each(obj, function (key, value) { if (value.label !== undefined) { flat[prefix + key] = value; } else { $.extend(flat, flattenFields(value, prefix + key + ".")); } }); return flat; } function generateCheckboxes(type) { if (!type) { $(".select-type-text").text("Select a report type to load fields"); $("#fieldsContainer").empty(); return; } var fields = reportFields[type] || {}; var multibranch_active = $('#multibranch_active').val(); // 🔹 Remove branch if multibranch is not active if (multibranch_active != 1 && fields.branch) { delete fields.branch; } var flatFields = flattenFields(fields); // Create lookup map from prevFields var prevMap = {}; prevFields.forEach(function (item) { prevMap[item.field] = item.order; }); var entries = Object.entries(flatFields); var half = Math.ceil(entries.length / 2); // Helper to build checkbox grid function buildColumn(items) { var html = `