$(document).ready(function() {
	$('#listaconti').DataTable({
		"responsive": true,
		"order": [[0, "desc"]]
	});
});

$(".draggable").draggable();

var d = new Date();
var month = d.getMonth()+1;
var day = d.getDate();
var strDate = d.getFullYear() + '-' +
    (month<10 ? '0' : '') + month + '-' +
    (day<10 ? '0' : '') + day;


$(document).on('click', '.open_modal_conto', function() {
	console.log(strDate);
	$("#nomeConto").empty();
	$("#Banca").empty();
	$('#form').find('input[type="text"], textarea, input[type="number"],input[type="date"],option').val("");
	$('#form').find('input[type="date"]').val(strDate);
	$('#myModal').modal('show');
	$('.modal-title').text(' Nuovo Conto');
	$('#form').attr('action', '/admin/conti');
});


$(document).on('click', '.open_modal_modifica', function() {
	var url = "/admin/conti";
	var riga_id = $(this).val();
	$("#Banca").empty();
	$("#IBAN").empty();
    $('#form').attr('method', 'POST');
    $('#form').attr('action', '/admin/conti' + '/' + riga_id+'?_method=PUT');
	$.getJSON(url + '/' + riga_id +'/edit', function(data) {
		// success data
        console.log(data[0]);
		$('.modal-title').text('Modifica conto');
		$('#nomeConto').val(data[0].nomeConto);
		$('#Banca').val(data[0].Banca);
		$('#IBAN').val(data[0].IBAN);
        $('#saldo_iniziale').val(data[0].saldo_iniziale);
        $('#note').val(data[0].note);
		$('#myModal').modal('show');


	});

});

