<div class="modal fade" id="CrearEjemplar" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title caption-subject font-blue-secondary sbold uppercase">Crear Ejemplar</h4>
            </div>
            {{ Form::open(['route' => 'ejemplar.crear','class'=>'form-horizontal','id' => 'form-validation','style'=>'padding: 5px 5px 5px 5px;','enctype'=> 'multipart/form-data']) }}
            {{ csrf_field() }}
            {{ Form::hidden('id', $libro->id) }}
            <div class="modal-body">
                <div id="ejemplarinfo">
                    <div class="col-xs-12 row" style="padding-bottom: 25px">
                        <h4 class="page-head">
                            Datos del Ejemplar
                        </h4>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-3 col-xs-12">
                            <label class = "caption-subject font-blue-secondary sbold">
                                Codigo
                            </label>
                        </div>
                        <div class="col-md-9 col-xs-12">
                            {!! Form::text('codigo_CS', null, ['class' => 'form-control', 'id' => 'codigo_CS', 'required' => 'required']) !!}
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-3 col-xs-12">
                            <label class = "caption-subject font-blue-secondary sbold">
                                Año
                            </label>
                        </div>
                        <div class="col-md-9 col-xs-12">
                            {!! Form::text('anio', null, ['class' => 'form-control fecha_publicacion form-control-inline date-picker','id' => 'fecha_publicacion','type'=> 'text', 'required' => 'required']) !!}
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-3 col-xs-12">
                            <label class = "caption-subject font-blue-secondary sbold">
                                Edición
                            </label>
                        </div>
                        <div class="col-md-9 col-xs-12">
                            {!! Form::text('edicion', null, ['class' => 'form-control', 'required' => 'required']) !!}
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" id="btn-submit" class="btn btn-primary mt-ladda-btn ladda-button" data-style="slide-down">
                    <span class="ladda-label">Guardar</span>
                    <span class="ladda-spinner"></span>
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancelar</button>
            </div>
            {!! Form::close() !!}
        </div>
    </div>
</div>
<script>
    Ladda.bind('.mt-ladda-btn');
    $("#form-validation").validate();
    var currentYear =  new Date().getFullYear().toString();

    $(function () {
        $('.fecha_publicacion').datepicker({
            format: " yyyy",
            viewMode: "years",
            minViewMode: "years",
            maxViewMode: "years",
            endDate: currentYear,
            inline: true,
            autoclose:true
        });
    });



    var O = false;
    $(document).ready(function () {
        $("#btn-submit").on('click',function() {
            $.ajax({
                type: 'post',
                url: "{{url('bibliografia/CutterSanborn')}}",
                data: {code : $('#codigo_CS').val()},
                success: function (data) {
                    if(data == 200 ){
                        $("#form-validation").submit();
                    }else if(data == 500){
                        O = false;

                        $("#CrearEjemplar").modal('hide');

                        swal("Advertencia",'El Código del ejemplar ya existe','warning');

                    }

                },
                error: function (data) {
                    swal('error','','warning');
                }
            });
        });
    });

</script>