add out of stock action cable
This commit is contained in:
@@ -1543,11 +1543,11 @@ $(function() {
|
||||
image_path = menu_items[field].image;
|
||||
}
|
||||
if (out_of_stock === true) {
|
||||
// oos_item = out_of_stock_item
|
||||
oos_item = '<div class="card custom-card testimonial-card fadeInRight" style="height:100%;background-image:url(../../'+image_path+');background-repeat: no-repeat;pointer-events: none;opacity: 0.4;">'
|
||||
oos_header = '<div style="position: absolute;z-index: 5;top: 0;left: 0;right: 0;text-align: center;background: #fb483a;margin: auto;color: #fff;padding: 8px;font-weight: bolder;">OUT OF STOCK</div>'
|
||||
oos_item = out_of_stock_item
|
||||
oos_item = '<div class="card custom-card testimonial-card fadeInRight" id="'+ code +'" style="height:100%;background-image:url(../../'+image_path+');background-repeat: no-repeat;pointer-events: none;opacity: 0.4;">'
|
||||
oos_header = '<div class="head'+code+'" style="position: absolute;z-index: 5;top: 0;left: 0;right: 0;text-align: center;background: #fb483a;margin: auto;color: #fff;padding: 8px;font-weight: bolder;">OUT OF STOCK</div>'
|
||||
}else{
|
||||
oos_item = '<div class="card custom-card testimonial-card fadeInRight" style="height:100%;background-image:url(../../'+image_path+');background-repeat: no-repeat;">'
|
||||
oos_item = '<div class="card custom-card testimonial-card fadeInRight" id="'+ code +'" style="height:100%;background-image:url(../../'+image_path+');background-repeat: no-repeat;">'
|
||||
oos_header = ''
|
||||
}
|
||||
row = '<div class="col-md-6 col-sm-6 col-lg-3">'
|
||||
@@ -1596,15 +1596,15 @@ $(function() {
|
||||
}else{
|
||||
if (out_of_stock === true) {
|
||||
// oos_item = out_of_stock_item
|
||||
oos_item = '<div class="card custom-card testimonial-card fadeInRight" style="height:100%; pointer-events: none;opacity: 0.4;">'
|
||||
oos_header = '<div style="position: absolute;z-index: 5;top: 0;left: 0;right: 0;text-align: center;background: #fb483a;margin: auto;color: #fff;padding: 8px;font-weight: bolder;">OUT OF STOCK</div>'
|
||||
oos_item = '<div class="card custom-card testimonial-card fadeInRight" id="'+ code +'" style="height:100%; pointer-events: none;opacity: 0.4;">'
|
||||
oos_header = '<div class="head'+code+'" style="position: absolute;z-index: 5;top: 0;left: 0;right: 0;text-align: center;background: #fb483a;margin: auto;color: #fff;padding: 8px;font-weight: bolder;">OUT OF STOCK</div>'
|
||||
}else{
|
||||
oos_item = '<div class="card custom-card testimonial-card fadeInRight" style="height:100%;">'
|
||||
oos_item = '<div class="card custom-card testimonial-card fadeInRight" id="'+ code +'" style="height:100%;">'
|
||||
oos_header = ''
|
||||
}
|
||||
row = '<div class="col-md-6 col-sm-6 col-lg-3 mt-1">'
|
||||
+ oos_item + oos_header
|
||||
+'<div class="custom-card-no-img-head card-head '+add_icon+' " style="margin:0px;display:flex;!important "'
|
||||
+'<div class="custom-card-no-img-head card-head '+add_icon+' " id="oos'+ code +'" style="margin:0px;display:flex;!important "'
|
||||
+" data-item-code='"+ menu_items[field].code +"' "
|
||||
+" data-name='" + menu_items[field].name +"' "
|
||||
+" data-qty = '"+ qty +"' "
|
||||
|
||||
43
app/assets/javascripts/channels/out_of_stock.js
Normal file
43
app/assets/javascripts/channels/out_of_stock.js
Normal file
@@ -0,0 +1,43 @@
|
||||
App.checkin = App.cable.subscriptions.create('OutOfStockChannel', {
|
||||
|
||||
connected: function() {},
|
||||
|
||||
disconnected: function() {},
|
||||
|
||||
received: function(data) {
|
||||
if (data && data.item_instance_code) {
|
||||
console.log("out of stock channel!!!!");
|
||||
item_code = data.item_instance_code;
|
||||
item_code_id = '#' + data.item_instance_code;
|
||||
oos_id = '#oos' + data.item_instance_code;
|
||||
head_oos = 'head' + data.item_instance_code;
|
||||
rm_oos = '.' + head_oos;
|
||||
menus = localStorage.getItem('menus');
|
||||
|
||||
if (menus) {
|
||||
menus = jQuery.parseJSON(menus);
|
||||
menus.forEach(m =>
|
||||
m.categories.forEach(c =>
|
||||
c.items.forEach(i =>
|
||||
i.instances.forEach(instance => {
|
||||
if (instance.code == item_code) {
|
||||
if (data.status == true) {
|
||||
instance.out_of_stock = true;
|
||||
oos_header = '<div class="'+head_oos+'" style="position: absolute;z-index: 5;top: 0;left: 0;right: 0;text-align: center;background: #fb483a;margin: auto;color: #fff;padding: 8px;font-weight: bolder;">OUT OF STOCK</div>';
|
||||
$(item_code_id).css({"height": "100%", "pointer-events": "none", "opacity": "0.4"});
|
||||
$(oos_header).insertBefore($(oos_id));
|
||||
} else {
|
||||
instance.out_of_stock = false;
|
||||
$(item_code_id).css({"height": "", "pointer-events": "", "opacity": ""});
|
||||
$(rm_oos).remove();
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
localStorage.setItem('menus', JSON.stringify(menus));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user