File manager - Edit - /home/gzbnyc5/pty-app/realstate/public/js/pty.v2.datatable.js
Back
"use strict"; var KTDatatablesServerSide = (function () { // Shared variables var table; var dt; // Private functions var initDatatable = function () { const tableElement = $("#" + PtyDatatableVars.tableDefId); dt = tableElement .DataTable({ info: false, searchDelay: 500, processing: true, serverSide: true, order: [], stateSave: false, select: { style: "os", selector: "td:first-child", className: "row-selected", }, lengthMenu: [ [100, 250, 500, 2000], [100, 250, 500, 2000], ], ajax: { url: viewUrls["list"], data: buildSearchData, method: PtyDatatableVars.ajaxMethod, }, columns: PtyDatatableVars.columns, columnDefs: PtyDatatableVars.columnDefs, createdRow: function (row, data, dataIndex) { if (typeof tableRowTemplateOverride !== "undefined") { tableRowTemplateOverride(row, data, dataIndex); } }, // col-sm-12 col-md-5 d-flex align-items-center justify-content-center justify-content-md-start dom: "<'row'<'col-sm-12 col-md-12 d-flex align-items-center justify-content-center justify-content-md-end'p>><'pty-fake-scrollbar'<>><'table-responsive't><'row'<'col-sm-12 col-md-5 d-flex align-items-center justify-content-center justify-content-md-start'l><'col-sm-12 col-md-7 d-flex align-items-center justify-content-center justify-content-md-end'p>>", }) .on("xhr", function () { const data = dt.ajax.json(); if ($("#pty-table-results-total").length > 0) { let totals = data.meta.total; if (data.count_substract && !isNaN(data.count_substract)) { totals -= data.count_substract; } $("#pty-table-results-total").text(totals); } }); table = dt.$; // Re-init functions on every table re-draw -- more info: https://datatables.net/reference/event/draw dt.on("draw", function () { initToggleToolbar(); toggleToolbars(); handleEditRow(); handleArchiveRow(); handleDeleteRow(); KTMenu.createInstances(); $(".pty-fake-scrollbar > div").css("width", tableElement.width()); }); const fakeScrollBar = $(".pty-fake-scrollbar"); fakeScrollBar.scroll(function () { $(".table-responsive").scrollLeft($(this).scrollLeft()); }); $(".table-responsive").scroll(function () { fakeScrollBar.scrollLeft($(".table-responsive").scrollLeft()); }); }; // Search Datatable --- official docs reference: https://datatables.net/reference/api/search() var handleSearchDatatable = function () { const filterSearch = document.querySelector('[data-kt-table-filter="search"]'); filterSearch.addEventListener("keyup", function (e) { dt.search(e.target.value).draw(); }); }; var buildSearchData = (data) => { data.query = {}; document.querySelectorAll("[data-kt-table-filter-column]").forEach((el) => { const objecType = $(el).attr("type"); const value = objecType == "checkbox" ? ($(el).is(":checked") ? $(el).val() : "") : $(el).val(); if (!value || (value && value.length === 0)) { return; } const column = el.dataset.ktTableFilterColumn; data.query[column] = value; }); return data; }; var handleFilterDatatable = () => { // Select filter options const filterButton = document.querySelector('[data-kt-table-filter="filter"]'); if (!filterButton) { return; } filterButton.addEventListener("click", function (e) { dt.draw(); }); }; // Edit row var handleEditRow = () => { // Select all edit buttons const editButtons = document.querySelectorAll('[data-kt-table-row-action="edit_row"]'); editButtons.forEach((d) => { // Edit button on click d.addEventListener("click", function (e) { const rowId = d.dataset.recordId; const queryStringParts = viewUrls.modify.split("?"); window.location = `${queryStringParts[0]}/${rowId}${queryStringParts.length > 1 ? "?" + queryStringParts[1] : ""}`; }); }); }; // Archive rows var handleArchiveRow = () => { // Select all delete buttons const archiveButtons = document.querySelectorAll('[data-kt-table-row-action="archive_row"],[data-kt-table-row-action="unarchive_row"]'); archiveButtons.forEach((d) => { // Delete button on click d.addEventListener("click", function (e) { e.preventDefault(); // Select parent row const parent = e.target.closest("tr"); // Get the record name const recordNameItem = parent.querySelectorAll(".row-record-name"); const recordName = recordNameItem.length > 0 ? recordNameItem[0].innerText : " this record"; const option = d.dataset.ktTableRowAction === "archive_row" ? "archive" : "unarchive"; const words = option === "archive" ? { processing: "Archiving", processed: "Archived" } : { processing: "Unarchiving", processed: "Unarchived" }; const ids = Array.from(parent.querySelectorAll(".form-check-record-id")).map((input) => Number(input.value)); postRowOptions({ option, ids }, recordName, words); }); }); }; // Delete rows var handleDeleteRow = () => { // Select all delete buttons const deleteButtons = document.querySelectorAll('[data-kt-table-row-action="delete_row"]'); deleteButtons.forEach((d) => { // Delete button on click d.addEventListener("click", function (e) { e.preventDefault(); // Select parent row const parent = e.target.closest("tr"); // Get the record name const recordNameItem = parent.querySelectorAll(".row-record-name"); const recordName = recordNameItem.length > 0 ? recordNameItem[0].innerText : " this record"; // SweetAlert2 pop up --- official docs reference: https://sweetalert2.github.io/ Swal.fire({ text: "Are you sure you want to delete " + recordName + "?", icon: "warning", showCancelButton: true, buttonsStyling: false, confirmButtonText: "Yes, delete!", cancelButtonText: "No, cancel", customClass: { confirmButton: "btn fw-bold btn-danger", cancelButton: "btn fw-bold btn-active-light-primary", }, }).then(function (result) { if (result.value) { const ids = Array.from(parent.querySelectorAll(".form-check-record-id")).map((input) => Number(input.value)); postRowOptions({ option: "delete", ids }, recordName, { processing: "Deleting", processed: "Deleted", }); } else if (result.dismiss === "cancel") { Swal.fire({ text: recordName + " was not deleted.", icon: "error", buttonsStyling: false, confirmButtonText: "Ok, got it!", customClass: { confirmButton: "btn fw-bold btn-primary", }, }); } }); }); }); }; // Init toggle toolbar var initToggleToolbar = function () { // Toggle selected action toolbar // Select all checkboxes const container = document.querySelector("#" + PtyDatatableVars.tableDefId); const checkboxes = container.querySelectorAll('[type="checkbox"]'); // Deselect header checkbox const headerCheckbox = container.querySelectorAll('[type="checkbox"]')[0]; if (headerCheckbox) { headerCheckbox.checked = false; } // Toggle delete selected toolbar checkboxes.forEach((c) => { // Checkbox on click event c.addEventListener("click", function () { setTimeout(function () { toggleToolbars(); }, 50); }); }); }; var initDeleteSelected = function () { const deleteSelected = document.querySelector('[data-kt-table-select="delete_selected"]'); if (!deleteSelected) { return; } deleteSelected.addEventListener("click", function () { // SweetAlert2 pop up --- official docs reference: https://sweetalert2.github.io/ Swal.fire({ text: "Are you sure you want to delete selected records?", icon: "warning", showCancelButton: true, buttonsStyling: false, showLoaderOnConfirm: true, confirmButtonText: "Yes, delete!", cancelButtonText: "No, cancel", customClass: { confirmButton: "btn fw-bold btn-danger", cancelButton: "btn fw-bold btn-active-light-primary", }, }).then(function (result) { if (result.value) { const ids = Array.from(document.querySelectorAll(".form-check-record-id:checked")).map((input) => Number(input.value)); postRowOptions({ option: "delete", ids }, undefined, { processing: "Deleting", processed: "Deleted", }); } else if (result.dismiss === "cancel") { Swal.fire({ text: "Selected records were not deleted.", icon: "error", buttonsStyling: false, confirmButtonText: "Ok, got it!", customClass: { confirmButton: "btn fw-bold btn-primary", }, }); } }); }); }; var initArchiveSelected = function () { const archiveSelected = document.querySelector('[data-kt-table-select="archive_selected"]'); const unarchiveSelected = document.querySelector('[data-kt-table-select="unarchive_selected"]'); if (archiveSelected) { archiveSelected.addEventListener("click", function () { const words = { processing: "Archiving", processed: "Archived" }; const ids = Array.from(document.querySelectorAll(".form-check-record-id:checked")).map((input) => Number(input.value)); postRowOptions({ option: "archive", ids }, undefined, words); }); } if (unarchiveSelected) { unarchiveSelected.addEventListener("click", function () { const words = { processing: "Unarchiving", processed: "Unarchived" }; const ids = Array.from(document.querySelectorAll(".form-check-record-id:checked")).map((input) => Number(input.value)); postRowOptions({ option: "unarchive", ids }, undefined, words); }); } }; // Toggle toolbars var toggleToolbars = function () { // Define variables const container = document.querySelector("#" + PtyDatatableVars.tableDefId); const toolbarBase = document.querySelector('[data-kt-table-toolbar="base"]'); const toolbarSelected = document.querySelector('[data-kt-table-toolbar="selected"]'); const selectedCount = document.querySelector('[data-kt-table-select="selected_count"]'); // Select refreshed checkbox DOM elements const allCheckboxes = container.querySelectorAll('tbody [type="checkbox"]'); // Check if viewing archived records const selectArchived = document.querySelector('[data-kt-table-filter="is_archived"]'); if (selectArchived && selectArchived.value == "N") { $('[data-kt-table-select="archive_selected"').removeAttr("hidden"); $('[data-kt-table-select="unarchive_selected"').attr("hidden", true); } else if (selectArchived && selectArchived.value == "Y") { $('[data-kt-table-select="archive_selected"').attr("hidden", true); $('[data-kt-table-select="unarchive_selected"').removeAttr("hidden"); } // Detect checkboxes state & count let checkedState = false; let count = 0; // Count checked boxes allCheckboxes.forEach((c) => { if (c.checked) { checkedState = true; count++; } }); // Toggle toolbars if (checkedState) { selectedCount.innerHTML = count; toolbarBase.classList.add("d-none"); toolbarSelected.classList.remove("d-none"); } else { toolbarBase.classList.remove("d-none"); toolbarSelected.classList.add("d-none"); } }; // Main Checkbox var initCheck = function () { // Toggle Handler KTUtil.on(document.body, '[data-kt-check="true"]', "change", function (e) { var check = this; var targets = document.querySelectorAll(check.dataset.ktCheckTarget); KTUtil.each(targets, function (target) { if (target.type == "checkbox") { target.checked = check.checked; } else { target.classList.toggle("active"); } }); }); }; // Row option post request var postRowOptions = function (postData, recordName, words) { let textProcessing = `${words.processing} selected records`; let textProcessed = `You have ${words.processed.toLowerCase()} all selected records!.`; const textError = "Sorry, looks like there are some errors detected, please try again."; if (recordName) { textProcessing = `${words.processing} ${recordName}`; textProcessed = `You have ${words.processed.toLowerCase()} ${recordName}!.`; } Swal.fire({ text: textProcessing, icon: "info", buttonsStyling: false, showConfirmButton: false, }); $.ajax({ url: viewUrls["row-options"], dataType: "JSON", type: "POST", data: postData, success: function (response, status, xhr, $form) { if (response.error === 0) { Swal.fire({ text: textProcessed, icon: "success", buttonsStyling: false, confirmButtonText: "Ok, got it!", customClass: { confirmButton: "btn fw-bold btn-primary", }, }).then(function () { dt.draw(); }); } else { swal.fire({ text: textError, icon: "error", buttonsStyling: false, confirmButtonText: "Ok, got it!", customClass: { confirmButton: "btn fw-bold btn-light-primary", }, }); } }, error: function (error) { swal.fire({ text: "Sorry, looks like there are some errors detected, please try again.", icon: "error", buttonsStyling: false, confirmButtonText: "Ok, got it!", customClass: { confirmButton: "btn fw-bold btn-light-primary", }, }); }, }); }; const refreshTable = function () { dt.draw(); }; // Public methods return { init: function () { initDatatable(); initToggleToolbar(); initDeleteSelected(); initArchiveSelected(); initCheck(); handleFilterDatatable(); handleSearchDatatable(); handleEditRow(); handleDeleteRow(); }, refreshTable, }; })(); // On document ready KTUtil.onDOMContentLoaded(function () { KTDatatablesServerSide.init(); });
| ver. 1.4 |
Github
|
.
| PHP 8.2.31 | Generation time: 0 |
proxy
|
phpinfo
|
Settings