diff --git a/03_js-dom/unterricht/tag23/01_product-manager/assets/css/main.css b/03_js-dom/unterricht/tag23/01_product-manager/assets/css/main.css new file mode 100644 index 0000000..553ae7f --- /dev/null +++ b/03_js-dom/unterricht/tag23/01_product-manager/assets/css/main.css @@ -0,0 +1,22 @@ +*, +html { + box-sizing: border-box; +} + +html, +body { + padding: 0; + margin: 0; + height: 100%; +} + +/* Mobile first */ +.product-manager table tfoot .row > * { + margin-bottom: 0.5rem; +} + +@media (min-width: 992px) { + .product-manager table tfoot .row > * { + margin-bottom: 0; + } +} diff --git a/03_js-dom/unterricht/tag23/01_product-manager/assets/js/main.js b/03_js-dom/unterricht/tag23/01_product-manager/assets/js/main.js new file mode 100644 index 0000000..9112cd8 --- /dev/null +++ b/03_js-dom/unterricht/tag23/01_product-manager/assets/js/main.js @@ -0,0 +1,76 @@ +'use strict'; + +(() => { + // === DOM & VARS ======= + + const module = document.querySelector('.product-manager') || console.warn('Product Manager Element not found'); + + if (!module) return; + + const DOM = { + module, + table: module.querySelector('.table-products'), + tbody: module.querySelector('tbody'), + inputName: module.querySelector('.input-product-name'), + inputPrice: module.querySelector('.input-product-price'), + btnAdd: module.querySelector('.button-product-add'), + }; + + console.log(DOM); + + // === INIT ============= + const init = () => { + // Funktionsaufrufe zu beginn der Anwendung + initProducts(); + // Event-Lauscher zu beginn der Anwendung + DOM.btnAdd.addEventListener('click', onClickAdd); + }; + + // === EVENTHANDLER ===== + const onClickAdd = (e) => { + const product = { + name: DOM.inputName.value, // + price: Number(DOM.inputPrice.valueAsNumber), + }; + + addProduct(product); + }; + // === XHR/FETCH ======== + + // === FUNCTIONS ======== + const initProducts = () => { + // PRODUCTS.forEach((product) => { + // addProduct(product); + // }); + PRODUCTS.forEach(addProduct); + }; + + const addProduct = (product) => { + const { name, price } = product; + const tdNameEl = createTd(name, 'td-name'); + const tdPriceEl = createTd(price, 'td-price'); + const trEl = createTr(tdNameEl, tdPriceEl); + + DOM.tbody.appendChild(trEl); + }; + + const createTd = (text, ...classNames) => { + const td = document.createElement('td'); + td.classList.add(...classNames); + td.textContent = text; + + return td; + }; + + const createTr = (...tds) => { + const tr = document.createElement('tr'); + // tds.forEach((td) => { + // tr.appendChild(td); + // }); + tr.append(...tds); + + return tr; + }; + + init(); +})(); diff --git a/03_js-dom/unterricht/tag23/01_product-manager/data/products.js b/03_js-dom/unterricht/tag23/01_product-manager/data/products.js new file mode 100644 index 0000000..abae521 --- /dev/null +++ b/03_js-dom/unterricht/tag23/01_product-manager/data/products.js @@ -0,0 +1,5 @@ +const PRODUCTS = [ + { name: '3Doodler 3D Printing Pen', price: 29.99 }, + { name: 'Powerstation 5- E. Maximus Chargus', price: 44.95 }, + { name: '8-Bit Legendary Hero Heat-Change Mug', price: 6.99 }, +]; diff --git a/03_js-dom/unterricht/tag23/01_product-manager/index.html b/03_js-dom/unterricht/tag23/01_product-manager/index.html new file mode 100644 index 0000000..e5d47eb --- /dev/null +++ b/03_js-dom/unterricht/tag23/01_product-manager/index.html @@ -0,0 +1,73 @@ + + + + + + Productmanager + + + + + + + +
+ +
+
+

Productmanager

+ + + + + + + + + + + + + + + + +
NamePrice in €
+
+
+ +
+
+
+ € + +
+
+
+ +
+
+
+
+
+
+ + diff --git a/03_js-dom/unterricht/tag23/01_product-manager/package.json b/03_js-dom/unterricht/tag23/01_product-manager/package.json new file mode 100644 index 0000000..50b089b --- /dev/null +++ b/03_js-dom/unterricht/tag23/01_product-manager/package.json @@ -0,0 +1,11 @@ +{ + "name": "01_product-manager", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "dev": "npx http-server -p 3000 -c-1" + }, + "keywords": [], + "type": "module" +} diff --git a/03_js-dom/unterricht/tag23/02_dom-creation/index.html b/03_js-dom/unterricht/tag23/02_dom-creation/index.html new file mode 100644 index 0000000..127e5e9 --- /dev/null +++ b/03_js-dom/unterricht/tag23/02_dom-creation/index.html @@ -0,0 +1,53 @@ + + + + + + DOM Creation + + + + +
+
+

DOM Creation

+
+ +
+
+ + + diff --git a/03_js-dom/unterricht/tag23/03_product-manager/assets/css/main.css b/03_js-dom/unterricht/tag23/03_product-manager/assets/css/main.css new file mode 100644 index 0000000..553ae7f --- /dev/null +++ b/03_js-dom/unterricht/tag23/03_product-manager/assets/css/main.css @@ -0,0 +1,22 @@ +*, +html { + box-sizing: border-box; +} + +html, +body { + padding: 0; + margin: 0; + height: 100%; +} + +/* Mobile first */ +.product-manager table tfoot .row > * { + margin-bottom: 0.5rem; +} + +@media (min-width: 992px) { + .product-manager table tfoot .row > * { + margin-bottom: 0; + } +} diff --git a/03_js-dom/unterricht/tag23/03_product-manager/assets/js/main.js b/03_js-dom/unterricht/tag23/03_product-manager/assets/js/main.js new file mode 100644 index 0000000..9112cd8 --- /dev/null +++ b/03_js-dom/unterricht/tag23/03_product-manager/assets/js/main.js @@ -0,0 +1,76 @@ +'use strict'; + +(() => { + // === DOM & VARS ======= + + const module = document.querySelector('.product-manager') || console.warn('Product Manager Element not found'); + + if (!module) return; + + const DOM = { + module, + table: module.querySelector('.table-products'), + tbody: module.querySelector('tbody'), + inputName: module.querySelector('.input-product-name'), + inputPrice: module.querySelector('.input-product-price'), + btnAdd: module.querySelector('.button-product-add'), + }; + + console.log(DOM); + + // === INIT ============= + const init = () => { + // Funktionsaufrufe zu beginn der Anwendung + initProducts(); + // Event-Lauscher zu beginn der Anwendung + DOM.btnAdd.addEventListener('click', onClickAdd); + }; + + // === EVENTHANDLER ===== + const onClickAdd = (e) => { + const product = { + name: DOM.inputName.value, // + price: Number(DOM.inputPrice.valueAsNumber), + }; + + addProduct(product); + }; + // === XHR/FETCH ======== + + // === FUNCTIONS ======== + const initProducts = () => { + // PRODUCTS.forEach((product) => { + // addProduct(product); + // }); + PRODUCTS.forEach(addProduct); + }; + + const addProduct = (product) => { + const { name, price } = product; + const tdNameEl = createTd(name, 'td-name'); + const tdPriceEl = createTd(price, 'td-price'); + const trEl = createTr(tdNameEl, tdPriceEl); + + DOM.tbody.appendChild(trEl); + }; + + const createTd = (text, ...classNames) => { + const td = document.createElement('td'); + td.classList.add(...classNames); + td.textContent = text; + + return td; + }; + + const createTr = (...tds) => { + const tr = document.createElement('tr'); + // tds.forEach((td) => { + // tr.appendChild(td); + // }); + tr.append(...tds); + + return tr; + }; + + init(); +})(); diff --git a/03_js-dom/unterricht/tag23/03_product-manager/data/products.js b/03_js-dom/unterricht/tag23/03_product-manager/data/products.js new file mode 100644 index 0000000..abae521 --- /dev/null +++ b/03_js-dom/unterricht/tag23/03_product-manager/data/products.js @@ -0,0 +1,5 @@ +const PRODUCTS = [ + { name: '3Doodler 3D Printing Pen', price: 29.99 }, + { name: 'Powerstation 5- E. Maximus Chargus', price: 44.95 }, + { name: '8-Bit Legendary Hero Heat-Change Mug', price: 6.99 }, +]; diff --git a/03_js-dom/unterricht/tag23/03_product-manager/index.html b/03_js-dom/unterricht/tag23/03_product-manager/index.html new file mode 100644 index 0000000..e5d47eb --- /dev/null +++ b/03_js-dom/unterricht/tag23/03_product-manager/index.html @@ -0,0 +1,73 @@ + + + + + + Productmanager + + + + + + + +
+ +
+
+

Productmanager

+ + + + + + + + + + + + + + + + +
NamePrice in €
+
+
+ +
+
+
+ € + +
+
+
+ +
+
+
+
+
+
+ + diff --git a/03_js-dom/unterricht/tag23/03_product-manager/package.json b/03_js-dom/unterricht/tag23/03_product-manager/package.json new file mode 100644 index 0000000..b20544a --- /dev/null +++ b/03_js-dom/unterricht/tag23/03_product-manager/package.json @@ -0,0 +1,11 @@ +{ + "name": "03_product-manager", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "dev": "npx http-server -p 3000 -c-1" + }, + "keywords": [], + "type": "module" +}