added prototype
This commit is contained in:
@@ -2428,13 +2428,13 @@
|
||||
return [].concat(...element.children).filter((child2) => child2.matches(selector));
|
||||
},
|
||||
parents(element, selector) {
|
||||
const parents = [];
|
||||
const parents2 = [];
|
||||
let ancestor = element.parentNode.closest(selector);
|
||||
while (ancestor) {
|
||||
parents.push(ancestor);
|
||||
parents2.push(ancestor);
|
||||
ancestor = ancestor.parentNode.closest(selector);
|
||||
}
|
||||
return parents;
|
||||
return parents2;
|
||||
},
|
||||
prev(element, selector) {
|
||||
let previous = element.previousElementSibling;
|
||||
@@ -5566,6 +5566,14 @@
|
||||
}
|
||||
return element;
|
||||
};
|
||||
var parents = (el, selector) => {
|
||||
const parents2 = [];
|
||||
let currentEl = el;
|
||||
while ((currentEl = currentEl.parentElement) && currentEl !== null && currentEl !== document.documentElement) {
|
||||
if (!selector || currentEl.matches(selector)) parents2.push(currentEl);
|
||||
}
|
||||
return parents2;
|
||||
};
|
||||
|
||||
// dev/scripts/modules/ProductManager.ts
|
||||
var ProductManager = (el) => {
|
||||
@@ -5685,7 +5693,7 @@
|
||||
const onClickEdit = (e) => {
|
||||
const btnEl = e.currentTarget;
|
||||
const currentRow = parents(btnEl, "tr")[0];
|
||||
const id = currentRow.dataset.id;
|
||||
const id = String(currentRow.dataset.id);
|
||||
getProduct(id).then((data) => {
|
||||
showModalEdit(data);
|
||||
});
|
||||
@@ -5694,13 +5702,13 @@
|
||||
const btnEl = e.currentTarget;
|
||||
const currentRow = parents(btnEl, "tr")[0];
|
||||
const id = currentRow.dataset.id;
|
||||
const productName = currentRow.querySelector(".td-name").textContent.trim();
|
||||
const productName = querySelectorTyped(".td-name", currentRow).textContent.trim();
|
||||
DOM.btnConfirmDelete.dataset.id = id;
|
||||
DOM.productName.textContent = productName;
|
||||
};
|
||||
const onClickConfirmDelete = (e) => {
|
||||
const btnEl = e.currentTarget;
|
||||
const id = btnEl.dataset.id;
|
||||
const id = String(btnEl.dataset.id);
|
||||
deleteProduct(id).then((data) => {
|
||||
if (data.success) {
|
||||
Toast_default(data.msg, "success").show();
|
||||
@@ -5801,7 +5809,11 @@
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
Toast_default(error, "error").show();
|
||||
if (error instanceof Error) {
|
||||
Toast_default(error.message, "error").show();
|
||||
} else {
|
||||
Toast_default("An unknown error occurred.", "error").show();
|
||||
}
|
||||
console.error(error);
|
||||
return error;
|
||||
}
|
||||
@@ -5839,7 +5851,11 @@
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (error instanceof Error) {
|
||||
console.error(error.message);
|
||||
} else {
|
||||
console.error("An unknown error occurred.");
|
||||
}
|
||||
return error;
|
||||
}
|
||||
};
|
||||
@@ -5875,7 +5891,11 @@
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (error instanceof Error) {
|
||||
console.error(error.message);
|
||||
} else {
|
||||
console.error("An unknown error occurred.");
|
||||
}
|
||||
return error;
|
||||
}
|
||||
};
|
||||
@@ -5917,16 +5937,16 @@
|
||||
};
|
||||
const addProduct = (product) => {
|
||||
const { name, price, _id: id, position } = product;
|
||||
const trEl = DOM.templateRow.content.firstElementChild.cloneNode(true);
|
||||
const tdNameEl = trEl.querySelector(".td-name");
|
||||
const tdPriceEl = trEl.querySelector(".td-price");
|
||||
const btnRemoveEl = trEl.querySelector(".button-product-remove");
|
||||
const btnMoveUpEl = trEl.querySelector(".button-product-move-up");
|
||||
const btnMoveDownEl = trEl.querySelector(".button-product-move-down");
|
||||
const btnDragEl = trEl.querySelector(".button-drag");
|
||||
const btnEditEl = trEl.querySelector(".button-product-edit");
|
||||
tdNameEl.textContent = name;
|
||||
tdPriceEl.textContent = price;
|
||||
const trEl = DOM.templateRow.content.firstElementChild?.cloneNode(true);
|
||||
const tdNameEl = querySelectorTyped(".td-name", trEl);
|
||||
const tdPriceEl = querySelectorTyped(".td-price", trEl);
|
||||
const btnRemoveEl = querySelectorTyped(".button-product-remove", trEl);
|
||||
const btnMoveUpEl = querySelectorTyped(".button-product-move-up", trEl);
|
||||
const btnMoveDownEl = querySelectorTyped(".button-product-move-down", trEl);
|
||||
const btnDragEl = querySelectorTyped(".button-drag", trEl);
|
||||
const btnEditEl = querySelectorTyped(".button-product-edit", trEl);
|
||||
tdNameEl.textContent = String(name);
|
||||
tdPriceEl.textContent = String(price);
|
||||
btnEditEl.addEventListener("click", onClickEdit);
|
||||
btnRemoveEl.addEventListener("click", onClickRemove);
|
||||
btnMoveUpEl.addEventListener("click", onClickMoveUp);
|
||||
@@ -5937,15 +5957,15 @@
|
||||
trEl.addEventListener("dragover", onDragOver);
|
||||
trEl.addEventListener("drop", onDrop);
|
||||
trEl.dataset.id = id;
|
||||
trEl.dataset.position = position;
|
||||
trEl.dataset.position = String(position);
|
||||
DOM.tBody.appendChild(trEl);
|
||||
};
|
||||
const showModalEdit = (product) => {
|
||||
const { name = "", price = 0, _id: id, position } = product;
|
||||
DOM.inputEditName.value = name;
|
||||
DOM.inputEditPrice.value = price;
|
||||
DOM.inputEditId.value = id;
|
||||
DOM.inputEditPosition.value = position;
|
||||
DOM.inputEditPrice.value = String(price);
|
||||
DOM.inputEditId.value = String(id);
|
||||
DOM.inputEditPosition.value = String(position);
|
||||
};
|
||||
const resetFields = () => {
|
||||
DOM.btnAdd.disabled = true;
|
||||
@@ -5955,19 +5975,12 @@
|
||||
};
|
||||
const disableNonFunctionalButtons = () => {
|
||||
Array.from(DOM.tBody.querySelectorAll("tr")).forEach((tr) => {
|
||||
const btnMoveUp = tr.querySelector(".button-product-move-up");
|
||||
const btnMoveDown = tr.querySelector(".button-product-move-down");
|
||||
const btnMoveUp = querySelectorTyped(".button-product-move-up", tr);
|
||||
const btnMoveDown = querySelectorTyped(".button-product-move-down", tr);
|
||||
btnMoveUp.disabled = !tr.previousElementSibling;
|
||||
btnMoveDown.disabled = !tr.nextElementSibling;
|
||||
});
|
||||
};
|
||||
const parents = (el2, selector) => {
|
||||
const parents2 = [];
|
||||
while ((el2 = el2.parentNode) && el2 !== document) {
|
||||
if (!selector || el2.matches(selector)) parents2.push(el2);
|
||||
}
|
||||
return parents2;
|
||||
};
|
||||
init();
|
||||
return {
|
||||
init,
|
||||
|
||||
Reference in New Issue
Block a user