$(document).on('turbolinks:load', function() {
  $(".processitems").click(function(event){
    event.preventDefault();
    console.log($(this).data("id"));
    var item = $(this).data("id");
    $(this).toggleClass("opi_selected");

  });

  $(".processingitems_all").click(function(event){
    event.preventDefault();

    console.log($(this).data("id"));
    var group_id = $(this).data("id");
    var selector = "#" + group_id + " li div";
    console.log ($(selector));

    $(selector).removeClass("opi_selected");
    $(selector).addClass("opi_selected");
  });

  $(".processingitems_clr").click(function(event){
    event.preventDefault();

    console.log($(this).data("id"));
    var group_id = $(this).data("id");
    var selector = "#" + group_id + " li div";
    console.log ($(selector));

    $(selector).removeClass("opi_selected");
  });

  //Process the menu item data before submitting
  $("form").submit(function(e){
    //e.preventDefault();
    var items = new Array();
    selected_div = $(".opi_selected");
    $.each( selected_div, function( key, value ) {
      console.log($(value).attr("data-id"));
      items.push($(value).attr("data-id"));
    });

    $("#order_queue_station_processing_items").val(JSON.stringify(items));
    //$(this).submit();
  })
})
