Skip to content
Snippets Groups Projects
Commit c4f0d7f2 authored by Mingsong Hu's avatar Mingsong Hu
Browse files

New feature: In place editor

parent 1c7f906f
No related branches found
No related tags found
No related merge requests found
...@@ -16,15 +16,17 @@ ...@@ -16,15 +16,17 @@
const searchTextID = (parentID) ? '#hm-jstree-search-' + parentID : '#hm-jstree-search'; const searchTextID = (parentID) ? '#hm-jstree-search-' + parentID : '#hm-jstree-search';
const optionsJson = treeContainer.attr("options"); const optionsJson = treeContainer.attr("options");
const dataURL = treeContainer.attr('data-source') + '&parent=0'; const dataURL = treeContainer.attr('data-source') + '&parent=0';
const updateURL = treeContainer.attr('url-update') const updateURL = treeContainer.attr('url-update');
const newWindow = false;
let $popDialog = [];
let reload = true; let reload = true;
let rollback = false; let rollback = false;
let after = 1;
let themes = { let themes = {
dots: false, dots: false,
name: 'default' name: 'default'
}; };
let options; let options;
var offset = 0;
if (optionsJson) { if (optionsJson) {
options = JSON.parse(optionsJson); options = JSON.parse(optionsJson);
...@@ -104,8 +106,36 @@ ...@@ -104,8 +106,36 @@
// Node selected event. // Node selected event.
treeContainer.on("select_node.jstree", function(event, data) { treeContainer.on("select_node.jstree", function(event, data) {
var href = data.node.a_attr.href; var href = data.node.a_attr.href;
// Todo: make the target of the new window configurable. if (newWindow) {
window.open(href, "_self"); 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();
}
}); });
// Search filter box. // Search filter box.
......
...@@ -75,6 +75,7 @@ class HmDisplayJstree extends HmDisplayPluginBase implements HmDisplayPluginInte ...@@ -75,6 +75,7 @@ class HmDisplayJstree extends HmDisplayPluginBase implements HmDisplayPluginInte
$form['#attached']['library'][] = 'hierarchy_manager/libraries.jquery.jstree.' . $theme; $form['#attached']['library'][] = 'hierarchy_manager/libraries.jquery.jstree.' . $theme;
$form['#attached']['library'][] = 'hierarchy_manager/feature.hm.jstree'; $form['#attached']['library'][] = 'hierarchy_manager/feature.hm.jstree';
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
} }
return $form; return $form;
...@@ -96,7 +97,9 @@ class HmDisplayJstree extends HmDisplayPluginBase implements HmDisplayPluginInte ...@@ -96,7 +97,9 @@ class HmDisplayJstree extends HmDisplayPluginBase implements HmDisplayPluginInte
$jstree_node['parent'] = '#'; $jstree_node['parent'] = '#';
} }
// Custom data // Custom data
$jstree_node['a_attr'] = ['href' => $jstree_node['edit_url']]; $jstree_node['a_attr'] = [
'href' => $jstree_node['edit_url'],
];
unset($jstree_node['edit_url']); unset($jstree_node['edit_url']);
// Add this node into the data array. // Add this node into the data array.
$jstree_data[] = $jstree_node; $jstree_data[] = $jstree_node;
......
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