mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-09-10 18:34:09 +08:00
60 lines
1.6 KiB
HTML
60 lines
1.6 KiB
HTML
<%
|
|
local map = self.map
|
|
local api = map.api
|
|
local appname = map.config
|
|
local section = self.section
|
|
-%>
|
|
<script type="text/javascript">
|
|
//<![CDATA[
|
|
const shunt_list = JSON.parse('<%=self.shunt_list%>');
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
const id = "cbid.<%=appname%>.<%=section%>.node";
|
|
let node = null;
|
|
const onChange = (e) => {
|
|
const new_val = e.target.value;
|
|
const new_hasItem = shunt_list.some(element => element.id == new_val);
|
|
if (new_hasItem) {
|
|
XHR.get('<%=api.url("update_config")%>', {
|
|
id: "<%=section%>",
|
|
data: JSON.stringify({
|
|
node: new_val,
|
|
mode: "1"
|
|
})
|
|
}, function(x, data) {
|
|
if (x && x.status == 200 && data.code == 1) {
|
|
window.location.reload();
|
|
} else {
|
|
alert("<%:Error%>");
|
|
}
|
|
});
|
|
} else {
|
|
document.getElementById("cbi-<%=appname%>-shunt_option_list")?.style.setProperty("display", "none");
|
|
}
|
|
};
|
|
const check = () => {
|
|
const el = document.getElementById(id);
|
|
if (el === node) return;
|
|
if (node && !el) {
|
|
document.getElementById("cbi-<%=appname%>-shunt_option_list")?.style.setProperty("display", "none");
|
|
} else {
|
|
let o_hasItem = shunt_list.some(element => element.id == el.value);
|
|
if (o_hasItem) {
|
|
document.getElementById("cbi-<%=appname%>-shunt_option_list")?.style.setProperty("display", "");
|
|
}
|
|
}
|
|
node = el;
|
|
if (node) {
|
|
node.addEventListener("change", onChange);
|
|
}
|
|
};
|
|
const observer = new MutationObserver(check);
|
|
observer.observe(document.body, {
|
|
childList: true,
|
|
subtree: true
|
|
});
|
|
check();
|
|
});
|
|
//]]>
|
|
</script>
|