Skip to content

Commit

Permalink
core / treeview - move double click event inside treeview js code for…
Browse files Browse the repository at this point in the history
… easier re-use.
  • Loading branch information
AdSchellevis committed Dec 10, 2023
1 parent b921d8f commit ccee859
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
29 changes: 2 additions & 27 deletions src/opnsense/mvc/app/views/OPNsense/Diagnostics/treeview.volt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}

.modal-body {
max-height: calc(100% - 120px);
height: calc(100% - 120px);
overflow-y: scroll;
}
@media (min-width: 768px) {
Expand All @@ -46,38 +46,13 @@

<script>
$( document ).ready(function() {
let tree = null;
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
$(".tab-icon").removeClass("fa-refresh");
if ($("#"+e.target.id).data('tree-target') !== undefined) {
$("#"+e.target.id).unbind('click').click(function(){
ajaxGet($("#"+e.target.id).data('tree-endpoint'), {}, function (data, status) {
if (status == "success") {
tree = update_tree(data, "#" + $("#"+e.target.id).data('tree-target'));
if (!tree.hasClass('tree_events_added')) {
/* add double click event */
tree.on(
'tree.dblclick',
function(event) {
let table = treeview_node_to_table(event.node);
if (table) {
BootstrapDialog.show({
title: event.node.id,
message: table,
type: BootstrapDialog.TYPE_INFO,
draggable: true,
buttons: [{
label: "{{ lang._('Close') }}",
action: function(dialogItself){
dialogItself.close();
}
}]
});
}
}
);
tree.addClass('tree_events_added');
}
update_tree(data, "#" + $("#"+e.target.id).data('tree-target'));
}
});
});
Expand Down
18 changes: 18 additions & 0 deletions src/opnsense/www/js/opnsense-treeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@ function update_tree(src_data, target)
$tree.bind('tree.click', function(e) {
$tree.tree('toggle', e.node);
});
// open table on label dblclick
$tree.bind('tree.dblclick',function(event) {
let table = treeview_node_to_table(event.node);
if (table) {
BootstrapDialog.show({
title: event.node.id,
message: table,
type: BootstrapDialog.TYPE_INFO,
draggable: true,
buttons: [{
label: '<i class="fa fa-fw fa-close"></i>',
action: function(dialogItself){
dialogItself.close();
}
}]
});
}
});
} else {
let curent_state = $tree.tree('getState');
$tree.tree('loadData', tree_data);
Expand Down

0 comments on commit ccee859

Please sign in to comment.