function configSubmit(i){
  $.ajaxSetup({
    headers: {
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
      }
  });
  $.ajax({
    url:$(i).attr('action'),
    type:'PATCH',    
    data:$(i).serialize(),
    beforeSend: function( xhr ) {

    }
  })
  .done(function(data) {
    if(jQuery.isEmptyObject(data.error)){
      $('.resp-'+$(i).attr('data-id')).removeClass('alert alert-danger').addClass('alert alert-success').html(data.success).fadeIn(100);
    }else{
      $('.resp-'+$(i).attr('data-id')).removeClass('alert alert-success').addClass('alert alert-danger').html(data.error).fadeIn(100);
    }
  })
  .fail(function() {
    console.log("error");
  })
  .always(function(data) {

  });
}
$(function() {
  var count =0;
  $(document).on("click",".additem",function( event ) {  
    count++;
    var id = $(this).attr('data-id');
    var parent = $(this).attr('data-parent');
    var order = $(this).attr('data-order');
    $('.itemr-'+id).append('<li class="menu-list">'+
      '<a href="#" class="item-menu" >'+
        '<div href="#" class="alert-config">'+
          '<i class="icon-home4"></i>'+
          '<span> NEW item'+
           
          '</span>'+
        '<span class="config" style="float: right;">'+
          '<i class="open-ico icon-arrow-down32"></i>'+
        '</span>'+
        '</div>'+

      '</a>'+
    '<div class="info-menu-js ">'+
      '<div class="resp-">'+
      '</div>'+
        '<form action="" data-id="" onsubmit="configSubmit(this); return false">'+
          '<input type="hidden" name="parent" value="'+parent+'"> '+
          '<input type="hidden" name="order" value="'+order+'"> '+
          '<input type="hidden" name="action" value="addoption"> '+
          '<div class="form-group">'+
            '<label for="">Nombre option:</label>'+
            '<input type="text" name="name" value="" class="form-control form-cont">'+
          '</div>'+
          '<div class="form-group">'+
            '<label for="">Url:</label>'+
            '<input type="text" name="url" value="" class="form-control form-cont">'+
          '</div>'+
          '<div class="form-group">'+
            '<label for="">Icons:</label>'+
            '<input type="text" name="ico" value="" class="form-control  form-cont">'+
          '</div>'+
          '<div class="col-12 text-center">'+
          '<button class="btn btn-primary">Guardar</button>'+
        '</div>'+
        '</form>'+
      '</div>'+
    '</li>');
    event.preventDefault();
  });
});