Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
15333 stevensc 1
<?php
2
 
1 www 3
use LeadersLinked\Model\CompanyUser;
4
 
5
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
6
$currentUser    = $this->currentUserHelper();
7
 
8
$roleName = $currentUser->getUserTypeId();
9
 
10
 
11
//$routeAdd       = $this->url('users/add');
12
$routeDatatable = $this->url('users');
13
$routeInvite    = $this->url('users/invite');
14
$routeUpload    = $this->url('users/upload');
15
 
16
 
17
 
18
$allowInvite            = $acl->isAllowed($roleName, 'users/invite') ? 1 : 0;
19
$allowAccept            = $acl->isAllowed($roleName, 'users/accept') ? 1 : 0;
20
$allowCancel            = $acl->isAllowed($roleName, 'users/cancel') ? 1 : 0;
21
$allowReject            = $acl->isAllowed($roleName, 'users/reject') ? 1 : 0;
22
$allowEdit              = $acl->isAllowed($roleName, 'users/edit') ? 1 : 0;
23
$allowUpload            = $acl->isAllowed($roleName, 'users/upload') ? 1 : 0;
24
$allowChangePassword    = $acl->isAllowed($roleName, 'users/change-password') ? 1 : 0;
25
$allowUnblock           = $acl->isAllowed($roleName, 'users/unblock') ? 1 : 0;
26
 
27
 
16822 efrain 28
$this->inlineScript()->appendFile($this->basePath('assets/vendors/popper/umd/popper.js'));
29
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));
30
$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.js'));
1 www 31
 
16822 efrain 32
$this->inlineScript()->appendFile($this->basePath('assets/vendors/ckeditor/ckeditor.js'));
1 www 33
 
34
 
35
 
16912 efrain 36
 
16929 efrain 37
 
38
 
39
 
16822 efrain 40
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.css'));
16912 efrain 41
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.css'));
1 www 42
 
16822 efrain 43
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net/jquery.dataTables.js'));
44
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.js'));
16912 efrain 45
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/dataTables.responsive.min.js'));
46
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.min.js'));
1 www 47
 
48
 
16822 efrain 49
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
50
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
1 www 51
 
52
 
16822 efrain 53
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-autocomplete/bootstrap-autocomplete.js'));
1 www 54
 
55
 
16822 efrain 56
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap-fileinput/css/fileinput.min.css'));
57
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap-fileinput/themes/explorer-fa/theme.css'));
58
 
16843 efrain 59
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/plugins/piexif.js'));
60
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/plugins/sortable.js'));
16822 efrain 61
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/fileinput.js'));
62
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/locales/es.js'));
63
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/themes/fa/theme.js'));
64
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/themes/explorer-fa/theme.js'));
65
 
16954 efrain 66
 
1 www 67
$this->headStyle()->captureStart();
16954 efrain 68
echo <<<CSS
1 www 69
 
16954 efrain 70
 
71
#gridTableUsers {
72
    display: flex;
73
    flex-flow: column;
74
    width: 100%;
75
}
76
 
77
#gridTableUsers thead {
78
    flex: 0 0 auto;
79
}
80
 
81
#gridTableUsers tbody {
82
    flex: 1 1 auto;
83
    display: block;
84
    overflow-y: auto;
85
    overflow-x: hidden;
86
}
87
 
88
#gridTableUsers tr {
89
    width: 100%;
90
    display: table;
91
    table-layout: fixed;
92
}
93
 
94
CSS;
95
$this->headStyle()->captureEnd();
96
 
1 www 97
$this->inlineScript()->captureStart();
98
echo <<<JS
99
    jQuery( document ).ready(function( $ ) {
100
        $.validator.addMethod('passwordStrengthCheck', function(value) {
101
            return /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$^x%x*-]).{6,16}$/.test(value)
102
        }, 'ERROR_PASSWORD_STRENGTH');
103
 
104
        $.validator.setDefaults({
105
            debug: true,
106
            highlight: function(element) {
107
                $(element).closest('.sn-field').addClass('sn-field-has-error');
108
            },
109
            unhighlight: function(element) {
110
                $(element).closest('.sn-field').removeClass('sn-field-has-error');
111
            },
112
            errorElement: 'div',
113
            errorClass: 'sn-field-invalid-feedback',
114
            errorPlacement: function(error, element) {
115
 
116
                if(element.parent('.sn-field').length) {
117
                    error.insertAfter(element.parent());
118
                } else if (element.parent('.fgt-sec').length) {
119
                    error.insertAfter(element.parent());
120
                } else {
121
                    error.insertAfter(element);
122
                }
123
            }
124
        });
125
 
126
 
127
        var allowInvite = $allowInvite;
128
        var allowAccept = $allowAccept;
129
        var allowCancel = $allowCancel;
130
        var allowReject = $allowReject;
131
        var allowEdit  = $allowEdit;
132
        var allowUpload = $allowUpload;
133
        var allowChangePassword = $allowChangePassword;
134
        var allowUnblock = $allowUnblock;
135
 
