Skip to content

Commit

Permalink
Add treeview sync code to the BS5 theme (#1616)
Browse files Browse the repository at this point in the history
Add the treeview sync fix on hover javascript code to the Bootstrap 5
dominion theme.
  • Loading branch information
anvit committed Jul 4, 2023
1 parent 70ac390 commit b0d0011
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions plugins/arDominionB5Plugin/js/fullWidthTreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
this.addButtonSection();
this.$accordionWrapper.after(this.$buttonSection);

// Keep track of which syncs have been initiated
this.syncInitiated = {};

// Declare jsTree options
this.options = {
plugins: ["types", "dnd"],
Expand Down Expand Up @@ -127,6 +130,7 @@
.jstree(options)
.bind("ready.jstree", this.readyListener)
.bind("select_node.jstree", this.selectNodeListener)
.bind("hover_node.jstree", this.hoverNodeListener)
.bind("move_node.jstree", this.moveNodeListener);

// Clicking "more" will add next page of results to tree
Expand Down Expand Up @@ -368,6 +372,42 @@
this.showAlert(moveResponse.success, "alert-info");
}
};

hoverNodeListener = (e, data) => {
let parent = data.node.parent;
let parentNode = this.$fwTreeView.jstree("get_json", parent);

if (
parent != "#" &&
document.cookie.indexOf("atom_authenticated=1") != -1 &&
!(parent in this.syncInitiated) &&
"href" in parentNode.a_attr
) {
this.syncInitiated[parent] = true;
this.commandNodeAndChildren(this.$fwTreeView, parent, "disable_node");

let url =
parentNode.a_attr.href + "/informationobject/fullWidthTreeViewSync";

$.get(url, (response) => {
if (response["repair_successful"] === true) {
// Refresh parent's child nodes if a repair was needed and was successful
this.$fwTreeView.jstree("refresh_node", parent);
} else if (response["repair_successful"] === false) {
// Allow for syncing to be attempted again if a repair was needed, but failed
delete this.syncInitiated[parent];
}

this.commandNodeAndChildren(this.$fwTreeView, parent, "enable_node");
});
}
};

commandNodeAndChildren = ($fwTreeView, id, command) => {
let parent = $fwTreeView.jstree().get_node(id);
$fwTreeView.jstree(command, id);
parent.children.forEach((child) => $fwTreeView.jstree(command, child));
};
}

$(() => {
Expand Down

0 comments on commit b0d0011

Please sign in to comment.