Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 1024 | Rev 1026 | 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;
    var sections = [];
    /**
     * 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 #id_section').val('');
        $('#form-section #title-section').val('');
        $('#form-section #text-section').val('');
        $('#form-section #type-section').val($('#form-section #type-section option:first').val());
        $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
        $('#modal-section').modal('show');
    });
    /**
     * Clicked edit section
     */

   

   


    /**
     * Clicked save section
     */
    $('#btn-save-section').click(function(e) {
        
        if($('#title-section').val()==''){

            $.fn.showError('Ingrese un nombre');
            return;

        }else{
            if($('#id_section').val()==""){
                addSection(
                    $('#title-section').val(),
                    $('#text-section').val(),
                    $('#type-section').val(),
                    ) 
            }else{
                editSection(
                    $('#id_section').val(),
                    $('#title-section').val(),
                    $('#text-section').val(),
                    $('#type-section').val()
                ) 
            }
            $('#modal-section').modal('hide');
            return;
        
        }

        
    });

    /**
     * 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) {
              
                }
            }
        });
    });

    $("button.btn-edit-section").click(function(){
    console.log(1);
});

    
    /**
     * 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 renderData= (data) => {
        console.log(data);

        $("#rows").html($("#sectionTemplate").render(data));
    }

    /**
     * Add Section to array
     */
    const addSection = (title, text, type) => {
        sections.push({
            'id_section': new Date().getTime(),
            'title': title,
            'type': type,
            'text': text,
            'options': []
        });
        renderData(sections);
    }
    /**
     * Edit item behavior
     */
    const editSection = (id, title, type, text) => {
        sections.map((item) => {
            if (item.id_section == id) {
                item.title = title;
                item.type = type;
                item.text = text;
            }
        });
        renderData(sections);
    }
    /**
     * Remove behavior
     */
    const removeSection = (id) => {
        sections = sections.filter((item) => item.id_section != id);
        renderData(sections);
    }

     /**
     * Add Option to array
     */
    const addOption = (section, title) => {
        sections.map((item) => {
            if (item.id_option == section) {
                item.options.push({
                    'id_option': new Date().getTime(),
                    'title': title,
                });
            }
        });
        renderData(sections);
    }
    /**
    * Edit item Option
    */
    const editOption = (section, id, tilte) => {
        sections.map((item) => {
            if (item.id_section == section) {
                item.options.map((opt)=>{
                    if(opt.id_option == id){
                        opt.title = title
                    }
                });
            }
        });
        renderData(sections);
    }
    /**
     * Remove Option
     */
    const removeOption = (section, id) => {

        sections.map((item) => {
            if (item.id_section == section) {
                item.options = item.options.filter((opt) => opt.id_option != id) || []
            }
        });

        renderData(sections);
    }
    /**
     * 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="id_section" id="id_section" />
                <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="title-section">LABEL_FIRST_NAME</label>
                            <input type="text" name="title-section" id="title-section" class="form-control" maxlength="50" value="" />
                        </div>
                        <div class="form-group">
                            <label for="text-section">LABEL_TEXT</label>
                            <textarea  name="text-section" id="text-section" rows="5" class="form-control"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="type-section">LABEL_TYPE</label>
                            <select name="type-section" id="type-section" class="form-control">
                                <option value="simple">Simple</option>
                                <option value="multiple">Multiple</option>
                            </select>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" id="btn-save-section" 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="button" 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 -->

    <!---Template Sections --->
    <script id="sectionTemplate" type="text/x-jsrender">

    <div class="panel panel-default" id="panel-{{:id_section}}">
        <div class="panel-heading">
            <h4 class="panel-title">
                <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:id_section}}" href="#collapse-{{:id_section}}">
                    <span class="section-name{{:id_section}}">
                        {{:name}}
                    </span>
                </a>
            </h4>
        </div>
        <div id="collapse-{{:id_section}}" class="panel-collapse in collapse show">
            <div class="panel-body">
                <div class="table-responsive">
                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th style="width: 10%;">LABEL_ELEMENT</th>
                                <th style="width: 40%;">LABEL_TEXT</th>
                                <th style="width: 10%;">LABEL_TYPE</th>
                                <th style="width: 30%;">LABEL_ACTIONS</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr class="tr-section">
                                <td class="text-left">LABEL_SECTION</td>
                                <td class="text-left">{{:title}}</td>
                                <td>
                                    
                                    {{if type == 'simple'}} Simple {{/if}}
                                    {{if type == 'multiple'}} Multiple {{/if}}
            

                                </td>
                                <td>
                                    <button type="button" class="btn btn-default btn-edit-section" data-section="{{:id_section}}" data-toggle="tooltip"  data-original-title="LABEL_EDIT LABEL_SECTION"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_SECTION </button>

                                    <button  type="button" class="btn btn-default btn-delete-section" data-section="{{:id_section}}" data-toggle="tooltip"  data-original-title="LABEL_DELETE LABEL_SECTION"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_SECTION </button> 

                                     {{if type == 'multiple'}}
                                    <button type="button" class="btn btn-default btn-add-option" data-section="{{:id_section}}" data-toggle="tooltip"  data-original-title="LABEL_ADD  LABEL_OPTION"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_ADD  LABEL_OPTION </button> 
                                    {{/if}}
                                </td>
                            </tr>
                            {{for options}}
                            <tr >
                                <td class="text-left">--LABEL_OPTION</td>
                                <td class="text-left">
                                    {{:title}}
                                </td>
                                <td></td>
                                <td></td>
                                <td>
                                    <button type="button" class="btn btn-default btn-edit-option" data-section="{{:id_section}}" data-option="{{:id_option}}" data-toggle="tooltip"  data-original-title="LABEL_EDIT LABEL_OPTION"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_OPTION</button> 


                                    <button type="button" class="btn btn-default btn-delete-option" data-section="{{:id_section}}" data-option="{{:id_option}}" data-toggle="tooltip"  data-original-title="LABEL_DELETE LABEL_OPTION"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_OPTION</button> 
                                
                                </td>
                            </tr>
                      
                            {{/for}}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    </script>

<!-- End Template Sections-->

</section>