diff --git a/js/Plugin/fancytree/hm.fancytree.js b/js/Plugin/fancytree/hm.fancytree.js deleted file mode 100644 index e44ba1fc6ae71da4d9dcb8437e4b733658ff486f..0000000000000000000000000000000000000000 --- a/js/Plugin/fancytree/hm.fancytree.js +++ /dev/null @@ -1,165 +0,0 @@ -(function($, Drupal) { - $(document).ready(() => { - $(".fancytree").each(function(index) { - const $treeElement = $(this); - const sourceURL = $treeElement.attr("data-source"); - const updateURL = $treeElement.attr("url-update"); - $treeElement.fancytree({ - extensions: ["dnd5", "filter"], - source: { - url: sourceURL, - data: { depth: 1, parent: 0 }, - cache: false - }, - // Event handler - dblclick: function(event, data) { - const node = data.node; - if (node.data.edit_url) { - event.stopPropagation(); - event.preventDefault(); - // Todo: make the target of the new window configurable. - window.open(node.data.edit_url, "_self"); - } - }, - // Called when a lazy node is expanded for the first time: - lazyLoad: function(event, data) { - const node = data.node; - // Load child nodes via Ajax GET sourceURL?depth=1&parent={node.key} - data.result = { - url: sourceURL, - data: { depth: 1, parent: node.key }, - cache: false - }; - }, - filter: { - autoApply: true, // Re-apply last filter if lazy data is loaded - autoExpand: true, // Expand all branches that contain matches while filtered - counter: true, // Show a badge with number of matching child nodes near parent icons - fuzzy: false, // Match single characters in order, e.g. 'fb' will match 'FooBar' - hideExpandedCounter: false, // Hide counter badge if parent is expanded - hideExpanders: false, // Hide expanders if all child nodes are hidden by filter - highlight: true, // Highlight matches by wrapping inside <mark> tags - leavesOnly: false, // Match end nodes only - nodata: true, // Display a 'no data' status node if result is empty - mode: "hide" // Grayout unmatched nodes (pass "hide" to remove unmatched node instead) - }, - dnd5: { - // autoExpandMS: 400, - preventForeignNodes: true, - preventNonNodes: true, - preventRecursion: true, // Prevent dropping nodes on own descendants - // preventSameParent: true, - preventVoidMoves: true, // Prevent moving nodes 'before self', etc. - // effectAllowed: "all", - // dropEffectDefault: "move", // "auto", - - // --- Drag-support: - - dragStart: function(node, data) { - /* This function MUST be defined to enable dragging for the tree. - * - * Return false to cancel dragging of node. - * data.dataTransfer.setData() and .setDragImage() is available - * here. - */ - - // Return true to allow the drag operation - return true; - }, - dragEnter: function(node, data) { - return true; - }, - dragDrop: function(node, data) { - /* This function MUST be defined to enable dropping of items on - * the tree. - */ - const mode = data.dropEffect; - - if (data.otherNode) { - // Drop another Fancytree node from same frame (maybe a different tree however) - // var sameTree = (data.otherNode.tree === data.tree); - - if (mode === "move") { - let parentKey; - const childrenNodeIDs = []; - let i = 0; - const hitMode = - data.hitMode === "over" ? "firstChild" : data.hitMode; - - // Get all nodes moving. - data.otherNodeList.forEach(element => { - childrenNodeIDs[i++] = element.key; - }); - // The parent key of the target. - parentKey = node.parent.key; - - // For drupal, the ID of the root node is 0. - if (parentKey === "root_1") { - parentKey = 0; - } - // Update the data on server side. - $.post(updateURL, { - keys: childrenNodeIDs, - target: node.key, - parent: parentKey, - mode: hitMode - }) - .done(response => { - if (response.result === "success") { - // Move the nodes. - data.otherNode.moveTo(node, hitMode, function (affectedNodes) { - let parentNode = affectedNodes.parent; - if (parentNode) { - if (!parentNode.folder) { - parentNode.folder = true; - } - else { - /* if (!parentNode.lazy) { - parentNode.lazy = true; - } - parentNode.load(true);*/ - } - } - }); - } else { - alert("Server error:" + response.result); - } - }) - .fail(() => { - alert("Error: Can't connect to the server."); - }); - } else { - /* Todo: duplicate nodes - */ - } - } else if (data.otherNodeData) { - // Drop Fancytree node from different frame or window, so we only have - // JSON representation available - /* Todo: move node from different tree - node.addChild(data.otherNodeData, data.hitMode); - */ - } - node.setExpanded(); - } - }, - }); - }); - - // Event handlers. - $("input[name=fancytree-search]") - .on("keyup", function(e) { - // Todo: Deal with multiple tree and search text field. - const tree = $.ui.fancytree.getTree(); - const match = $(this).val(); - - if ((e && e.which === $.ui.keyCode.ESCAPE) || $.trim(match) === "") { - tree.clearFilter(); - return; - } - - // Pass a string to perform case insensitive matching - tree.filterBranches(match); - }) - .focus(); - }); -})(jQuery, Drupal); diff --git a/src/Plugin/HmDisplayPlugin/HmDisplayFancytree.php b/src/Plugin/HmDisplayPlugin/HmDisplayFancytree.php deleted file mode 100644 index 63ded5924905e5f7ea0ff0ea2af14b0be779009b..0000000000000000000000000000000000000000 --- a/src/Plugin/HmDisplayPlugin/HmDisplayFancytree.php +++ /dev/null @@ -1,82 +0,0 @@ -<?php - -namespace Drupal\hierarchy_manager\Plugin\HmDisplayPlugin; - -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\hierarchy_manager\Plugin\HmDisplayPluginInterface; -use Drupal\hierarchy_manager\Plugin\HmDisplayPluginBase; - -/** - * Fancytree display plugin. - * - * @HmDisplayPlugin( - * id = "hm_display_fancytree", - * label = @Translation("Fancytree") - * ) - */ -class HmDisplayFancytree extends HmDisplayPluginBase implements HmDisplayPluginInterface { - use StringTranslationTrait; - - /** - * {@inheritdoc} - */ - public function getForm(string $url_source, string $url_update, array &$form = [], FormStateInterface &$form_state = NULL) { - /* if (!empty($url_source)) { - // Search input. - $form['title'] = [ - '#type' => 'textfield', - '#title' => $this - ->t('Search'), - '#description' => $this->t('Type in the search keyword here to filter the tree below. Empty the keyword or press ESC key to reset the tree.'), - '#attributes' => [ - 'name' => 'fancytree-search', - ], - '#size' => 60, - '#maxlength' => 128, - ]; - - $form['fancytree'] = [ - '#type' => 'html_tag', - '#suffix' => '<div class="description">' . $this->t('You can double click a taxonomy term to edit it.') . '<br>' . $this->t('A taxonomy term in the tree above can be dragged and dropped') . '</div>', - '#tag' => 'div', - '#value' => '', - '#attributes' => [ - 'class' => [ - 'fancytree', - ], - 'data-source' => $url_source, - 'url-update' => $url_update, - ], - ]; - - $form['#attached']['library'][] = 'hierarchy_manager/libraries.jquery.fancytree'; - $form['#attached']['library'][] = 'hierarchy_manager/libraries.jquery.fancytree.skin-win8'; - $form['#attached']['library'][] = 'hierarchy_manager/feature.hm.fancytree'; - } -*/ - return $form; - } - - /** - * Build the data array that FancyTree accepts. - */ - public function treeData(array $data) { - $fancytree_data = []; - - // The array key of Fancytree is different from the data source. - // So we need to translate them. - foreach ($data as $tree_node) { - $fancytree_node = $tree_node; - $fancytree_node['key'] = $fancytree_node['id']; - unset($fancytree_node['id']); - $fancytree_node['folder'] = $fancytree_node['lazy'] = $fancytree_node['has_children']; - unset($fancytree_node['has_children']); - // Add this node into the data array. - $fancytree_data[] = $fancytree_node; - } - - return $fancytree_data; - } - -}