diff --git a/css/index.css b/css/index.css index cae62fe..3ca5740 100644 --- a/css/index.css +++ b/css/index.css @@ -64,10 +64,17 @@ body { background-color: #3331; } -span.price { +.priceWrapper { float: right; + text-align: right; +} +span.price { font-family: var(--bs-font-monospace); font-size: 0.9rem; + padding-right: 3px; +} +span.price::after { + content: ' kr'; } .subtotal { @@ -109,4 +116,21 @@ span.price { .drag-over { border-bottom: dashed 3px red; border-bottom-width: 1px; -} \ No newline at end of file +} + +#totalPriceWrapper { + /*position: fixed;*/ + /*bottom: 0;*/ + /*right: 0;*/ + /*color: #fff;*/ + + background: #fff; + padding: 10px; + margin: 25px auto 0; + width: 90vw; + text-align: left; + max-width: 20rem; + border-radius: 30px; + font-weight: bold; +} +/*}*/ \ No newline at end of file diff --git a/plan/index.php b/plan/index.php index 34ca261..cf7d7c8 100644 --- a/plan/index.php +++ b/plan/index.php @@ -24,6 +24,7 @@
+


diff --git a/plan/plan.js b/plan/plan.js index 560f01d..f63efc5 100644 --- a/plan/plan.js +++ b/plan/plan.js @@ -13,8 +13,8 @@ class Store { html += "
"; html += "
"+this.title+"
"; html += "
"; - html += " edit name"; - html += " remove store"; + html += " edit name"; + html += " remove store"; html += "
"; html += "
"; html += "
"; - html += " "; + html += " "; html += "
"; this.selector = $(html).appendTo("#stores"); @@ -53,12 +53,10 @@ class Store { }); - this.selector.find('.editStoreName').one('click keyup', ev => { this.editNameFn(ev); }); + this.selector.find('.editStoreName').one('click', ev => { this.editNameFn(ev); }); - this.selector.find('.removeStore').on('click keyup', ev => { - if(ev.type === 'click' || ev.keyCode === 13){ - if(confirm("Are you sure you want to remove this store?")){ this.removeStore(); } - } + this.selector.find('.removeStore').on('click', ev => { + if(confirm("Are you sure you want to remove this store?")){ this.removeStore(); } }); $(function () { @@ -71,7 +69,7 @@ class Store { } editNameFn(ev){ - if(ev.type === 'click' || ev.keyCode === 13){ + if(ev.type === 'click'){ $(ev.target).parent().hide(); @@ -99,6 +97,7 @@ class Store { }); headerElem.find(".newName").on('keyup', ev3 => { this.resetEditNameFn(ev3); }); + headerElem.find('input').first().focus(); // $("body").one('click', ev3 => { this.resetEditNameFn(ev3); }); } } @@ -146,18 +145,18 @@ class Store { html += "
  • "; html += " "+text+""; - /* + /* * / html += "
    "; html += "
    "; - html += " "; - html += " "; - html += " x"+price.toFixed(2)+" kr"; - html += " "; + html += " "; + html += " "; + html += " x"+price.toFixed(2)+""; + html += " "; html += "
    "; html += "
    "; - */ - html += " "+price.toFixed(2)+" kr "; - html += "Remove item"; + /* */ + html += "
    "+price.toFixed(2)+""; + html += "Remove item
    "; html += "
  • "; this.selector.find("ul").append(html); @@ -203,8 +202,16 @@ class Store { return true; } - setItemAmount(pos, amount){ - this.items[pos].amount = amount; + setItemAmount(itemID, amount){ + + this.items.forEach((item, key) => { + if(item.itemID === itemID){ + this.items[key].amount = amount; + this.selector.find('#item_'+itemID+" .priceWrapper .price").html(Number(this.items[key].amount*this.items[key].price).toFixed(2)); + } + + }); + // this.items[pos].amount = amount; this.verify(); @@ -228,7 +235,7 @@ class Store { total += item.price*item.amount; // console.log("verify - item: "+item.price+"*"+item.amount); }); - $(this.selector).find(".subtotal .price").html(total.toFixed(2)+" kr"); + $(this.selector).find(".subtotal .price").html(total.toFixed(2)); // SHOW if-empty MESSAGE if(this.selector.find("li").length <= 1){ @@ -236,34 +243,23 @@ class Store { } // BIND add/remove item amount - this.selector.find('.itemAmountDown').each((key, val) => { - let that = this; - $(val).unbind().click(function(){ - let newValue = Number($(this).parent().find('.itemAmount').val())-1; - if(newValue > 0){ - $(this).parent().find('.itemAmount').val(newValue); - // UPDATE VALUE - that.setItemAmount(key+1, newValue); - } - }); - }); - this.selector.find('.itemAmountUp').each((key, val) => { - let that = this; - $(val).unbind().click(function(){ - let newValue = Number($(this).parent().find('.itemAmount').val())+1; - if(newValue < 100){ - $(this).parent().find('.itemAmount').val(newValue); - // UPDATE VALUE - that.setItemAmount(key+1, newValue); - } - }); - }); - this.selector.find('.itemAmount').each((key, val) => { - $(val).unbind().on('change', function(){ - let newValue = Number( console.log($(this).val()) ); - // UPDATE VALUE - that.setItemAmount(key+1, newValue); - }); + let that = this; + this.selector.find('.itemAmountBtn').off().on('click change', function(e){ + let itemid = $(this).parent().parent().parent().attr('data-itemid'); + let amountElem = $(this).parent().find('.itemAmount'); + let newValue = Number(amountElem.val()); + + if($(this).html() === "-"){ + newValue--; + } + else if($(this).html() === "+"){ + newValue++; + } + + if(newValue > 0 && newValue < 100){ + amountElem.val(newValue); + that.setItemAmount(itemid, newValue); + } }); // DRAGGABLE @@ -311,9 +307,10 @@ class Store { }); // BIND remove-buttons - $(this.selector).find(".remItem").unbind().each((key, val) => { + $(this.selector).find(".remItem").each((key, val) => { let that = this; - $(val).click(function(){ + $(val).off().on('click', function(){ + console.log("remItem", $(this).hasClass("confirm"), $(this)); if($(this).hasClass("confirm")){ that.remItem(key+1, $(this).attr('data-itemID'), $(this).attr("data-price")); @@ -323,15 +320,23 @@ class Store { catch(ignore){} } else { + console.log("remItem addClass"); $(".confirm").removeClass("confirm"); - $(this).addClass("confirm"); + setTimeout(() => { $(this).addClass("confirm"); }, 10); let newThat = this; setTimeout(function(){ $(newThat).removeClass("confirm"); }, 5000); } }); }); + + $(this.selector).find(".ariaButton").off('keydown').on('keydown', function(e){ + if(e.code === "Space" || e.code === "Enter"){ + e.preventDefault(); + $(this).trigger('click'); + } + }); } // STORE MANIPULATION @@ -480,7 +485,12 @@ function ajaxReq( data ){ function handleJsonErrors(json){ if(typeof json.status != "undefined" && json.status != 0){ - alert(json.message); + if(json.message === "Not logged in"){ + location.href = '../login.php'; + } + else { + alert(json.message); + } return true; }