diff --git a/admin/index.php b/admin/index.php index 3f24e6e..08d662c 100644 --- a/admin/index.php +++ b/admin/index.php @@ -2,20 +2,26 @@ $relativePath = "../"; ob_start(); ?> + + Nom + Quantité + Prix + Code Barre + Type + Image + Actions + +

Gestion des Stocks

Ajouter un article

- - - - - - - - + + ' + @@ -32,13 +40,32 @@ function generateLine(item) { '' + '' + '' + - '' + + '' + + '' + '' + '' ); + // Fill in the type cell + for (let i = 0; i < item.type.length; i++) { + $('#typeList_' + item.code).append( + '
  • ' + item.type[i] + '
  • ' + ); + } +} + +function generateTypeCheckboxes() { + for (let i = 0; i < defaultTypes.length; i++) { + let id = 'typeCheck_' + defaultTypes[i]; + $('#typeCheckboxesCell').append( + '
    ' + + '' + + '' + + '
    ' + ); + } } function getItemOfCode(code) { @@ -52,13 +79,29 @@ function getItemOfCode(code) { return item; } +function addNewItem() { + if (isItemInputFilled()) { + let item = { + name: $.selector_cache('#nameInput').val(), + quantity: $.selector_cache('#quantityInput').val(), + price: $.selector_cache('#priceInput').val(), + code: $.selector_cache('#codeInput').val(), + type: getTypesChecked(), + image: $.selector_cache('#imageInput').val(), + }; + if (isCodeAvailable(item.code)) { + setEditFieldValues('', '', '', '', [], ''); + currentDataset.push(item); + generateLine(item); + } + } +} function editItem(elem) { if (isItemInputEmpty()) { let code = elem.id.replace('edit_', ''); let item = getItemOfCode(code); - console.log(item); - setEditFieldValues(item.name, item.quantity, item.price, item.code); + setEditFieldValues(item.name, item.quantity, item.price, item.code, item.type, item.image); removeItemFromList(item); // Move the item in the edit fields } } @@ -66,7 +109,6 @@ function editItem(elem) { function deleteItem(elem) { let code = elem.id.replace('delete_', ''); let item = getItemOfCode(code); - console.log(item); removeItemFromList(item); } @@ -75,28 +117,60 @@ function removeItemFromList(item) { $('#row_' + item.code).remove(); } -function setEditFieldValues(name, quantity, price, code) { +function getTypesChecked() { + let types = []; + for (let i = 0; i < defaultTypes.length; i++) { + let id = 'typeCheck_' + defaultTypes[i]; + if ($('#' + id).is(':checked')) { + types.push(defaultTypes[i]); + } + } + return types; +} + +function setTypesChecked(types) { + for (let i = 0; i < defaultTypes.length; i++) { + let id = 'typeCheck_' + defaultTypes[i]; + $('#' + id).prop('checked', types.indexOf(defaultTypes[i]) !== -1); + } + return types; +} + +function setEditFieldValues(name, quantity, price, code, type, image) { $.selector_cache('#nameInput').val(name); $.selector_cache('#quantityInput').val(quantity); $.selector_cache('#priceInput').val(price); $.selector_cache('#codeInput').val(code); + $.selector_cache('#codeInput').val(code); + setTypesChecked(type); + $.selector_cache('#imageInput').val(image); +} + +function isCodeAvailable (code) { + let isAvailable = true; + for (let i = 0; i < currentDataset.length; i++) { + if (currentDataset[i].code === code) { + isAvailable = false; + break; + } + } + return isAvailable; } function isItemInputEmpty() { return $.selector_cache('#nameInput').val() === '' && $.selector_cache('#quantityInput').val() === '' && $.selector_cache('#priceInput').val() === '' && - $.selector_cache('#codeInput').val() === ''; + $.selector_cache('#codeInput').val() === '' && + $.selector_cache('#imageInput').val() === '' && + getTypesChecked().length === 0; } -function addNewItem() { - let item = { - name: $.selector_cache('#nameInput').val(), - quantity: $.selector_cache('#quantityInput').val(), - price: $.selector_cache('#priceInput').val(), - code: $.selector_cache('#codeInput').val(), - }; - setEditFieldValues('', '', '', ''); - currentDataset.push(item); - generateLine(item); +function isItemInputFilled() { + return $.selector_cache('#nameInput').val() !== '' && + $.selector_cache('#quantityInput').val() !== '' && + $.selector_cache('#priceInput').val() !== '' && + $.selector_cache('#codeInput').val() !== '' && + $.selector_cache('#imageInput').val() !== '' && + getTypesChecked().length > 0; }
    NomQuantitéPrixCode BarreImageActions
    @@ -28,9 +34,12 @@ ob_start(); + + - + @@ -43,14 +52,7 @@ ob_start();

    Liste d'articles

    - - - - - - - - +
    NomQuantitéPrixCode BarreImageActions
    diff --git a/assets/css/stock.css b/assets/css/stock.css index a535a22..b1eeccc 100644 --- a/assets/css/stock.css +++ b/assets/css/stock.css @@ -3,12 +3,25 @@ table { margin-bottom: 20px; } -.name-column { - width : 30%; +.quantity-column, .price-column { + width: 150px; } .code-column { - width: 20%; + width: 200px; +} + +.type-column { + width: 200px; + overflow-x: auto; +} + +.image-column { + width: 150px; +} + +.actions-column { + width: 100px; } .stock-container { @@ -16,10 +29,7 @@ table { margin: 50px auto auto auto; } -.actions-column { - width: 100px; +#stockTable tr { + border-bottom: 1px solid #dedede; } -.image-column { - width: 150px; -} diff --git a/assets/js/stock.js b/assets/js/stock.js index bfacfb2..ff4ff9c 100644 --- a/assets/js/stock.js +++ b/assets/js/stock.js @@ -1,9 +1,17 @@ +let defaultTypes = [ + 'Nouveau', + 'Alimentaire', + 'Boissons', + 'Utilitaires' +]; + let defaultStock = [ { name: 'Granola', quantity: '2', price: '1.3', code: '7622210601988', + image : 'https://cookieandkate.com/images/2015/10/granola-mixed-in-bowl.jpg', type: [ 'Alimentaire', ] @@ -15,6 +23,7 @@ let currentDataset = []; $(document).ready(function () { currentDataset = defaultStock; generateTable(currentDataset); + generateTypeCheckboxes(); }); @@ -24,7 +33,6 @@ function generateTable(dataset) { } } - function generateLine(item) { $.selector_cache('#stockTable').append( '
    ' + item.quantity + '' + item.price + '' + item.code + 'LINK
      LINK' + '' + '' + '