Proyectos de Subversion LeadersLinked - Backend

Rev

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