Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 1005 | Rev 1007 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

<?php
$acl = $this->viewModel()->getRoot()->getVariable('acl');
$currentUser = $this->currentUserHelper();

$roleName = $currentUser->getUserTypeId();

$routeAdd = $this->url('performance-evaluation/forms/add');
$routeDatatable = $this->url('performance-evaluation/forms');
$routeDashboard = $this->url('dashboard');

$allowAdd = $acl->isAllowed($roleName, 'performance-evaluation/forms/add') ? 1 : 0;
$allowEdit = $acl->isAllowed($roleName, 'performance-evaluation/forms/edit') ? 1 : 0;
$allowDelete = $acl->isAllowed($roleName, 'performance-evaluation/forms/delete') ? 1 : 0;


$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));


$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));


$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));

$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));

$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));


$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.min.css'));
$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css'));

$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/select2.full.min.js'));

$this->inlineScript()->appendFile($this->basePath('plugins/moment/moment-with-locales.min.js'));
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'));


$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));

$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-input-number/input-number-format.jquery.js'));

// bootbox Alert //
$this->inlineScript()->appendFile($this->basePath('plugins/bootbox/bootbox.min.js'));

// JsRender //
$this->inlineScript()->appendFile($this->basePath('plugins/jsrender/jsrender.min.js'));

$this->inlineScript()->captureStart();
echo <<<JS
   
