Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
17003 efrain 1
<?php
2
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
3
$currentUser    = $this->currentUserHelper();
4
 
5
$roleName = $currentUser->getUserTypeId();
6
 
7
 
8
$routeUpload       = $this->url('media/files/upload');
9
$routeDatatable = $this->url('media/files');
10
 
11
 
12
if($categories) {
13
 
14
    $allowUpload = $acl->isAllowed($roleName, 'media/files/upload') ? 1 : 0;
15
} else {
16
    $allowUpload = false;
17
}
18
 
19
$allowDelete = $acl->isAllowed($roleName, 'media/files/delete') ? 1 : 0;
20
 
21
 
22
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));
23
$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.js'));
24
 
25
 
26
 
27
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap-fileinput/css/fileinput.min.css'));
28
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap-fileinput/themes/explorer-fas/theme.css'));
29
 
30
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/plugins/piexif.js'));
31
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/plugins/sortable.js'));
32
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/fileinput.js'));
33
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/locales/es.js'));
34
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/themes/fas/theme.js'));
35
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/themes/explorer-fas/theme.js'));
36
 
37
 
38
 
39
$this->inlineScript()->appendFile($this->basePath('assets/vendors/select2/js/select2.js'));
40
$this->inlineScript()->appendFile($this->basePath('assets/vendors/select2/js/i18n/es.js'));
41
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/select2/css/select2.css'));
42
 
43
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/select2-bootstrap5-theme/select2-bootstrap-5-theme.css'));
44
 
45
 
46
 
47
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.css'));
48
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.css'));
49
 
50
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net/jquery.dataTables.js'));
51
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5/dataTables.bootstrap5.js'));
52
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/dataTables.responsive.min.js'));
53
$this->inlineScript()->appendFile($this->basePath('assets/vendors/datatables.net-bs5-responsive/responsive.bootstrap5.min.js'));
54
 
55
 
56
 
