Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15596 | Rev 15605 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
15387 efrain 1
<?php
2
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
3
$currentUser    = $this->currentUserHelper();
4
 
5
$roleName = $currentUser->getUserTypeId();
15574 anderson 6
$routeDatatable = $this->url('reports/users-blocked');
15387 efrain 7
 
8
$allowDownload  = $acl->isAllowed($roleName, 'reports/users-blocked/excel') ? 1 : 0;
15597 anderson 9
$allowEdit              = $acl->isAllowed($roleName, 'reports/users-blocked/edit') ? 1 : 0;
15387 efrain 10
 
11
 
12
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
13
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
14
$this->inlineScript()->appendFile($this->basePath('plugins/jsrender/jsrender.js'));
15
 
15570 anderson 16
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
17
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
18
 
19
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
20
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
21
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
22
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
23
 
15387 efrain 24
$this->headStyle()->captureStart();
25
echo <<<CSS
26
 
27
 
28
#tableStudents {
29
    display: flex;
30
    flex-flow: column;
31
    width: 100%;
32
}
33
 
34
#tableStudents thead {
35
    flex: 0 0 auto;
36
}
37
 
38
#tableStudents tbody {
39
    flex: 1 1 auto;
40
    display: block;
41
    overflow-y: auto;
42
    overflow-x: hidden;
43
}
44
 
45
#tableStudents tr {
46
    width: 100%;
47
    display: table;
48
    table-layout: fixed;
49
}
50
CSS;
51
$this->headStyle()->captureEnd();
52
 
53
 
54
 
