diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index 04b81bea..dd8bed28 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -36,18 +36,34 @@ $(document).ready(function(){ }); // complete for queue item - $('.order-complete').on('click',function(){ + $('.order-complete').on('click',function(){ + var _self= $(this); var assigned_item_id=$(this).attr('id').substr(15); var params = { 'id':assigned_item_id }; - // $(this).parent().parent(".queue_station").remove(); + var station=$(this).parent().parent(".queue_station").parent().parent().attr('id'); + $.ajax({ type: 'POST', url: '/oqs/update_delivery', data: params, dataType: 'json', - success: function(data){ - $('.order-complete').parent().parent(".queue_station").remove(); - alert('updated!'); + success: function(data){ + var queue_station=_self.parent().parent(".queue_station"); + + // Remove a queue card from current station + queue_station.remove(); + + // Remove a queue card from current station + queue_station.children('.card-footer').remove(); + + // Add removed queue card from station to completed + $("#completed").children('.card-columns').append(queue_station); + + // update queue item count in station + $("#"+station+"_count").text(parseInt($("#"+station+"_count").text())-1); + $("#completed_count").text(parseInt($("#completed_count").text())+1); + + alert("updated!"); } }); }); diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index e448ff23..bbfb166d 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -28,15 +28,10 @@ class Oqs::HomeController < BaseOqsController # update delivery status when complete click def update_delivery_status - puts "WWWW" + params[:id] assigned_item_id = params[:id] assigned_item=AssignedOrderItem.find(assigned_item_id) assigned_item.delivery_status=true - assigned_item.save - # respond_to do |format| - # format.json { render json: "updated" } - # end - flash[:success] = "updated!" + assigned_item.save end # Query for OQS with status @@ -49,7 +44,7 @@ class Oqs::HomeController < BaseOqsController left join order_items as odt ON odt.item_code = assigned_order_items.item_code left join customers as cus ON cus.id = od.customer_id") .where('assigned_order_items.delivery_status=' + status) - .group('oqs.station_name') + .group('assigned_order_items.id') .order("odt.item_name DESC") end end diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 7982e00d..69fe3f20 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -6,7 +6,7 @@