增加常用名稱驗證|取消 jquery popper 引用 會導致require出錯

This commit is contained in:
JouChun 2024-05-13 09:49:51 -04:00
parent a5334662cf
commit 1389533087

View File

@ -173,6 +173,7 @@
name="favoriteName"
placeholder="名稱"
/>
<small class="input_error_text text-danger"></small>
</div>
</form>
</div>
@ -194,12 +195,6 @@
}
</style>
<script
src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"
></script>
<script>
var historyTable2 = null;
var buildingTag = null;
@ -281,25 +276,24 @@
return result;
}
function showDeviceList(data){
temp_device_list = data;
let strHtml = "";
let i1 = null,
i2 = null,
first = true;
$.each(data, function (index, building) {
let innerHtml = "";
$.each(building.device_list, function (index2, val2) {
innerHtml += ` <li class="card-header px-5 list-group-item">
function showDeviceList(data) {
temp_device_list = data;
let strHtml = "";
let i1 = null,
i2 = null,
first = true;
$.each(data, function (index, building) {
let innerHtml = "";
$.each(building.device_list, function (index2, val2) {
innerHtml += ` <li class="card-header px-5 list-group-item">
<input class="custom-control-input opacity-100 mx-2" style="z-index: 0" type="checkbox" name="Device_list" data-device="${val2.device_number}" value="${val2.device_number}" id="dev_${val2.device_number}">
<p class="h6 mb-0">
${val2.device_name}
</p>
</li>`;
});
});
strHtml += ` <div class="card">
strHtml += ` <div class="card">
<div class="card-header px-3">
<input class="custom-control-input opacity-100" style="z-index: 0" type="checkbox" name="bui_selected" data-building="${building.building_tag}" value="${building.building_tag}" id="bui_${building.building_tag}">
<p class="h6 mb-0 ml-2"
@ -317,9 +311,9 @@
</div>
</div>
</div>`;
});
});
let wholeContent = `
let wholeContent = `
<div class="card">
<div class="card-header px-3">
<input class="custom-control-input opacity-100 mx-2" style="z-index: 0" type="checkbox" name="bui_selected" data-building="all" value="all" id="bui_all">
@ -328,51 +322,55 @@
</div>
</div>
`;
$(".js_nested_list").html(wholeContent);
$(`[data-toggle="collapse"]`).first().click();
}
$(".js_nested_list").html(wholeContent);
$(`[data-toggle="collapse"]`).first().click();
}
document.querySelector("#js_nested_list_filter").addEventListener("keyup",(e)=>{
if(e.key==="Enter"){
document
.querySelector("#js_nested_list_filter")
.addEventListener("keyup", (e) => {
if (e.key === "Enter") {
let searchDev = [];
device_list.forEach((d) => {
const devs = d.device_list.filter(({device_name})=>device_name.includes(e.target.value))
if(devs.length>0){
searchDev = [...searchDev, {
...d,
device_list: devs
}];
const devs = d.device_list.filter(({ device_name }) =>
device_name.includes(e.target.value)
);
if (devs.length > 0) {
searchDev = [
...searchDev,
{
...d,
device_list: devs,
},
];
}
});
showDeviceList(searchDev)
showDeviceList(searchDev);
}
})
});
function selectAllBuildingDevice(e) {
let curData=[], curBuisDev=[], checkBui=[];
function selectAllBuildingDevice(e) {
let curData = [],
curBuisDev = [],
checkBui = [];
if (e.target.name === "bui_selected") {
if (e.target.dataset.building == "all") {
temp_device_list.forEach(({ device_list }) => {
curData = [...curData, ...device_list];
});
curBuisDev = curData.map(
({ device_number }) => device_number
);
if(e.target.checked){
checkBui = temp_device_list.map(({ device_list, building_tag }) => ({
curBuisDev = curData.map(({ device_number }) => device_number);
if (e.target.checked) {
checkBui = temp_device_list.map(({ device_list, building_tag }) => ({
building_tag,
builing_check:true
builing_check: true,
}));
}else{
checkBui = temp_device_list.map(({ device_list, building_tag }) => ({
} else {
checkBui = temp_device_list.map(({ device_list, building_tag }) => ({
building_tag,
builing_check:false
builing_check: false,
}));
}
} else {
curData = temp_device_list.find(
({ building_tag }) => e.target.dataset.building === building_tag
@ -392,17 +390,17 @@
list = list.filter((dev) => !curBuisDev.includes(dev));
}
checkBui.forEach(({ building_tag, builing_check }) => {
if (builing_check) {
$(
`[name="bui_selected"][data-building="${building_tag}"]`
)[0].checked = true;
} else {
$(
`[name="bui_selected"][data-building="${building_tag}"]`
)[0].checked = false;
}
});
checkBui.forEach(({ building_tag, builing_check }) => {
if (builing_check) {
$(
`[name="bui_selected"][data-building="${building_tag}"]`
)[0].checked = true;
} else {
$(
`[name="bui_selected"][data-building="${building_tag}"]`
)[0].checked = false;
}
});
$('[name="Device_list"]').each((i, e) => {
if (list.includes(e.dataset.device)) {
@ -413,12 +411,12 @@
});
}
}
document
.querySelector(".js_nested_list")
.addEventListener("change", selectAllBuildingDevice);
// 取得右側sidebar
// 取得右側sidebar
function getSidebar(subTag) {
// let subTag = $("[name=subRadio]:checked").val()
let sendData = {
@ -430,10 +428,9 @@
e.stopPropagation();
}
function success(res) {
device_list = res.data;
temp_device_list = res.data;
showDeviceList(res.data)
showDeviceList(res.data);
$(`[name="Device_list"]`).first().click();
devPointsList();
}
@ -676,7 +673,6 @@
var editGuid = "";
var favorite_setting = [];
function openModal(favorite_guid) {
console.log(favorite_guid);
editGuid = "";
if (favorite_guid) {
$("#favoriteName").val(
@ -689,10 +685,12 @@
}
function closeModal() {
$("#favoriteName").val("");
$("#favoriteModal").modal("hide");
}
async function addFavorite() {
$(".input_error_text").text("");
let token = cookies.get("JWT-Authorization");
const form = $("#device_list_form")[0];
const formData = new FormData(form);
@ -700,25 +698,36 @@
const favoriteForm = $("#favoriteForm")[0];
const favoriteFormData = new FormData(favoriteForm);
const favorite_name = favoriteFormData.get("favoriteName");
const json = await fetch(baseApiUrl + "/api/History/SaveHistoryFavorite", {
method: "POST",
headers: {
Authorization: "Bearer " + token,
"Content-Type": "application/json",
},
body: JSON.stringify({
favorite_name: favoriteFormData.get("favoriteName"),
device_name_tag: $("[name=subRadio]:checked").val(),
Type: pageAct.dateType,
Points: pageAct.devicePoiName,
Device_list,
}),
});
if (favorite_name) {
const json = await fetch(
baseApiUrl + "/api/History/SaveHistoryFavorite",
{
method: "POST",
headers: {
Authorization: "Bearer " + token,
"Content-Type": "application/json",
},
body: JSON.stringify({
favorite_name,
device_name_tag: $("[name=subRadio]:checked").val(),
Type: pageAct.dateType,
Points: pageAct.devicePoiName,
Device_list,
}),
}
);
const res = await json.json();
if (res && res.code == "0000") {
getFavorite();
const res = await json.json();
if (res && res.code == "0000") {
getFavorite();
closeModal();
} else {
toast_error(res.msg || common.SysErr);
}
} else {
$(".input_error_text").text("請輸入名稱");
}
}
@ -726,21 +735,32 @@
let token = cookies.get("JWT-Authorization");
const favoriteForm = $("#favoriteForm")[0];
const favoriteFormData = new FormData(favoriteForm);
const favorite_name = favoriteFormData.get("favoriteName");
const json = await fetch(baseApiUrl + "/api/History/EditHistoryFavorite", {
method: "POST",
headers: {
Authorization: "Bearer " + token,
"Content-Type": "application/json",
},
body: JSON.stringify({
favorite_name: favoriteFormData.get("favoriteName"),
favorite_guid,
}),
});
const res = await json.json();
if (res && res.code == "0000") {
getFavorite();
if (favorite_name) {
const json = await fetch(
baseApiUrl + "/api/History/EditHistoryFavorite",
{
method: "POST",
headers: {
Authorization: "Bearer " + token,
"Content-Type": "application/json",
},
body: JSON.stringify({
favorite_name,
favorite_guid,
}),
}
);
const res = await json.json();
if (res && res.code == "0000") {
getFavorite();
closeModal();
} else {
toast_error(res.msg || common.SysErr);
}
} else {
$(".input_error_text").text("請輸入名稱");
}
}
@ -772,7 +792,6 @@
} else {
addFavorite();
}
closeModal();
}
document