55
$this->inlineScript()->captureStart();
56
echo <<<JS
57
jQuery( document ).ready(function( $ ) {
58
 
59
 
15574 anderson 60
    $.fn.loadData = function() {
61
        NProgress.start();
62
        $.ajax({
63
            'dataType'  : 'json',
64
            'accept'    : 'application/json',
65
            'method'    : 'get',
66
            'url'       :  $('#form-filter').attr('action'),
67
            'data'      :  $('#form-filter').serialize(),
68
        }).done(function(response) {
69
            if(response['success']) {
15387 efrain 70
 
71
 
72
 
15574 anderson 73
               $('#gridTable tbody').empty();
74
                if(response['data']['items']) {
15387 efrain 75
 
15574 anderson 76
                    $('#gridTable tbody').append(
77
                        $( "#itemRowTemplate" ).render( response['data']['items'] )
15387 efrain 78
 
15574 anderson 79
                    );
15387 efrain 80
 
15574 anderson 81
                } else {
82
                    $('#gridTable tbody').append(
83
                        $( "#itemEmptyRowTemplate" ).render([])
84
                    );
15387 efrain 85
 
15574 anderson 86
                }
15387 efrain 87
 
15574 anderson 88
                if(response['data']['link_download']) {
89
                    $('button.btn-download').data('href', response['data']['link_download']);
90
                    $('button.btn-download').show();
15387 efrain 91
 
15574 anderson 92
                } else {
93
                     $('button.btn-download').hide();
94
                }
15387 efrain 95
 
15574 anderson 96
            } else {
97
                if(jQuery.type(response['data']) == 'string') {
98
                    $.fn.showError(response['data']);
99
                } else  {
100
                    $.each(response['data'], function( fieldname, errors ) {
101
                        $.fn.showFormErrorValidator('#form-filter #' + fieldname, errors);
102
                    });
103
                }
104
            }
105
        }).fail(function( jqXHR, textStatus, errorThrown) {
106
            $.fn.showError(textStatus);
107
        }).always(function() {
108
            NProgress.done();
109
        });
110
        return false;
111
    }
15387 efrain 112
 
113
 
15574 anderson 114
 
115
 
116
 
15597 anderson 117
    var allowEdit   = $allowEdit;
15593 anderson 118
 
15574 anderson 119
    var gridTable = $('#gridTable').dataTable( {
120
            'processing': true,
121
            'serverSide': true,
122
            'searching': true,
123
            'order': [[ 0, 'asc' ]],
124
            'ordering':  true,
125
            'ordenable' : true,
126
            'responsive': true,
127
            'select' : false,
128
        	'paging': true,
129
            'pagingType': 'simple_numbers',
130
    		'ajax': {
131
    			'url' : '$routeDatatable',
132
    			'type' : 'get',
133
                'beforeSend': function (request) {
134
                  NProgress.start();
135
                },
136
                'dataFilter': function(response) {
137
                    var response = jQuery.parseJSON( response );
138
 
139
                    var json                = {};
140
                    json.recordsTotal       = 0;
141
                    json.recordsFiltered    = 0;
142
                    json.data               = [];
143
 
144
 
145
                    if(response.success) {
146
                        json.recordsTotal       = response.data.total;
147
                        json.recordsFiltered    = response.data.total;
148
                        json.data               = response.data.items;
149
                    } else {
150
                        $.fn.showError(response.data)
151
                    }
152
 
153
                    return JSON.stringify( json );
154
                }
155
    		},
156
            'language' : {
157
                'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
158
                'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
159
                'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
160
                'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
161
                'sInfo':           'LABEL_DATATABLE_SINFO',
162
                'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
163
                'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
164
                'sInfoPostFix':    '',
165
                'sSearch':         'LABEL_DATATABLE_SSEARCH',
166
                'sUrl':            '',
167
                'sInfoThousands':  ',',
168
                'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
169
                'oPaginate': {
170
                    'sFirst':    'LABEL_DATATABLE_SFIRST',
171
                    'sLast':     'LABEL_DATATABLE_SLAST',
172
                    'sNext':     'LABEL_DATATABLE_SNEXT',
173
                    'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
174
                },
175
                'oAria': {
176
                    'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
177
                    'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
178
                },
179
            },
180
            'drawCallback': function( settings ) {
181
                NProgress.done();
182
                $('button.btn-delete').confirmation({
183
                    rootSelector: 'button.btn-delete',
184
                    title : 'LABEL_ARE_YOU_SURE',
185
                    singleton : true,
186
                    btnOkLabel: 'LABEL_YES',
187
                    btnCancelLabel: 'LABEL_NO',
188
                    onConfirm: function(value) {
189
                        action = $(this).data('href');
190
                        NProgress.start();
191
                        $.ajax({
192
                            'dataType'  : 'json',
193
                            'accept'    : 'application/json',
194
                            'method'    : 'post',
195
                            'url'       :  action,
196
                        }).done(function(response) {
197
                            if(response['success']) {
198
                                $.fn.showSuccess(response['data']);
199
                                gridTable.api().ajax.reload(null, false);
200
                            } else {
201
                                $.fn.showError(response['data']);
202
                            }
203
                        }).fail(function( jqXHR, textStatus, errorThrown) {
204
                            $.fn.showError(textStatus);
205
                        }).always(function() {
206
                            NProgress.done();
207
                        });
208
                    },
209
                });
210
            },
211
            'aoColumns': [
15575 anderson 212
                { 'mDataProp': 'first_name' },
213
                { 'mDataProp': 'last_name' },
15591 anderson 214
                { 'mDataProp': 'status' },
215
                { 'mDataProp': 'actions' },
15574 anderson 216
    	    ],
217
            'columnDefs': [
218
                {
219
                    'targets': 0,
220
                    'className' : 'text-vertical-middle',
221
                },
222
                {
223
                    'targets': 1,
224
                    'className' : 'text-vertical-middle',
225
                },
226
                {
227
                    'targets': -2,
228
                    'orderable': false,
229
                    'className' : 'text-center',
230
                      'render' : function ( data, type, row ) {
231
 
232
                        checked = data == 'a' ? ' checked="checked" ' : '';
233
                        return '<div class="checkbox checkbox-success">' +
234
                            '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
235
                            '<label ></label></div>';
236
                    }
237
                },
238
                {
239
                    'targets': -1,
240
                    'orderable': false,
15595 anderson 241
                    'render' : function ( data, type, row ) {
15597 anderson 242
                        s = '';
15574 anderson 243
 
15597 anderson 244
                        if(allowEdit &&  data['link_edit']) {
245
                            s = s + '<button class="btn btn-primary btn-edit" data-href="' + data['link_edit']+ '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pencil"></i> LABEL_EDIT </button>&nbsp;';
246
                        }
247
                        if(allowDelete && data['link_delete']) {
248
                            s = s + '<button class="btn btn-delete" data-href="' + data['link_delete']+ '" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-trash"></i> LABEL_DELETE </button>&nbsp;';
249
                        }
250
                        return s;
15595 anderson 251
                    }
15574 anderson 252
                }
253
              ],
254
        });
255
 
256
 
257
 
258
 
259
 
260
 
261
 
262
 
263
 
264
 
265
 
266
 
267
 
15387 efrain 268
    $('button.btn-download').click(function(e) {
269
        e.preventDefault();
270
        var action   = $(this).data('href');
271
 
272
        NProgress.start();
273
        $.ajax({
274
            'dataType'  : 'json',
275
            'method'    : 'get',
276
            'url'       :  action,
277
        }).done(function(response) {
278
            if(response['success']) {
279
                var anchor = window.document.createElement("a");
280
                anchor.href = 'data:application/octet-stream;charset=utf-8;base64,' + response['data']['content'] ;
281
                anchor.download = response['data']['basename'];
282
                document.body.appendChild(anchor);
283
                anchor.click();  // IE: "Access is denied"; see: https://connect.microsoft.com/IE/feedback/details/797361/ie-10-treats-blob-url-as-cross-origin-and-denies-access
284
                document.body.removeChild(anchor);
285
            } else {
286
                $.fn.showError(response['data']);
287
            }
288
        }).fail(function( jqXHR, textStatus, errorThrown) {
289
            showError(textStatus);
290
        }).always(function() {
291
            NProgress.done();
292
        });
293
 
294
 
295
    });
296
 
297
 
298
    $('button.btn-refresh').click(function(e) {
299
        e.preventDefault();
300
        $.fn.loadData();
301
 
302
 
303
    });
304
 
305
 
306
 
307
    $.fn.loadData();
308
    $('button.btn-download').hide();
309
 
310
});
311
JS;
312
$this->inlineScript()->captureEnd();
313
?>
314
 
