From 0869891af46e0417a5da4d71635ccd179c6dde5b Mon Sep 17 00:00:00 2001 From: dench0 <dench0@896504.no-reply.drupal.org> Date: Tue, 5 Jan 2021 10:50:59 +1100 Subject: [PATCH] Issue #3188871 by dench0, elgandoz, Mingsong: Ajax Links for the dialog opening --- js/Plugin/jstree/hm.jstree.js | 39 +++---------------- .../HmDisplayPlugin/HmDisplayJstree.php | 10 +++++ 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/js/Plugin/jstree/hm.jstree.js b/js/Plugin/jstree/hm.jstree.js index 94e48cb..5b5025a 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 6351974..3b59017 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. -- GitLab