From bbcce13a2e2c068f73d8dfb7457af72f1402a12a Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 13 Sep 2017 09:21:35 +0630 Subject: [PATCH] update addorder --- app/assets/javascripts/OQS.js | 6 +- app/assets/javascripts/addorder.js | 69 +++++++++++++++---- .../menu_item_attributes_controller.rb | 5 +- .../menu_item_attributes/show.json.jbuilder | 8 +++ app/views/origami/addorders/detail.html.erb | 21 +++++- config/routes.rb | 2 +- 6 files changed, 86 insertions(+), 25 deletions(-) create mode 100644 app/views/api/restaurant/menu_item_attributes/show.json.jbuilder diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index c4035ead..64ebc678 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -18,8 +18,6 @@ //= require cable $(document).ready(function(){ - - $(".nav-completed").on("click", function(){ $("#completed").removeClass('hide') @@ -36,9 +34,7 @@ $(document).ready(function(){ var oqs_id = $(this).find(".oqs-id").text(); var url = 'oqs/get_items/'+oqs_id; - show_details(url); - - + show_details(url); }); //End Click diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index a394e468..ca424526 100644 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -8,12 +8,6 @@ $(function(){ }); //End menu category Click - $("#set_change_qty").change(function(){ - qty = $(this).val(); - price = $("#set_total_price").text(); - $("#set_total_price").text(qty*price); - }); - //show menu item list when click menu category function show_menu_item_list(url_item){ var menu_list = $('.menu_items_list'); @@ -152,7 +146,8 @@ $(function(){ $('#set_item_instances').text(instances); $('#set_name').text(data.attr('data-name')); $('#set_item_code').text(data.attr('data-item-code')); - $('#set_total_price').text(data.attr('data-price')); + // $('#set_total_price').text(data.attr('data-price')); + $('#set_total_price').text(0); $('#set_unit_price').text(data.attr('data-price')); }); // click instance for add item set @@ -179,7 +174,8 @@ $(function(){ sub_total = $('#set_total_price').text(); name = $(this).data('name'); price = $(this).data('price'); - qty = $('#set_change_qty').val(); + // qty = $('#set_change_qty').val(); + qty = document.getElementById("count").value; total = qty*price; var total_price = +sub_total - +total; $(this).removeClass('selected-instance'); @@ -187,10 +183,12 @@ $(function(){ $(this).removeAttr('data-options'); $('#instance_option').text('') }else { + sub_total = $('#set_total_price').text(); name = $(this).data('name'); price = $(this).data('price'); - qty = $('#set_change_qty').val(); + // qty = $('#set_change_qty').val(); + qty = document.getElementById("count").value; total = qty*price; var total_price = +sub_total + +total; $(this).addClass('selected-instance'); @@ -273,21 +271,48 @@ $(function(){ for(var field in instances) { value = instances[field].values; $(value).each(function(i){ - options = value[i]; - instance_attributes.push(options); + // options = value[i]; + // instance_attributes.push(options); + $.ajax({ + type: "GET", + url: '../../api/restaurant/menu_item_attributes/'+value[i], + data: {id:value[i]}, + success:function(result){ + + options = result["name"]; + instance_attributes.push(options); + } + }); }); } + selected_arr = [] + $(selected_item).each(function(i){ + $.ajax({ + type: "GET", + url: '../../api/restaurant/menu_item_attributes/'+selected_item[i], + data: {id:selected_item[i]}, + success:function(result){ + name = result["name"]; + selected_arr.push(name); + } + }); + }); + + for(var field in attributes) { value = attributes[field]["values"]; type = attributes[field]["type"] - row = "

"+attributes[field]["type"]+"

" + row = "

"+attributes[field]["type"]+"

"; + console.log(selected_arr); + console.log(value); + + console.log(instance_attributes); + $(value).each(function(i){ disabled = "" status =""; - - - if(parseInt(jQuery.inArray(value[i], selected_item))!== -1){ + if(parseInt(jQuery.inArray(value[i], selected_arr)) !== -1){ status = "selected-attribute"; } if(parseInt(jQuery.inArray(value[i], instance_attributes)) == -1){ @@ -654,13 +679,18 @@ $(function(){ var count = 1; var countEl = document.getElementById("count"); + $("#plus").on("click", function(){ count++; countEl.value = count; price = $("#unit_price").text(); $("#total_price").text(count*price); + + set_price = $("#set_unit_price").text(); + $("#set_total_price").text(qty*set_price); }); + $("#minus").on("click", function(){ if (count > 1) { count--; @@ -668,9 +698,18 @@ $(function(){ price = $("#unit_price").text(); $("#total_price").text(count*price); + + set_price = $("#set_unit_price").text(); + $("#set_total_price").text(qty*set_price); } }) + // $("#set_change_qty").change(function(){ + // qty = $(this).val(); + // price = $("#set_total_price").text(); + // $("#set_total_price").text(qty*price); + // }); + // $(".change_qty").change(function(){ // qty = $(this).val(); // price = $("#unit_price").text(); diff --git a/app/controllers/api/restaurant/menu_item_attributes_controller.rb b/app/controllers/api/restaurant/menu_item_attributes_controller.rb index 1b6a48d4..37719c37 100644 --- a/app/controllers/api/restaurant/menu_item_attributes_controller.rb +++ b/app/controllers/api/restaurant/menu_item_attributes_controller.rb @@ -1,9 +1,12 @@ class Api::Restaurant::MenuItemAttributesController < Api::ApiController - + skip_before_action :authenticate #Description # Pull the default menu details and also other available (active) menus # Input Params - order_id def index @menu_attributes = MenuItemAttribute.all end + def show + @attribute = MenuItemAttribute.find(params[:id]) + end end diff --git a/app/views/api/restaurant/menu_item_attributes/show.json.jbuilder b/app/views/api/restaurant/menu_item_attributes/show.json.jbuilder new file mode 100644 index 00000000..e158f807 --- /dev/null +++ b/app/views/api/restaurant/menu_item_attributes/show.json.jbuilder @@ -0,0 +1,8 @@ +if(@attribute) + json.id @attribute.id + json.type @attribute.attribute_type + json.name @attribute.name + json.value @attribute.value +else + json.success false +end \ No newline at end of file diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 4c32390b..c5da651b 100644 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -120,7 +120,7 @@ - + + + + + + + + diff --git a/config/routes.rb b/config/routes.rb index 6ac723aa..72d129ad 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,7 +33,7 @@ Rails.application.routes.draw do resources :menu, only: [:index, :show] resources :menu_categories, only: [:index, :show] resources :menu_items, only: [:index, :show] - resources :menu_item_attributes, only: [:index] + resources :menu_item_attributes, only: [:index, :show] resources :menu_item_options, only: [:index] resources :menu_sold_out, only: [:index] resources :menu_item_instances, only: [:show]