45 lines
1.6 KiB
JavaScript
45 lines
1.6 KiB
JavaScript
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));
|
|
}
|
|
}
|
|
}
|
|
});
|