57
$this->inlineScript()->captureStart();
58
echo <<<JS
59
    jQuery( document ).ready(function( $ ) {
60
 
61
        $.validator.setDefaults({
62
            debug: true,
63
            highlight: function(element) {
64
                $(element).addClass('is-invalid');
65
            },
66
            unhighlight: function(element) {
67
                $(element).removeClass('is-invalid');
68
            },
69
            errorElement: 'span',
70
            errorClass: 'error invalid-feedback',
71
            errorPlacement: function(error, element) {
72
                if(element.parent('.btn-file').length) {
73
                    error.insertAfter(element.parent().parent());
74
                } else if(element.parent('.toggle').length) {
75
                    error.insertAfter(element.parent().parent());
76
                } else {
77
                    error.insertAfter(element.parent());
78
                }
79
            }
80
        });
81
 
82
 
83
        var allowDelete = $allowDelete;
84
 
85
        var gridTable = $('#gridTable').dataTable( {
86
            'processing': true,
87
            'serverSide': true,
88
            'searching': true,
89
            'order': [[ 0, 'asc' ]],
90
            'ordering':  true,
91
            'ordenable' : true,
92
            'responsive': true,
93
            'select' : false,
94
        	'paging': true,
95
            'pagingType': 'simple_numbers',
96
 
97
    		'ajax': {
98
    			'url' : '$routeDatatable',
99
                'type' : 'get',
100
                'data': function ( d ) {
101
                        d.category = $('#form-filter #category').val();
102
 
103
                 },
104
                'beforeSend': function (request) {
105
                  NProgress.start();
106
                },
107
                'dataFilter': function(response) {
108
                    var response = jQuery.parseJSON( response );
109
 
110
                    var json                = {};
111
                    json.recordsTotal       = 0;
112
                    json.recordsFiltered    = 0;
113
                    json.data               = [];
114
 
115
 
116
                    if(response.success) {
117
                        json.recordsTotal       = response.data.total;
118
                        json.recordsFiltered    = response.data.total;
119
                        json.data               = response.data.items;
120
                    } else {
121
                        $.fn.showError(response.data)
122
                    }
123
 
124
                    return JSON.stringify( json );
125
                }
126
    		},
127
            'language' : {
128
                'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
129
                'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
130
                'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
131
                'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
132
                'sInfo':           'LABEL_DATATABLE_SINFO',
133
                'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
134
                'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
135
                'sInfoPostFix':    '',
136
                'sSearch':         'LABEL_DATATABLE_SSEARCH',
137
                'sUrl':            '',
138
                'sInfoThousands':  ',',
139
                'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
140
                'oPaginate': {
141
                    'sFirst':    'LABEL_DATATABLE_SFIRST',
142
                    'sLast':     'LABEL_DATATABLE_SLAST',
143
                    'sNext':     'LABEL_DATATABLE_SNEXT',
144
                    'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
145
                },
146
                'oAria': {
147
                    'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
148
                    'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
149
                },
150
            },
151
            'drawCallback': function( settings ) {
152
                NProgress.done();
153
 
154
            },
155
            'aoColumns': [
156
                { 'mDataProp': 'name' },
157
                { 'mDataProp': 'file' },
158
                { 'mDataProp': 'preview' },
159
                { 'mDataProp': 'actions' },
160
    	    ],
161
            'columnDefs': [
162
                {
163
                    'targets': 0,
164
                    'className' : 'text-vertical-middle',
165
                },
166
                {
167
                    'targets': 1,
168
                    'orderable': false,
169
                    'render' : function ( data, type, row ) {
170
                        s = '';
171
 
172
 
173
                        if(data['type'] == 'image') {
174
                            s =  data['filename'] + '&nbsp; <i data-href="'  + data['url'] + '"  class="btn-view-image fa fa-external-link-alt"></i>';
175
                        }
176
                        else if(data['type'] == 'video') {
177
                            s = data['filename'] + '&nbsp; <i  data-href="'  + data['url'] + '" class="btn-play-video fa fa-external-link-alt"></i>';
178
                        }
179
                        else if(data['type'] == 'audio') {
180
                            s = data['filename'] + '&nbsp; <i href="#" data-href="'  + data['url'] + '" class="btn-play-audio fa fa-external-link-alt"></i>';
181
                        }
182
 
183
 
184
                        return s;
185
                    }
186
                },
187
                {
188
                    'targets': 2,
189
                    'orderable': false,
190
                    'render' : function ( data, type, row ) {
191
                        s = '';
192
 
193
 
194
                        if(data['filename'] != '') {
195
                            s = data['filename'] + '&nbsp;<i  href="#" data-href="'  + data['url'] + '" class="btn-view-image fa fa-external-link-alt"></i>';
196
                        }
197
 
198
 
199
                        return s;
200
                    }
201
                },
202
                {
203
                    'targets': -1,
204
                    'orderable': false,
205
                    'render' : function ( data, type, row ) {
206
                        s = '';
207
 
208
 
209
                        if(allowDelete && data['link_delete']  ) {
210
                            s = s + '<button class="btn btn-danger btn-sm btn-delete" data-href="' + data['link_delete']+ '" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-trash"></i> Eliminar</button>&nbsp;';
211
                        }
212
                        return s;
213
                    }
214
                }
215
              ],
216
        });
217
 
218
 
219
    var validator = $('#form').validate({
220
        debug: true,
221
        onclick: false,
222
        onkeyup: false,
223
        ignore: [],
224
        rules: {
225
            'name': {
226
                required: true,
227
                maxlength: 100,
228
            },
229
           'file': {
230
                required: true,
231
                extension: 'mov|webm|mp4|mpeg|jpg|jpeg|png|wav|mp3',
232
                accept: 'video/quicktime, video/webm, video/mp4, video/mpeg,image/jpg,image/jpeg,image/png,audio/wav,audio/mpeg'
233
            },
234
        },
235
        submitHandler: function(form)
236
        {
237
            var formdata = false;
238
            if (window.FormData){
239
                formdata = new FormData(form); //form[0]);
240
            }
241
 
242
 
243
			$('.info_noticia').prop('disabled', true);
244
			NProgress.start();
245
            $.ajax({
246
                'dataType'  : 'json',
247
                'accept'    : 'application/json',
248
                'method'    : 'post',
249
                'url'       :  $('#form').attr('action'),
250
                'data'      :  formdata,
251
                'processData': false,
252
                'contentType': false,
253
            }).done(function(response) {
254
				console.log(response)
255
				if(response['success']) {
256
                    $.fn.showSuccess(response['data']);
257
 
258
                    $('#row-upload').hide();
259
                    $('#row-listing').show();
260
 
261
 
262
                    gridTable.api().ajax.reload(null, false);
263
                } else {
264
                    validator.resetForm();
265
                    if(jQuery.type(response['data']) == 'string') {
266
                        $.fn.showError(response['data']);
267
                    } else  {
268
                        $.each(response['data'], function( fieldname, errors ) {
269
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
270
                        });
271
                    }
272
                }
273
            }).fail(function( jqXHR, textStatus, errorThrown) {
274
 
275
 
276
                $.fn.showError(textStatus);
277
            }).always(function() {
278
 
279
                NProgress.done();
280
            });
281
            return false;
282
        },
283
        invalidHandler: function(form, validator) {
284
 
285
        }
286
    });
287
 
288
 
289
    $('body').on('click', 'button.btn-delete', function(e) {
290
        e.preventDefault();
291
        var action = $(this).data('href');
292
 
293
 
294
          swal.fire({
295
            title: 'LABEL_ARE_YOU_SURE',
296
            icon: 'question',
297
            cancelButtonText: 'LABEL_NO',
298
            showCancelButton: true,
299
            confirmButtonText: 'LABEL_YES'
300
          }).then((result) => {
301
            if (result.isConfirmed) {
302
 
303
                    NProgress.start();
304
                    $.ajax({
305
                        'dataType'  : 'json',
306
                        'accept'    : 'application/json',
307
                        'method'    : 'post',
308
                        'url'       :  action,
309
                    }).done(function(response) {
310
                        if(response['success']) {
311
                            $.fn.showSuccess(response['data']);
312
                            gridTable.api().ajax.reload(null, false);
313
                        } else {
314
                            $.fn.showError(response['data']);
315
                        }
316
                    }).fail(function( jqXHR, textStatus, errorThrown) {
317
                        $.fn.showError(textStatus);
318
                    }).always(function() {
319
                        NProgress.done();
320
                    });
321
                }
322
           });
323
        });
324
 
325
 
326
        $('body').on('click', '.btn-view-image-app', function(e) {
327
            e.preventDefault();
328
 
329
            $('#image-app').attr('src', $(this).data('href'));
330
            $('#modalPreviewImage').modal('show');
331
            return false;
332
        });
333
 
334
 
335
 
336
        $('body').on('click', 'button.btn-upload', function(e) {
337
            e.preventDefault();
338
 
339
            $('#form #category').val( $('#form-filter #category').val() );
340
            $('#form #name').val('');
341
            $('#form #name').val('');
342
 
343
            $('#form #file').fileinput('reset');
344
            $('#form #file').val('');
345
 
346
            validator.resetForm();
347
 
348
 
349
            $('#row-listing').hide();
350
            $('#row-upload').show();
351
 
352
 
353
            return false;
354
        });
355
 
356
 
357
 
358
          $('#form #file').fileinput({
359
                theme: 'fa',
360
                language: 'es',
361
                showUpload: false,
362
                dropZoneEnabled: false,
363
                maxFileCount: 1,
364
                allowedFileExtensions: ['mov','webm','mp4','mpeg','jpg','jpeg','png','wav','mp3'],
365
            });
366
 
367
 
368
 
369
 
370
        $('body').on('click', 'button.btn-cancel', function(e) {
371
            e.preventDefault();
372
            $('#row-upload').hide();
373
            $('#row-edit').hide();
374
            $('#row-listing').show();
375
 
376
        });
377
 
378
        $('body').on('click', 'button.btn-refresh', function(e) {
379
            e.preventDefault();
380
            gridTable.api().ajax.reload(null, false);
381
        });
382
 
383
 
384
        $('#form-filter #category').change(function(e) {
385
            e.preventDefault();
386
 
387
            gridTable.api().ajax.reload(null, false);
388
        });
389
 
390
        $('#form-filter #category').select2({
391
            theme: 'bootstrap-5',
392
            width: '100%',
393
            dropdownParent: $('#modal'),
394
        });
395
 
396
 
397
 
398
    $('body').on('click', '.btn-view-image', function(e) {
399
        e.preventDefault();
400
 
401
        $('#modal-view-image-box').modal('show');
402
 
403
        $('#image-view').attr('src', $(this).data('href'));
404
 
405
        return false;
406
    });
407
 
408
 
409
    $('body').on('click', '.btn-play-video', function(e) {
410
        e.preventDefault();
411
 
412
        $('#play-video').attr('src', $(this).data('href'));
413
        $('#modal-play-video-box').modal('show');
414
 
415
        return false;
416
    });
417
 
418
    $('body').on('click', '.btn-play-audio', function(e) {
419
        e.preventDefault();
420
 
421
 
422
        $('#play-audio').attr('src', $(this).data('href'));
423
        $('#modal-play-audio-box').modal('show');
424
 
425
        return false;
426
    });
427
 
428
    $('body').on('click', '.btn-view-document', function(e) {
429
        e.preventDefault();
430
 
431
 
432
        $('#document-view').attr('src', $(this).data('href'));
433
        $('#modal-view-document-box').modal('show');
434
 
435
        return false;
436
    });
437
 
438
    });