136
        var gridTable = $('#gridTable').dataTable( {
137
            'processing': true,
138
            'serverSide': true,
139
            'searching': true,
140
            'order': [[ 0, 'asc' ]],
141
            'ordering':  true,
142
            'ordenable' : true,
143
            'responsive': true,
144
            'select' : false,
145
        	'paging': true,
146
            'pagingType': 'simple_numbers',
147
    		'ajax': {
148
    			'url' : '$routeDatatable',
149
    			'type' : 'get',
150
                'data' : function(data) {
151
                    data.status = $('#form-filter #status').val();
152
                } ,
153
                'beforeSend': function (request) {
154
                  NProgress.start();
155
                },
156
                'dataFilter': function(response) {
157
                    var response = jQuery.parseJSON( response );
158
 
159
                    var json                = {};
160
                    json.recordsTotal       = 0;
161
                    json.recordsFiltered    = 0;
162
                    json.data               = [];
163
 
164
 
165
                    if(response.success) {
166
                        json.recordsTotal       = response.data.total;
167
                        json.recordsFiltered    = response.data.total;
168
                        json.data               = response.data.items;
169
                    } else {
170
                        $.fn.showError(response.data)
171
                    }
172
 
173
                    return JSON.stringify( json );
174
                }
175
    		},
176
            'language' : {
177
                'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
178
                'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
179
                'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
180
                'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
181
                'sInfo':           'LABEL_DATATABLE_SINFO',
182
                'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
183
                'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
184
                'sInfoPostFix':    '',
185
                'sSearch':         'LABEL_DATATABLE_SSEARCH',
186
                'sUrl':            '',
187
                'sInfoThousands':  ',',
188
                'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
189
                'oPaginate': {
190
                    'sFirst':    'LABEL_DATATABLE_SFIRST',
191
                    'sLast':     'LABEL_DATATABLE_SLAST',
192
                    'sNext':     'LABEL_DATATABLE_SNEXT',
193
                    'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
194
                },
195
                'oAria': {
196
                    'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
197
                    'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
198
                },
199
            },
200
            'drawCallback': function( settings ) {
201
                NProgress.done();
16822 efrain 202
 
1 www 203
            },
204
            'aoColumns': [
205
                { 'mDataProp': 'first_name' },
206
                { 'mDataProp': 'last_name' },
207
                { 'mDataProp': 'email' },
208
                { 'mDataProp': 'details' },
209
                { 'mDataProp': 'actions' },
210
    	    ],
211
            'columnDefs': [
212
                {
213
                    'targets': 0,
214
                    'className' : 'text-vertical-middle',
215
                },
216
                {
217
                    'targets': 1,
218
                    'className' : 'text-vertical-middle',
219
                },
220
                {
221
                    'targets': 2,
222
                    'className' : 'text-vertical-middle',
223
                },
224
                {
225
                    'targets': -2,
226
                    'orderable': false,
227
                    'render' : function ( data, type, row ) {
228
                        var s =  '';
229
                        s = s + 'LABEL_STATUS : <br>' + data['status'] + '<br>';
230
                        s = s + 'LABEL_ACCESS_BACKEND : ' + data['backend'] + '<br>';
231
                        s = s + 'LABEL_CREATOR : ' + data['creator'] + '<br>';
232
 
233
                        s = s + 'LABEL_EDIT : <br>';
234
 
235
                        $.each(data['roles'], function(i, role) {
236
                            s = s + role + '<br>';
237
                        });
238
 
239
                        s = s + 'LABEL_BLOCKED : ' + data['blocked'] + '<br>';
240
                        s = s + 'LABEL_EMAIL_VERIFIED : ' + data['email_verified'] + '<br>';
241
                        s = s + 'LABEL_LOGIN_ATTEMP : ' + data['login_attempt'] + '<br>';
242
                        return s;
243
                    }
244
                },
245
                {
246
                    'targets': -1,
247
                    'orderable': false,
248
                    'render' : function ( data, type, row ) {
249
                        s = '';
15333 stevensc 250
 
251
                        $('#gridTable_wrapper .row:nth-child(2) .col-sm-12').addClass( "table table-responsive" );
1 www 252
 
253
                        if(allowAccept && data['link_accept']) {
16822 efrain 254
                            s = s + '<button class="btn btn-sm btn-accept btn-primary" style="margin-top: 5px" data-href="' + data['link_accept']+ '" data-toggle="tooltip" title="LABEL_ACCEPT"><i class="fa fa-check"></i> LABEL_ACCEPT </button><br>';
1 www 255
                        }
15261 stevensc 256
                        if(allowEdit && data['link_edit']) {
16906 efrain 257
                            s = s + '<button class="btn btn-sm btn-edit btn-primary" style="margin-top: 5px" data-href="' + data['link_edit']+ '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pen"></i> LABEL_EDIT </button><br>';
15261 stevensc 258
                        }
1 www 259
                        if(allowCancel && data['link_cancel']) {
16822 efrain 260
                            s = s + '<button class="btn btn-sm btn-cancel btn-danger" style="margin-top: 5px" data-href="' + data['link_cancel']+ '" data-toggle="tooltip" data-singleton="true" title="LABEL_CANCEL"><i class="fa fa-times"></i> LABEL_CANCEL </button><br>';
1 www 261
                        }
262
                        if(allowReject && data['link_reject']) {
16822 efrain 263
                            s = s + '<button class="btn btn-sm btn-reject btn-danger" style="margin-top: 5px" data-href="' + data['link_reject']+ '" data-toggle="tooltip" title="LABEL_REJECT"><i class="fa fa-times"></i> LABEL_REJECT </button><br>';
1 www 264
                        }
265
 
266
                        if(allowChangePassword && data['link_change_password']) {
16822 efrain 267
                            s = s + '<button class="btn btn-sm btn-primary btn-change-password" style="margin-top: 5px" data-href="' + data['link_change_password']+ '" data-toggle="tooltip" title="LABEL_CHANGE_PASSWORD"><i class="fa fa-key"></i> LABEL_PASSWORD </button><br>';
1 www 268
                        }
269
                        if(allowUnblock && data['link_unblock']) {
16822 efrain 270
                            s = s + '<button class="btn btn-sm btn-info btn-unblock" style="margin-top: 5px" data-href="' + data['link_unblock']+ '" data-toggle="tooltip" title="LABEL_UNBLOCK"><i class="fa fa-unlock"></i> LABEL_UNBLOCK </button><br>';
1 www 271
                        }
272
 
273
 
274
                        return s;
275
                    }
276
                }
277
 
278
            ],
279
        });
280
 
281
 
282
        $('#form-filter #status').change(function(e) {
283
            e.preventDefault();
284
            gridTable.api().ajax.reload(null, false);
285
        });
286
 
287
 
288
        $('body').on('click', 'button.btn-refresh', function(e) {
289
            e.preventDefault();
290
            gridTable.api().ajax.reload(null, false);
291
        });
