phpldapadmin/public/js/custom.js

69 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-09-05 23:46:27 +00:00
function expandChildren(node) {
if (node.data.autoExpand && !node.isExpanded()) {
node.setExpanded(true);
}
if (node.children && node.children.length > 0) {
try {
node.children.forEach(expandChildren);
} catch (error) {
}
}
}
$(document).ready(function() {
2020-09-13 11:30:04 +00:00
// If our bases have been set, we'll render them directly
if (typeof basedn !== 'undefined') {
sources = basedn;
} else {
sources = { url: 'api/bases' };
}
2020-09-05 23:46:27 +00:00
// Attach the fancytree widget to an existing <div id="tree"> element
// and pass the tree options as an argument to the fancytree() function:
$('#tree').fancytree({
clickFolderMode: 3,
extensions: ['glyph'],
autoCollapse: true, // Automatically collapse all siblings, when a node is expanded.
autoScroll: true, // Automatically scroll nodes into visible area.
focusOnSelect: true, // Set focus when node is checked by a mouse click
2020-09-13 11:30:04 +00:00
click: function(event,data) {
if (data.targetType == 'title') {
$.ajax({
url: 'render',
method: 'POST',
data: { key: data.node.data.item },
dataType: 'html',
2020-09-18 14:08:00 +00:00
beforeSend: function() {
content = $('.main-content').contents();
$('.main-content').empty().append('<div class="fa-3x"><i class="fas fa-spinner fa-pulse"></i></div>');
}
2020-09-13 11:30:04 +00:00
}).done(function(html) {
$('.main-content').empty().append(html);
}).fail(function() {
alert('Failed');
});
}
2020-09-05 23:46:27 +00:00
},
2020-09-13 11:30:04 +00:00
source: sources,
2020-09-05 23:46:27 +00:00
lazyLoad: function(event,data) {
data.result = {
url: '/api/children',
2020-09-05 23:46:27 +00:00
data: {key: data.node.data.item,depth: 1}
};
expandChildren(data.tree.rootNode);
},
keydown: function(event, data){
switch( $.ui.fancytree.eventToString(data.originalEvent) ) {
case 'return':
case 'space':
2020-09-05 23:46:27 +00:00
data.node.toggleExpanded();
break;
}
}
});
});