Bugfixes state-change.

master
Eirik Th S 2021-06-08 15:09:41 +02:00
parent 8a656b93e1
commit 2905911756
2 changed files with 42 additions and 57 deletions

View File

@ -191,7 +191,7 @@ if(!empty($data) && isset($user_id)){
else {
$sql = "SELECT `plan_store_id`, `name`, `created` FROM plan_store WHERE space_id = $spaceID";
$sql = "SELECT `plan_store_id`, `name`, `created`, `state` FROM plan_store WHERE space_id = $spaceID";
$result = $db->query($sql);
if($result->num_rows > 0){

View File

@ -64,9 +64,8 @@ class Store {
});
/** CHANGE STATE **/
this.selector.find('.iconWrapper .page-item').on('click', ev=>{
console.log(ev);
this.selector.find('.page-item.active').removeClass('active');
$(ev.currentTarget).addClass('active');
@ -80,25 +79,7 @@ class Store {
else if($(ev.currentTarget).hasClass('closedState')){
this.setState('closed');
}
});
/**
this.selector.find('.lockStore').tooltip({title: 'Lock Store'});
this.selector.find('.lockStore').on('click', ev => {
let lockIcon = $(ev.target);
if(this.lockStore() === 1){
lockIcon.attr({ 'src': '../icon/lock.svg', 'title': 'Unlock store' });
lockIcon.tooltip('dispose');
lockIcon.tooltip({title: 'Unlock Store'});
lockIcon.tooltip('show');
}
else {
lockIcon.attr({ 'src': '../icon/unlock.svg', 'title': 'Lock store' });
lockIcon.tooltip('dispose');
lockIcon.tooltip({title: 'Lock Store'});
lockIcon.tooltip('show');
}
});*/
this.selector.find('.editStoreName').one('click', ev => { this.editNameFn(ev); });
@ -111,44 +92,47 @@ class Store {
});
}
lockStore(){
if(this.state === "planning"){
this.setState("shopping");
return 1;
setState(state, animTime){
animTime = animTime || 200;
let prevState = this.state;
if(state === "planning"){
this.state = "planning";
this.selector.find('.itemAmountButtons').slideDown(animTime);
this.selector.find('.itemAmountText').slideUp(animTime);
this.selector.find('.addItemFormWrapper').slideDown(animTime);
}
this.setState("planning");
return 0;
}
setState(state){
switch (state){
case "planning":
this.state = "planning";
this.selector.find('.itemAmountButtons').slideDown(200);
this.selector.find('.itemAmountText').slideUp(200);
this.selector.find('.addItemFormWrapper').slideDown(200);
break;
case "shopping":
this.state = "shopping";
this.selector.find('.itemAmountButtons').slideUp(200);
this.selector.find('.itemAmountText:not(.oneItem)').slideDown(200);
this.selector.find('.addItemFormWrapper').slideUp(200);
break;
case "closed":
this.state = "closed";
break;
if(state !== "planning"){
this.selector.find('.itemAmountButtons').slideUp(animTime);
this.selector.find('.itemAmountText:not(.oneItem)').slideDown(animTime);
this.selector.find('.addItemFormWrapper').slideUp(animTime);
}
ajaxReq({ plan: 'setState', storeID: this.storeID, state: this.state });
if(state === "shopping"){
this.state = "shopping";
}
if(state !== "shopping"){
}
if(state === "closed"){
this.state = "closed";
this.selector.find('.remItem').hide();
}
if(state !== "closed"){
this.selector.find('.remItem').show();
}
if(prevState !== state){
ajaxReq({ plan: 'setState', storeID: this.storeID, state: this.state });
}
}
editNameFn(ev){
if(ev.type === 'click'){
$(ev.target).parent().hide();
this.selector.find('.iconWrapper').hide();
// $(ev.target).parent().hide();
let headerElem = $(ev.target).parent().parent().find(".card-header");
let orgHtml = headerElem.html();
@ -226,7 +210,7 @@ class Store {
html += "<img src='../icon/dash-circle.svg' alt='Remove item' class='remItem ariaButton' data-itemID='"+itemID+"' data-price='"+price+"' style='margin-right: 3px;' tabindex='0' role='button'></div>";
html += " <span class='itemAmountWrapper' style='float: left; padding: 0 10px;'>";
html += " <div class='input-group itemAmountButtons'>";
html += " <div class='input-group itemAmountButtons' >"; // "+(this.state !== "planning"?"style='display: none;'":'')+"
html += " <button class='btn btn-outline-danger itemAmountBtn' type='button'>-</button>";
html += " <input class='form-control itemAmount itemAmountBtn' type='number' value='"+amount+"' min='0' max='99' aria-label='Amount of item' >";
if(price !== 0) {
@ -234,7 +218,7 @@ class Store {
}
html += " <button class='btn btn-outline-success itemAmountBtn' type='button'>+</button>";
html += " </div>";
html += " <div class='itemAmountText "+(amount <= 1?"oneItem":"")+"' style='display: none;'>";
html += " <div class='itemAmountText "+(amount <= 1?"oneItem":"")+"' style='display: none;'>"; // "+(this.state !== "shopping"?"style='display: none;'":'')+"
html += " Amount: <span class='itemAmount' style='padding-left: 10px;'>"+amount+"</span>x <span class='price'>" + price.toFixed(2) + "</span>";
html += " </div>";
html += " </span>";
@ -555,16 +539,17 @@ function getStores(spaceID){
// console.log(json);
for(const store in json.data){
let storeID = stores.length;
let storeKey = stores.length;
stores.push(new Store(json.data[store].name, json.data[store].plan_store_id));
stores.push(new Store(json.data[store].name, json.data[store].plan_store_id, json.data[store].state));
for(const item in json.data[store].items){
stores[storeID].addItemHtml(
stores[storeKey].addItemHtml(
json.data[store].items[item].name,
json.data[store].items[item].price,
json.data[store].items[item].plan_item_id,
json.data[store].items[item].amount);
}
stores[storeKey].setState(json.data[store].state, 1);
}
updateTotalPrice();
})