phpldapadmin/public/js/custom.js

109 lines
3.0 KiB
JavaScript
Raw Permalink 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) {
}
}
}
2023-03-31 04:55:08 +00:00
function getNode(item) {
$.ajax({
2023-09-02 10:50:54 +00:00
url: '/dn',
2023-03-31 04:55:08 +00:00
method: 'POST',
data: { key: item },
dataType: 'html',
beforeSend: function() {
content = $('.main-content').contents();
$('.main-content').empty().append('<div class="fa-3x"><i class="fas fa-spinner fa-pulse"></i></div>');
}
}).done(function(html) {
$('.main-content').empty().append(html);
}).fail(function(item) {
switch(item.status) {
case 404:
$('.main-content').empty().append(item.responseText);
break;
case 419:
alert('Session has expired, reloading the page and try again...');
location.reload();
break;
case 500:
$('.main-content').empty().append(item.responseText);
break;
default:
alert(item.status+': Well that didnt work?');
}
});
}
2020-09-05 23:46:27 +00:00
$(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,
2023-03-27 11:23:23 +00:00
extensions: ['glyph','persist'],
2020-09-05 23:46:27 +00:00
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
glyph: {
preset: 'bootstrap3', // @todo look at changing this to awesome5
map: {}
},
2023-03-27 11:23:23 +00:00
persist: {
// Available options with their default:
cookieDelimiter: '~', // character used to join key strings
cookiePrefix: undefined, // 'fancytree-<treeId>-' by default
cookie: { // settings passed to jquery.cookie plugin
raw: false,
expires: '',
path: '',
domain: '',
secure: false
},
expandLazy: true, // true: recursively expand and load lazy nodes
expandOpts: undefined, // optional `opts` argument passed to setExpanded()
overrideSource: true, // true: cookie takes precedence over `source` data attributes.
store: 'auto', // 'cookie': use cookie, 'local': use localStore, 'session': use sessionStore
types: 'active expanded focus selected' // which status types to store
},
2020-09-13 11:30:04 +00:00
click: function(event,data) {
if (data.targetType == 'title') {
2023-03-31 04:55:08 +00:00
getNode(data.node.data.item);
2020-09-13 11:30:04 +00:00
}
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);
},
2023-03-31 04:55:08 +00:00
keydown: function(event,data){
2020-09-05 23:46:27 +00:00
switch( $.ui.fancytree.eventToString(data.originalEvent) ) {
case 'return':
case 'space':
2020-09-05 23:46:27 +00:00
data.node.toggleExpanded();
break;
}
2023-03-31 04:55:08 +00:00
},
restore: function(event,data) {
//getNode(data.tree.getActiveNode().data.item);
2020-09-05 23:46:27 +00:00
}
});
});