Feat: Product Variations page get, filter, and save. \n Fix: Active column changed to Add / Delete / Undelete column - this change has only been applied to Product Variations page
This commit is contained in:
@@ -174,7 +174,7 @@ export default class TableBasePage extends BasePage {
|
||||
let records = [];
|
||||
let record;
|
||||
document.querySelectorAll(idTableMain + ' > tbody > tr').forEach((row) => {
|
||||
if (dirtyOnly && !row.classList.contains(flagDirty)) return;
|
||||
if (dirtyOnly && !DOM.hasDirtyChildrenContainer(row)) return;
|
||||
record = this.getJsonRow(row);
|
||||
records.push(record);
|
||||
});
|
||||
@@ -217,28 +217,22 @@ export default class TableBasePage extends BasePage {
|
||||
});
|
||||
}
|
||||
hookupButtonAddRowTable() {
|
||||
this.hookupEventHandler("click", idFormFilters + ' button.' + flagAdd, (event, button) => {
|
||||
event.stopPropagation();
|
||||
let tbody = document.querySelector(idTableMain + ' tbody');
|
||||
let row = _rowBlank.cloneNode(true);
|
||||
row.classList.remove(flagInitialised);
|
||||
row.querySelectorAll('.' + flagInitialised).forEach(function(element) {
|
||||
element.classList.remove(flagInitialised);
|
||||
});
|
||||
let countRows = document.querySelectorAll(idTableMain + ' > tbody > tr').length;
|
||||
row.setAttribute(this.constructor.attrIdRowObject, -1 - countRows);
|
||||
/* Shared nethods
|
||||
let newDisplayOrder = parseInt(tbody.querySelector('tr:last-child').querySelector('td.' + flagDisplayOrder + ' .' + flagSlider).getAttribute(attrValueCurrent)) + 1;
|
||||
let slider = tbody.querySelector('tr:last-child').querySelector('td.' + flagDisplayOrder + ' .' + flagSlider);
|
||||
if (slider) {
|
||||
slider.setAttribute(attrValueCurrent, newDisplayOrder);
|
||||
slider.setAttribute(attrValuePrevious, newDisplayOrder);
|
||||
}
|
||||
*/
|
||||
this.initialiseRowNew(row);
|
||||
tbody.appendChild(row);
|
||||
this.hookupTableMain();
|
||||
this.hookupEventHandler("click", idFormFilters + ' button.' + flagAdd, (event, button) => { this.handleClickAddRowTable(event, button); });
|
||||
}
|
||||
handleClickAddRowTable(event, button) {
|
||||
event.stopPropagation();
|
||||
_rowBlank.setAttribute(this.constructor.attrIdRowObject, -1 - _rowBlank.getAttribute(this.constructor.attrIdRowObject));
|
||||
let tbody = document.querySelector(idTableMain + ' tbody');
|
||||
let row = _rowBlank.cloneNode(true);
|
||||
row.classList.remove(flagInitialised);
|
||||
row.querySelectorAll('.' + flagInitialised).forEach(function(element) {
|
||||
element.classList.remove(flagInitialised);
|
||||
});
|
||||
let countRows = document.querySelectorAll(idTableMain + ' > tbody > tr').length;
|
||||
row.setAttribute(this.constructor.attrIdRowObject, -1 - countRows);
|
||||
this.initialiseRowNew(row);
|
||||
tbody.appendChild(row);
|
||||
this.hookupTableMain();
|
||||
}
|
||||
initialiseRowNew(row) {
|
||||
if (this.constructor === TableBasePage) {
|
||||
@@ -260,10 +254,12 @@ export default class TableBasePage extends BasePage {
|
||||
let selectorRowNew = idTableMain + ' tbody tr.' + flagRowNew;
|
||||
let rowBlankTemp = document.querySelector(selectorRowNew);
|
||||
if (_verbose) { console.log("row blank temp: ", rowBlankTemp); }
|
||||
let countRows = document.querySelectorAll(idTableMain + ' > tbody > tr').length;
|
||||
_rowBlank = rowBlankTemp.cloneNode(true);
|
||||
document.querySelectorAll(selectorRowNew).forEach(function(row) {
|
||||
row.remove();
|
||||
});
|
||||
_rowBlank.setAttribute(this.constructor.attrIdRowObject, -1 - countRows);
|
||||
}
|
||||
hookupSlidersDisplayOrderTable() {
|
||||
let selectorDisplayOrder = idTableMain + ' tbody tr td.' + flagDisplayOrder + ' input.' + flagSlider + '.' + flagDisplayOrder;
|
||||
@@ -299,12 +295,12 @@ export default class TableBasePage extends BasePage {
|
||||
handleChangeElementCellTable(event, element) {
|
||||
let row = DOM.getRowFromElement(element);
|
||||
let td = DOM.getCellFromElement(element);
|
||||
let wasDirtyRow = DOM.hasDirtyChildrenNotDeletedContainer(row);
|
||||
let wasDirtyRow = DOM.hasDirtyChildrenContainer(row);
|
||||
let wasDirtyElement = element.classList.contains(flagDirty);
|
||||
let isDirtyElement = DOM.updateAndCheckIsElementDirty(element);
|
||||
if (isDirtyElement != wasDirtyElement) {
|
||||
DOM.handleDirtyElement(td, isDirtyElement);
|
||||
let isNowDirtyRow = DOM.hasDirtyChildrenNotDeletedContainer(row);
|
||||
let isNowDirtyRow = DOM.hasDirtyChildrenContainer(row);
|
||||
if (isNowDirtyRow != wasDirtyRow) {
|
||||
DOM.handleDirtyElement(row, isNowDirtyRow);
|
||||
let rows = this.getTableRecords(true);
|
||||
@@ -326,12 +322,12 @@ export default class TableBasePage extends BasePage {
|
||||
}
|
||||
let row = DOM.getRowFromElement(element);
|
||||
let td = DOM.getCellFromElement(element);
|
||||
let wasDirtyRow = DOM.hasDirtyChildrenNotDeletedContainer(row);
|
||||
let wasDirtyRow = DOM.hasDirtyChildrenContainer(row);
|
||||
let wasDirtyElement = element.classList.contains(flagDirty);
|
||||
let isDirtyElement = DOM.updateAndCheckIsElementDirty(element);
|
||||
if (isDirtyElement != wasDirtyElement) {
|
||||
DOM.handleDirtyElement(td, isDirtyElement);
|
||||
let isNowDirtyRow = DOM.hasDirtyChildrenNotDeletedContainer(row);
|
||||
let isNowDirtyRow = DOM.hasDirtyChildrenContainer(row);
|
||||
if (isNowDirtyRow != wasDirtyRow) {
|
||||
DOM.handleDirtyElement(row, isNowDirtyRow);
|
||||
let rows = this.getTableRecords(true);
|
||||
@@ -345,18 +341,18 @@ export default class TableBasePage extends BasePage {
|
||||
let rowTable = rowSubtable.closest(idTableMain + ' > tbody > tr');
|
||||
let td = DOM.getCellFromElement(element);
|
||||
// let tdSubtable = td.closest('td.' + flagFieldSubtable);
|
||||
let wasDirtyRowSubtable = DOM.hasDirtyChildrenNotDeletedContainer(rowSubtable);
|
||||
let wasDirtyRowTable = DOM.hasDirtyChildrenNotDeletedContainer(rowTable);
|
||||
let wasDirtyRowSubtable = DOM.hasDirtyChildrenContainer(rowSubtable);
|
||||
let wasDirtyRowTable = DOM.hasDirtyChildrenContainer(rowTable);
|
||||
let wasDirtyElement = element.classList.contains(flagDirty);
|
||||
let isDirtyElement = DOM.updateAndCheckIsElementDirty(element);
|
||||
console.log({isDirtyElement, wasDirtyElement});
|
||||
if (isDirtyElement != wasDirtyElement) {
|
||||
DOM.handleDirtyElement(td, isDirtyElement);
|
||||
let isNowDirtyRowSubtable = DOM.hasDirtyChildrenNotDeletedContainer(rowSubtable);
|
||||
let isNowDirtyRowSubtable = DOM.hasDirtyChildrenContainer(rowSubtable);
|
||||
console.log({isNowDirtyRowSubtable, wasDirtyRowSubtable});
|
||||
if (isNowDirtyRowSubtable != wasDirtyRowSubtable) {
|
||||
DOM.handleDirtyElement(rowSubtable, isNowDirtyRowSubtable);
|
||||
let isNowDirtyRowTable = DOM.hasDirtyChildrenNotDeletedContainer(rowTable);
|
||||
let isNowDirtyRowTable = DOM.hasDirtyChildrenContainer(rowTable);
|
||||
console.log({isNowDirtyRowTable, wasDirtyRowTable});
|
||||
if (isNowDirtyRowTable != wasDirtyRowTable) {
|
||||
DOM.handleDirtyElement(rowTable, isNowDirtyRowTable);
|
||||
@@ -370,13 +366,14 @@ export default class TableBasePage extends BasePage {
|
||||
*/
|
||||
handleChangeNestedElementCellTable(event, element) {
|
||||
let wasDirtyParentRows = this.getAllIsDirtyRowsInParentTree(element);
|
||||
let wasDirtyElement = element.classList.contains(flagDirty);
|
||||
let wasDirtyElement = DOM.isElementDirty(element);
|
||||
let isDirtyElement = DOM.updateAndCheckIsElementDirty(element);
|
||||
if (_verbose) { console.log({isDirtyElement, wasDirtyElement, wasDirtyParentRows}); }
|
||||
if (isDirtyElement != wasDirtyElement) {
|
||||
let td = DOM.getCellFromElement(element);
|
||||
DOM.setElementAttributeValueCurrent(td, DOM.getElementAttributeValueCurrent(element));
|
||||
this.toggleShowButtonsSaveCancel(isDirtyElement);
|
||||
DOM.handleDirtyElement(td, isDirtyElement);
|
||||
this.updateAndToggleShowButtonsSaveCancel();
|
||||
this.cascadeChangedIsDirtyNestedElementCellTable(element, isDirtyElement, wasDirtyParentRows);
|
||||
}
|
||||
}
|
||||
@@ -396,15 +393,15 @@ export default class TableBasePage extends BasePage {
|
||||
cascadeChangedIsDirtyNestedElementCellTable(element, isDirtyElement, wasDirtyParentRows) {
|
||||
if (Validation.isEmpty(wasDirtyParentRows)) return;
|
||||
let td = DOM.getCellFromElement(element);
|
||||
let isDirtyTd = isDirtyElement || DOM.hasDirtyChildrenNotDeletedContainer(tr);
|
||||
let isDirtyTd = isDirtyElement || DOM.hasDirtyChildrenContainer(tr);
|
||||
DOM.handleDirtyElement(td, isDirtyTd);
|
||||
let tr = DOM.getRowFromElement(td);
|
||||
let isDirtyRow = isDirtyTd || DOM.hasDirtyChildrenNotDeletedContainer(tr);
|
||||
let wasDirtyRow = wasDirtyParentRows.pop();
|
||||
let isDirtyRow = isDirtyTd || DOM.hasDirtyChildrenContainer(tr);
|
||||
let wasDirtyRow = wasDirtyParentRows.shift();
|
||||
if (_verbose) { console.log({isDirtyRow, wasDirtyRow}); }
|
||||
if (isDirtyRow != wasDirtyRow) {
|
||||
DOM.handleDirtyElement(tr, isDirtyRow);
|
||||
this.toggleShowButtonsSaveCancel(isDirtyRow);
|
||||
this.updateAndToggleShowButtonsSaveCancel();
|
||||
this.cascadeChangedIsDirtyNestedElementCellTable(tr.parentElement, isDirtyRow, wasDirtyParentRows);
|
||||
}
|
||||
}
|
||||
@@ -480,8 +477,18 @@ export default class TableBasePage extends BasePage {
|
||||
hookupTextareasDescriptionTable() {
|
||||
this.hookupChangeHandlerTableCells(idTableMain + ' tbody tr td.' + flagDescription + ' textarea');
|
||||
}
|
||||
hookupInputsActiveTable() {
|
||||
this.hookupChangeHandlerTableCells(idTableMain + ' > tbody > tr > td.' + flagActive + ' input[type="checkbox"]');
|
||||
hookupFieldsActive(flagTable = '', handleClickRowNew = (event, element) => { this.handleClickAddRowTable(event, element); }) {
|
||||
let selectorButton = 'table' + (Validation.isEmpty(flagTable) ? '' : '.' + flagTable) + ' > tbody > tr > td.' + flagActive + ' button';
|
||||
let selectorButtonDelete = selectorButton + '.' + flagDelete;
|
||||
let selectorButtonUndelete = selectorButton + ':not(.' + flagDelete + ')';
|
||||
console.log("hookupFieldsActive: ", selectorButtonDelete, selectorButtonUndelete);
|
||||
this.hookupButtonsRowDelete(selectorButtonDelete, selectorButtonUndelete);
|
||||
this.hookupButtonsRowUndelete(selectorButtonDelete, selectorButtonUndelete);
|
||||
this.hookupEventHandler(
|
||||
"click"
|
||||
, 'table' + (Validation.isEmpty(flagTable) ? '' : '.' + flagTable) + ' > thead > tr > th.' + flagActive + ' button'
|
||||
, (event, button) => { handleClickRowNew(event, button); }
|
||||
);
|
||||
}
|
||||
hookupButtonsRowDelete(selectorButtonDelete, selectorButtonUndelete) {
|
||||
this.hookupEventHandler("click", selectorButtonDelete, (event, element) => {
|
||||
@@ -489,14 +496,18 @@ export default class TableBasePage extends BasePage {
|
||||
});
|
||||
}
|
||||
handleClickButtonRowDelete(event, element, selectorButtonDelete, selectorButtonUndelete) {
|
||||
let row = DOM.getRowFromElement(element);
|
||||
row.classList.add(flagDelete);
|
||||
|
||||
let buttonAdd = document.createElement("button");
|
||||
// let row = DOM.getRowFromElement(element);
|
||||
// row.classList.add(flagDelete);
|
||||
let buttonAdd = element.cloneNode(false); // document.createElement("button");
|
||||
buttonAdd.classList.remove(flagInitialised);
|
||||
buttonAdd.classList.remove(flagDelete);
|
||||
buttonAdd.classList.add(flagAdd);
|
||||
buttonAdd.textContent = '+';
|
||||
// DOM.setElementAttributeValueCurrent(buttonAdd, false);
|
||||
element.replaceWith(buttonAdd);
|
||||
this.handleChangeNestedElementCellTable(null, buttonAdd);
|
||||
this.hookupButtonsRowUndelete(selectorButtonDelete, selectorButtonUndelete);
|
||||
this.updateAndToggleShowButtonsSaveCancel();
|
||||
}
|
||||
hookupButtonsRowUndelete(selectorButtonDelete, selectorButtonUndelete) {
|
||||
this.hookupEventHandler("click", selectorButtonUndelete, (event, element) => {
|
||||
@@ -504,14 +515,18 @@ export default class TableBasePage extends BasePage {
|
||||
});
|
||||
}
|
||||
handleClickButtonRowUndelete(event, element, selectorButtonDelete, selectorButtonUndelete) {
|
||||
let row = DOM.getRowFromElement(element);
|
||||
row.classList.add(flagDelete);
|
||||
|
||||
let buttonAdd = document.createElement("button");
|
||||
buttonAdd.classList.add(flagAdd);
|
||||
buttonAdd.textContent = '+';
|
||||
element.replaceWith(buttonAdd);
|
||||
// let row = DOM.getRowFromElement(element);
|
||||
// row.classList.remove(flagDelete);
|
||||
let buttonDelete = element.cloneNode(false); // document.createElement("button");
|
||||
buttonDelete.classList.remove(flagInitialised);
|
||||
buttonDelete.classList.remove(flagAdd);
|
||||
buttonDelete.classList.add(flagDelete);
|
||||
buttonDelete.textContent = 'x';
|
||||
// DOM.setElementAttributeValueCurrent(buttonDelete, true);
|
||||
element.replaceWith(buttonDelete);
|
||||
this.handleChangeNestedElementCellTable(null, buttonDelete);
|
||||
this.hookupButtonsRowDelete(selectorButtonDelete, selectorButtonUndelete);
|
||||
this.updateAndToggleShowButtonsSaveCancel();
|
||||
}
|
||||
hookupTdsAccessLevel() {
|
||||
let cellSelector = idTableMain + ' tbody td.' + flagAccessLevel;
|
||||
@@ -571,7 +586,7 @@ export default class TableBasePage extends BasePage {
|
||||
let row = DOM.getRowFromElement(ddl);
|
||||
let td = DOM.getCellFromElement(ddl);
|
||||
console.log("td: ", td);
|
||||
let wasDirtyRow = DOM.hasDirtyChildrenNotDeletedContainer(row);
|
||||
let wasDirtyRow = DOM.hasDirtyChildrenContainer(row);
|
||||
let wasDirtyElement = ddl.classList.contains(flagDirty);
|
||||
let isDirtyElement = DOM.updateAndCheckIsElementDirty(ddl);
|
||||
console.log("isDirtyElement: ", isDirtyElement);
|
||||
@@ -580,7 +595,7 @@ export default class TableBasePage extends BasePage {
|
||||
DOM.handleDirtyElement(td, isDirtyElement);
|
||||
let optionSelected = ddl.options[ddl.selectedIndex];
|
||||
DOM.setElementAttributeValueCurrent(td, optionSelected.value);
|
||||
let isNowDirtyRow = DOM.hasDirtyChildrenNotDeletedContainer(row);
|
||||
let isNowDirtyRow = DOM.hasDirtyChildrenContainer(row);
|
||||
console.log("isNowDirtyRow: ", isNowDirtyRow);
|
||||
console.log("wasDirtyRow: ", wasDirtyRow);
|
||||
if (isNowDirtyRow != wasDirtyRow) {
|
||||
@@ -885,16 +900,24 @@ export default class TableBasePage extends BasePage {
|
||||
let columnThHasFlag = columnTh.classList.contains(classnameFlag);
|
||||
if (isRequiredFlag == columnThHasFlag) return;
|
||||
DOM.toggleElementHasClassnameFlag(columnTh, isRequiredFlag, classnameFlag);
|
||||
/*
|
||||
let columnTds = table.querySelectorAll('td.' + columnFlag);
|
||||
columnTds.forEach((columnTd) => {
|
||||
DOM.toggleElementHasClassnameFlag(columnTd, isRequiredFlag, classnameFlag);
|
||||
});
|
||||
*/
|
||||
}
|
||||
toggleColumnHeaderHasClassnameFlag(columnFlag, isRequiredFlag, classnameFlag) {
|
||||
let table = TableBasePage.getTableMain();
|
||||
let columnTh = table.querySelector('th.' + columnFlag);
|
||||
DOM.toggleElementHasClassnameFlag(columnTh, isRequiredFlag, classnameFlag);
|
||||
}
|
||||
|
||||
updateAndToggleShowButtonsSaveCancel() {
|
||||
let records = this.getTableRecords(true);
|
||||
let existsDirtyRecord = records.length > 0;
|
||||
this.toggleShowButtonsSaveCancel(existsDirtyRecord);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ export default class PageStoreManufacturingPurchaseOrders extends TableBasePage
|
||||
this.hookupCurrencyFields();
|
||||
this.hookupCostAndPriceInputs();
|
||||
this.hookupOrderItemsFields();
|
||||
this.hookupInputsActiveTable();
|
||||
this.hookupFieldsActive();
|
||||
}
|
||||
hookupCostAndPriceInputs() {
|
||||
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagCostTotalLocalVatExcl + ' input');
|
||||
|
||||
@@ -102,7 +102,7 @@ export default class PageStoreProductCategories extends TableBasePage {
|
||||
this.hookupTextareasNameTable();
|
||||
this.hookupTextareasDescriptionTable();
|
||||
this.hookupTdsAccessLevel();
|
||||
this.hookupInputsActiveTable();
|
||||
this.hookupFieldsActive();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
245
static/js/pages/store/product_variations.js
Normal file
245
static/js/pages/store/product_variations.js
Normal file
@@ -0,0 +1,245 @@
|
||||
|
||||
import API from "../../api.js";
|
||||
import BusinessObjects from "../../lib/business_objects/business_objects.js";
|
||||
import DOM from "../../dom.js";
|
||||
import Events from "../../lib/events.js";
|
||||
import TableBasePage from "../base_table.js";
|
||||
import Utils from "../../lib/utils.js";
|
||||
import Validation from "../../lib/validation.js";
|
||||
import StoreTableMixinPage from "./mixin_table.js";
|
||||
|
||||
export default class PageStoreProductVariations extends TableBasePage {
|
||||
static hash = hashPageStoreProductVariations;
|
||||
static attrIdRowObject = attrIdProductVariation;
|
||||
callFilterTableContent = API.getProductVariationsByFilters;
|
||||
callSaveTableContent = API.saveProductVariations;
|
||||
|
||||
constructor(router) {
|
||||
super(router);
|
||||
this.storeMixin = new StoreTableMixinPage(this);
|
||||
}
|
||||
|
||||
initialize() {
|
||||
this.sharedInitialize();
|
||||
}
|
||||
|
||||
hookupFilters() {
|
||||
this.sharedHookupFilters();
|
||||
this.hookupFilterActive();
|
||||
this.hookupFilterIsNotEmpty();
|
||||
}
|
||||
|
||||
loadRowTable(rowJson) {
|
||||
}
|
||||
getJsonRow(row) {
|
||||
if (row == null) return;
|
||||
let inputDisplayOrder = row.querySelector('td.' + flagDisplayOrder + ' input');
|
||||
let textareaCode = row.querySelector('td.' + flagCode + ' textarea');
|
||||
let textareaName = row.querySelector('td.' + flagName + ' textarea');
|
||||
let textareaNamePlural = row.querySelector('td.' + flagNamePlural + ' textarea');
|
||||
let tdProductVariations = row.querySelector('td.' + flagProductVariations);
|
||||
let buttonActive = row.querySelector('td.' + flagActive + ' button');
|
||||
|
||||
let jsonRow = {};
|
||||
jsonRow[attrIdProductVariationType] = row.getAttribute(attrIdProductVariationType);
|
||||
if (Validation.isEmpty(jsonRow[attrIdProductVariationType])) jsonRow[attrIdProductVariationType] = -1;
|
||||
jsonRow[flagDisplayOrder] = DOM.getElementAttributeValueCurrent(inputDisplayOrder);
|
||||
jsonRow[flagCode] = DOM.getElementAttributeValueCurrent(textareaCode);
|
||||
jsonRow[flagName] = DOM.getElementAttributeValueCurrent(textareaName);
|
||||
jsonRow[flagNamePlural] = DOM.getElementAttributeValueCurrent(textareaNamePlural);
|
||||
|
||||
let variations = [];
|
||||
if (tdProductVariations.classList.contains(flagDirty)) {
|
||||
let trsProductVariation = tdProductVariations.querySelectorAll('tr.' + flagProductVariation + '.' + flagDirty);
|
||||
if (trsProductVariation != null) {
|
||||
trsProductVariation.forEach((tr, indexRow) => {
|
||||
variations.push(this.getJsonRowProductVariation(tr, indexRow));
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
// variations = BusinessObjects.getListObjectsFromIdDictAndCsv(productVariationTypes, DOM.getElementAttributeValueCurrent(tdProductVariations));
|
||||
}
|
||||
jsonRow[flagProductVariations] = variations;
|
||||
jsonRow[flagActive] = buttonActive.classList.contains(flagDelete);
|
||||
return jsonRow;
|
||||
}
|
||||
getJsonRowProductVariation(tr, indexRow) {
|
||||
let inputDisplayOrder = tr.querySelector('td.' + flagDisplayOrder + ' input');
|
||||
let textareaCode = tr.querySelector('td.' + flagCode + ' textarea');
|
||||
let textareaName = tr.querySelector('td.' + flagName + ' textarea');
|
||||
// let checkboxActive = tr.querySelector('td.' + flagActive + ' input');
|
||||
let buttonActive = tr.querySelector('td.' + flagActive + ' button');
|
||||
|
||||
let jsonRow = {};
|
||||
jsonRow[attrIdProductVariation] = tr.getAttribute(attrIdProductVariation);
|
||||
if (Validation.isEmpty(jsonRow[attrIdProductVariation])) jsonRow[attrIdProductVariation] = -1 - indexRow;
|
||||
jsonRow[attrIdProductVariationType] = tr.getAttribute(attrIdProductVariationType);
|
||||
jsonRow[flagDisplayOrder] = DOM.getElementAttributeValueCurrent(inputDisplayOrder);
|
||||
jsonRow[flagCode] = DOM.getElementAttributeValueCurrent(textareaCode);
|
||||
jsonRow[flagName] = DOM.getElementAttributeValueCurrent(textareaName);
|
||||
jsonRow[flagActive] = buttonActive.classList.contains(flagDelete);
|
||||
|
||||
return jsonRow;
|
||||
}
|
||||
initialiseRowNew(row) {
|
||||
super.initialiseRowNew(row);
|
||||
}
|
||||
|
||||
hookupTableMain() {
|
||||
super.hookupTableMain();
|
||||
this.hookupSlidersDisplayOrderTable();
|
||||
this.hookupTextareasCodeTable();
|
||||
this.hookupTextareasNameTable();
|
||||
this.hookupTextareasNamePluralTable();
|
||||
this.hookupFieldsProductVariation();
|
||||
this.hookupFieldsActive();
|
||||
}
|
||||
hookupTextareasNamePluralTable() {
|
||||
this.hookupChangeHandlerTableCells(idTableMain + ' tbody tr td.' + flagNamePlural + ' textarea');
|
||||
}
|
||||
hookupFieldsProductVariation() {
|
||||
this.hookupProductVariationsPreviews();
|
||||
this.hookupFieldsProductVariationDisplayOrder();
|
||||
this.hookupFieldsProductVariationCode();
|
||||
this.hookupFieldsProductVariationName();
|
||||
this.hookupFieldsProductVariationActive();
|
||||
}
|
||||
hookupProductVariationsPreviews() {
|
||||
this.hookupEventHandler("click", idTableMain + ' td.' + flagProductVariations, (event, td) => {
|
||||
if (!td.classList.contains(flagCollapsed)) return;
|
||||
this.handleClickProductVariationsPreview(event, td);
|
||||
});
|
||||
}
|
||||
handleClickProductVariationsPreview(event, element) {
|
||||
if (_verbose) { console.log("click order items preview"); }
|
||||
this.toggleColumnHeaderCollapsed(flagProductVariations, false);
|
||||
element.classList.remove(flagCollapsed);
|
||||
|
||||
let row = DOM.getRowFromElement(element);
|
||||
let idProductVariationType = row.getAttribute(attrIdProductVariationType);
|
||||
if (idProductVariationType == null || idProductVariationType < 1) return;
|
||||
let productVariationType = productVariationTypes[idProductVariationType];
|
||||
let tblProductVariations = document.createElement("table");
|
||||
tblProductVariations.classList.add(flagProductVariations);
|
||||
let thead = document.createElement("thead");
|
||||
let tr = document.createElement("tr");
|
||||
|
||||
let thDisplayOrder = document.createElement("th");
|
||||
thDisplayOrder.classList.add(flagDisplayOrder);
|
||||
thDisplayOrder.textContent = 'Display Order';
|
||||
let thCode = document.createElement("th");
|
||||
thCode.classList.add(flagCode);
|
||||
thCode.textContent = 'Code';
|
||||
let thName = document.createElement("th");
|
||||
thName.classList.add(flagName);
|
||||
thName.textContent = 'Name';
|
||||
let thActive = document.createElement("th");
|
||||
thActive.classList.add(flagActive);
|
||||
// thActive.textContent = 'Active';
|
||||
let buttonAdd = document.createElement("button");
|
||||
buttonAdd.classList.add(flagActive);
|
||||
buttonAdd.classList.add(flagAdd);
|
||||
buttonAdd.textContent = '+';
|
||||
thActive.appendChild(buttonAdd);
|
||||
|
||||
tr.appendChild(thDisplayOrder);
|
||||
tr.appendChild(thCode);
|
||||
tr.appendChild(thName);
|
||||
tr.appendChild(thActive);
|
||||
thead.appendChild(tr);
|
||||
tblProductVariations.appendChild(thead);
|
||||
|
||||
let tbody = document.createElement("tbody");
|
||||
productVariationType[flagProductVariations].forEach((productVariation, index) => {
|
||||
this.addRowProductVariation(tbody, productVariation);
|
||||
});
|
||||
tblProductVariations.appendChild(tbody);
|
||||
|
||||
let cell = DOM.getCellFromElement(element);
|
||||
let cellNew = cell.cloneNode(false);
|
||||
cellNew.appendChild(tblProductVariations);
|
||||
row.replaceChild(cellNew, cell);
|
||||
if (_verbose) { console.log("tblProductVariations: ", tblProductVariations); }
|
||||
this.hookupFieldsProductVariation();
|
||||
}
|
||||
addRowProductVariation(tbody, productVariation) {
|
||||
if (_verbose) { console.log("addRowProductVariation: ", productVariation); }
|
||||
|
||||
let tdDisplayOrder = document.createElement("td");
|
||||
tdDisplayOrder.classList.add(flagDisplayOrder);
|
||||
let inputDisplayOrder = document.createElement("input");
|
||||
inputDisplayOrder.classList.add(flagDisplayOrder);
|
||||
inputDisplayOrder.type = 'number';
|
||||
inputDisplayOrder.step = 1;
|
||||
DOM.setElementValuesCurrentAndPrevious(inputDisplayOrder, productVariation[flagDisplayOrder]);
|
||||
tdDisplayOrder.appendChild(inputDisplayOrder);
|
||||
|
||||
let tdCode = document.createElement("td");
|
||||
tdCode.classList.add(flagCode);
|
||||
let textareaCode = document.createElement("textarea");
|
||||
textareaCode.classList.add(flagCode);
|
||||
DOM.setElementValuesCurrentAndPrevious(textareaCode, productVariation[flagCode]);
|
||||
tdCode.appendChild(textareaCode);
|
||||
|
||||
let tdName = document.createElement("td");
|
||||
tdName.classList.add(flagName);
|
||||
let textareaName = document.createElement("textarea");
|
||||
textareaName.classList.add(flagName);
|
||||
DOM.setElementValuesCurrentAndPrevious(textareaName, productVariation[flagName]);
|
||||
tdName.appendChild(textareaName);
|
||||
|
||||
let tdActive = document.createElement("td");
|
||||
tdActive.classList.add(flagActive);
|
||||
let buttonActive = document.createElement("button");
|
||||
buttonActive.classList.add(flagActive);
|
||||
buttonActive.classList.add(productVariation[flagActive] ? flagDelete : flagAdd);
|
||||
buttonActive.textContent = productVariation[flagActive] ? 'x' : '+';
|
||||
DOM.setElementAttributesValuesCurrentAndPrevious(buttonActive, productVariation[flagActive]);
|
||||
tdActive.appendChild(buttonActive);
|
||||
|
||||
let tr = document.createElement("tr");
|
||||
tr.classList.add(flagProductVariation);
|
||||
tr.setAttribute(attrIdProductVariationType, productVariation[attrIdProductVariationType]);
|
||||
tr.setAttribute(attrIdProductVariation, productVariation[attrIdProductVariation]);
|
||||
tr.appendChild(tdDisplayOrder);
|
||||
tr.appendChild(tdCode);
|
||||
tr.appendChild(tdName);
|
||||
tr.appendChild(tdActive);
|
||||
tbody.appendChild(tr);
|
||||
}
|
||||
hookupFieldsProductVariationDisplayOrder() {
|
||||
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagProductVariations + ' td.' + flagDisplayOrder + ' input');
|
||||
}
|
||||
hookupFieldsProductVariationCode() {
|
||||
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagProductVariations + ' textarea.' + flagCode);
|
||||
}
|
||||
hookupFieldsProductVariationName() {
|
||||
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagProductVariations + ' textarea.' + flagName);
|
||||
}
|
||||
hookupFieldsProductVariationActive() {
|
||||
this.hookupFieldsActive(flagProductVariations, (event, element) => { this.hookupButtonsProductVariationAdd(event, element); });
|
||||
}
|
||||
hookupButtonsProductVariationAdd(event, element) {
|
||||
let row = element.closest(idTableMain + ' > tbody > tr');
|
||||
let idProductVariationType = row.getAttribute(attrIdProductVariationType);
|
||||
let idProductVariation = row.getAttribute(attrIdProductVariation);
|
||||
let countProductVariations = row.querySelectorAll('td.' + flagProductVariations + ' tr').length;
|
||||
let productVariation = {
|
||||
[attrIdProductVariationType]: idProductVariationType,
|
||||
[attrIdProductVariation]: idProductVariation,
|
||||
[flagCode]: '',
|
||||
[flagName]: '',
|
||||
[flagDisplayOrder]: countProductVariations,
|
||||
[flagActive]: true,
|
||||
};
|
||||
let tbody = row.querySelector('td.' + flagProductVariations + ' table tbody');
|
||||
this.addRowProductVariation(tbody, productVariation);
|
||||
this.hookupFieldsProductVariation();
|
||||
}
|
||||
|
||||
leave() {
|
||||
super.leave();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ export default class PageStoreProducts extends TableBasePage {
|
||||
this.hookupTextareasNameTable();
|
||||
this.hookupInputsHasVariationsTable();
|
||||
this.hookupTdsAccessLevel();
|
||||
this.hookupInputsActiveTable();
|
||||
this.hookupFieldsActive();
|
||||
}
|
||||
hookupTdsProductCategory() {
|
||||
let cellSelector = idTableMain + ' tbody td.' + flagProductCategory;
|
||||
|
||||
@@ -97,7 +97,7 @@ export default class PageStoreSupplierPurchaseOrders extends TableBasePage {
|
||||
this.hookupCurrencyFields();
|
||||
this.hookupCostInputs();
|
||||
this.hookupOrderItemsFields();
|
||||
this.hookupInputsActiveTable();
|
||||
this.hookupFieldsActive();
|
||||
}
|
||||
hookupSupplierFields() {
|
||||
this.hookupTableCellDdlPreviews(idTableMain + ' td.' + flagSupplier, Utils.getListFromDict(suppliers));
|
||||
|
||||
@@ -100,7 +100,7 @@ export default class PageStoreSuppliers extends TableBasePage {
|
||||
this.hookupEmailInputs();
|
||||
this.hookupWebsiteInputs();
|
||||
this.hookupCurrencyFields();
|
||||
this.hookupInputsActiveTable();
|
||||
this.hookupFieldsActive();
|
||||
}
|
||||
hookupNameCompanyInputs() {
|
||||
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagNameCompany + ' textarea');
|
||||
|
||||
Reference in New Issue
Block a user