439
JS;
440
$this->inlineScript()->captureEnd();
441
?>
442
 
443
<div class="container">
444
	<div class="card" id="row-listing">
445
	 	<div class="card-header">
446
	 		<h6 class="card-title">LABEL_MEDIA_FILES</h6>
447
	 	</div>
448
	 	<div class="card-body">
449
	 		<div class="row">
450
	 	         <div class="col-12 mt-3">
451
	 	         	<form name="form-filter" id="form-filter">
452
	 	         		<label form="category" ">LABEL_CATEGORY</label>
453
	 	         		<select name="category" id="category" class="form-control">
454
	 	         		<?php foreach($categories as $key => $value ) : ?>
455
	 	         		<option value="<?php echo $key ?>"><?php echo $value ?></option>
456
	 	         		<?php endforeach; ?>
457
	 	         		</select>
458
 
459
	 	         	</form>
460
	 	         </div>
461
	 	    </div>
462
	 		<div class="row">
463
	 	         <div class="col-12 mt-3">
464
 
465
	 	     	<table id="gridTable" class="table   table-bordered">
466
							<thead>
467
								<tr>
468
									<th>LABEL_NAME</th>
469
									<th>LABEL_FILE</th>
470
									<th>LABEL_PREVIEW</th>
471
									<th>LABEL_ACTIONS</th>
