增加常用名稱驗證|取消 jquery popper 引用 會導致require出錯
This commit is contained in:
parent
a5334662cf
commit
1389533087
@ -173,6 +173,7 @@
|
|||||||
name="favoriteName"
|
name="favoriteName"
|
||||||
placeholder="名稱"
|
placeholder="名稱"
|
||||||
/>
|
/>
|
||||||
|
<small class="input_error_text text-danger"></small>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@ -194,12 +195,6 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</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>
|
<script>
|
||||||
var historyTable2 = null;
|
var historyTable2 = null;
|
||||||
var buildingTag = null;
|
var buildingTag = null;
|
||||||
@ -281,25 +276,24 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showDeviceList(data) {
|
||||||
function showDeviceList(data){
|
temp_device_list = data;
|
||||||
temp_device_list = data;
|
let strHtml = "";
|
||||||
let strHtml = "";
|
let i1 = null,
|
||||||
let i1 = null,
|
i2 = null,
|
||||||
i2 = null,
|
first = true;
|
||||||
first = true;
|
$.each(data, function (index, building) {
|
||||||
$.each(data, function (index, building) {
|
let innerHtml = "";
|
||||||
let innerHtml = "";
|
$.each(building.device_list, function (index2, val2) {
|
||||||
$.each(building.device_list, function (index2, val2) {
|
innerHtml += ` <li class="card-header px-5 list-group-item">
|
||||||
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}">
|
<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">
|
<p class="h6 mb-0">
|
||||||
${val2.device_name}
|
${val2.device_name}
|
||||||
</p>
|
</p>
|
||||||
</li>`;
|
</li>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
strHtml += ` <div class="card">
|
strHtml += ` <div class="card">
|
||||||
<div class="card-header px-3">
|
<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}">
|
<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"
|
<p class="h6 mb-0 ml-2"
|
||||||
@ -317,9 +311,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
let wholeContent = `
|
let wholeContent = `
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header px-3">
|
<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">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
$(".js_nested_list").html(wholeContent);
|
$(".js_nested_list").html(wholeContent);
|
||||||
$(`[data-toggle="collapse"]`).first().click();
|
$(`[data-toggle="collapse"]`).first().click();
|
||||||
}
|
}
|
||||||
|
|
||||||
document.querySelector("#js_nested_list_filter").addEventListener("keyup",(e)=>{
|
document
|
||||||
|
.querySelector("#js_nested_list_filter")
|
||||||
if(e.key==="Enter"){
|
.addEventListener("keyup", (e) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
let searchDev = [];
|
let searchDev = [];
|
||||||
device_list.forEach((d) => {
|
device_list.forEach((d) => {
|
||||||
const devs = d.device_list.filter(({device_name})=>device_name.includes(e.target.value))
|
const devs = d.device_list.filter(({ device_name }) =>
|
||||||
if(devs.length>0){
|
device_name.includes(e.target.value)
|
||||||
searchDev = [...searchDev, {
|
);
|
||||||
...d,
|
if (devs.length > 0) {
|
||||||
device_list: devs
|
searchDev = [
|
||||||
}];
|
...searchDev,
|
||||||
|
{
|
||||||
|
...d,
|
||||||
|
device_list: devs,
|
||||||
|
},
|
||||||
|
];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
showDeviceList(searchDev)
|
showDeviceList(searchDev);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
function selectAllBuildingDevice(e) {
|
function selectAllBuildingDevice(e) {
|
||||||
let curData=[], curBuisDev=[], checkBui=[];
|
let curData = [],
|
||||||
|
curBuisDev = [],
|
||||||
|
checkBui = [];
|
||||||
if (e.target.name === "bui_selected") {
|
if (e.target.name === "bui_selected") {
|
||||||
if (e.target.dataset.building == "all") {
|
if (e.target.dataset.building == "all") {
|
||||||
temp_device_list.forEach(({ device_list }) => {
|
temp_device_list.forEach(({ device_list }) => {
|
||||||
curData = [...curData, ...device_list];
|
curData = [...curData, ...device_list];
|
||||||
});
|
});
|
||||||
curBuisDev = curData.map(
|
curBuisDev = curData.map(({ device_number }) => device_number);
|
||||||
({ device_number }) => device_number
|
if (e.target.checked) {
|
||||||
);
|
checkBui = temp_device_list.map(({ device_list, building_tag }) => ({
|
||||||
if(e.target.checked){
|
|
||||||
checkBui = temp_device_list.map(({ device_list, building_tag }) => ({
|
|
||||||
building_tag,
|
building_tag,
|
||||||
builing_check:true
|
builing_check: true,
|
||||||
}));
|
}));
|
||||||
}else{
|
} else {
|
||||||
|
checkBui = temp_device_list.map(({ device_list, building_tag }) => ({
|
||||||
checkBui = temp_device_list.map(({ device_list, building_tag }) => ({
|
|
||||||
building_tag,
|
building_tag,
|
||||||
builing_check:false
|
builing_check: false,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
curData = temp_device_list.find(
|
curData = temp_device_list.find(
|
||||||
({ building_tag }) => e.target.dataset.building === building_tag
|
({ building_tag }) => e.target.dataset.building === building_tag
|
||||||
@ -392,17 +390,17 @@
|
|||||||
list = list.filter((dev) => !curBuisDev.includes(dev));
|
list = list.filter((dev) => !curBuisDev.includes(dev));
|
||||||
}
|
}
|
||||||
|
|
||||||
checkBui.forEach(({ building_tag, builing_check }) => {
|
checkBui.forEach(({ building_tag, builing_check }) => {
|
||||||
if (builing_check) {
|
if (builing_check) {
|
||||||
$(
|
$(
|
||||||
`[name="bui_selected"][data-building="${building_tag}"]`
|
`[name="bui_selected"][data-building="${building_tag}"]`
|
||||||
)[0].checked = true;
|
)[0].checked = true;
|
||||||
} else {
|
} else {
|
||||||
$(
|
$(
|
||||||
`[name="bui_selected"][data-building="${building_tag}"]`
|
`[name="bui_selected"][data-building="${building_tag}"]`
|
||||||
)[0].checked = false;
|
)[0].checked = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('[name="Device_list"]').each((i, e) => {
|
$('[name="Device_list"]').each((i, e) => {
|
||||||
if (list.includes(e.dataset.device)) {
|
if (list.includes(e.dataset.device)) {
|
||||||
@ -413,12 +411,12 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document
|
document
|
||||||
.querySelector(".js_nested_list")
|
.querySelector(".js_nested_list")
|
||||||
.addEventListener("change", selectAllBuildingDevice);
|
.addEventListener("change", selectAllBuildingDevice);
|
||||||
|
|
||||||
// 取得右側sidebar
|
// 取得右側sidebar
|
||||||
function getSidebar(subTag) {
|
function getSidebar(subTag) {
|
||||||
// let subTag = $("[name=subRadio]:checked").val()
|
// let subTag = $("[name=subRadio]:checked").val()
|
||||||
let sendData = {
|
let sendData = {
|
||||||
@ -430,10 +428,9 @@
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
function success(res) {
|
function success(res) {
|
||||||
|
|
||||||
device_list = res.data;
|
device_list = res.data;
|
||||||
temp_device_list = res.data;
|
temp_device_list = res.data;
|
||||||
showDeviceList(res.data)
|
showDeviceList(res.data);
|
||||||
$(`[name="Device_list"]`).first().click();
|
$(`[name="Device_list"]`).first().click();
|
||||||
devPointsList();
|
devPointsList();
|
||||||
}
|
}
|
||||||
@ -676,7 +673,6 @@
|
|||||||
var editGuid = "";
|
var editGuid = "";
|
||||||
var favorite_setting = [];
|
var favorite_setting = [];
|
||||||
function openModal(favorite_guid) {
|
function openModal(favorite_guid) {
|
||||||
console.log(favorite_guid);
|
|
||||||
editGuid = "";
|
editGuid = "";
|
||||||
if (favorite_guid) {
|
if (favorite_guid) {
|
||||||
$("#favoriteName").val(
|
$("#favoriteName").val(
|
||||||
@ -689,10 +685,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function closeModal() {
|
function closeModal() {
|
||||||
|
$("#favoriteName").val("");
|
||||||
$("#favoriteModal").modal("hide");
|
$("#favoriteModal").modal("hide");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addFavorite() {
|
async function addFavorite() {
|
||||||
|
$(".input_error_text").text("");
|
||||||
let token = cookies.get("JWT-Authorization");
|
let token = cookies.get("JWT-Authorization");
|
||||||
const form = $("#device_list_form")[0];
|
const form = $("#device_list_form")[0];
|
||||||
const formData = new FormData(form);
|
const formData = new FormData(form);
|
||||||
@ -700,25 +698,36 @@
|
|||||||
|
|
||||||
const favoriteForm = $("#favoriteForm")[0];
|
const favoriteForm = $("#favoriteForm")[0];
|
||||||
const favoriteFormData = new FormData(favoriteForm);
|
const favoriteFormData = new FormData(favoriteForm);
|
||||||
|
const favorite_name = favoriteFormData.get("favoriteName");
|
||||||
|
|
||||||
const json = await fetch(baseApiUrl + "/api/History/SaveHistoryFavorite", {
|
if (favorite_name) {
|
||||||
method: "POST",
|
const json = await fetch(
|
||||||
headers: {
|
baseApiUrl + "/api/History/SaveHistoryFavorite",
|
||||||
Authorization: "Bearer " + token,
|
{
|
||||||
"Content-Type": "application/json",
|
method: "POST",
|
||||||
},
|
headers: {
|
||||||
body: JSON.stringify({
|
Authorization: "Bearer " + token,
|
||||||
favorite_name: favoriteFormData.get("favoriteName"),
|
"Content-Type": "application/json",
|
||||||
device_name_tag: $("[name=subRadio]:checked").val(),
|
},
|
||||||
Type: pageAct.dateType,
|
body: JSON.stringify({
|
||||||
Points: pageAct.devicePoiName,
|
favorite_name,
|
||||||
Device_list,
|
device_name_tag: $("[name=subRadio]:checked").val(),
|
||||||
}),
|
Type: pageAct.dateType,
|
||||||
});
|
Points: pageAct.devicePoiName,
|
||||||
|
Device_list,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const res = await json.json();
|
const res = await json.json();
|
||||||
if (res && res.code == "0000") {
|
if (res && res.code == "0000") {
|
||||||
getFavorite();
|
getFavorite();
|
||||||
|
closeModal();
|
||||||
|
} else {
|
||||||
|
toast_error(res.msg || common.SysErr);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$(".input_error_text").text("請輸入名稱");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -726,21 +735,32 @@
|
|||||||
let token = cookies.get("JWT-Authorization");
|
let token = cookies.get("JWT-Authorization");
|
||||||
const favoriteForm = $("#favoriteForm")[0];
|
const favoriteForm = $("#favoriteForm")[0];
|
||||||
const favoriteFormData = new FormData(favoriteForm);
|
const favoriteFormData = new FormData(favoriteForm);
|
||||||
|
const favorite_name = favoriteFormData.get("favoriteName");
|
||||||
|
|
||||||
const json = await fetch(baseApiUrl + "/api/History/EditHistoryFavorite", {
|
if (favorite_name) {
|
||||||
method: "POST",
|
const json = await fetch(
|
||||||
headers: {
|
baseApiUrl + "/api/History/EditHistoryFavorite",
|
||||||
Authorization: "Bearer " + token,
|
{
|
||||||
"Content-Type": "application/json",
|
method: "POST",
|
||||||
},
|
headers: {
|
||||||
body: JSON.stringify({
|
Authorization: "Bearer " + token,
|
||||||
favorite_name: favoriteFormData.get("favoriteName"),
|
"Content-Type": "application/json",
|
||||||
favorite_guid,
|
},
|
||||||
}),
|
body: JSON.stringify({
|
||||||
});
|
favorite_name,
|
||||||
const res = await json.json();
|
favorite_guid,
|
||||||
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("請輸入名稱");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -772,7 +792,6 @@
|
|||||||
} else {
|
} else {
|
||||||
addFavorite();
|
addFavorite();
|
||||||
}
|
}
|
||||||
closeModal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document
|
document
|
||||||
|
Loading…
Reference in New Issue
Block a user