jQuery(document).ready(function($) {

    var allowEdit = $allowEdit;
    var allowDelete = $allowDelete;
    /**
     * Get rows and set data table
     */
    var tableForm = $('#gridTable').dataTable({
        'processing': true,
        'serverSide': true,
        'searching': true,
        'order': [
            [0, 'asc']
        ],
        'ordering': true,
        'ordenable': true,
        'responsive': true,
        'select': false,
        'paging': true,
        'pagingType': 'simple_numbers',
        'ajax': {
            'url': '$routeDatatable',
            'type': 'get',
            'beforeSend': function(request) {
                NProgress.start();
            },
            'dataFilter': function(response) {
                var response = jQuery.parseJSON(response);
                var json = {};
                json.recordsTotal = 0;
                json.recordsFiltered = 0;
                json.data = [];
                if (response.success) {
                    json.recordsTotal = response.data.total;
                    json.recordsFiltered = response.data.total;
                    json.data = response.data.items;
                } else {
                    $.fn.showError(response.data)
                }
                return JSON.stringify(json);
            }
        },
        'language': {
            'sProcessing': 'LABEL_DATATABLE_SPROCESSING',
            'sLengthMenu': 'LABEL_DATATABLE_SLENGTHMENU',
            'sZeroRecords': 'LABEL_DATATABLE_SZERORECORDS',
            'sEmptyTable': 'LABEL_DATATABLE_SEMPTYTABLE',
            'sInfo': 'LABEL_DATATABLE_SINFO',
            'sInfoEmpty': 'LABEL_DATATABLE_SINFOEMPTY',
            'sInfoFiltered': 'LABEL_DATATABLE_SINFOFILTERED',
            'sInfoPostFix': '',
            'sSearch': 'LABEL_DATATABLE_SSEARCH',
            'sUrl': '',
            'sInfoThousands': ',',
            'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
            'oPaginate': {
                'sFirst': 'LABEL_DATATABLE_SFIRST',
                'sLast': 'LABEL_DATATABLE_SLAST',
                'sNext': 'LABEL_DATATABLE_SNEXT',
                'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
            },
            'oAria': {
                'sSortAscending': ': LABEL_DATATABLE_SSORTASCENDING',
                'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
            },
        },
        'drawCallback': function(settings) {
            NProgress.done();
            $('button.btn-delete').confirmation({
                rootSelector: 'button.btn-delete',
                title: 'LABEL_ARE_YOU_SURE',
                singleton: true,
                btnOkLabel: 'LABEL_YES',
                btnCancelLabel: 'LABEL_NO',
                onConfirm: function(value) {
                    action = $(this).data('href');
                    NProgress.start();
                    $.ajax({
                        'dataType': 'json',
                        'accept': 'application/json',
                        'method': 'post',
                        'url': action,
                    }).done(function(response) {
                        if (response['success']) {
                            $.fn.showSuccess(response['data']);
                            tableForm.fnDraw();
                        } else {
                            $.fn.showError(response['data']);
                        }
                    }).fail(function(jqXHR, textStatus, errorThrown) {
                        $.fn.showError(textStatus);
                    }).always(function() {
                        NProgress.done();
                    });
                },
            });
        },
        'aoColumns': [{
                'mDataProp': 'name'
            },
            {
                'mDataProp': 'language'
            },
            {
                'mDataProp': 'status'
            },
            {
                'mDataProp': 'actions'
            },
        ],
        'columnDefs': [{
                'targets': 0,
                'className': 'text-vertical-middle',
            },
            {
                'targets': 1,
                'className': 'text-vertical-middle',
            },
            {
                'targets': -2,
                'orderable': false,
                'className': 'text-center',
                'render': function(data, type, row) {
                    checked = data == 'a' ? ' checked="checked" ' : '';
                    return '<div class="checkbox checkbox-success">' +
                        '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
                        '<label ></label></div>';
                }
            },
            {
                'targets': -1,
                'orderable': false,
                'render': function(data, type, row) {
                    s = '';
                    if (allowEdit) {
                        s = s + '<button class="btn btn-primary btn-edit-form" data-href="' + data['link_edit'] + '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pencil"></i> LABEL_EDIT </button>&nbsp;';
                    }
                    if (allowDelete) {
                        s = s + '<button class="btn btn-danger btn-delete" data-href="' + data['link_delete'] + '" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-trash"></i> LABEL_DELETE </button>&nbsp;';
                    }
                    return s;
                }
            }
        ],
    });
    /**
     * Clicked on edit form
     */
    $('body').on('click', 'button.btn-edit-form', function(e) {
        e.preventDefault();
        form_id = $(this).data('id')
        var action = $(this).data('href');
        $.ajax({
            'dataType': 'json',
            'accept': 'application/json',
            'method': 'get',
            'url': action,
        }).done(function(response) {
            if (response['success']) {
 
                $('#form-main').attr('action', action);
                $('#form-main #form-id').val(response['data']['id']),
                $('#form-main #form-continue').val('0');
                $('#form-main #form-name').val(response['data']['name']),

                /*----------Set Ckeditor ------------*/
                CKEDITOR.instances['form-description'].setData(response['data']['description']);
                CKEDITOR.instances['form-text'].setData(response['data']['text']);

                $('#form-main #form-language').val(response['data']['language']),
                $('#form-main #form-status').val(response['data']['status']);

                /*-------------Render Sections -------*/
                
                renderSectionData();
                
                $('#row-lists').hide();
                $('#row-form').show();
                $('#form-main #form-name').focus();

            } else {
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
            }
        }).fail(function(jqXHR, textStatus, errorThrown) {
            $.fn.showError(textStatus);
        });
    });
   

    /**
     * Clicked add new section
     */
    $('#btn-add-section').click(function(e) {
        $('#form-section #section-id').val('');
        CKEDITOR.instances['section-text'].setData('');
        $('#form-section #section-type').val($('#form-section #section-type option:first').val());
        $('#form-section #section-max-length').val('0');
        $('#form-section #section-max-length').parent().show();
        $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
        $('#modal-section').modal('show');
    });
    /**
     * Clicked edit section
     */
    $('#btn-edit-section').click(function(e) {
        console.log(0)
        $('#modal-section').modal('show');
    });
    /**
     * Clicked remove section
     */
    $('#btn-delete-section').click(function(e) {
        var id = $(this).data('section');
        bootbox.confirm({
            title: "LABEL_DELETE LABEL_SECTION",
            message: "LABEL_SECTION_DELETE",
            buttons: {
                cancel: {
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
                },
                confirm: {
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
                }
            },
            callback: function(result) {
                if (result) {
                    objFormGenerator.deletesection(id);
                    renderSectionData(objFormGenerator.sections);
                }
            }
        });
    });
    
    /**
     * Clicked new Form
     */
    $('button.btn-add-form').click(function(e) {
        $('#form-main').attr('action', '$routeAdd');
        $('#form-main #form-id').val('0');
        $('#form-main #form-continue').val('0');
        $('#form-main #form-name').val('');
        $('#row-lists').hide();
        $('#row-form').show();
        $('#form-main #form-name').focus();
    });
    /**
     * Clicked cancel new/edit Form
     */
    $('button.btn-edit-cancel').click(function(e) {
        e.preventDefault();
        $('#row-form').hide();
        $('#row-lists').show();
    });
    /**
     * Clicked save and continue new Form
     */
    $('button.btn-form-save-continue').click(function(e) {
        e.preventDefault();
        $('#form-main #form-continue').val('1')
        $('#form-main').submit();
    });
    /**
     * Clicked save and close new/edit Form
     */
    $('button.btn-form-save-close').click(function(e) {
        e.preventDefault();
        $('#form-main #form-continue').val('0')
        $('#form-main').submit();
    });
    /**
     * Remove Html Tags
     */
    const removeTags = (str) => str.toString().replace( /(<([^>]+)>)/ig, '')
    /**
     * Render Sections data
     */
    const renderSectionData = (data) => $("#rows").html('');


    /**
     * Clear Div Section data 
     */
    const clearSectionData = () => $("#rows").html('');
    /**
     * Clicked refresh button
     */
    $('button.btn-refresh').click(function(e) {
        tableForm.fnDraw();
    });
     
});
JS;
$this->inlineScript()->captureEnd();
?>