292
 
16822 efrain 293
    $('body').on('click', 'button.btn-unblock', function(e) {
294
        e.preventDefault();
295
        var action = $(this).data('href');
1 www 296
 
297
 
16822 efrain 298
          swal.fire({
299
            title: 'LABEL_ARE_YOU_SURE',
300
            icon: 'question',
301
            cancelButtonText: 'LABEL_NO',
302
            showCancelButton: true,
303
            confirmButtonText: 'LABEL_YES'
304
          }).then((result) => {
305
            if (result.isConfirmed) {
1 www 306
 
16822 efrain 307
                    NProgress.start();
308
                    $.ajax({
309
                        'dataType'  : 'json',
310
                        'accept'    : 'application/json',
311
                        'method'    : 'post',
312
                        'url'       :  action,
313
                    }).done(function(response) {
314
                        if(response['success']) {
315
                            $.fn.showSuccess(response['data']);
316
                            gridTable.api().ajax.reload(null, false);
317
                        } else {
318
                            $.fn.showError(response['data']);
319
                        }
320
                    }).fail(function( jqXHR, textStatus, errorThrown) {
321
                        $.fn.showError(textStatus);
322
                    }).always(function() {
323
                        NProgress.done();
324
                    });
325
            }
326
       });
327
    });
1 www 328
 
16822 efrain 329
 $('body').on('click', 'button.btn-reject', function(e) {
330
        e.preventDefault();
331
        var action = $(this).data('href');
332
 
333
 
334
          swal.fire({
335
            title: 'LABEL_ARE_YOU_SURE',
336
            icon: 'question',
337
            cancelButtonText: 'LABEL_NO',
338
            showCancelButton: true,
339
            confirmButtonText: 'LABEL_YES'
340
          }).then((result) => {
341
            if (result.isConfirmed) {
342
 
343
                    NProgress.start();
344
                    $.ajax({
345
                        'dataType'  : 'json',
346
                        'accept'    : 'application/json',
347
                        'method'    : 'post',
348
                        'url'       :  action,
349
                    }).done(function(response) {
350
                        if(response['success']) {
351
                            $.fn.showSuccess(response['data']);
352
                            gridTable.api().ajax.reload(null, false);
353
                        } else {
354
                            $.fn.showError(response['data']);
355
                        }
356
                    }).fail(function( jqXHR, textStatus, errorThrown) {
357
                        $.fn.showError(textStatus);
358
                    }).always(function() {
359
                        NProgress.done();
360
                    });
361
            }
362
       });
363
    });
364
 
365
 $('body').on('click', 'button.btn-cancel', function(e) {
366
        e.preventDefault();
367
        var action = $(this).data('href');
368
 
369
 
370
          swal.fire({
371
            title: 'LABEL_ARE_YOU_SURE',
372
            icon: 'question',
373
            cancelButtonText: 'LABEL_NO',
374
            showCancelButton: true,
375
            confirmButtonText: 'LABEL_YES'
376
          }).then((result) => {
377
            if (result.isConfirmed) {
378
 
379
                    NProgress.start();
380
                    $.ajax({
381
                        'dataType'  : 'json',
382
                        'accept'    : 'application/json',
383
                        'method'    : 'post',
384
                        'url'       :  action,
385
                    }).done(function(response) {
386
                        if(response['success']) {
387
                            $.fn.showSuccess(response['data']);
388
                            gridTable.api().ajax.reload(null, false);
389
                        } else {
390
                            $.fn.showError(response['data']);
391
                        }
392
                    }).fail(function( jqXHR, textStatus, errorThrown) {
393
                        $.fn.showError(textStatus);
394
                    }).always(function() {
395
                        NProgress.done();
396
                    });
397
            }
398
       });
399
    });
400
 
401
 
1 www 402
        $('body').on('click', 'button.btn-invite', function(e) {
403
            e.preventDefault();
16926 efrain 404
 
17330 ariadna 405
            // Limpiar el campo antes de abrir el modal
406
            $('#form-invite #user_uuid').val('');
1 www 407
            $('#form-invite #user_uuid_selected').val('');
17330 ariadna 408
 
409
            // Abrir el modal
1 www 410
            $('#modalInvite').modal('show');
411
        });
412
 
413
        $('body').on('click', 'button.btn-accept', function(e) {
414
            e.preventDefault();
415
            action = $(this).data('href');
416
            NProgress.start();
417
            $.ajax({
418
                'dataType'  : 'json',
419
                'accept'    : 'application/json',
420
                'method'    : 'post',
421
                'url'       :  action
422
            }).done(function(response) {
423
                if(response['success']) {
424
                    $.fn.showSuccess(response['data']);
425
                    gridTable.api().ajax.reload(null, false);
426
                } else {
427
                    $.fn.showError(response['data']);
428
                }
429
            }).fail(function( jqXHR, textStatus, errorThrown) {
430
                $.fn.showError(textStatus);
431
            }).always(function() {
432
                NProgress.done();
433
            });
434
        });
435
 
17330 ariadna 436
        // Inicializar autoComplete para el campo de búsqueda de usuarios