472
								</tr>
473
							</thead>
474
							<tbody>
475
							</tbody>
476
						</table>
477
 
478
	 	         </div>
479
	 	     </div>
480
	 	</div>
481
	 	<div class="card-footer text-right">
482
			<button type="button" class="btn btn-info btn-refresh"><i class="fa fa-sync"></i> LABEL_REFRESH </button>
483
			<?php if ($allowUpload) : ?>
484
			<button type="button" class="btn btn-primary btn-upload"><i class="fa fa-plus"></i> LABEL_ADD </button>
485
			<?php endif; ?>
486
	 	</div>
487
	</div>
488
 
489
	<div class="card" id="row-upload" style="display:none">
490
	 	<div class="card-header">
491
	 		<h6 class="card-title">LABEL_ADD</h6>
492
	 	</div>
493
	 	<?php
494
		$form = $this->form;
495
		$form->setAttributes([
496
			'method'  => 'post',
497
			'action'  => $routeUpload,
498
			'name'    => 'form',
499
			'id'      => 'form',
500
		]);
501
 
502
		$form->prepare();
503
		echo $this->form()->openTag($form);
504
 
505
		?>
506
		<input type="hidden" name="category" id="category" value="" />
507
	 	<div class="card-body">
508
			<div class="row">
509
    	 		<div class="col-12 mt-3">
510
    			<?php
511
    			$element = $form->get('name');
512
 
513
    			$element->setAttributes(['class' => 'form-control']);
514
    			$element->setOptions(['label' => 'LABEL_NAME']);
515
    			echo $this->formLabel($element);
516
    			echo $this->formText($element);
517
    			?>
518
    			</div>
519
    		</div>
520
 
521
             <div class="row">
522
    	 		<div class="col-12 mt-3">
523
                            <?php
524
                            $element = $form->get('file');
525
                            $element->setOptions(['label' => 'LABEL_FILE']);
526
                            $element->setAttributes(['class' => 'form-control']);
527
                            $element->setAttributes(['accept' => 'video/quicktime, video/webm, video/mp4, video/mpeg, image/jpg ,image/jpeg, image/png, audio/wav, audio/mpeg, application/pdf']);
