diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 2d53ed99..277fa690 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -62,7 +62,7 @@ $(function() { +'' - +"
"+type+"
" $(value).each(function(i){ - row +=""; }); @@ -553,7 +563,7 @@ $(function() { // click plus icon for add $(document).on('click', '.add_icon', function(event){ - if($(this).find('.product_box')) { + if($(this).hasClass('product_item')) { $('.sx_item_detailModal').modal('hide'); var item_data = $(this); @@ -590,6 +600,28 @@ $(function() { return } else { + count = 0 + for (var i in $(this).data('instances')) { + if(!$(this).data('instances')[i].out_of_stock) { + count += 1; + } + } + + if (count === 1) { + $('.sx_item_detailModal').modal('hide'); + + var item_data = $(this); + code = $(this).data('instance-code'); + + if ($('#server_mode').val() != "cloud" && second_display_lookup == 2) { + item = get_item(item_data,"add_icon"); + customer_display_view(item,"add"); + } + show_item_detail(item_data,"add_icon"); + calculate_sub_total(); + autoScrollToItem(code) + return + } attributes = $(this).data('id'); selected_item = $(this).data('attributes'); @@ -648,12 +680,17 @@ $(function() { total_price = 0 for(var field in instances) { - if (instances[field].out_of_stock && instances[field].is_default) { + if (instances[field].out_of_stock) { oos_values = instances[field].values; $('#add_to_order').attr('disabled', true); $('#minus').attr('disabled', true); $('#plus').attr('disabled', true); $('#count').attr('readonly', true) + } else { + $('.add_to_order').removeAttr('disabled'); + $('#minus').removeAttr('disabled'); + $('#plus').removeAttr('disabled'); + $('#count').removeAttr('readonly'); } value = instances[field].values; @@ -669,6 +706,10 @@ $(function() { oos_values = oos_values.sort() } + if (attributes.length === 0) { // for product_box + total_price = data.attr('data-price'); + } + for(var field in attributes) { value = attributes[field]["values"]; type = attributes[field]["type"] @@ -691,7 +732,9 @@ $(function() { row +=""; }); @@ -724,10 +767,14 @@ $(function() { // click select option icon for add $(document).on('click', '.attribute_btn', function(event){ + $('.attributes-list button').removeClass('bg-gray box-shadow-none'); + // $('.change_qty').val(1); value = $(this).data('value'); type = $(this).data('type'); instances = $(this).data('instances'); + item_attributes = $(this).data('attributes'); + selected_values = [] attributes = $(".attribute_btn"); $(attributes).each(function(i){ @@ -737,10 +784,44 @@ $(function() { }); $(this).addClass('selected-attribute'); - // if ($(".attribute_btn").attr("data-type")==type){ - // $('.'+type).removeClass("selected-attribute"); - // } - // $(this).addClass('selected-attribute'); + $('button.selected-attribute').each(function(i) { + selected_values.push($(this).data('value')); + }) + + for(var sv in selected_values) { + current_type = $('.attributes-list').find(`button[data-value='${selected_values[sv]}']`).data('type') + for (var i in item_attributes) { + available_btn = [] + if (item_attributes[i].type != current_type) { + for(var j in instances) { + if (instances[j].values.includes(selected_values[sv]) && instances[j].out_of_stock == false) { + $.map(instances[j].values, function(v) { + if (v != selected_values[sv]) { + available_btn.push(v) + } + }) + } + } + if (available_btn.length == 0) { + element = $('.attributes-list').find(`button[data-type!='${current_type}']`) + $.map(element, function(elem) { + if (!$(elem).hasClass('bg-gray')) { + $(elem).addClass('bg-gray box-shadow-none'); + } + }) + } else { + $.map(available_btn, function(btn) { + element = $('.attributes-list').find(`button[data-type !='${current_type}'][data-value!='${btn}']`) + $.map(element, function(elem) { + if (!$(elem).hasClass('bg-gray') && !available_btn.includes($(elem).data('value'))) { + $(elem).addClass('bg-gray box-shadow-none') + } + }) + }); + } + } + } + } var selected_attr = get_selected_attributes('selected-attribute'); @@ -770,7 +851,7 @@ $(function() { } } $('#wanring_text').text('') - $('#wanring_text').append('' + text + ' is sold out.') + $('#wanring_text').append('' + text + ' is out of stock.') $('#add_to_order').attr('disabled', true) $('#minus').attr('disabled', true); $('#plus').attr('disabled', true); @@ -823,7 +904,6 @@ $(function() { value = $(this).data('value'); type = $(this).data('type'); group = $(this).data('group'); - console.log(group); options = $(".option_btn"); $(options).each(function(i){ if ($(options[i]).attr('data-type')==type){ @@ -919,8 +999,6 @@ $(function() { attribute_arr = attribute_arr.sort() instance_arr = instances[field].values.sort() if (JSON.stringify(attribute_arr) === JSON.stringify(instance_arr)) { - console.log('instances'); - console.log(attrbu); $('.add_to_order').attr('data-instance-code',instances[field].code); $('.add_to_order').attr('data-instance',instances[field].name); $('.add_to_order').attr('data-price',instances[field].price); @@ -954,7 +1032,6 @@ $(function() { // scroll to element function autoScrollToItem(code) { - console.log(code) element = $('.summary-items').find(`[data-instance-code='${code}']`); item_qty = element.find('#item_qty').text() parent = element.parents('.card-text') @@ -991,12 +1068,10 @@ $(function() { function isNotInView(elem, parent){ // for scroll up | for scroll down result = (($(elem).offset().top - 100) < $(elem).height() || $(parent).height() < (elem.position().top + elem.outerHeight(true))); - console.log(result) return result // reutn boolean } function scrollToELement(elem) { - console.log('Scroll into view') elem[0].scrollIntoView(); } @@ -1649,8 +1724,8 @@ $(function() { function show_menu_list(menu_items) { var menu_list = $('.menu_items_list'); menu_list.empty(); + console.log(menu_items); for(var field in menu_items) { - console.log(menu_items[field].instances); if (menu_items[field].is_sub_item == false) { instances = menu_items[field].instances ; @@ -1693,7 +1768,7 @@ $(function() { add_icon = "add_icon" $(instances).each(function(i){ - if (instances[i].is_default === true) { + if (instances[i].is_default === true && !instances[i].out_of_stock) { code = instances[i].code; name = instances[i].name; price = parseFloat(instances[i].price).toFixed(2); @@ -1710,26 +1785,55 @@ $(function() { pointer_event = 'cursor' opacity = '' status = '' - if (instances.length == 1) { - if (instances[0].out_of_stock == true) { - pointer_event = 'none' - opacity = '0.5' - status = 'out of stock' - } - } else { - count = 0; - $(instances).each(function(i) { - if (instances[i].out_of_stock == true) { - count += 1 + count = 0; + $(instances).each(function(i) { + if (instances[i].out_of_stock == true) { + count += 1 + if (instances.length == count) { // all attributes out of stock + pointer_event = 'none' status = 'out of stock' - - if (instances.length == count) { // all attributes out of stock - pointer_event = 'none' - opacity = '0.5' - } - + opacity = '0.5' } - }) + + } + }) + + if (JSON.stringify(menu_items[field].item_sets)!='[]') { // check all item_sets out of stock?? + item_sets = menu_items[field].item_sets + oos_count = 0 + available_count = 0 + for(var f in item_sets) { + value = item_sets[f]["instances"]; + $(value).each(function(i){ + menus = JSON.parse(localStorage.getItem("menus")); + if (menus != null) { + for(var j in menus) { + var categories = menus[j]["categories"]; + for(var ii in categories) { + var items = categories[ii]["items"]; + for(var iii in items) { + var result = items[iii]["instances"]; + for(var v in result) { + if (value[i]["id"] == result[v]["id"]) { + if (result[v].is_available) { + available_count += 1 + if (result[v].out_of_stock) { + oos_count += 1 + } + } + } + } + } + } + } + } + }) + if(available_count == oos_count) { + pointer_event = 'none' + opacity = '0.5' + status = 'out of stock' + } + } } if (status) { @@ -1744,7 +1848,7 @@ $(function() { }else{ image_path = menu_items[field].image; } - oos_item = '