diff --git a/www/css/index.css b/www/css/index.css index c10ce37..e3c9e4d 100644 --- a/www/css/index.css +++ b/www/css/index.css @@ -39,9 +39,9 @@ body { } .iconWrapper { - float: right; - margin-top: -30px; - margin-right: 10px; + /*float: right; */ + /*margin-top: -35px;*/ + /*margin-right: 10px;*/ } .iconWrapper img { margin-left: 10px; @@ -75,6 +75,7 @@ body { #stores .card-header { font-weight: bold; + height: 38px; } .priceWrapper { @@ -116,6 +117,10 @@ body.dollars span.price::after { text-align: center; } +.checkedItem span { + text-decoration: line-through; +} + .addItemForm div.form-control { transition: width 0.5s; } diff --git a/www/plan/do.php b/www/plan/do.php index 53619f0..8bb4373 100644 --- a/www/plan/do.php +++ b/www/plan/do.php @@ -98,6 +98,19 @@ if(!empty($data) && isset($user_id)){ } } + else if($data['plan'] == "checkItem"){ + if(($temp = checkArgs(array("storeID"=>@$data['storeID'], "itemID"=>@$data['itemID'], "checked"=>@$data['checked']))) !== true){ + returns("Missing a value: $temp", 1); + } + + if( checkItem($data['storeID'], $data['itemID'], $data['checked']) ){ + returns(); + } + else { + returns($db->error,1); + } + } + else if($data['plan'] == "remItem"){ if(($temp = checkArgs(array("storeID"=>@$data['storeID'], "itemID"=>@$data['itemID'], "price"=>@$data['price']))) !== true){ returns("Missing a value: $temp", 1); @@ -198,7 +211,7 @@ if(!empty($data) && isset($user_id)){ while($stores = $result->fetch_assoc()){ - if($result2 = $db->query("SELECT `plan_item_id`, `name`, `price`, `amount` FROM plan_store_item WHERE `plan_store_id` = '$stores[plan_store_id]' ORDER BY pos")){ + if($result2 = $db->query("SELECT `plan_item_id`, `name`, `price`, `amount`, `checked` FROM plan_store_item WHERE `plan_store_id` = '$stores[plan_store_id]' ORDER BY pos")){ $stores['items'] = []; if($result2->num_rows > 0){ @@ -371,13 +384,25 @@ function addItem($storeID, $name, $price){ return false; } +function checkItem($storeID, $itemID, $checked){ + global $db, $spaceID; + + $verifyUserOwnershipSQL = "SELECT `plan_store_id` FROM plan_store WHERE `space_id` = '$spaceID' AND `plan_store_id` = '$storeID'"; + $findRowSql = "SELECT `plan_item_id` FROM plan_store_item WHERE `plan_store_id` = ($verifyUserOwnershipSQL) AND `plan_item_id` = '$itemID'"; + $checkItemSql = "UPDATE plan_store_item SET `checked` = ".($checked?1:0)." WHERE `plan_item_id` = ($findRowSql);"; + if($db->query($checkItemSql)){ + return true; + } + return false; +} + function remItem($storeID, $itemID, $price){ global $db, $spaceID; $verifyUserOwnershipSQL = "SELECT `plan_store_id` FROM plan_store WHERE `space_id` = '$spaceID' AND `plan_store_id` = '$storeID'"; $findRowSql = "SELECT `plan_item_id` FROM plan_store_item WHERE `plan_store_id` = ($verifyUserOwnershipSQL) AND `plan_item_id` = '$itemID'"; - $removeItemsql = "DELETE FROM plan_store_item WHERE `plan_item_id` = ($findRowSql) AND `price` = '$price';"; - if($db->query($removeItemsql) && mysqli_affected_rows($db) > 0){ + $removeItemSql = "DELETE FROM plan_store_item WHERE `plan_item_id` = ($findRowSql) AND `price` = '$price';"; + if($db->query($removeItemSql) && mysqli_affected_rows($db) > 0){ return true; } return false; diff --git a/www/plan/index.php b/www/plan/index.php index 6c3800b..160a383 100644 --- a/www/plan/index.php +++ b/www/plan/index.php @@ -33,32 +33,5 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/www/plan/plan.js b/www/plan/plan.js index 4ce5718..7619bf9 100644 --- a/www/plan/plan.js +++ b/www/plan/plan.js @@ -2,7 +2,7 @@ class Store { constructor(title, storeID, state) { - this.items = []; + this.itemsObj = {}; this.state = state || 'planning'; // states: planning/shopping/closed let storeNum = $(".store").length+1; @@ -11,19 +11,19 @@ class Store { let html = ""; html += "
"; - html += "
"+this.title+"
"; - html += "
"; + html += "
"; html += " "; html += "
"; - html += "
"; + html += "
"; html += " edit name"; // html += " sort items"; html += " remove store"; html += "
"; + html += "
"+this.title+"
"; html += "
"; html += "
    "; html += "
  • No items added
  • "; @@ -98,14 +98,18 @@ class Store { if(state === "planning"){ this.state = "planning"; - this.selector.find('.itemAmountButtons').slideDown(animTime); - this.selector.find('.itemAmountText').slideUp(animTime); + this.selector.find('li:not(.checkedItem) .itemAmountButtons').slideDown(animTime); + this.selector.find('li:not(.checkedItem) .itemAmountText').slideUp(animTime); + this.selector.find('.checkedItem .itemAmountText').slideDown(animTime); + this.selector.find('.addItemFormWrapper').slideDown(animTime); + this.selector.find('.remItem').show(); } if(state !== "planning"){ this.selector.find('.itemAmountButtons').slideUp(animTime); this.selector.find('.itemAmountText:not(.oneItem)').slideDown(animTime); this.selector.find('.addItemFormWrapper').slideUp(animTime); + this.selector.find('.remItem').hide(); } if(state === "shopping"){ @@ -117,10 +121,10 @@ class Store { if(state === "closed"){ this.state = "closed"; - this.selector.find('.remItem').hide(); + } if(state !== "closed"){ - this.selector.find('.remItem').show(); + } if(prevState !== state){ @@ -196,21 +200,23 @@ class Store { } } - addItemHtml(text, price, itemID, amount){ + addItemHtml(text, price, itemID, amount, checked){ amount = amount || 1; + checked = Number(checked) || 0; + try { price = Number(price); - this.items.push({ text: text, price: price, itemID: itemID, amount: amount }); + this.itemsObj[itemID] = { text: text, price: price, itemID: itemID, amount: amount, checked: checked }; let html = "\n"; - html += "
  • "; + html += "
  • "; html += " "+text+""; html += "
    "+(price*amount).toFixed(2)+""; html += "Remove item
    "; html += " "; - html += "
    "; // "+(this.state !== "planning"?"style='display: none;'":'')+" + html += "
    "; html += " "; html += " "; if(price !== 0) { @@ -218,7 +224,7 @@ class Store { } html += " "; html += "
    "; - html += "