<!-- Content Header (Page header) -->
<section class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-12">
                <h1>LABEL_PERFORMANCE_EVALUATION</h1>
            </div>
        </div>
    </div>
    <!-- /.container-fluid -->
</section>
<section class="content">
    <div class="container-fluid" id="row-lists">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <table id="gridTable" class="table   table-hover">
                            <thead>
                                <tr>
                                    <th>LABEL_NAME</th>
                                    <th>LABEL_LANGUAGE</th>
                                    <th>LABEL_ACTIVE</th>
                                    <th>LABEL_ACTIONS</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                    </div>
                    <div class="card-footer clearfix">
                        <div style="float:right;">
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
                            <?php if ($allowAdd) : ?>
                                <button type="button" class="btn btn-primary btn-add-form"><i class="fa fa-plus"></i> LABEL_ADD </button>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Create/Edit Form -->

    <div class="row" id="row-form" style="display: none">
        <div class="col-xs-12 col-md-12">
            <form action="#" name="form-main" id="form-main">
                <input type="hidden" name="form-id" id="form-id" value="0" />
                <input type="hidden" name="form-continue" id="form-continue" value="0" />
                <div class="form-group">
                    <label for="form-name">LABEL_FIRST_NAME</label>
                    <input type="text" name="form-name" id="form-name" class="form-control" maxlength="50" />
                </div>
                <div class="row">
                    <div class="col-xs-12 col-md-12 text-right">
                        <button type="button" class="btn btn-primary" id="btn-add-section" data-toggle="tooltip" title="LABEL_ADD LABEL_SECTION"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_ADD LABEL_SECTION</button>
                    </div>
                </div>
                <br />  
                <div class="row">
                    <div class="col-xs-12 col-md-12">
                        <div class="panel-group" id="rows"></div>
                    </div>
                </div>
                <div class="form-group">
                    <button type="submit" form="form-main" class="btn btn-info btn-form-save-continue">LABEL_SAVE & LABEL_CONTINUE</button>
                    <button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE & LABEL_CLOSE</button>
                    <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
                </div>
            </form>
        </div>
    </div>

    <!-- Create/Edit Form-->

     <!-- section Modal -->

    <div  id="modal-section" class="modal" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-lg" role="document">
            <form action="#" name="form-section" id="form-section">
                <input type="hidden" name="section-id" id="section-id" />
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">LABEL_ADD LABEL_SECTION</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="section-text">LABEL_TEXT</label>
                            <!--  ckeditor -->
                            <textarea  name="section-text" id="section-text" rows="5" class="ckeditor form-control"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="section-type">LABEL_TYPE</label>
                            <select name="section-type" id="section-type" class="form-control">
                                <option value="open">LABEL_OPEN</option>
                                <option value="simple">Simple</option>
                                <option value="multiple">Multiple</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="section-max-length">LABEL_MAXLENGTH</label>
                            <input type="text" name="section-max-length" id="section-max-length"  class="form-control" />
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <!-- End Modal section -->

    <!-- Modal Options -->

    <div  id="modal-option" class="modal" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-lg" role="document">
            <form action="#" name="form-option" id="form-option">
                <input type="hidden" name="option-section" id="option-section" value="" />
                <input type="hidden" name="option-section" id="option-section" value="" />
                <input type="hidden" name="option-slug" id="option-slug" value="" />
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">LABEL_OPTION</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="option-text">LABEL_TEXT</label>
                            <!--  ckeditor -->
                            <textarea  name="option-text" id="option-text" rows="5" class="ckeditor form-control"></textarea>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <!-- End Modal Options -->

   

</section>