Edit: project-dashboard.js
jQuery(document).ready(function ($) { "use strict"; function showToast(message, type = "success") { const toast = $('<div class="dnxte-toast"></div>') .text(message) .addClass(type) .appendTo("body"); setTimeout(() => toast.addClass("show"), 50); setTimeout(() => { toast.removeClass("show"); setTimeout(() => toast.remove(), 300); }, 3000); } function toggleRenameOptions() { const isRenameChecked = $("#dnxte_rename_projects_cpt").is(":checked"); const $renameFields = $("#dnxte_rename_projects_cpt") .closest(".dnext-ee-row") .nextAll(".dnext-ee-row") .slice(0, 8); // Adjust the number of rows if needed if (isRenameChecked) { $renameFields.show(); } else { $renameFields.hide(); } } function toggleProjectOptions() { const isHideChecked = $("#dnxte_hide_projects").is(":checked"); const $projectRow = $("#dnxte_hide_projects").closest(".dnext-ee-row"); const $followingRows = $projectRow.nextAll(".dnext-ee-row"); if (isHideChecked) { $followingRows.hide(); } else { $followingRows.show(); toggleRenameOptions(); // Apply rename logic after showing } } // Initial state setup toggleProjectOptions(); // Event bindings $("#dnxte_hide_projects").on("change", function () { toggleProjectOptions(); }); $("#dnxte_rename_projects_cpt").on("change", function () { const isHideChecked = $("#dnxte_hide_projects").is(":checked"); if (!isHideChecked) { toggleRenameOptions(); } }); // Sanitize slug function for project-cpt slug, tag, and cat function sanitizeSlug(str) { return str .toLowerCase() .replace(/[\s-]+/g, '_') // replace spaces and dashes with underscore .replace(/[^a-z0-9_]/g, '') // remove anything that's not a-z, 0-9, or underscore .replace(/_+/g, '_') // collapse multiple underscores .replace(/^_+|_+$/g, ''); // trim leading/trailing underscores } $('#dnxte_project_slug, #dnxte_project_category_slug, #dnxte_project_tag_slug').on('blur', function() { const formatted = sanitizeSlug($(this).val()); $(this).val(formatted); }); // AJAX save handler $(".dnext-pe-wrapper form").on("submit", function (e) { e.preventDefault(); const $form = $(this); const formData = $form.serialize(); $.ajax({ url: ajaxurl, type: "POST", data: formData, success: function (response) { if (response.success) { showToast("Settings saved successfully.", "success"); window.location.reload(); } else { showToast("Failed to save settings.", "error"); } }, error: function (xhr, status, error) { showToast("AJAX error: " + error, "error"); } }); }); // Dashicons picker $('.dnxte-open-dashicon-picker').on('click', function(e) { e.preventDefault(); $(this).siblings('.dnxte-dashicon-picker-container').show(); }); // Close dashicon picker $('.dnxte-close-dashicon-picker').on('click', function() { $(this).closest('.dnxte-dashicon-picker-container').hide(); }); // Dashicon selection $('.dnxte-dashicon-item').on('click', function() { const $item = $(this); const iconClass = $item.data('icon'); const $selector = $item.closest('.dnxte-dashicon-selector'); // Remove previous selection $selector.find('.dnxte-dashicon-item').removeClass('selected'); $item.addClass('selected'); // Update hidden input $selector.find('input[type="hidden"]').val(iconClass); // Update visible icon $selector.find('.dnxte-icon-input-wrapper .dashicons') .removeClass() .addClass('dashicons ' + iconClass); // Update visible name span $selector.find('.dnxte-dashicon-name').text(iconClass); // Update input text value $selector.find('#dnxte_project_dashboard_icon').val(iconClass); // Close picker $selector.find('.dnxte-dashicon-picker-container').hide(); }); // Dashicon search $('.dnxte-dashicon-search').on('input', function() { const term = $(this).val().toLowerCase(); $(this).closest('.dnxte-dashicon-picker-container').find('.dnxte-dashicon-item').each(function() { const $icon = $(this); const iconName = $icon.data('icon').toLowerCase(); $icon.toggle(iconName.includes(term)); }); }); });
Save
Back