App.check_new_order = App.cable.subscriptions.create('CheckNewOrderChannel', {
  connected: function() {},

  disconnected: function() {},

  received: function(data) {   
    var hostname = location.hostname.trim();
    if(data.from == "" || hostname == data.from){ 
      var order  = data.data;
      var shop_code  = data.shop_code;
      if(order.length > 0){
        var order_lists = "";
        $.each(order, function(key, value){
          if(key==0){
            order_lists = value.order_reservation_id;
          }else if(key == (order.length - 1)){
            order_lists += ' and ' + value.order_reservation_id;
          }else{
            order_lists += ', ' + value.order_reservation_id;
          }
        });
        // alert(order_lists);
        if (typeof checkNewOrderAlert !== 'undefined' && $.isFunction(checkNewOrderAlert)) {
          checkNewOrderAlert(shop_code, order_lists);
        }
        // $("#notify_new_order_lists").text(order_lists);
        // if($("#"+shop_code+"_notify_new_order").hasClass("hidden")){
          // $("#"+shop_code+"_notify_new_order").removeClass("hidden");
        // }
        // $("#"+shop_code+"_notify_new_order").on('shown.bs.modal', function(e){
        //   // $(document).off('focusin.modal');
        //   $("#"+shop_code+"_notify_new_order").focus();
        //   $("#"+shop_code+"_doemal_new_order").addClass("hidden");
        //   $("#"+shop_code+"_notify_order_send_to_kitchen").addClass("hidden");
        //   $("#"+shop_code+"_notify_order_ready_to_delivery").addClass("hidden");
        // }).on('hide.bs.modal', function (e) {
        //   $("#"+shop_code+"_notify_new_order").addClass("hidden");
        // }).modal({show: true, keyboard: false, backdrop: false});
      }
    }
  }
});

