2021-12-22 23:41:59 +00:00
|
|
|
/**
|
|
|
|
* Template Name: NiceAdmin - v2.2.0
|
|
|
|
* Template URL: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/
|
|
|
|
* Author: BootstrapMade.com
|
|
|
|
* License: https://bootstrapmade.com/license/
|
|
|
|
*/
|
2022-04-12 11:59:25 +00:00
|
|
|
(function () {
|
2021-12-22 23:41:59 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Easy selector helper function
|
|
|
|
*/
|
|
|
|
const select = (el, all = false) => {
|
|
|
|
el = el.trim()
|
|
|
|
if (all) {
|
|
|
|
return [...document.querySelectorAll(el)]
|
2022-04-29 12:07:04 +00:00
|
|
|
}
|
|
|
|
return document.querySelector(el)
|
|
|
|
|
2021-12-22 23:41:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Easy event listener function
|
|
|
|
*/
|
|
|
|
const on = (type, el, listener, all = false) => {
|
|
|
|
if (all) {
|
|
|
|
select(el, all).forEach(e => e.addEventListener(type, listener))
|
|
|
|
} else {
|
|
|
|
select(el, all).addEventListener(type, listener)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Easy on scroll event listener
|
|
|
|
*/
|
|
|
|
const onscroll = (el, listener) => {
|
2022-04-20 10:04:53 +00:00
|
|
|
el.addEventListener("scroll", listener)
|
2021-12-22 23:41:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sidebar toggle
|
|
|
|
*/
|
2022-04-20 10:04:53 +00:00
|
|
|
if (select(".toggle-sidebar-btn")) {
|
|
|
|
on("click", ".toggle-sidebar-btn", (e) => {
|
|
|
|
select("body").classList.toggle("toggle-sidebar")
|
2021-12-22 23:41:59 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search bar toggle
|
|
|
|
*/
|
2022-04-20 10:04:53 +00:00
|
|
|
if (select(".search-bar-toggle")) {
|
|
|
|
on("click", ".search-bar-toggle", (e) => {
|
|
|
|
select(".search-bar").classList.toggle("search-bar-show")
|
2021-12-22 23:41:59 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Navbar links active state on scroll
|
|
|
|
*/
|
2022-04-20 10:04:53 +00:00
|
|
|
const navbarlinks = select("#navbar .scrollto", true)
|
2021-12-22 23:41:59 +00:00
|
|
|
const navbarlinksActive = () => {
|
2022-04-20 10:04:53 +00:00
|
|
|
const position = window.scrollY + 200
|
2021-12-22 23:41:59 +00:00
|
|
|
navbarlinks.forEach(navbarlink => {
|
|
|
|
if (!navbarlink.hash) return
|
2022-04-20 10:04:53 +00:00
|
|
|
const section = select(navbarlink.hash)
|
2021-12-22 23:41:59 +00:00
|
|
|
if (!section) return
|
|
|
|
if (position >= section.offsetTop && position <= (section.offsetTop + section.offsetHeight)) {
|
2022-04-20 10:04:53 +00:00
|
|
|
navbarlink.classList.add("active")
|
2021-12-22 23:41:59 +00:00
|
|
|
} else {
|
2022-04-20 10:04:53 +00:00
|
|
|
navbarlink.classList.remove("active")
|
2021-12-22 23:41:59 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-04-20 10:04:53 +00:00
|
|
|
window.addEventListener("load", navbarlinksActive)
|
2021-12-22 23:41:59 +00:00
|
|
|
onscroll(document, navbarlinksActive)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle .header-scrolled class to #header when page is scrolled
|
|
|
|
*/
|
2022-04-20 10:04:53 +00:00
|
|
|
const selectHeader = select("#header")
|
2021-12-22 23:41:59 +00:00
|
|
|
if (selectHeader) {
|
|
|
|
const headerScrolled = () => {
|
|
|
|
if (window.scrollY > 100) {
|
2022-04-20 10:04:53 +00:00
|
|
|
selectHeader.classList.add("header-scrolled")
|
2021-12-22 23:41:59 +00:00
|
|
|
} else {
|
2022-04-20 10:04:53 +00:00
|
|
|
selectHeader.classList.remove("header-scrolled")
|
2021-12-22 23:41:59 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-20 10:04:53 +00:00
|
|
|
window.addEventListener("load", headerScrolled)
|
2021-12-22 23:41:59 +00:00
|
|
|
onscroll(document, headerScrolled)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Back to top button
|
|
|
|
*/
|
2022-04-20 10:04:53 +00:00
|
|
|
const backtotop = select(".back-to-top")
|
2021-12-22 23:41:59 +00:00
|
|
|
if (backtotop) {
|
|
|
|
const toggleBacktotop = () => {
|
|
|
|
if (window.scrollY > 100) {
|
2022-04-20 10:04:53 +00:00
|
|
|
backtotop.classList.add("active")
|
2021-12-22 23:41:59 +00:00
|
|
|
} else {
|
2022-04-20 10:04:53 +00:00
|
|
|
backtotop.classList.remove("active")
|
2021-12-22 23:41:59 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-20 10:04:53 +00:00
|
|
|
window.addEventListener("load", toggleBacktotop)
|
2021-12-22 23:41:59 +00:00
|
|
|
onscroll(document, toggleBacktotop)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initiate tooltips
|
|
|
|
*/
|
2022-04-20 10:04:53 +00:00
|
|
|
const tooltipTriggerList = [].slice.call(document.querySelectorAll("[data-bs-toggle=\"tooltip\"]"))
|
|
|
|
const tooltipList = tooltipTriggerList.map((tooltipTriggerEl) => new bootstrap.Tooltip(tooltipTriggerEl))
|
2021-12-22 23:41:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initiate quill editors
|
|
|
|
*/
|
2022-04-20 10:04:53 +00:00
|
|
|
if (select(".quill-editor-default")) {
|
|
|
|
new Quill(".quill-editor-default", {
|
|
|
|
theme: "snow"
|
2021-12-22 23:41:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-20 10:04:53 +00:00
|
|
|
if (select(".quill-editor-bubble")) {
|
|
|
|
new Quill(".quill-editor-bubble", {
|
|
|
|
theme: "bubble"
|
2021-12-22 23:41:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-20 10:04:53 +00:00
|
|
|
if (select(".quill-editor-full")) {
|
2021-12-22 23:41:59 +00:00
|
|
|
new Quill(".quill-editor-full", {
|
|
|
|
modules: {
|
|
|
|
toolbar: [
|
|
|
|
[{
|
|
|
|
font: []
|
|
|
|
}, {
|
|
|
|
size: []
|
|
|
|
}],
|
|
|
|
["bold", "italic", "underline", "strike"],
|
|
|
|
[{
|
2022-04-12 11:41:18 +00:00
|
|
|
color: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
background: []
|
|
|
|
}
|
2021-12-22 23:41:59 +00:00
|
|
|
],
|
|
|
|
[{
|
2022-04-12 11:41:18 +00:00
|
|
|
script: "super"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
script: "sub"
|
|
|
|
}
|
2021-12-22 23:41:59 +00:00
|
|
|
],
|
|
|
|
[{
|
2022-04-12 11:41:18 +00:00
|
|
|
list: "ordered"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
list: "bullet"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indent: "-1"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indent: "+1"
|
|
|
|
}
|
2021-12-22 23:41:59 +00:00
|
|
|
],
|
|
|
|
["direction", {
|
|
|
|
align: []
|
|
|
|
}],
|
|
|
|
["link", "image", "video"],
|
|
|
|
["clean"]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
theme: "snow"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initiate Bootstrap validation check
|
|
|
|
*/
|
2022-04-20 10:04:53 +00:00
|
|
|
const needsValidation = document.querySelectorAll(".needs-validation")
|
2021-12-22 23:41:59 +00:00
|
|
|
|
|
|
|
Array.prototype.slice.call(needsValidation)
|
2022-04-20 10:04:53 +00:00
|
|
|
.forEach((form) => {
|
|
|
|
form.addEventListener("submit", (event) => {
|
2021-12-22 23:41:59 +00:00
|
|
|
if (!form.checkValidity()) {
|
|
|
|
event.preventDefault()
|
|
|
|
event.stopPropagation()
|
|
|
|
}
|
|
|
|
|
2022-04-20 10:04:53 +00:00
|
|
|
form.classList.add("was-validated")
|
2021-12-22 23:41:59 +00:00
|
|
|
}, false)
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initiate Datatables
|
|
|
|
*/
|
2022-04-20 10:04:53 +00:00
|
|
|
const datatables = select(".datatable", true)
|
2021-12-22 23:41:59 +00:00
|
|
|
datatables.forEach(datatable => {
|
|
|
|
new simpleDatatables.DataTable(datatable);
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Autoresize echart charts
|
|
|
|
*/
|
2022-04-20 10:04:53 +00:00
|
|
|
const mainContainer = select("#main");
|
2022-04-12 11:59:25 +00:00
|
|
|
if (mainContainer) {
|
|
|
|
setTimeout(() => {
|
2022-04-20 10:04:53 +00:00
|
|
|
new ResizeObserver(() => {
|
|
|
|
select(".echart", true).forEach(getEchart => {
|
2022-04-12 11:59:25 +00:00
|
|
|
echarts.getInstanceByDom(getEchart).resize();
|
|
|
|
})
|
|
|
|
}).observe(mainContainer);
|
|
|
|
}, 200);
|
|
|
|
}
|
2021-12-22 23:41:59 +00:00
|
|
|
|
2022-04-12 09:38:31 +00:00
|
|
|
/**
|
|
|
|
* Avoid hide dropdown when user clicked inside
|
|
|
|
*/
|
2022-05-22 16:20:04 +00:00
|
|
|
const dropdownLotSelector = document.getElementById("dropDownLotsSelector")
|
|
|
|
if (dropdownLotSelector != null) { // If exists selector it will set click event
|
|
|
|
dropdownLotSelector.addEventListener("click", event => {
|
|
|
|
event.stopPropagation();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-04-12 09:38:31 +00:00
|
|
|
|
2022-04-12 11:41:18 +00:00
|
|
|
/**
|
|
|
|
* Search form functionality
|
|
|
|
*/
|
|
|
|
window.addEventListener("DOMContentLoaded", () => {
|
2022-04-20 10:04:53 +00:00
|
|
|
const searchForm = document.getElementById("SearchForm")
|
|
|
|
const inputSearch = document.querySelector("#SearchForm > input")
|
|
|
|
const doSearch = true
|
2022-04-12 11:41:18 +00:00
|
|
|
|
|
|
|
searchForm.addEventListener("submit", (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
})
|
|
|
|
|
|
|
|
let timeoutHandler = setTimeout(() => { }, 1)
|
2022-04-20 10:04:53 +00:00
|
|
|
const dropdownList = document.getElementById("dropdown-search-list")
|
|
|
|
const defaultEmptySearch = document.getElementById("dropdown-search-list").innerHTML
|
2022-04-12 11:41:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
inputSearch.addEventListener("input", (e) => {
|
|
|
|
clearTimeout(timeoutHandler)
|
2022-04-20 10:04:53 +00:00
|
|
|
const searchText = e.target.value
|
|
|
|
if (searchText == "") {
|
2022-04-12 11:41:18 +00:00
|
|
|
document.getElementById("dropdown-search-list").innerHTML = defaultEmptySearch;
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let resultCount = 0;
|
|
|
|
function searchCompleted() {
|
|
|
|
resultCount++;
|
2022-04-12 11:59:25 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
if (resultCount == 2 && document.getElementById("dropdown-search-list").children.length == 2) {
|
2022-04-12 11:41:18 +00:00
|
|
|
document.getElementById("dropdown-search-list").innerHTML = `
|
|
|
|
<li id="deviceSearchLoader" class="dropdown-item">
|
|
|
|
<i class="bi bi-x-lg"></i>
|
|
|
|
<span style="margin-right: 10px">Nothing found</span>
|
|
|
|
</li>`
|
2022-04-12 11:59:25 +00:00
|
|
|
}
|
|
|
|
}, 100)
|
2022-04-12 11:41:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
timeoutHandler = setTimeout(async () => {
|
|
|
|
dropdownList.innerHTML = `
|
|
|
|
<li id="deviceSearchLoader" class="dropdown-item">
|
|
|
|
<i class="bi bi-laptop"></i>
|
|
|
|
<div class="spinner-border spinner-border-sm" role="status">
|
|
|
|
<span class="visually-hidden">Loading...</span>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<li id="lotSearchLoader" class="dropdown-item">
|
|
|
|
<i class="bi bi-folder2"></i>
|
|
|
|
<div class="spinner-border spinner-border-sm" role="status">
|
|
|
|
<span class="visually-hidden">Loading...</span>
|
|
|
|
</div>
|
|
|
|
</li>`;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
Api.search_device(searchText.toUpperCase()).then(devices => {
|
|
|
|
dropdownList.querySelector("#deviceSearchLoader").style = "display: none"
|
|
|
|
|
|
|
|
for (let i = 0; i < devices.length; i++) {
|
|
|
|
const device = devices[i];
|
|
|
|
|
|
|
|
// See: ereuse_devicehub/resources/device/models.py
|
2022-04-20 10:04:53 +00:00
|
|
|
const verboseName = `${device.type} ${device.manufacturer} ${device.model}`
|
2022-04-12 11:41:18 +00:00
|
|
|
|
|
|
|
const templateString = `
|
|
|
|
<li>
|
|
|
|
<a class="dropdown-item" href="${API_URLS.devices_detail.replace("ReplaceTEXT", device.devicehubID)}" style="display: flex; align-items: center;" href="#">
|
|
|
|
<i class="bi bi-laptop"></i>
|
|
|
|
<span style="margin-right: 10px">${verboseName}</span>
|
|
|
|
<span class="badge bg-secondary" style="margin-left: auto;">${device.devicehubID}</span>
|
|
|
|
</a>
|
|
|
|
</li>`;
|
|
|
|
dropdownList.innerHTML += templateString
|
|
|
|
if (i == 4) { // Limit to 4 resullts
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
searchCompleted();
|
|
|
|
})
|
|
|
|
} catch (error) {
|
|
|
|
dropdownList.innerHTML += `
|
|
|
|
<li id="deviceSearchLoader" class="dropdown-item">
|
|
|
|
<i class="bi bi-x"></i>
|
|
|
|
<div class="spinner-border spinner-border-sm" role="status">
|
|
|
|
<span class="visually-hidden">Error searching devices</span>
|
|
|
|
</div>
|
|
|
|
</li>`;
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Api.get_lots().then(lots => {
|
|
|
|
dropdownList.querySelector("#lotSearchLoader").style = "display: none"
|
|
|
|
for (let i = 0; i < lots.length; i++) {
|
|
|
|
const lot = lots[i];
|
|
|
|
if (lot.name.toUpperCase().includes(searchText.toUpperCase())) {
|
|
|
|
const templateString = `
|
|
|
|
<li>
|
|
|
|
<a class="dropdown-item" href="${API_URLS.lots_detail.replace("ReplaceTEXT", lot.id)}" style="display: flex; align-items: center;" href="#">
|
|
|
|
<i class="bi bi-folder2"></i>
|
|
|
|
<span style="margin-right: 10px">${lot.name}</span>
|
|
|
|
</a>
|
|
|
|
</li>`;
|
|
|
|
dropdownList.innerHTML += templateString
|
|
|
|
if (i == 4) { // Limit to 4 resullts
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
searchCompleted();
|
|
|
|
})
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
dropdownList.innerHTML += `
|
|
|
|
<li id="deviceSearchLoader" class="dropdown-item">
|
|
|
|
<i class="bi bi-x"></i>
|
|
|
|
<div class="spinner-border spinner-border-sm" role="status">
|
|
|
|
<span class="visually-hidden">Error searching lots</span>
|
|
|
|
</div>
|
|
|
|
</li>`;
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
}, 1000)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-12-22 23:41:59 +00:00
|
|
|
})();
|