diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 71cf182e..59b1081a 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -1,7 +1,9 @@ $(function() { var role = $('#role').val(); + localStorage.removeItem("menus") type = window.location.href.indexOf("quick_service"); modify_order = window.location.href.indexOf("modify_order"); + //click menu sidebar menu category $(".product").on("click", function(){ var url = $(this).attr('data-ref'); @@ -62,8 +64,8 @@ $(function() { +JSON.stringify(item_attributes)+"' data-id = '" +JSON.stringify(item_attributes)+"' data-item = '" +JSON.stringify(item_attributes)+"' data-option = '" - +JSON.stringify(menu_items[field].options)+"'data-opt = '" - +JSON.stringify(menu_items[field].options)+"' data-item-sets = '" + +JSON.stringify(product[field].options)+"'data-opt = '" + +JSON.stringify(product[field].options)+"' data-item-sets = '" +JSON.stringify(item_attributes)+"' data-image='"+image_path+"' data-toggle='modal' data-target='.sx_item_detailModal'>" +"" +'view_list' @@ -76,8 +78,8 @@ $(function() { + product[field].unit_price +"' data-instance-code = '"+ product[field].item_code +"' data-instance = '" + product[field].name +"' data-promotion-price = '"+ 1 +"' data-attributes = '" + JSON.stringify(item_attributes) +"' data-options = '" - + JSON.stringify(menu_items[field].options) +"' data-opt = '" - + JSON.stringify(menu_items[field].options) +"' data-image='"+image_path+"'>" + + JSON.stringify(product[field].options) +"' data-opt = '" + + JSON.stringify(product[field].options) +"' data-image='"+image_path+"'>" // +"
" // +"" @@ -96,8 +98,8 @@ $(function() { } //end show list function //click menu sidebar menu category - $('.menu_category').on("click", function(){ - // event.preventDefault(); + $(document).on('click', '.menu_category', function(e){ + e.preventDefault(); $('.sub_category_list').addClass("hidden"); var menu_id = $(this).attr("data-id"); var url = "get_menu_category/"+menu_id; @@ -105,7 +107,7 @@ $(function() { var sub_id = $(this).attr("data-sub-id"); if (sub_id == "true") { var sub_url = "get_menu_sub_category/"+menu_id; - sub_category = $(this).find('.sub_category_list'); + sub_category = $(this).siblings('.sub_category_list'); show_sub_category_list(sub_url,sub_category,menu_id); } }); @@ -113,9 +115,11 @@ $(function() { //click menu sidebar menu category $(document).on('click', '.menu_sub_category', function(event){ - event.preventDefault(); + // event.preventDefault(); + // $(".menu_sub_category").on("click", function(){ $('.sub_category_list').addClass("hidden"); var menu_id = $(this).attr("data-id"); + console.log(menu_id); var url = "get_menu_category/"+menu_id; show_menu_item_list(url,menu_id); }); @@ -133,117 +137,6 @@ $(function() { for(var ii in categories) { if (categories[ii]["id"] == menu_id) { var menu_items = categories[ii]["items"]; - // for(var field in menu_items) { - // if (menu_items[field].is_sub_item == false) { - // instances = menu_items[field].instances ; - - // if (!instances.length > 0) { - // swal("Hello Please Check!","Does not have instance item in this menu items ("+ menu_items[field].name+")","warning"); - // } - // if (instances.length > 0) { - // qty = 1; - // options = []; - // price = 0; - - // if (JSON.stringify(menu_items[field].item_sets)!='[]') { - // fa_plus = ''; - // add = ''; - // menu_item_box = 'add_icon'; - // data_target = 'sx_item_set_detailModal'; - // data_modal = 'modal' - // add_icon = "set_item_box" - // code = menu_items[field].code; - // name = menu_items[field].name; - // instances = menu_items[field].instances; - // $(instances).each(function(i){ - // if (instances[i].is_default == true) { - // price = parseFloat(instances[i].price).toFixed(2); - // }else{ - // price = 0; - // } - // }); - // is_available = menu_items[field].is_available ; - // is_on_promotion = 0; - // item_attributes = menu_items[field].attributes; - // promotion_price = menu_items[field].promotion_price; - // }else{ - // fa_plus = 'material-icons'; - // add = 'view_list' - // menu_item_box = 'menu_item_box'; - // data_target = 'sx_item_detailModal'; - // data_modal = '' - // add_icon = "add_icon" - - // $(instances).each(function(i){ - // if (instances[i].is_default === true) { - // code = instances[i].code; - // name = instances[i].name; - // price = parseFloat(instances[i].price).toFixed(2); - // is_available = instances[i].is_available ; - // is_on_promotion = instances[i].is_on_promotion; - // item_attributes = instances[i].values; - // promotion_price = instances[i].promotion_price; - // code = instances[i].code; - // } - // }); - // } - - // if (menu_items[field].image) { - // if (modify_order) { - // image_path = "../../"+menu_items[field].image; - // }else{ - // image_path = menu_items[field].image; - // } - - // }else{ - // if (modify_order) { - // image_path = "../../image/logo.png"; - // }else{ - // image_path = "image/logo.png"; - // } - // } - - // row = '
' - // +'
' - // +'
'+ menu_items[field].name +'
' - // +"
" - // +"" - // +add+ '' - // +'
' - // +'
' - // +"
" - - // // +"
" - // // +"" - // // +"
" - - // +'' - // +'
'; - // $('.menu_items_list').append(row); - // } - // //end instances in menu-items alest 1 instance - // } - // //end is_sub_item false - // } show_menu_list(menu_items); } } @@ -272,118 +165,7 @@ $(function() { var menu_items_list = $('.menu_items_list'); menu_items_list.empty(); menu_items = data.menu_items; -show_menu_list(menu_items); - // for(var field in menu_items) { - // if (menu_items[field].is_sub_item == false) { - // instances = menu_items[field].instances ; - - // if (!instances.length > 0) { - // swal("Hello Please Check!","Does not have instance item in this menu items ("+ menu_items[field].name+")","warning"); - // } - // if (instances.length > 0) { - // qty = 1; - // options = []; - // price = 0; - - // if (JSON.stringify(menu_items[field].item_sets)!='[]') { - // fa_plus = ''; - // add = ''; - // menu_item_box = 'add_icon'; - // data_target = 'sx_item_set_detailModal'; - // data_modal = 'modal' - // add_icon = "set_item_box" - // code = menu_items[field].code; - // name = menu_items[field].name; - // instances = menu_items[field].instances; - // $(instances).each(function(i){ - // if (instances[i].is_default == true) { - // price = parseFloat(instances[i].price).toFixed(2); - // }else{ - // price = 0; - // } - // }); - // is_available = menu_items[field].is_available ; - // is_on_promotion = 0; - // item_attributes = menu_items[field].attributes; - // promotion_price = menu_items[field].promotion_price; - // }else{ - // fa_plus = 'material-icons'; - // add = 'view_list' - // menu_item_box = 'menu_item_box'; - // data_target = 'sx_item_detailModal'; - // data_modal = '' - // add_icon = "add_icon" - - // $(instances).each(function(i){ - // if (instances[i].is_default === true) { - // code = instances[i].code; - // name = instances[i].name; - // price = parseFloat(instances[i].price).toFixed(2); - // is_available = instances[i].is_available ; - // is_on_promotion = instances[i].is_on_promotion; - // item_attributes = instances[i].values; - // promotion_price = instances[i].promotion_price; - // code = instances[i].code; - // } - // }); - // } - - // if (menu_items[field].image) { - // if (modify_order) { - // image_path = "../../"+menu_items[field].image; - // }else{ - // image_path = menu_items[field].image; - // } - - // }else{ - // if (modify_order) { - // image_path = "../../image/logo.png"; - // }else{ - // image_path = "image/logo.png"; - // } - // } - - // row = '
' - // +'
' - // +'
'+ menu_items[field].name +'
' - // +"
" - // +"" - // +add+ '' - // +'
' - // +'
' - // +"
" - - // // +"
" - // // +"" - // // +"
" - - // +'' - // +'
'; - // $('.menu_items_list').append(row); - // } - // //end instances in menu-items alest 1 instance - // } - // //end is_sub_item false - // } + show_menu_list(menu_items); } }); //end Ajax @@ -405,26 +187,30 @@ show_menu_list(menu_items); item_options = $(this).data('options'); for(var field in item_sets) { - + $('.set_order').attr('data-min-qty',item_sets[field]["min_selectable_qty"]); value = item_sets[field]["instances"]; - $(value).each(function(i){ + $(value).each(function(i){ menus = JSON.parse(localStorage.getItem("menus")); if (menus != null) { - for(var i in menus) { - var categories = menus[i]["categories"]; + 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 iv in result) { - if (value[i]["id"] == result[iv]["id"]) { + for(var v in result) { + + if (value[i]["id"] == result[v]["id"]) { + + console.log("ssssssss") + row = '
' - +"
" +'
' - +''+result[iv]["name"]+'' + +''+result[v]["name"]+'' +'
' +'
' +'' +' ' +'
' +'' +'
' @@ -452,6 +238,8 @@ show_menu_list(menu_items); } } }else{ + type = window.location.href.indexOf("quick_service"); + modify_order = window.location.href.indexOf("modify_order"); if (type != -1 && modify_order != -1) { url = '../../../addorders/get_item_instance/'+value[i]["id"]; console.log("ssssssss") @@ -1376,7 +1164,6 @@ show_menu_list(menu_items); $(".keypress_qty").on('keyup change', function (){ // $('.keypress_qty').keyup(function(e){ - id = $(this).attr('id'); value = $(this).val(); @@ -1429,11 +1216,7 @@ show_menu_list(menu_items); for(var j in menus) { var categories = menus[j]["categories"]; for(var ii in categories) { - if (menu_id == categories[ii]["parent_id"]) { - console.log("parrrrrrrrrrrrrrrrr"); - console.log(categories[ii]["parent_id"]); - console.log(menu_id); - + if (menu_id == categories[ii]["parent_id"]) { $(sub_category).removeClass('hidden'); row = '' ; $(sub_category).append(row); diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index fd298fb3..e4e17328 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -18,14 +18,17 @@ class Origami::AddordersController < BaseOrigamiController if check_mobile @webview = true end - - # if params[:menus].present? - # @menus = JSON.parse(params[:menus], object_class: OpenStruct) - # @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') - # else - @menus = Menu.all - @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') - # end +puts params[:menu] +puts "sssssssssssssssssssssssssss" + if params[:menus].present? + @menus = JSON.parse(params[:menus], object_class: OpenStruct) + @menu = JSON.parse(params[:category], object_class: OpenStruct) + puts @menus.to_json + puts @menu.to_json + else + @menus = Menu.all + @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') + end @table_id = params[:id] @table = DiningFacility.find(@table_id) diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 43ab6db0..76b18ca1 100644 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -5,29 +5,16 @@ <% type = request.path_info.include?('quick_service')%> <% modify_order = request.path_info.include?('modify_order')%> -
+
-
- -
  • +
  • - <%= @menus[0].name %> - -
  • - -
    -
    -
    -
    - +
    + + + + + +
    +
    +
    +
    + + <%end %>
    +
    -
    +
    <% if type && modify_order%> -
    - <% else%> - -
    +
    + +
    + <% else%> + +
    -
    -
    - -
    - <% end%> - - -
    +
    +
    + +
    + <% end%> +
    <% else %>
    @@ -212,6 +219,7 @@ +