diff --git a/.eslintrc.json b/.eslintrc.json index 0d9213bb..56f4296d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -27,7 +27,8 @@ "strict": "off", "class-methods-use-this": "off", "eqeqeq": "warn", - "radix": "warn" + "radix": "warn", + "max-classes-per-file": ["error", 2] }, "globals": { "API_URLS": true, diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index 380bb962..1bddad27 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -17,6 +17,38 @@ $(document).ready(() => { // $('#selectLot').selectpicker(); }) +class TableController { + static #tableRows = table.rows().dt.activeRows; + + /** + * @returns This will return all input attributes from selected devices + */ + static getSelectedDevices() { + return this.#ProcessTR(this.#tableRows.filter(element => element.querySelector("input").checked)) + } + + /** + * @returns This will return all input attributes from all devices in list + */ + static getAllDevices() { + return this.#ProcessTR(this.#tableRows) + } + + /** + * + * @param {HTMLElement} DOMElements + * @returns Procesed input atributes to an Object class + */ + static #ProcessTR(DOMElements) { + return DOMElements.map(element => { + const info = {} + info.checked = element.querySelector("input").checked + Object.values(element.querySelector("input").attributes).forEach(attrib => {info[attrib.nodeName] = attrib.nodeValue}) + return info + }) + } +} + function deviceSelect() { const devices_count = $(".deviceSelect").filter(":checked").length; get_device_list(); @@ -340,7 +372,7 @@ async function processSelectedDevices() { const listHTML = $("#LotsSelector") // Get selected devices - const selectedDevicesID = table.rows().dt.activeRows.filter(item => item.querySelector("input").checked).map(item => item.querySelector("input").attributes.data.value) + const selectedDevicesID = TableController.getSelectedDevices().map(item => item.data) if (selectedDevicesID.length <= 0) { listHTML.html("