diff --git a/js/Plugin/jstree/hm.jstree.js b/js/Plugin/jstree/hm.jstree.js index 94e48cb355745408225276c3525668b04718c4e2..5b5025a5a11b441213d985d3d35e9492770ba6d5 100644 --- a/js/Plugin/jstree/hm.jstree.js +++ b/js/Plugin/jstree/hm.jstree.js @@ -103,39 +103,12 @@ } }); - // Node selected event. - treeContainer.on("select_node.jstree", function(event, data) { - var href = data.node.a_attr.href; - if (newWindow) { - window.open(href, "_self"); - } - else { - Drupal.ajax({ - url: href, - success: function(response) { - response.forEach(function(element) { - if (element.command && element.data) { - if (element.command === 'insert' && element.selector === null) { - $popDialog[offset] = $('<div>' + element.data + '</div>').appendTo('body'); - } - } - }); - - if ($popDialog[offset]) { - let margin = parseInt(offset * 10 % 40); - let options = { - title: 'Edit ' + data.node.text, - minWidth: 600, - draggable: true, - resizable: true, - autoResize: false, - position: {'my': 'right bottom', 'at':'right-' + margin + ' bottom-' + margin}, - }; - Drupal.dialog($popDialog[offset++], options).show(); - } - } - }).execute(); - } + treeContainer.on('ready.jstree', function (event, data) { + Drupal.attachBehaviors(event.target); + }); + + treeContainer.on('open_node.jstree', function (event, data) { + Drupal.attachBehaviors(event.target); }); // Search filter box. diff --git a/src/Plugin/HmDisplayPlugin/HmDisplayJstree.php b/src/Plugin/HmDisplayPlugin/HmDisplayJstree.php index 6351974ffb92d6a190264e3e52096c9501a29be5..3b590176ed34b6eb03cc1dadc65b065df9e79fd7 100644 --- a/src/Plugin/HmDisplayPlugin/HmDisplayJstree.php +++ b/src/Plugin/HmDisplayPlugin/HmDisplayJstree.php @@ -2,6 +2,7 @@ namespace Drupal\hierarchy_manager\Plugin\HmDisplayPlugin; +use Drupal\Component\Serialization\Json; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\hierarchy_manager\Plugin\HmDisplayPluginInterface; @@ -96,9 +97,18 @@ class HmDisplayJstree extends HmDisplayPluginBase implements HmDisplayPluginInte if (empty($tree_node['parent'])) { $jstree_node['parent'] = '#'; } + + $dialog_options = [ + 'minWidth' => '300', + 'width' => '960', + 'title' => $this->t('Edit') . ' ' . $tree_node['text'], + ]; // Custom data $jstree_node['a_attr'] = [ 'href' => $jstree_node['edit_url'], + 'class' => 'use-ajax', + 'data-dialog-type' => 'modal', + 'data-dialog-options' => Json::encode($dialog_options), ]; unset($jstree_node['edit_url']); // Add this node into the data array.