Skip to content
Snippets Groups Projects
Commit 0869891a authored by Denis K****'s avatar Denis K**** Committed by Mingsong Hu
Browse files

Issue #3188871 by dench0, elgandoz, Mingsong: Ajax Links for the dialog opening

parent d751eebf
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment