add item to the dropdown menu
This commit is contained in:
57
Asset/js/relocate.js
Normal file
57
Asset/js/relocate.js
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* BulkMoveTasks -- place the "Move tasks in bulk" entry inside the native column menu.
|
||||
*
|
||||
* Kanboard only exposes the template:board:column:dropdown hook AFTER the column menu
|
||||
* <ul>, and its dropdown JS clones just that <ul> when the menu opens. So the hook item
|
||||
* cannot reach the menu on its own. The column_dropdown.php template renders the item
|
||||
* hidden next to the menu; this script moves each such item into that column's real <ul>
|
||||
* so it appears alongside "Hide this column", "Create tasks in bulk", etc.
|
||||
*
|
||||
* It re-runs when the board is redrawn (AJAX polling / drag-and-drop refresh).
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function relocate() {
|
||||
var items = document.querySelectorAll(".bulkmovetasks-menu-item");
|
||||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var li = items[i];
|
||||
|
||||
// Already moved into a menu list: just make sure it is visible.
|
||||
if (li.closest("ul")) {
|
||||
li.style.display = "";
|
||||
continue;
|
||||
}
|
||||
|
||||
// The hook renders the item as a child of the column's dropdown wrapper;
|
||||
// its first <ul> is the native menu.
|
||||
var menu = li.parentNode ? li.parentNode.querySelector("ul") : null;
|
||||
|
||||
if (menu) {
|
||||
menu.appendChild(li);
|
||||
li.style.display = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
if (!document.getElementById("board")) {
|
||||
return;
|
||||
}
|
||||
|
||||
relocate();
|
||||
|
||||
var container = document.getElementById("board-container");
|
||||
|
||||
if (container && window.MutationObserver) {
|
||||
new MutationObserver(relocate).observe(container, { childList: true, subtree: true });
|
||||
}
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
})();
|
||||
@@ -8,9 +8,14 @@ class Plugin extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
// Add a "Move all tasks to another column" entry to the board column
|
||||
// header dropdown. The hook passes the current $column and $swimlane.
|
||||
// Render the "Move tasks in bulk" entry. The only column hook sits outside the
|
||||
// native menu <ul>, so column_dropdown.php renders it hidden and relocate.js
|
||||
// moves it into the menu (passes the current $column and $swimlane).
|
||||
$this->template->hook->attach('template:board:column:dropdown', 'bulkMoveTasks:board/column_dropdown');
|
||||
|
||||
$this->hook->on('template:layout:js', array(
|
||||
'template' => 'plugins/BulkMoveTasks/Asset/js/relocate.js',
|
||||
));
|
||||
}
|
||||
|
||||
public function getPluginName()
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<?php if ($column['nb_tasks'] > 0 && $this->user->hasProjectAccess('TaskModificationController', 'update', $column['project_id'])): ?>
|
||||
<li>
|
||||
<?= $this->modal->medium('arrows-h', t('Move all tasks to another column'), 'BulkMoveController', 'show', array(
|
||||
<?php /* Rendered here (outside the menu <ul>) by the only available hook, then moved
|
||||
into the column's real dropdown <ul> by Asset/js/relocate.js so it sits next
|
||||
to the native entries. Hidden until relocated to avoid a flash in the header. */ ?>
|
||||
<li class="bulkmovetasks-menu-item" style="display: none;">
|
||||
<?= $this->modal->medium('arrows-h', t('Move tasks in bulk'), 'BulkMoveController', 'show', array(
|
||||
'plugin' => 'BulkMoveTasks',
|
||||
'project_id' => $column['project_id'],
|
||||
'column_id' => $column['id'],
|
||||
|
||||
Reference in New Issue
Block a user