437
        function initializeAutoComplete() {
438
            console.log('Initializing autoComplete...'); // Debug
439
 
440
            if (typeof $.fn.autoComplete === 'undefined') {
441
                console.error('autoComplete library not loaded!');
442
                return;
443
            }
444
 
445
            // Destruir instancia anterior si existe
446
            if ($('#form-invite #user_uuid').data('autoComplete')) {
447
                $('#form-invite #user_uuid').autoComplete('clear');
448
            }
449
 
450
            $('#form-invite #user_uuid').autoComplete({
451
                resolver: 'custom',
452
                minLength: 3,
453
                noResultsText: 'LABEL_AUTOCOMPLETE_USERS_NOT_FOUND',
454
                events: {
455
                    search: function (qry, callback) {
456
                        console.log('Searching for:', qry); // Debug
457
                        NProgress.start();
458
                        $.ajax({
459
                            'url' : '$routeInvite',
460
                            'method': 'get',
461
                            'data': { 'search': qry },
462
                            'dataType': 'json'
463
                        }).done(function (response) {
464
                            console.log('Response:', response); // Debug
465
                            if(response.success) {
466
                                callback(response.data);
467
                            } else {
468
                                console.error('Search error:', response.data); // Debug
469
                                $.fn.showError(response.data);
17329 ariadna 470
                                callback([]);
17330 ariadna 471
                            }
472
                        }).fail(function( jqXHR, textStatus, errorThrown) {
473
                            console.error('AJAX error:', textStatus, errorThrown); // Debug
474
                            $.fn.showError(textStatus);
475
                            callback([]);
476
                        }).always(function() {
477
                            NProgress.done();
478
                        });
17329 ariadna 479
                    }
17330 ariadna 480
                }
481
            });
482
            console.log('autoComplete initialized successfully'); // Debug
483
        }
484
 
485
        // Inicializar cuando el documento esté listo
486
        initializeAutoComplete();
1 www 487
 
488
	    $('#form-invite #user_uuid').on('autocomplete.select', function (evt, item) {
17330 ariadna 489
            console.log('Item selected:', item); // Debug
490
            $('#form-invite #user_uuid_selected').val(item.value);
491
            console.log('Hidden field value set to:', item.value); // Debug
1 www 492
        });
493
 
494
        var validatorFormInvite = $('#form-invite').validate({
495
            debug: true,
496
            onclick: false,
497
            onkeyup: false,
498
            ignore: [':hidden'],
499
            rules: {
500
 
501
                'user_uuid': {
502
                    required: true,
503
                },
504
            },
505
            submitHandler: function(form)
506
            {
507
                NProgress.start();
508
                $.ajax({
509
                    'dataType'  : 'json',
510
                    'accept'    : 'application/json',
511
                    'method'    : 'post',
512
                    'url'       : '$routeInvite',
513
                    'data'      : {
514
                        'id' : $('#form-invite #user_uuid_selected').val(),
515
                    }
516
                 }).done(function(response) {
517
                    if(response.success) {
518
                        $.fn.showSuccess(response.data);
519
 
520
                        $('#modalInvite').modal('hide');
521
                         gridTable.api().ajax.reload(null, false);
522
                    } else {
523
                        if(jQuery.type(response.data) == 'string') {
524
                            $.fn.showError(response.data)
525
                        } else  {
526
                            $.each(response.data, function( fieldname, errors ) {
527
                                $.fn.showFormErrorValidator('#form-invite #' + fieldname, errors);
528
                            });
529
                        }
530
                    }
531
                }).fail(function( jqXHR, textStatus, errorThrown) {
532
                    $.fn.showError(textStatus)
533
 
534
                }).always(function() {
535
                    NProgress.done();
536
                })
537
            },
538
            invalidHandler: function(form, validator) {
539
            }
540
        });
541
 
15460 efrain 542
    var validatorUploadUsers = $('#form-upload-users').validate({
1 www 543
        debug: true,
544
        onclick: false,
545
        onkeyup: false,
546
        onfocusout: false,
547
        ignore: [],
548
        rules: {
549
            'file' : {
550
                required: true,
551
                extension: 'xls|xlsx',
552
                accept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel'
553
            },
554
        },
555
 
556
        submitHandler: function(form)
557
        {
558
            NProgress.start();
559
            var formdata = false;
560
            if (window.FormData){
561
                formdata = new FormData(form);
562
            }
563
            formdata.append('step','validation');
564
 
565
 
566
            $.ajax({
567
                'dataType'  : 'json',
568
                'accept'    : 'application/json',
569
                'method'    : 'post',
570
                'url'       : '$routeUpload',
571
                'data'      :  formdata,
572
                'processData': false,
573
                'contentType': false,
574
            }).done(function(response) {
575
                if(response['success']) {
576
 
577
                    $('#table-upload-users-key').val(response['data']['key']);
578
 
579
                    $('#gridTableUploadUsers tbody').empty();
580
 
581
                    $.each(response['data']['items'], function(index, item) {
582
 
583
 
584
                        var s = '<tr>';
585
                        s = s + '<td>' + item['first_name'] + '</td>';
586
                        s = s + '<td>' + item['last_name'] + '</td>';
587
                        s = s + '<td>' + item['email'] + '</td>';
588
                        s = s + '<td>' + item['password'] + '</td>';
15460 efrain 589
                        s = s + '<td>' + item['is_adult'] + '</td>';
1 www 590
                        s = s + '</tr>';
591
 
592
                        $('#gridTableUploadUsers tbody').append(s);
593
 
594
 
595
                    });
596
 
597
                    $('#modalFormUploadUsers').modal('hide');
598
                    $('#modalUploadUsers').modal('show');
599
 
600
 
601
 
602
                } else {
15460 efrain 603
                    validatorUploadUsers.resetForm();
1 www 604
                    if(jQuery.type(response['data']) == 'string') {
605
                        $.fn.showError(response['data']);
606
                    } else  {
607
                        $.each(response['data'], function( fieldname, errors ) {
608
                            $.fn.showFormErrorValidator('#form-upload-users #' + fieldname, errors);
609
                        });
610
                    }
611
                }
612
            }).fail(function( jqXHR, textStatus, errorThrown) {
613
                $.fn.showError(textStatus);
614
            }).always(function() {
615
 
616
                NProgress.done();
617
            });
618
            return false;
619
        },
620
        invalidHandler: function(form, validator) {
621
 
622
        }
623
    });
624
 
625
 
626
    $('#form-upload-users #file').fileinput({
15460 efrain 627
        theme: 'fa',
1 www 628
        language: 'es',
629
        showUpload: false,
630
        dropZoneEnabled: false,
631
        maxFileCount: 1,
632
        allowedFileExtensions: ['xls', 'xlsx'],
633
    });
634
 
