File manager - Edit - /home/autoph/public_html/projects/tickets-autohub/public/js/authentication/forms/index.js
Back
(function () { "use strict"; var search_type_filter = []; var userTableForms = null; var id = null; var currentPage = 0; function delay(callback, ms) { var timer = 0; return function () { var context = this, args = arguments; clearTimeout(timer); timer = setTimeout(function () { callback.apply(context, args); }, ms || 0); }; } function initActionEdit() { $("[data-action-edit]").each(function (e) { $(this).on('click', function (e) { var row = $(this).closest("tr"); id = userTableForms.row(row).data().id; window.open("/roles/assignment/" + id); // window.location.href = "/roles/assignment/" + id; }); }); } function initActionDestroy() { } function getDataTableData() { var data = {}; // data.status = $('select[name="status"]').val(); return data; } function initList() { $("#txt_search").on( "keyup", delay(function (e) { userTableForms.search($("#txt_search").val()).draw(); }, 500) ); var search_type_default = "Name"; var search_types = ["Name"]; $.each(search_types, function (i, n) { $("._ticket_search_type").append( `<li class="dropdown-item cursor-pointer py-0"><span class="text-sm">` + n + `</span></li>` ); }); $("._ticket_search_type li").each(function () { if ($(this).text() == search_type_default) { $(this).removeClass("active").addClass("active"); var active_items_arr = []; active_items_arr.push(search_type_default); search_type_filter = JSON.stringify(active_items_arr); } $(this).on("click", function () { //remove all selected menu $("._ticket_search_type") .find("li.active") .map(function () { $(this).removeClass("active"); }); $(this).toggleClass("active"); var active_items = $("._ticket_search_type") .find("li.active") .map(function () { var item = {}; // item.id = this.value; item.status = $(this).text(); return item; }); var active_items_arr = []; $.each(active_items, function (i, n) { active_items_arr.push(n.status); }); search_type_filter = JSON.stringify(active_items_arr); // refreshOrcrPlateTable(); // if ($('#txt_search').val() != '') { userTableForms.ajax.reload(); // } }); }); var cols = [ { title: "#", data: '#', className: 'align-middle p-1 dt-left', orderable: true, width: "5%", render: function (data, type, row, meta) { return meta.row + meta.settings._iDisplayStart + 1; } }, { title: "Name", data: null, className: 'align-middle p-1 dt-left', orderable: true, width: "20%", render: function (data, type, row, meta) { var icon = '<i class="fa fa-file text-secondary"></i>'; // Default icon if (data.file_extension) { switch (data.file_extension.toLowerCase()) { case 'pdf': icon = '<i class="fa fa-file-pdf-o text-danger"></i>'; break; case 'doc': case 'docx': icon = '<i class="fa fa-file-word text-primary"></i>'; break; case 'xls': case 'xlsx': icon = '<i class="fa fa-file-excel text-success"></i>'; break; case 'jpg': case 'jpeg': case 'png': case 'gif': icon = '<i class="fa fa-file-image-o text-success"></i>'; break; case 'zip': case 'rar': icon = '<i class="fa fa-file-archive text-muted"></i>'; break; case 'txt': icon = '<i class="fa fa-file-alt text-info"></i>'; break; } } return ` <div class="d-flex align-items-center"> ${icon} <span class="ml-2">${data.name}</span> </div> `; } }, { title: "Department", data: null, className: 'align-middle p-1 dt-left', orderable: true, width: "10%", render: function (data, type, row, meta) { return data.department; } }, { title: "Description", data: null, className: 'align-middle p-1 dt-left', orderable: true, width: "10%", render: function (data, type, row, meta) { return ` <div class="d-flex align-items-center"> <span class="ml-2 text-italic">${data.description}</span> </div> `; } }, { title: "Date uploaded", data: null, className: 'align-middle p-1 dt-left', orderable: true, width: "10%", render: function (data, type, row, meta) { return data.created_at; } }, { title: "Uploaded by", data: null, className: 'align-middle p-1 dt-left', orderable: true, width: "10%", render: function (data, type, row, meta) { return data.created_by; } }, { title: "Action", data: null, className: 'align-middle p-1 dt-left', orderable: false, width: "5%", // Adjust width as needed render: function(data, type, row, meta){ var isAuthorized = (AuthUserRole == 'system-admin' || AuthUserRole == 'department-access'); // Build the dropdown menu var dropdownMenu = ` <div class="btn-group"> <button class="btn btn-sm btn-light dropdown-toggle no-caret" type="button" data-bs-toggle="dropdown" aria-expanded="false" title="Actions"> <i class="fa fa-ellipsis-v" aria-hidden="true"></i> </button> <ul class="dropdown-menu dropdown-menu-end"> <li><a class="dropdown-item" data-action-download data-file-path="${row.file_path}" style="cursor:pointer;"> <i class="fa fa-cloud-download text-info"></i> Download</a> </li> `; // Add the Delete button only for authorized users if (isAuthorized) { dropdownMenu += ` <li><a class="dropdown-item" data-action-delete data-file-path="${row.file_path}" data-record-id="${row.id}" style="cursor:pointer;"> <i class="fa fa-trash-o text-danger"></i> Delete</a> </li> `; } dropdownMenu += `</ul></div>`; // Close dropdown return dropdownMenu; } } ]; var userTableForms = $('#userTableForms').DataTable({ fnDrawCallback: function () { initActionEdit(); }, order: [[0, "desc"]], retrieve: true, columns: cols, paging: true, lengthChange: false, searching: true, pageLength: 10, info: true, autoWidth: true, responsive: true, processing: true, serverSide: true, columnDefs: [ { width: '20%', targets: 0 } ], fixedColumns: true, ajax: { url: '/dl-forms/list-forms', data: function (d) { // Adding custom parameters to the request return $.extend({}, d, { search_type: search_type_filter, data: getDataTableData(), // Sending the page number to the server start: d.start || currentPage * d.length }); }, dataSrc: function (response) { // Preserve the current page currentPage = userTableForms.page(); return response.data; }, error: function (settings, techNote, message) { toastRWithTime("Please check your filter parameter", "error"); } }, sDom: "lrtip", }).on('page', function () { currentPage = userTableForms.page(); // Store the current page number }); } $(function (e) { initList(); $('[name="_reloaduserTableforms"]').on('click', function (e) { userTableForms.draw(false); // Preserve the current page }); }); $(document).on('click', '[data-action-download]', function() { var filePath = $(this).data('file-path'); if (filePath) { var fullUrl = `/storage/${filePath}`; var link = document.createElement("a"); link.href = fullUrl; link.setAttribute("download", ""); // Forces download document.body.appendChild(link); link.click(); document.body.removeChild(link); } else { alert("File not found!"); } }); $(document).on('click', '[data-action-delete]', function() { var filePath = $(this).data('file-path'); var recordId = $(this).data('record-id'); if (!filePath || !recordId) { Swal.fire({ icon: "error", title: "Error", text: "Invalid file or record.", allowOutsideClick: false }); return; } Swal.fire({ title: "Are you sure?", text: "This action will permanently delete the file!", icon: "warning", showCancelButton: true, confirmButtonColor: "#d33", cancelButtonColor: "#3085d6", confirmButtonText: "Yes, delete it!" }).then((result) => { if (result.isConfirmed) { $.ajax({ url: "/dl-forms/delete-file", type: "POST", data: { file_path: filePath, record_id: recordId, _token: $('meta[name="csrf-token"]').attr('content') // Ensure CSRF token is included }, success: function(response) { if (response.success) { Swal.fire({ icon: "success", title: "Deleted!", text: "File has been deleted successfully.", allowOutsideClick: false }).then(() => { location.reload(); // Reload the table after deletion }); } else { Swal.fire({ icon: "error", title: "Error", text: "Failed to delete the file.", allowOutsideClick: false }); } }, error: function() { Swal.fire({ icon: "error", title: "Error", text: "An error occurred while deleting the file.", allowOutsideClick: false }); } }); } }); }); function addNoCaretStyle() { var style = document.createElement('style'); style.type = 'text/css'; style.innerHTML = '.no-caret::after { display: none !important; }'; document.head.appendChild(style); } // Call the function to add the style addNoCaretStyle(); })();
| ver. 1.4 |
.
| PHP 8.1.32 | Generation time: 0.32 |
proxy
|
phpinfo
|
Settings