jQuery(function() { var $board = jQuery('.kanban-board'); var $mycard = jQuery('.kanban-card'); if (!$board.length) return; var boardName = $board.data('board'); // Helper to send data to PHP function saveCardData($card) { jQuery.post(DOKU_BASE + 'lib/exe/ajax.php', { call: 'kanban_save', // Match this with your action.php check board: boardName, card_id: $card.data('id'), column: $card.closest('.kanban-col').data('id'), name: $card.find('.card-title').text(), importance: $card.attr('class').split(' ').filter(c => ['high','medium','low'].includes(c))[0] || 'medium', desc: $card.find('.card-desc').text(), note: $card.find('.card-note').text(), checked: $card.find('.checkbox-inline').prop('checked') }).done(function(res){ console.log("Saved:", res); }); } // Prevent movement of the card column placeholder /* jQuery(function() { jQuery(".cards-container").sortable({ // Only allow children WITHOUT the 'fixed-top-item' class to be moved items: "> div:not(.fixed-top)", // Listen for when an item is being moved to a new position update: function(event, ui) { // ui.item.index() returns the current position in the DOM if (ui.item.index() === 0) { // Find the fixed element var $fixed = jQuery(this).find(".fixed-top"); // Immediately force the dropped item to go AFTER the fixed div ui.item.insertAfter($fixed); } } }); }); */ // Initialize Drag and Drop ONCE jQuery(".cards-container").sortable({ connectWith: ".cards-container", placeholder: "ui-sortable-placeholder", tolerance: "pointer", start: function(e, ui) { //start-added const card = document.querySelector('.kanban-card'); distance: 15, // Dragging won't trigger until moved 15px // Add and start the draggable class only AFTER the 15px threshold is met ui.item.addClass("is-dragging"); //distance: -15, // Dragging won't trigger until moved -15px // Add and start the draggable class only AFTER the -15px threshold is met //ui.item.addClass("is-left-dragging"); //end-added ui.placeholder.height(ui.item.outerHeight()); }, stop: function(event, ui) { //Remove the draggable class when you are done ui.item.removeClass("is-dragging"); //ui.item.removeClass("is-left-dragging"); //Fires once when dropped //alert(ui.item.text()); //debugging function works //alert(ui.item.data('id')); //debugging function //saveCardData(ui.item); //Modified to capture the text value in JQuery format //saveCardData(ui.item); saveCardData(ui.item); //replaced to bring about real name for saving //const divId = ui.item.closest('.kanban-col').data('id'); //ui.item.closest('.kanban-col').preventDefault(); // This is required to allow a drop //console.log("Dropped on ID:", divId); } }).disableSelection(); // Fix: Event Delegation for "Add Card" $board.on('click', '.add-card-btn', function() { var name = prompt("Job Name:"); if (!name) return; var imp = (prompt("Importance (high, medium, low):", "medium") || "medium").toLowerCase(); var cardId = "c" + Date.now(); var note = "There are no notes on this card yet."; var $newCard = jQuery(`