635
    $('body').on('click', 'button.btn-upload', function(e) {
636
        e.preventDefault();
637
 
638
        $('#form-upload-users #file').fileinput('reset');
639
        $('#form-upload-users #file').val('');
640
 
641
        $('#modalFormUploadUsers').modal('show');
642
    });
643
 
644
    $('body').on('click', 'button.btn-upload-users-step2', function(e) {
645
        e.preventDefault();
646
        NProgress.start();
647
 
648
        $.ajax({
649
            'dataType'  : 'json',
650
            'accept'    : 'application/json',
651
            'method'    : 'post',
652
            'url'       : '$routeUpload',
653
            'data'      :  {
654
                'step' : 'process',
655
                'key' : $('#table-upload-users-key').val(),
656
            }
657
        }).done(function(response) {
658
            if(response['success']) {
15460 efrain 659
                if(response['data']['users_created'] == 1) {
660
                    $.fn.showSuccess(response['data']['users_created'] + ' LABEL_USER_CREATED');
1 www 661
                } else {
15460 efrain 662
                    $.fn.showSuccess(response['data']['users_created'] + ' LABEL_USERS_CREATED');
1 www 663
                }
664
                 gridTable.api().ajax.reload(null, false);
665
                $('#modalUploadUsers').modal('hide');
666
            } else {
667
                $.fn.showError(response['data']);
668
            }
669
        }).fail(function( jqXHR, textStatus, errorThrown) {
670
            $.fn.showError(textStatus);
671
        }).always(function() {
672
            NProgress.done();
673
        });
674
        return false;
675
    });
676
 
677
    $('body').on('click', 'button.btn-edit', function(e) {
678
        e.preventDefault();
679
 
680
        var href = $(this).data('href');
681
        $('#form-edit').attr('action', href);
682
 
683
        NProgress.start();
684
        $.ajax({
685
            'dataType'  : 'json',
686
            'accept'    : 'application/json',
687
            'method'    : 'get',
688
            'url'       :  href,
689
        }).done(function(response) {
690
            if(response['success']) {
691
                $('#form-edit #backend').prop('checked', response['data']['backend'] );
692
                $('#table-roles tbody').empty();
693
 
694
                $.each(response['data']['roles'], function(index, role) {
695
 
696
                    var checked = role['checked'] ? ' checked="checked" ' : '';
697
                    var s = '<tr>';
698
                    s = s + '<td>' + role['name'] + '</td>';
16927 efrain 699
                    s = s + '<td><div class="form-check mb-3">';
16943 efrain 700
                    s = s + '<input type="checkbox" value="1" class="form-check-input" id="checked' + role['id'] + '" name="checked' + role['id'] + '" ' + checked + '> ';
16927 efrain 701
					s = s + '<label class="form-check-label" >&nbsp;</label>';
702
			        s = s + '</div></td>';
1 www 703
                    s = s + '</tr>';
704
 
705
                    $('#table-roles tbody').append(s);
706
 
707
                });
708
 
709
                $('#modalEdit').modal('show');
710
 
16926 efrain 711
 
16927 efrain 712
 
1 www 713
            } else {
714
                $.fn.showError(response['data']);
715
            }
716
        }).fail(function( jqXHR, textStatus, errorThrown) {
717
            $.fn.showError(textStatus);
718
        }).always(function() {
719
            NProgress.done();
720
        });
721
 
722
    });
723
 
724
    $('#form-edit').submit(function (e) {
725
        e.preventDefault();
726
        NProgress.start();
727
        $.ajax({
728
            'dataType'  : 'json',
729
            'accept'    : 'application/json',
730
            'method'    : 'post',
731
            'url'       : $('#form-edit').attr('action'),
732
            'data'      : $('#form-edit').serialize(),
733
        }).done(function(response) {
734
            if(response['success']) {
735
 
736
                $.fn.showSuccess(response['data']);
737
                $('#modalEdit').modal('hide');
738
                gridTable.api().ajax.reload(null, false);
739
 
740
            } else {
741
                $.fn.showError(response['data']);
742
            }
743
        }).fail(function( jqXHR, textStatus, errorThrown) {
744
            $.fn.showError(textStatus);
745
        }).always(function() {
746
            NProgress.done();
747
        });
748
        return false;
749
 
750
    });
751
 
752
    $('body').on('click', 'button.btn-cancel-modal', function(e) {
753
        e.preventDefault();
754
        $('#modalInvite').modal('hide');
755
        $('#modalFormUploadUsers').modal('hide');
756
        $('#modalEdit').modal('hide');
757
        $('#modalChangePassword').modal('hide');
758
    });
759
 
760
    var validatorChangePassword = $('#form-change-password').validate({
761
        debug: true,
762
        onclick: false,
763
        onkeyup: false,
764
        ignore: [':hidden'],
765
            rules: {
766
 
767
                'password': {
768
                    required: true,
769
                    minlength: 6,
770
                    maxlength: 16,
771
                    passwordStrengthCheck: true,
772
                },
773
                'confirmation' : {
774
                    required: true,
775
                    minlength: 6,
776
                    maxlength: 16,
777
                    equalTo: '#form-change-password #password'
778
                },
779
            },
780
            submitHandler: function(form)
781
            {
782
                NProgress.start();
783
                $.ajax({
784
                    'dataType'  : 'json',
785
                    'accept'    : 'application/json',
786
                    'method'    : 'post',
787
                    'url'       : $('#form-change-password').attr('action'),
788
                    'data'      : $('#form-change-password').serialize()
789
                 }).done(function(response) {
790
                    if(response.success) {
791
                        $.fn.showSuccess(response.data);
792
 
793
                        $('#modalChangePassword').modal('hide');
794
                         gridTable.api().ajax.reload(null, false);
795
                    } else {
796
                        if(jQuery.type(response.data) == 'string') {
797
                            $.fn.showError(response.data)
798
                        } else  {
799
                            $.each(response.data, function( fieldname, errors ) {
800
                                $.fn.showFormErrorValidator('#form-change-password #' + fieldname, errors);
801
                            });
802
                        }
803
                    }
804
                }).fail(function( jqXHR, textStatus, errorThrown) {
805
                    $.fn.showError(textStatus)
806
 
807
                }).always(function() {
808
                    NProgress.done();
809
                })
810
            },
811
            invalidHandler: function(form, validator) {
812
            }
813
        });
