-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
164 lines (147 loc) · 4.15 KB
/
script.js
File metadata and controls
164 lines (147 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Code for Modal
const modalElement = document.querySelector("uc-modal");
const confirmButtonLabelElement = document.querySelector(
"#confirm-button-label-input"
);
const cancelButtonLabelElement = document.querySelector(
"#cancel-button-label-input"
);
const checkboxElement = document.querySelector(
`.modal-controls.hide-cancel-button input[type="checkbox"]`
);
const onModalOpenButtonClick = function () {
const confirmLabel = confirmButtonLabelElement?.value;
const cancelLabel = cancelButtonLabelElement?.value;
const hideCancelButton = checkboxElement?.checked;
if (modalElement && !modalElement.isModalOpen) {
const attributeObj = {
"confirm-button-label": confirmLabel,
"cancel-button-label": cancelLabel,
"hide-cancel-button": hideCancelButton,
};
updateModalAttributes(attributeObj);
modalElement.open();
}
};
const updateModalAttributes = function (attributeObj) {
if (modalElement && attributeObj) {
for (const key in attributeObj) {
if (key === "hide-cancel-button") {
if (!attributeObj[key]) {
modalElement.removeAttribute(key);
} else {
modalElement.setAttribute(key, "");
}
} else {
modalElement.setAttribute(key, attributeObj[key]);
}
}
}
};
const resetModalAttributes = function () {
const modalAttributes = [
"confirm-button-label",
"cancel-button-label",
"hide-cancel-button",
];
if (modalElement) {
for (const attribute of modalAttributes) {
modalElement.removeAttribute(attribute);
}
}
};
const onResetControlsButtonClick = function () {
confirmButtonLabelElement.value = "";
cancelButtonLabelElement.value = "";
checkboxElement.checked = false;
};
if (modalElement) {
modalElement.addEventListener("confirm", () => {
console.log("Confirm clicked, closing modal");
});
modalElement.addEventListener("cancel", () => {
console.log("Canceled, closing modal");
});
}
// Code for Drawer
const drawerElement = document.querySelector("uc-drawer");
const onDrawerOpenButtonClick = function (position) {
if (drawerElement && !drawerElement.isDrawerOpen) {
drawerElement.setAttribute("position", position);
drawerElement.open();
}
};
// Code for Tree Structure
const data = [
{
name: "Node 1",
id: "0000001",
children: [
{
name: "Node 1-2",
id: "0000002",
children: [
{
name: "Node 1-2-1",
id: "0000005",
children: [
{
name: "Node 1-2-1-1",
id: "0000001",
children: [],
disabled: true,
},
],
},
],
},
{
name: "Node 1-3",
id: "0000003",
children: [
{ name: "Node 1-3-1", id: "0000006", children: [], disabled: true },
],
},
{ name: "Node 1-4", id: "0000004", children: [] },
],
},
{ name: "Node 2", id: "0000006", children: [] },
];
// For tree component that is selectable
const treeElement = document.querySelector("uc-tree#selectable-tree");
treeElement.data = data;
treeElement.addEventListener("node-click", (event) => {
console.log("Node Clicked", event.detail);
});
// For tree component that is not selectable
const treeElementUnSelectable = document.querySelector(
"uc-tree#un-selectable-tree"
);
treeElementUnSelectable.data = data;
treeElementUnSelectable.addEventListener("node-click", (event) => {
console.log("Node Clicked", event.detail);
});
// Common click events
const onTreeSetSelectedButtonClick = function (type) {
if (type === "selectable") {
treeElement.setSelected("0000005");
} else {
treeElementUnSelectable.setSelected("0000005");
}
};
const onTreeClearSelectedButtonClick = function (type) {
if (type === "selectable") {
treeElement.clearSelected();
} else {
treeElementUnSelectable.clearSelected();
}
};
const onTreeGetSelectedButtonClick = function (type) {
let selected = null;
if (type === "selectable") {
selected = treeElement.getSelected();
} else {
selected = treeElementUnSelectable.getSelected();
}
console.log("Selected node: ", selected);
};