315
<!-- Content Header (Page header) -->
316
<section class="content-header">
15570 anderson 317
    <div class="container-fluid">
318
        <div class="row mb-2">
319
            <div class="col-sm-12">
320
                <h1>LABEL_REPORTS_USERS_BLOCKED</h1>
321
            </div>
322
        </div>
323
    </div><!-- /.container-fluid -->
15387 efrain 324
</section>
325
 
326
<section class="content">
15570 anderson 327
    <div class="container-fluid">
328
        <div class="row">
329
            <div class="col-12">
330
                <div class="card">
331
                    <div class="card-header">
332
                        <div class="col-md-12 col-sm-12">
333
                            <div style="float:right;">
334
                                <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
335
                                <?php if ($allowDownload) :  ?>
15387 efrain 336
 
15570 anderson 337
                                    <button type="button" class="btn btn-info btn-download"><i class="fa fa-download"></i> LABEL_DOWNLOAD </button>
338
                                <?php endif; ?>
339
                            </div>
340
                        </div>
341
                    </div>
342
                    <div class="card-body">
343
                        <table id="gridTable" class="table   table-hover">
344
                            <thead>
345
                                <tr>
346
                                    <th style="width: 25%">LABEL_FIRST_NAME</th>
347
                                    <th style="width: 25%">LABEL_LAST_NAME</th>
348
                                    <th style="width: 30%">LABEL_EMAIL</th>
349
                                    <th style="width: 20%">LABEL_REPORTS_LAST_ACTIVITY</th>
15387 efrain 350
 
15570 anderson 351
 
15387 efrain 352
                                </tr>
15570 anderson 353
                            </thead>
354
                            <tbody>
355
                            </tbody>
356
                        </table>
357
                    </div>
358
                </div>
359
            </div>
360
        </div>
361
    </div>
362
</section>
15387 efrain 363
 
364
 
365
 
15570 anderson 366
 
15387 efrain 367
<script id="itemRowTemplate" type="text/x-jsrender">
368
    <tr>
369
        <td style="width: 25%">
370
            {{>first_name}}
371
        </td>
372
        <td style="width: 25%">
373
             {{>last_name}}
374
        </td>
375
        <td style="width: 30%">
376
            {{>email}}
377
        </td>
378
        <td style="width: 30%">
379
            {{>last_activity_on}}
380
        </td>
381
 
382
 
383
 
384
    </tr>
385
</script>
386
 
387
 
388
<script id="itemEmptyRowTemplate" type="text/x-jsrender">
389
    <tr>
390
        <td colspan="4">
391
            LABEL_NOT_RECORDS_FOUND
392
        </td>
393
    </tr>
15570 anderson 394
</script>