814
 
815
        $('body').on('click', 'button.btn-change-password', function(e) {
816
            e.preventDefault();
817
 
818
            NProgress.start();
819
            var action = $(this).data('href');
820
 
821
            $.ajax({
822
                'dataType'  : 'json',
823
                'accept'    : 'application/json',
824
                'method'    : 'get',
825
                'url'       :  action,
826
            }).done(function(response) {
827
                if(response['success']) {
828
 
829
                    $('#form-change-password').attr('action', action);
830
                    $('#form-change-password #first_name').val(response['data']['first_name']);
831
                    $('#form-change-password #last_name').val(response['data']['last_name']);
832
                    $('#form-change-password #email').val(response['data']['email']);
833
                    $('#form-change-password #password').val('');
834
                    $('#form-change-password #confirmation').val('');
835
                    validatorChangePassword.resetForm();
836
 
837
                    $('#modalChangePassword').modal('show');
838
                } else {
839
                    $.fn.showError(response['data']);
840
                }
841
            }).fail(function( jqXHR, textStatus, errorThrown) {
842
                $.fn.showError(textStatus);
843
            }).always(function() {
844
                NProgress.done();
845
            });
846
 
847
        });
848
 
17330 ariadna 849
        // Re-inicializar autoComplete cuando el modal se muestre
850
        $('#modalInvite').on('shown.bs.modal', function() {
851
            console.log('Modal shown, re-initializing autoComplete...'); // Debug
852
            setTimeout(function() {
853
                initializeAutoComplete();
854
            }, 100);
855
        });
1 www 856
 
857
    });
858
JS;
859
$this->inlineScript()->captureEnd();
15333 stevensc 860
?>
861
 
1 www 862
 
863
 
16840 efrain 864
<div class="container">
17328 ariadna 865
    <div class="card">
866
        <div class="card-header">
867
            <h6 class="card-title">LABEL_USERS_FOR_COMPANY</h6>
868
        </div>
869
        <div class="card-body">
870
 
871
 
872
            <form name="form-filter" id="form-filter">
873
                <div class="row">
874
                    <div class="col-12  mt-3">
875
                        <label for="status">LABEL_STATUS</label>
876
                        <select id="status" name="status" class="form-control">
877
                            <option value="">LABEL_ALL</option>
878
                            <option value="<?php echo CompanyUser::STATUS_PENDING ?>">LABEL_PENDING</option>
879
                            <option value="<?php echo CompanyUser::STATUS_ACCEPTED ?>">LABEL_ACCEPTED</option>
880
                            <option value="<?php echo CompanyUser::STATUS_ADMIN_WILL_ADD ?>">LABEL_ADMIN_WILL_ADD</option>
881
                            <option value="<?php echo CompanyUser::STATUS_SENT ?>">LABEL_INVITED</option>
16912 efrain 882
                            <option value="<?php echo CompanyUser::STATUS_CANCELLED ?>">LABEL_CANCELLED</option>
17328 ariadna 883
                            <option value="<?php echo CompanyUser::STATUS_REJECTED ?>">LABEL_REJECTED</option>
884
                        </select>
885
                    </div>
886
                </div>
887
            </form>
888
            <div class="row">
889
                <div class="col-12  mt-3">
890
                    <table id="gridTable" class="table table-bordered">
16912 efrain 891
                        <thead>
17328 ariadna 892
                            <tr>
893
                                <th>LABEL_FIRST_NAME</th>
894
                                <th>LABEL_LAST_NAME</th>
895
                                <th>LABEL_EMAIL</th>
896
                                <th>LABEL_DETAILS</th>
897
                                <th>LABEL_ACTIONS</th>
898
                            </tr>
899
                        </thead>
900
                        <tbody>
901
                        </tbody>
902
                    </table>
903
                </div>
16912 efrain 904
            </div>
15333 stevensc 905
        </div>
17328 ariadna 906
        <div class="card-footer text-right">
907
            <button type="button" class="btn btn-sm btn-info btn-refresh"><i class="fa fa-sync"></i> LABEL_REFRESH</button>
908
            <?php if ($allowUpload) : ?>
909
                <button type="button" class="btn btn-sm btn-primary btn-upload"><i class="fa fa-upload"></i> LABEL_UPLOAD </button>
910
            <?php endif; ?>
911
            <?php if ($allowInvite) : ?>
912
                <button type="button" class="btn btn-sm btn-primary btn-invite"><i class="fa fa-plus"></i> LABEL_INVITE </button>
913
            <?php endif; ?>
914
        </div>
915
    </div>
16840 efrain 916
</div>
15333 stevensc 917
 
918
 
1 www 919
<!-- The Modal -->
920
<div class="modal" id="modalInvite">
15333 stevensc 921
    <div class="modal-dialog  modal-xl">
922
        <div class="modal-content">
1 www 923
 
924
            <!-- Modal Header -->
15333 stevensc 925
            <div class="modal-header">
16935 efrain 926
                <h6 class="modal-title">LABEL_INVITE</h6>
15333 stevensc 927
            </div>
1 www 928
 
929
            <!-- Modal body -->
16840 efrain 930
            <form name="form-invite" id="form-invite">
17328 ariadna 931
                <div class="modal-body">
932
 
15333 stevensc 933
                    <input type="hidden" name="user_uuid_selected" id="user_uuid_selected" />
16840 efrain 934
                    <div class="row">
17328 ariadna 935
                        <div class="col-12  mt-3">
936
                            <label for="user_uuid">LABEL_USER (LABEL_MIN_LENGTH_3)</label>
937
                            <br />