528
                            echo $this->formLabel($element);
529
                            echo $this->formFile($element);
530
                            ?>
531
                	</div>
532
         	</div>
533
	 	</div>
534
	 	<div class="card-footer text-right">
535
	 	     <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
536
      		<button type="button" class="btn btn-light btn-cancel">LABEL_CANCEL</button>
537
	 	</div>
538
	 	<?php echo $this->form()->closeTag($form); ?>
539
	</div>
540
</div>
541
 
542
 
543
 
544
 
545
 
546
<!-- The Modal -->
547
<div class="modal" id="modal-play-video-box" >
548
	<div class="modal-dialog ">
549
    	<div class="modal-content">
550
 
551
            <!-- Modal Header -->
552
      		<div class="modal-header">
553
        		<h6 class="modal-title">LABEL_PLAY_VIDEO</h6>
554
        		<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="btn-close"></button>
555
      		</div>
556
 
557
            <!-- Modal body -->
558
            <div class="modal-body">
559
				<video src=""  style="width: 300px; height: auto" controls preload="false" autoplay="false"  poster="" id="play-video"></video>
560
      		</div>
561
 
562
            <!-- Modal footer -->
563
      		<div class="modal-footer text-right">
564
        		 <button type="button" class="btn btn-light" data-bs-dismiss="modal">LABEL_CLOSE</button>
565
          	</div>
566
         </div>
567
	</div>
568
</div>
569
 
570
 
571
 
572
 
573
 
574
<!-- The Modal -->
575
<div class="modal" id="modal-play-audio-box" >
576
	<div class="modal-dialog ">
577
    	<div class="modal-content">
578
 
579
            <!-- Modal Header -->
580
      		<div class="modal-header">
581
        		<h6 class="modal-title">LABEL_PLAY_AUDIO</h6>
582
        		<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="btn-close"></button>
583
      		</div>
584
 
585
            <!-- Modal body -->
586
            <div class="modal-body">
587
				<audio src="" controls autoplay="false"  id="play-audio" >
588
                  Your browser does not support the <code>audio</code> element.
589
                </audio>
590
      		</div>
591
 
592
            <!-- Modal footer -->
593
      		<div class="modal-footer text-right">
594
        		 <button type="button" class="btn btn-light" data-bs-dismiss="modal">LABEL_CLOSE</button>
595
          	</div>
596
         </div>
597
	</div>
598
</div>
599
 
600
 
601
<!-- The Modal -->
602
<div class="modal" id="modal-view-image-box">
603
	<div class="modal-dialog ">
604
    	<div class="modal-content">
605
 
606
            <!-- Modal Header -->
607
      		<div class="modal-header">
608
        		<h6 class="modal-title">LABEL_IMAGE</h6>
609
        		<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="btn-close"></button>
610
      		</div>
611
 
612
            <!-- Modal body -->
613
            <div class="modal-body text-center">
614
				<img src="" class="img img-responsive" style="width: 300px; height: auto" id="image-view" />
615
      		</div>
616
 
617
            <!-- Modal footer -->
618
      		<div class="modal-footer text-right">
619
        		 <button type="button" class="btn btn-light" data-bs-dismiss="modal">LABEL_CLOSE</button>
620
          	</div>
621
         </div>
622
	</div>
623
</div>
624
 
625
 
626
<!-- The Modal -->
627
<div class="modal" id="modal-view-document-box">
628
	<div class="modal-dialog ">
629
    	<div class="modal-content">
630
 
631
            <!-- Modal Header -->
632
      		<div class="modal-header">
633
        		<h6 class="modal-title">LABEL_DOCUMENT</h6>
634
        		<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="btn-close"></button>
635
      		</div>
636
 
637
            <!-- Modal body -->
638
            <div class="modal-body text-center">
639
            	<iframe id="document-view" style="width: 450px; height: 300px; scroll: auto">
640
 
641
            	</iframe>
642
       	</div>
643
 
644
            <!-- Modal footer -->
645
      		<div class="modal-footer text-right">
646
        		 <button type="button" class="btn btn-light" data-bs-dismiss="modal">LABEL_CLOSE</button>
647
          	</div>
648
         </div>
649
	</div>
650
</div>