<?php $__env->startSection('scripts'); ?>
    <?php echo Jqgrid::scripts(); ?>


    <script type="text/javascript">
        $(document).ready(function() {

            $('#jqgrid').jqGrid({
                url: '<?php echo e(url("subfamilias/datagrid")); ?>',
                colModel: <?php echo Jqgrid::js_colmodel(); ?>,
                gridComplete: function() {
                    $.jgrid.defaults.gridComplete();
                    $('#btn_editar>div.btn').addClass('disabled'); // deshabilita boton editar
                    $('#btn_eliminar>div.btn').addClass('disabled'); // deshabilita boton eliminar
                },
                onSelectRow: function(row_id) {
                    row_data = $("#jqgrid").getRowData(row_id);
                    $('#btn_editar>div.btn').removeClass('disabled'); //habilita boton editar
                    $('#Subfamilia_editar_id').val(row_data['NUMREG']); // setear id Subfamilia
                    $('#btn_eliminar>div.btn').removeClass('disabled'); //habilita boton eliminar
                    $('#Subfamilia_eliminar_id').val(row_data['NUMREG']); // setear id Subfamilia
                },
                sortname: 'NUMREG',
            });

            $('#jqgrid').jqGrid('filterToolbar', {stringResult: true, searchOnEnter: false, defaultSearch: 'cn'});

            // Botones
            $('#jqgrid').jqGrid('navGrid', '#jqgrid_pager', {add: false, edit: false, del: false, search: false});

            <?php if(can('Subfamilias_agregar')): ?>
            // botón agregar
            $('#jqgrid').jqGrid('navButtonAdd', '#jqgrid_pager', {caption: '', buttonicon: 'fa fa-plus',
                onClickButton: function() {
                    $('#Subfamilias_agregar_modal').modal('show');
                },
                position: 'last', title: 'Agregar Subfamilia', cursor: 'pointer', id: 'btn_agregar'}
            );

            // form agregar
            $('#Subfamilias_agregar_form').ajaxForm({
                resetForm: true,
                success: function(response, statusText, xhr, $form) {
                    clean_form_errors($form);
                    $('#Subfamilias_agregar_modal').modal('hide');
                    success_notification(response);
                    //actualizo grid
                    $('#jqgrid').trigger('reloadGrid');
                },
                error: function(response, statusText, xhr, $form) {
                    clean_form_errors($form);
                    show_form_errors(response, $form);
                    error_notification(response);
                }
            });
            <?php endif; ?>

            <?php if(can('Subfamilias_editar')): ?>
            // botón editar
            $('#jqgrid').jqGrid('navButtonAdd', '#jqgrid_pager', {caption: '', buttonicon: 'fa fa-pencil',
                onClickButton: function() {
                    if($('#btn_editar>div.btn').hasClass('disabled')) return false;
                    $('#Subfamilias_editar_form').formPopulate('<?php echo url("subfamilias/obtener"); ?>');
                    $('#Subfamilias_editar_modal').modal('show');
                },
                position: 'last', title: 'Editar Subfamilias', cursor: 'pointer', id: 'btn_editar'}
            );

            // form editar
            $('#Subfamilias_editar_form').ajaxForm({
                resetForm: true,
                success: function(response, statusText, xhr, $form) {
                    clean_form_errors($form);
                    $('#Subfamilias_editar_modal').modal('hide');
                    success_notification(response);
                    //actualizo grid
                    $('#jqgrid').trigger('reloadGrid');
                },
                error: function(response, statusText, xhr, $form) {
                    clean_form_errors($form);
                    show_form_errors(response, $form);
                    error_notification(response);
                }
            });
            <?php endif; ?>

            <?php if(can('Subfamilias_eliminar')): ?>
            // botón eliminar
            $('#jqgrid').jqGrid('navButtonAdd', '#jqgrid_pager', {caption: '', buttonicon: 'fa fa-trash-o',
                onClickButton: function() {
                    if($('#btn_eliminar>div.btn').hasClass('disabled')) return false;
                    $('#Subfamilias_eliminar_modal').modal('show');
                },
                position: 'last', title: 'Eliminar Subfamilias', cursor: 'pointer', id: 'btn_eliminar'}
            );

            // form eliminar
            $('#Subfamilias_eliminar_form').ajaxForm({
                resetForm: true,
                success: function(response, statusText, xhr, $form) {
                    clean_form_errors($form);
                    $('#Subfamilias_eliminar_modal').modal('hide');
                    success_notification(response);
                    //actualizo grid
                    $('#jqgrid').trigger('reloadGrid');
                },
                error: function(response, statusText, xhr, $form) {
                    clean_form_errors($form);
                    show_form_errors(response, $form);
                    error_notification(response);
                }
            });
            <?php endif; ?>

            // al cerrar modals, resetear form
            $('#Subfamilias_agregar_modal, #Subfamilias_editar_modal, #Subfamilias_eliminar_modal').on('hidden.bs.modal', function () {
                form = $(this).find('form').trigger('reset');
                clean_form_errors(form);
            });

        });
    </script>
    <?php $__env->stopSection(); ?>

    <?php $__env->startSection('content'); ?>
    <?php echo $__env->make('subviews.jqgrid_widget', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
    <?php if(can('Subfamilias_agregar')): ?>
    <!-- Modal Agregar -->
    <!-- Modal -->
    <div class="modal fade" id="Subfamilias_agregar_modal" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" tabindex="-1" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title">Agregar Subfamilia</h4>
                </div>
                <form method="POST" action="<?php echo url('subfamilias/agregar'); ?>" class="form-horizontal" id="Subfamilias_agregar_form">
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-md-12">
                                <div class='form-group form-group-sm'>
                                    <label class="control-label col-sm-3 text-align-left" for="roles">Descripción</label>
                                    <div class='col-sm-9'>
                                        <?php echo Form::text('DESCRIP', NULL, ['class' => 'form-control']); ?>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                        <button type="submit" class="btn btn-primary">Agregar</button>
                    </div>
                </form>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <!-- Fin Modal Agregar -->
    <?php endif; ?>

    <?php if(can('Subfamilias_editar')): ?>
    <!-- Modal Editar -->
    <!-- Modal -->
    <div class="modal fade" id="Subfamilias_editar_modal" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" tabindex="-1" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title">Editar Subfamilia</h4>
                </div>
                <form method="POST" action="<?php echo url('subfamilias/editar'); ?>" class="form-horizontal" id="Subfamilias_editar_form">
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-md-12">
                                <input type="hidden" name="id" value="" id="Subfamilia_editar_id">
                                <div class='form-group form-group-sm'>
                                    <label class="control-label col-sm-3 text-align-left" for="roles">Código</label>
                                    <div class='col-sm-9'>
                                        <?php echo Form::text('CODIGO', NULL, ['class' => 'form-control',  'readonly' => true]); ?>

                                    </div>
                                </div>
                                <div class='form-group form-group-sm'>
                                    <label class="control-label col-sm-3 text-align-left" for="roles">Descripción</label>
                                    <div class='col-sm-9'>
                                        <?php echo Form::text('DESCRIP', NULL, ['class' => 'form-control']); ?>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                        <button type="submit" class="btn btn-primary">Editar</button>
                    </div>
                </form>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <!-- Fin Modal Editar -->
    <?php endif; ?>

    <?php if(can('Subfamilias_eliminar')): ?>
    <!-- Modal Eliminar -->
    <!-- Modal -->
    <div class="modal fade warning" id="Subfamilias_eliminar_modal" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" tabindex="-1" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title">Eliminar Subfamilia</h4>
                </div>
                <form method="POST" action="<?php echo url('subfamilias/eliminar'); ?>" id="Subfamilias_eliminar_form">
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-md-12">
                                <input type="hidden" name="id" value="" id="Subfamilia_eliminar_id">
                                <div class="form-group col-sm-12">
                                    <h4>¿Está seguro de eliminar esta Subfamilia?</h4>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                        <button type="submit" class="btn btn-danger">Eliminar</button>
                    </div>
                </form>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <!-- Fin Modal Eliminar -->
    <?php endif; ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.default', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>