938
                            <input autocomplete="off" type="text" name="user_uuid" id="user_uuid" class="form-control" data-noresults-text="LABEL_AUTOCOMPLETE_USERS_NOT_FOUND">
939
                        </div>
940
                    </div>
1 www 941
 
942
 
17328 ariadna 943
 
944
 
945
                </div>
946
                <div class="modal-footer text-right">
947
                    <button type="submit" class="btn btn-sm btn-primary">LABEL_INVITE</button>
948
                    <button type="button" class="btn btn-sm btn-light btn-cancel-modal">LABEL_CANCEL</button>
949
                </div>
16840 efrain 950
            </form>
15333 stevensc 951
        </div>
952
    </div>
953
</div>
1 www 954
 
955
 
15333 stevensc 956
 
1 www 957
<!-- The Modal -->
958
<div class="modal" id="modalFormUploadUsers">
15333 stevensc 959
    <div class="modal-dialog  modal-xl">
960
        <div class="modal-content">
1 www 961
 
962
            <!-- Modal Header -->
15333 stevensc 963
            <div class="modal-header">
16935 efrain 964
                <h6 class="modal-title">LABEL_UPLOAD</h6>
15333 stevensc 965
            </div>
1 www 966
 
17328 ariadna 967
            <?php
968
            $form = $this->formUploadUsers;
969
            $form->setAttributes([
970
                'method'    => 'post',
971
                'name'      => 'form-upload-users',
972
                'id'        => 'form-upload-users'
973
            ]);
1 www 974
 
17328 ariadna 975
            $form->prepare();
976
            echo $this->form()->openTag($form);
977
            ?>
16840 efrain 978
            <!-- Modal body -->
979
            <div class="modal-body">
15333 stevensc 980
 
17328 ariadna 981
 
16840 efrain 982
                <div class="row">
17328 ariadna 983
                    <div class="col-12  mt-3">
15333 stevensc 984
 
985
 
986
                        <?php
17328 ariadna 987
                        $element = $form->get('file');
988
                        $element->setOptions(['label' => 'LABEL_EXCEL']);
989
                        echo $this->formLabel($element);
990
                        ?>
991
                        <div class="file-loading">
992
                            <?php
16816 stevensc 993
 
