<?php $__env->startSection('content'); ?>
    <h1 class="page-title">
        <a class=" icon-action-undo" href="<?php echo e(url('bibliografia')); ?>" style="padding: 5px;"></a>
        Gestión de Bibliografía
    </h1>

    <?php echo e(Form::open(['route' => 'bibliografia.crear','class'=>'form-horizontal','id' => 'form-validation','style'=>'padding: 5px 5px 5px 5px;','enctype'=> 'multipart/form-data'])); ?>

    <?php echo e(csrf_field()); ?>


    <div class="portlet light portlet-fit portlet-form bordered">
        <div class="portlet-title">
            <div class="caption">
                <span class="caption-subject sbold uppercase"> Creación de Bibliografía </span>
            </div>
        </div>
        <div class="portlet-body">
            <div class="col-xs-12" style="padding-bottom: 25px">
                <h4 class="page-head">
                    Datos Generales
                </h4>
            </div>

            <?php echo $__env->make('alerts.index', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

            <div class="Forum-ForumTopicList row" style="margin:20px">
                <div class="form-group row">
                    <div class="col-md-3 col-xs-12">
                        <label class="font-blue-secondary sbold">
                            Nombre
                        </label>
                    </div>
                    <div class="col-md-9 col-xs-12">
                        <?php echo Form::text('nombre', null, ['class' => 'form-control', '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">
                            Materia
                        </label>
                    </div>
                    <div class="col-md-9 col-xs-12">
                        <?php echo Form::text('materia', null, ['class' => 'form-control', '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">
                            Lugar de Publicación
                        </label>
                    </div>
                    <div class="col-md-9 col-xs-12">
                        <?php echo Form::text('ciudad_pais', null, ['class' => 'form-control', '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">
                            Epílogo
                        </label>
                    </div>
                    <div class="col-md-9 col-xs-12">
                        <?php echo Form::textarea('epilogo', null, ['class' => 'form-control', 'style' => 'resize:none;', '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">
                            Imagen
                        </label>
                    </div>
                    <div class="col-md-9 col-xs-12">
                        <div class="form-group col-xs-12">
                            <input name="img" type="file" class="filestyle" accept="image/jpeg" data-buttonText="Seleccionar un Archivo" data_buttonName="btn-primary" style="width:400px;"/>
                            <label class="" style="margin:0; font-size:11px;">
                                Sólo se permite archivos en formato jpeg.
                            </label>
                        </div>
                    </div>
                </div>
                <div class="form-group row">
                    <div class="col-md-3 col-xs-12">
                        <label class = "caption-subject font-blue-secondary sbold">
                            Editorial
                        </label>
                    </div>
                    <div class="col-md-9 col-xs-12">
                        <?php echo Form::text('editorial', null, ['class' => 'form-control', '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">
                            Tipo de Bibliografía
                        </label>
                    </div>
                    <div class="col-md-9 col-xs-12">
                        <?php echo Form::select('id_tipo_bibliografia', $tipos,'',['class' => 'form-control select2', '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">
                            Autor
                        </label>
                    </div>
                    <div id="the-basics" class="col-md-9 col-xs-12">
                        <div class="row" style="padding-left:15px; padding-right:15px">
                            <?php echo Form::select('id_autor', array(),'',['class' => 'form-control', 'id'=>'Autores', 'required' => 'required', 'style' => 'width:100%']); ?>

                        </div>
                    </div>
                </div>
                <div>
                    <div class="row">
                        <div class="col-md-3 col-xs-12">
                            <label class="caption-subject font-blue-seconday sbold">
                                Es Bibliografía Virtual ?
                            </label>
                        </div>
                        <div class="col-md-9 col-xs-12">
                            <input id="virtual" name="virtual" type="checkbox"/>
                        </div>
                    </div>
                </div>
                <div>
                    <div class="row">
                        <div class="col-md-3 col-xs-12">
                            <label class="caption-subject font-blue-seconday sbold">
                                La bibliografía esta en enlace web ?
                            </label>
                        </div>
                        <div class="col-md-9 col-xs-12">
                            <input id="enlacevirtual" name="enlacevirtual" type="checkbox"/>
                        </div>
                    </div>
                </div>
                <div id="ejemplarinfo">
                    <div class="col-xs-12 row" style="padding-top: 25px;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">
                            <?php echo 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">
                            <?php echo 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">
                            <?php echo Form::text('edicion', null, ['class' => 'form-control', 'required' => 'required']); ?>

                        </div>
                    </div>
                </div>
                <div id="subirarchivo" style="display:none;">
                    <div class="col-xs-12 row" style="padding-top: 25px;padding-bottom: 25px">
                        <h4 class="page-head">
                            Subida del Documento
                        </h4>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-3 col-xs-12">
                            <label class = "caption-subject font-blue-secondary sbold">
                                Documento
                            </label>
                        </div>
                        <div class="col-md-9 col-xs-12">
                            <div class="form-group col-xs-12">
                                <input name="documento" type="file" class="filestyle" accept="application/pdf" required data-buttonText = "Seleccionar un Archivo"
                                       data-placeholder="No se ha seleccionado ningun archivo" required data_buttonName = "btn-primary", @style  = "width:400px;"/>
                                <label class="" style="margin:0; font-size:11px;">
                                    Sólo se permite archivos en formato PDF.
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
                <div id="addenlace" style="display:none;">
                    <div class="form-group row">
                        <div class="col-md-3 col-xs-12">
                            <label class = "caption-subject font-blue-secondary sbold">
                                Enlace al libro
                            </label>
                        </div>
                        <div class="col-md-9 col-xs-12">
                            <?php echo Form::text('enlacelibro', null, ['class' => 'form-control','id' => 'enlacelibro', 'required' => 'required']); ?>

                        </div>
                    </div>
                </div>
                <div class="actions">
                    <button type="button" id="btn-submit" class="btn btn-primary mt-ladda-btn ladda-button">
                        <i class="fa fa-plus"></i>
                        <span class="ladda-label" >Guardar</span>
                        <span class="ladda-spinner"></span>
                    </button>
                </div>
            </div>

        </div>
    </div>
    <?php echo Form::close(); ?>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    <script>
        Ladda.bind('.mt-ladda-btn');
        $(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: "<?php echo e(url('bibliografia/CutterSanborn')); ?>",
                    data: {code : $('#codigo_CS').val()},
                    success: function (data) {
                        if(data == 200 ){
                            $("#form-validation").submit();
                        }else if(data == 500){
                            O = false;
                            swal("Advertencia",'El Código del ejemplar ya existe','warning');

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

        var currentYear =  new Date().getFullYear().toString();
        $("#form-validation").validate();

        $("#virtual").change(function(){
            if($(this).prop('checked'))
            {
                $("#ejemplarinfo").hide();
                $("#subirarchivo").show();
            }
            else{
                $("#ejemplarinfo").show();
                $("#subirarchivo").hide();
            }
        });
        $("#enlacevirtual").change(function(){
            if($(this).prop('checked'))
            {
                $("#ejemplarinfo").hide();
                $("#addenlace").show();
            }
            else{
                $("#ejemplarinfo").show();
                $("#addenlace").hide();
            }
        });

        $("#Autores").select2({
            ajax: {
                url: "<?php echo e(url('bibliografia/getautores')); ?>",
                dataType: 'json',
                delay: 250,
                data: function (params) {
                    console.log("params");
                    console.log(params);
                    return {
                        autores: params.term
                    };
                },
                processResults: function (data) {
                    console.log("processResults");
                    console.log(data);
                    return {
                        results:  $.map(data.data, function (item) {
                            return {
                                text: item.nombres,
                                id: item.id
                            }
                        })
                    };
                },
                cache: true
            },
            escapeMarkup: function (markup) { return markup; },
            minimumInputLength: 1
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('template.layout', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>