17328 ariadna 994
                            $element->setAttributes(['class' => 'form-control', 'accept' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel']);
995
                            echo $this->formFile($element);
996
                            ?>
16840 efrain 997
                        </div>
15333 stevensc 998
                    </div>
999
                </div>
1 www 1000
 
1001
 
1002
 
17328 ariadna 1003
 
16840 efrain 1004
            </div>
17328 ariadna 1005
            <div class="modal-footer text-right">
1006
                <button type="submit" class="btn btn-sm btn-primary">LABEL_UPLOAD</button>
1007
                <button type="button" class="btn btn-sm btn-light btn-cancel-modal">LABEL_CANCEL</button>
1008
            </div>
1009
            <?php echo $this->form()->closeTag($form); ?>
15333 stevensc 1010
        </div>
1011
    </div>
1012
</div>
1 www 1013
 
1014
 
15333 stevensc 1015
 
1 www 1016
<!-- The Modal -->
1017
<div class="modal" id="modalUploadUsers">
15333 stevensc 1018
    <div class="modal-dialog modal-xl">
1019
        <div class="modal-content">
1 www 1020
 
1021
            <!-- Modal Header -->
15333 stevensc 1022
            <div class="modal-header">
16935 efrain 1023
                <h6 class="modal-title">LABEL_USERS_FOR_COMPANY</h6>
16822 efrain 1024
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="btn-close"></button>
15333 stevensc 1025
            </div>
1 www 1026
 
1027
            <!-- Modal body -->
15333 stevensc 1028
            <div class="modal-body">
1029
                <form>
1030
                    <input type="hidden" name="table-upload-users-key" id="table-upload-users-key">
1031
                </form>
16840 efrain 1032
                <div class="row">
17328 ariadna 1033
                    <div class="col-12  mt-3" style="height: 300px;overflow: scroll;">
1034
                        <table id="gridTableUploadUsers" style="width: 100%" class="table table-bordered">
16840 efrain 1035
                            <thead>
1036
                                <tr>
1037
                                    <th>LABEL_FIRST_NAME</th>
1038
                                    <th>LABEL_LAST_NAME</th>
1039
                                    <th>LABEL_EMAIL</th>
1040
                                    <th>LABEL_PASSWORD</th>
1041
                                    <th>LABEL_IS_ADULT</th>
1042
                                </tr>
1043
                            </thead>
1044
                            <tbody>
1045
                            </tbody>
1046
                        </table>
17328 ariadna 1047
 
1048
                    </div>
15333 stevensc 1049
                </div>
1 www 1050
 
16840 efrain 1051
 
15333 stevensc 1052
            </div>
1053
 
1 www 1054
            <!-- Modal footer -->
16891 efrain 1055
            <div class="modal-footer text-right">
15333 stevensc 1056
                <button type="submit" class="btn btn-sm btn-primary btn-upload-users-step2">LABEL_SAVE</button>
1057
                <button type="button" class="btn btn-sm btn-danger" data-dismiss="modal">LABEL_CLOSE</button>
1058
            </div>
1 www 1059
 
15333 stevensc 1060
        </div>
1061
    </div>
1062
</div>
1 www 1063
 
1064
 
1065
<!-- The Modal -->
1066
<div class="modal" id="modalEdit">
15333 stevensc 1067
    <div class="modal-dialog  modal-xl">
1068
        <div class="modal-content">
1 www 1069
 
1070
            <!-- Modal Header -->
15333 stevensc 1071
            <div class="modal-header">
16935 efrain 1072
                <h6 class="modal-title">LABEL_USER_FOR_COMPANY - LABEL_EDIT</h6>
15333 stevensc 1073
            </div>
1 www 1074
 
17328 ariadna 1075
            <form name="form-edit" id="form-edit">
1076
                <!-- Modal body -->
1077
                <div class="modal-body">
1078
 
15333 stevensc 1079
                    <div class="row">
16841 efrain 1080
                        <div class="col-md-12 col-sm-12  mt-3">
17328 ariadna 1081
                            <div class="form-check mb-3">
1082
                                <input type="checkbox" name="backend" id="backend" value="y" class="form-check-input" style="width: 20px; height: 20px"> <label for="backend" class="form-check-label">LABEL_ACCESS_BACKEND</label>
1083
 
15333 stevensc 1084
                            </div>
1085
                        </div>
1086
                    </div>
1087
                    <div class="row">
16841 efrain 1088
                        <div class="col-md-12 col-sm-12  mt-3">
16822 efrain 1089
                            <table id="table-roles" class="table table-bordered">
15333 stevensc 1090
                                <thead>
1091
                                    <tr>
1092
                                        <th>LABEL_NAME</th>
1093
                                        <th>LABEL_ACTIVE</th>
1094
                                    </tr>
1095
                                </thead>
1096
                                <tbody>
1097
                                </tbody>
1098
                            </table>
1 www 1099
 
15333 stevensc 1100
                        </div>
1101
                    </div>
1102
 
17328 ariadna 1103
 
1104
                </div>
1105
                <div class="modal-footer text-right">
1106
                    <button type="submit" class="btn btn-sm btn-primary">LABEL_SAVE</button>
1107
                    <button type="button" class="btn btn-sm btn-light btn-cancel-modal">LABEL_CANCEL</button>
1108
                </div>
1109
            </form>
15333 stevensc 1110
        </div>
1111
    </div>
1 www 1112
</div>
1113
 
1114
 
1115
 
1116
<!-- The Modal -->
1117
<div class="modal" id="modalChangePassword">
15333 stevensc 1118
    <div class="modal-dialog">
1119
        <div class="modal-content">
1 www 1120
 
1121
            <!-- Modal Header -->
15333 stevensc 1122
            <div class="modal-header">
16935 efrain 1123
                <h6 class="modal-title">LABEL_USERS</h6>
15333 stevensc 1124
            </div>
1 www 1125
 
17328 ariadna 1126
            <?php
1127
            $form = $this->formChangePassword;
1128
            $form->setAttributes([
1129
                'method'    => 'post',
1130
                'name'      => 'form-change-password',
1131
                'id'        => 'form-change-password'
1132
            ]);
1 www 1133
 
17328 ariadna 1134
            $form->prepare();
1135
            echo $this->form()->openTag($form);
1136
            ?>
16929 efrain 1137
            <div class="modal-body">
1 www 1138
 
17328 ariadna 1139
                <div class="row">
1140
                    <div class="col-12 mt-3">
1141
                        <?php
1142
                        $element = $form->get('first_name');
1143
                        $element->setOptions(['label' => 'LABEL_FIRST_NAME']);
1144
                        $element->setAttributes(['class' => 'form-control', 'readonly' => 'readonly']);
1145
 
1146
                        echo $this->formLabel($element);
1147
                        echo $this->formText($element);
1148
                        ?>
16929 efrain 1149
                    </div>
15333 stevensc 1150
                </div>
17328 ariadna 1151
                <div class="row">
1152
                    <div class="col-12 mt-3">
1153
                        <?php
1154
                        $element = $form->get('last_name');
1155
                        $element->setOptions(['label' => 'LABEL_LAST_NAME']);
1156
                        $element->setAttributes(['class' => 'form-control', 'readonly' => 'readonly']);
1 www 1157
 
17328 ariadna 1158
                        echo $this->formLabel($element);
1159
                        echo $this->formText($element);
1160
                        ?>
16929 efrain 1161
                    </div>
15333 stevensc 1162
                </div>
17328 ariadna 1163
                <div class="row">
1164
                    <div class="col-12 mt-3">
1165
                        <?php
1166
                        $element = $form->get('email');
1167
                        $element->setOptions(['label' => 'LABEL_EMAIL']);
1168
                        $element->setAttributes(['class' => 'form-control', 'readonly' => 'readonly']);
1 www 1169
 
17328 ariadna 1170
                        echo $this->formLabel($element);
1171
                        echo $this->formText($element);
1172
                        ?>
16929 efrain 1173
                    </div>
15333 stevensc 1174
                </div>
17328 ariadna 1175
                <div class="row">
1176
                    <div class="col-12 mt-3">
1177
                        <?php
1178
                        $element = $form->get('password');
1179
                        $element->setOptions(['label' => 'LABEL_PASSWORD']);
1180
                        $element->setAttributes(['class' => 'form-control']);
1 www 1181
 
17328 ariadna 1182
                        echo $this->formLabel($element);
1183
                        echo $this->formPassword($element);
1184
                        ?>
16929 efrain 1185
                    </div>
15333 stevensc 1186
                </div>
17328 ariadna 1187
                <div class="row">
1188
                    <div class="col-12 mt-3">
1189
                        <?php
1190
                        $element = $form->get('confirmation');
1191
                        $element->setOptions(['label' => 'LABEL_CONFIRMATION']);
1192
                        $element->setAttributes(['class' => 'form-control']);
1 www 1193
 
17328 ariadna 1194
                        echo $this->formLabel($element);
1195
                        echo $this->formPassword($element);
1196
                        ?>
16929 efrain 1197
                    </div>
15333 stevensc 1198
                </div>
1199
 
1200
 
17328 ariadna 1201
 
16929 efrain 1202
            </div>
1203
            <div class="modal-footer text-right">
17328 ariadna 1204
                <button type="submit" class="btn btn-sm btn-primary">LABEL_SAVE</button>
1205
                <button type="button" class="btn btn-sm btn-light btn-cancel-modal">LABEL_CANCEL</button>
1206
            </div>
1207
            <?php echo $this->form()->closeTag($form); ?>
15333 stevensc 1208
 
1209
        </div>
1210
    </div>
1211
</div>