Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 166 | Rev 169 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 166 Rev 167
Línea 60... Línea 60...
60
$status_inactive = \LeadersLinked\Model\CompanySelfEvaluationForm::STATUS_INACTIVE;
60
$status_inactive = \LeadersLinked\Model\CompanySelfEvaluationForm::STATUS_INACTIVE;
Línea 61... Línea 61...
61
 
61
 
62
$lang_es = \LeadersLinked\Model\CompanySelfEvaluationForm::LANGUAGE_SPANISH;
62
$lang_es = \LeadersLinked\Model\CompanySelfEvaluationForm::LANGUAGE_SPANISH;
Línea 63... Línea 63...
63
$lang_en = \LeadersLinked\Model\CompanySelfEvaluationForm::LANGUAGE_ENGLISH;
63
$lang_en = \LeadersLinked\Model\CompanySelfEvaluationForm::LANGUAGE_ENGLISH;
64
 
64
 
65
                        
65
 
Línea -... Línea 376...
-
 
376
        }
-
 
377
}
-
 
378
 
-
 
379
function htmlEntities(str) {
-
 
380
    return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
-
 
381
}
-
 
382
jQuery(document).ready(function($) {
-
 
383
    var objFormGenerator = new classFormGenerator();
-
 
384
    objFormGenerator.render();
-
 
385
    var allowEdit = $allowEdit;
-
 
386
    var allowDelete = $allowDelete;
-
 
387
    var tableForm = $('#gridTable').dataTable({
-
 
388
        'processing': true,
-
 
389
        'serverSide': true,
-
 
390
        'searching': true,
-
 
391
        'order': [
-
 
392
            [0, 'asc']
-
 
393
        ],
-
 
394
        'ordering': true,
-
 
395
        'ordenable': true,
-
 
396
        'responsive': true,
-
 
397
        'select': false,
-
 
398
        'paging': true,
-
 
399
        'pagingType': 'simple_numbers',
-
 
400
        'ajax': {
-
 
401
            'url': '$routeDatatable',
-
 
402
            'type': 'get',
-
 
403
            'beforeSend': function(request) {
-
 
404
                NProgress.start();
-
 
405
            },
-
 
406
            'dataFilter': function(response) {
-
 
407
                var response = jQuery.parseJSON(response);
-
 
408
                var json = {};
-
 
409
                json.recordsTotal = 0;
-
 
410
                json.recordsFiltered = 0;
-
 
411
                json.data = [];
-
 
412
                if (response.success) {
-
 
413
                    json.recordsTotal = response.data.total;
-
 
414
                    json.recordsFiltered = response.data.total;
-
 
415
                    json.data = response.data.items;
-
 
416
                } else {
-
 
417
                    $.fn.showError(response.data)
-
 
418
                }
-
 
419
                return JSON.stringify(json);
-
 
420
            }
-
 
421
        },
-
 
422
        'language': {
-
 
423
            'sProcessing': 'LABEL_DATATABLE_SPROCESSING',
-
 
424
            'sLengthMenu': 'LABEL_DATATABLE_SLENGTHMENU',
-
 
425
            'sZeroRecords': 'LABEL_DATATABLE_SZERORECORDS',
-
 
426
            'sEmptyTable': 'LABEL_DATATABLE_SEMPTYTABLE',
-
 
427
            'sInfo': 'LABEL_DATATABLE_SINFO',
-
 
428
            'sInfoEmpty': 'LABEL_DATATABLE_SINFOEMPTY',
-
 
429
            'sInfoFiltered': 'LABEL_DATATABLE_SINFOFILTERED',
-
 
430
            'sInfoPostFix': '',
-
 
431
            'sSearch': 'LABEL_DATATABLE_SSEARCH',
-
 
432
            'sUrl': '',
-
 
433
            'sInfoThousands': ',',
-
 
434
            'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
-
 
435
            'oPaginate': {
-
 
436
                'sFirst': 'LABEL_DATATABLE_SFIRST',
-
 
437
                'sLast': 'LABEL_DATATABLE_SLAST',
-
 
438
                'sNext': 'LABEL_DATATABLE_SNEXT',
-
 
439
                'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
-
 
440
            },
-
 
441
            'oAria': {
-
 
442
                'sSortAscending': ': LABEL_DATATABLE_SSORTASCENDING',
-
 
443
                'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
-
 
444
            },
-
 
445
        },
-
 
446
        'drawCallback': function(settings) {
-
 
447
            NProgress.done();
-
 
448
            $('button.btn-delete').confirmation({
-
 
449
                rootSelector: 'button.btn-delete',
-
 
450
                title: 'LABEL_ARE_YOU_SURE',
-
 
451
                singleton: true,
-
 
452
                btnOkLabel: 'LABEL_YES',
-
 
453
                btnCancelLabel: 'LABEL_NO',
-
 
454
                onConfirm: function(value) {
-
 
455
                    action = $(this).data('href');
-
 
456
                    NProgress.start();
-
 
457
                    $.ajax({
-
 
458
                        'dataType': 'json',
-
 
459
                        'accept': 'application/json',
-
 
460
                        'method': 'post',
-
 
461
                        'url': action,
-
 
462
                    }).done(function(response) {
-
 
463
                        if (response['success']) {
-
 
464
                            $.fn.showSuccess(response['data']);
-
 
465
                            gridTable.api().ajax.reload(null, false);
-
 
466
                        } else {
-
 
467
                            $.fn.showError(response['data']);
-
 
468
                        }
-
 
469
                    }).fail(function(jqXHR, textStatus, errorThrown) {
-
 
470
                        $.fn.showError(textStatus);
-
 
471
                    }).always(function() {
-
 
472
                        NProgress.done();
-
 
473
                    });
-
 
474
                },
-
 
475
            });
-
 
476
        },
-
 
477
        'aoColumns': [{
-
 
478
                'mDataProp': 'name'
-
 
479
            },
-
 
480
            {
-
 
481
                'mDataProp': 'language'
-
 
482
            },
-
 
483
            {
-
 
484
                'mDataProp': 'status'
-
 
485
            },
-
 
486
            {
-
 
487
                'mDataProp': 'actions'
-
 
488
            },
-
 
489
        ],
-
 
490
        'columnDefs': [{
-
 
491
                'targets': 0,
-
 
492
                'className': 'text-vertical-middle',
-
 
493
            },
-
 
494
            {
-
 
495
                'targets': 1,
-
 
496
                'className': 'text-vertical-middle',
-
 
497
            },
-
 
498
            {
-
 
499
                'targets': -2,
-
 
500
                'orderable': false,
-
 
501
                'className': 'text-center',
-
 
502
                'render': function(data, type, row) {
-
 
503
                    checked = data == 'a' ? ' checked="checked" ' : '';
-
 
504
                    return '<div class="checkbox checkbox-success">' +
-
 
505
                        '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
-
 
506
                        '<label ></label></div>';
-
 
507
                }
-
 
508
            },
-
 
509
            {
-
 
510
                'targets': -1,
-
 
511
                'orderable': false,
-
 
512
                'render': function(data, type, row) {
-
 
513
                    s = '';
-
 
514
                    if (allowEdit) {
-
 
515
                        s = s + '<button class="btn btn-primary btn-edit-form" data-href="' + data['link_edit'] + '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pencil"></i> LABEL_EDIT </button>&nbsp;';
-
 
516
                    }
-
 
517
                    if (allowDelete) {
-
 
518
                        s = s + '<button class="btn btn-danger btn-delete" data-href="' + data['link_delete'] + '" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-trash"></i> LABEL_DELETE </button>&nbsp;';
-
 
519
                    }
-
 
520
                    return s;
643
		});
521
                }
-
 
522
            }
-
 
523
        ],
-
 
524
    });
-
 
525
    $('body').on('click', 'a.btn-delete-form', function(e) {
-
 
526
        e.preventDefault();
-
 
527
        form_id = $(this).data('id')
-
 
528
        bootbox.confirm({
-
 
529
            title: "LABEL_DELETE LABEL_FORM",
-
 
530
            message: "LABEL_QUESTION_DELETE",
-
 
531
            buttons: {
-
 
532
                cancel: {
-
 
533
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
-
 
534
                },
-
 
535
                confirm: {
-
 
536
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
-
 
537
                }
-
 
538
            },
-
 
539
            callback: function(result) {
-
 
540
                if (result) {
-
 
541
                    $.ajax({
-
 
542
                        'dataType': 'json',
-
 
543
                        'method': 'post',
-
 
544
                        'url': 'ajax.<?php echo $this->module; ?>.php?action=delete',
-
 
545
                        'data': {
-
 
546
                            'form-id': form_id
-
 
547
                        },
-
 
548
                    }).done(function(response) {
-
 
549
                        if (response['success']) {
-
 
550
                            $.fn.showSuccess(response['message']);
-
 
551
                            tableForm.fnDraw();
-
 
552
                        } else {
-
 
553
                            $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
-
 
554
                        }
-
 
555
                    }).fail(function(jqXHR, textStatus, errorThrown) {
-
 
556
                        $.fn.showError(textStatus);
-
 
557
                    });
644
		
558
                }
645
 
559
            }
646
    });
-
 
647
 
560
        });
648
    $(document).on('click','[data-action="delete"]',function(){
561
    });
649
 
562
    $(document).on('click', '[data-action="delete"]', function() {
650
    	bootbox.confirm({
563
        bootbox.confirm({
651
		    title: "LABEL_DELETE LABEL_FORMS_2",
564
            title: "LABEL_DELETE LABEL_FORMS_2",
652
		    message: "LABEL_QUESTION_DELETE",
565
            message: "LABEL_QUESTION_DELETE",
653
		    buttons: {
566
            buttons: {
654
		        cancel: {
567
                cancel: {
655
		            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
568
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
656
		        },
569
                },
657
		        confirm: {
570
                confirm: {
658
		            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
571
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
659
		        }
572
                }
660
		    },
573
            },
661
		    callback: function (result) {
574
            callback: function(result) {
662
			    if(result) {
575
                if (result) {
663
			    	var d = currentSelected();	
576
                    var d = currentSelected();
664
    		    	$.ajax({
577
                    $.ajax({
665
    	                'dataType': 'json',
578
                        'dataType': 'json',
666
    	                'method': 'post',
579
                        'method': 'post',
667
    	                'url' :  'ajax.<?php echo $this->module; ?>.php?action=delete-selected',
580
                        'url': 'ajax.<?php echo $this->module; ?>.php?action=delete-selected',
668
    	                'data' :{
581
                        'data': {
669
    	                	 selected : d
-
 
670
    	                },
582
                            selected: d
671
    	            }).done(function(response) {
583
                        },
672
    
584
                    }).done(function(response) {
673
    	                if(response['success']) {
585
                        if (response['success']) {
674
    	                	$.fn.showSuccess(response['message']);
586
                            $.fn.showSuccess(response['message']);
675
    	                	tableForm.fnDraw();
587
                            tableForm.fnDraw();
676
    	                } else {
588
                        } else {
677
    	                	$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
589
                            $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
678
    	                }
590
                        }
679
    	            }).fail(function( jqXHR, textStatus, errorThrown) {
591
                    }).fail(function(jqXHR, textStatus, errorThrown) {
680
    					$.fn.showError(textStatus);
592
                        $.fn.showError(textStatus);
681
    	            });
593
                    });
682
			    }
-
 
683
		    }
594
                }
684
		});
-
 
685
        
-
 
686
    });
595
            }
687
 
596
        });
688
 
597
    });
689
    $('body').on('switch-change', 'input[type="checkbox"].make-switch-form', function(e) {
-
 
690
		e.preventDefault();
598
    $('body').on('switch-change', 'input[type="checkbox"].make-switch-form', function(e) {
691
		e.stopPropagation();
599
        e.preventDefault();
692
 
-
 
693
		form_id =  $(this).data('id')
600
        e.stopPropagation();
694
		form_status = $(this).prop('checked') ? 'A' : 'D';
601
        form_id = $(this).data('id')
695
		
602
        form_status = $(this).prop('checked') ? 'A' : 'D';
696
		$.ajax({
603
        $.ajax({
697
        	'dataType': 'json',
604
            'dataType': 'json',
698
            'method': 'post',
605
            'method': 'post',
699
            'url' :  'ajax.<?php echo $this->module; ?>.php?action=status',
606
            'url': 'ajax.<?php echo $this->module; ?>.php?action=status',
700
            'data' :{
607
            'data': {
701
            	'form-id' : form_id,
608
                'form-id': form_id,
702
            	'form-status' : form_status
609
                'form-status': form_status
703
            },
610
            },
704
        }).done(function(response) {
611
        }).done(function(response) {
705
	        if(response['success']) {
612
            if (response['success']) {
706
	        	$.fn.showSuccess(response['message']);
613
                $.fn.showSuccess(response['message']);
707
	       } else {
614
            } else {
708
    	       	$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
615
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
709
            }
616
            }
710
         }).fail(function( jqXHR, textStatus, errorThrown) {
617
        }).fail(function(jqXHR, textStatus, errorThrown) {
711
			$.fn.showError(textStatus);
-
 
712
        })
618
            $.fn.showError(textStatus);
713
    }); 
619
        })
714
 
620
    });
715
	$('body').on('click', 'button.btn-edit-form',function(e) {
621
    $('body').on('click', 'button.btn-edit-form', function(e) {
716
		e.preventDefault();
622
        e.preventDefault();
717
		form_id =  $(this).data('id')
623
        form_id = $(this).data('id')
718
    var action = $(this).data('href');
624
        var action = $(this).data('href');
719
		$.ajax({
625
        $.ajax({
720
			'dataType'  : 'json',
626
            'dataType': 'json',
721
			'accept'    : 'application/json',
627
            'accept': 'application/json',
722
			'method'    : 'get',
628
            'method': 'get',
723
			'url'       :  action,
629
            'url': action,
724
		}).done(function(response) {
-
 
725
			if(response['success']) {
630
        }).done(function(response) {
726
					validatorForm.resetForm();
631
            if (response['success']) {
727
 
632
                validatorForm.resetForm();
728
					$('#form-main #form-id' ).val(response['id']),
-
 
729
					$('#form-main #form-continue').val('0');
-
 
730
					$('#form-main #form-name' ).val(response['name']),
633
                $('#form-main #form-id').val(response['id']),
731
 
634
                    $('#form-main #form-continue').val('0');
732
 
635
                $('#form-main #form-name').val(response['name']),
733
					instanceName = 'form-description'; 
636
                    instanceName = 'form-description';
734
					let editor = CKEDITOR.instances[instanceName ];
637
                let editor = CKEDITOR.instances[instanceName];
735
					editor.setData(response['description'], function() {
-
 
736
							editor.focus();
-
 
737
					});
638
                editor.setData(response['description'], function() {
738
					
639
                    editor.focus();
739
					
-
 
740
					instanceName = 'form-text'; 
640
                });
741
					CKEDITOR.instances[instanceName ].setData(response['text']);
641
                instanceName = 'form-text';
742
 
-
 
743
					$('#form-main #form-language' ).val(response['language']),
642
                CKEDITOR.instances[instanceName].setData(response['text']);
744
					$('#form-main #form-status' ).val(response['status']);
643
                $('#form-main #form-language').val(response['language']),
745
 
644
                    $('#form-main #form-status').val(response['status']);
746
					objFormGenerator.clear();
645
                objFormGenerator.clear();
747
					objFormGenerator.sections = response['sections'] || [];
646
                objFormGenerator.sections = response['sections'] || [];
748
					objFormGenerator.render();
-
 
749
					$('#row-forms').hide();
647
                objFormGenerator.render();
750
					$('#row-edit').show();
-
 
751
 
648
                $('#row-forms').hide();
752
					$('#form-main #form-name').focus();
649
                $('#row-edit').show();
753
					
650
                $('#form-main #form-name').focus();
754
				} else {
651
            } else {
755
					$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
652
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
-
 
653
            }
756
				}
654
        }).fail(function(jqXHR, textStatus, errorThrown) {
-
 
655
            $.fn.showError(textStatus);
-
 
656
        });
-
 
657
    });
-
 
658
    $(document).on('click', '[data-type="select_all"]', function() {
-
 
659
        if ($('input[name="select_all"]:checked').val() == 'all') {
-
 
660
            $('[data-type="select"]').prop('checked', true);
-
 
661
            $('[data-action="delete"]').removeClass('hide');
-
 
662
        } else {
757
			}).fail(function( jqXHR, textStatus, errorThrown) {
663
            $('[data-type="select"]').prop('checked', false);
Línea 758... Línea -...
758
				$.fn.showError(textStatus);
-
 
759
			});
-
 
760
    });
-
 
761
 
-
 
762
	 $(document).on('click','[data-type="select_all"]',function(){
-
 
763
 
-
 
764
	        if($('input[name="select_all"]:checked').val() == 'all'){
-
 
765
	            $('[data-type="select"]').prop('checked', true);
-
 
766
	            $('[data-action="delete"]').removeClass('hide');    
-
 
767
	        }else{
-
 
768
	            $('[data-type="select"]').prop('checked', false);    
-
 
769
	            $('[data-action="delete"]').addClass('hide');
664
            $('[data-action="delete"]').addClass('hide');
770
	        }
665
        }
771
	    });
-
 
772
 
-
 
773
	    function getLength(){
-
 
774
	        return $('[data-type="select"]').length;
-
 
775
	    }
-
 
776
 
-
 
777
	    function currentSelected(){
-
 
778
	        var selected = [];
-
 
779
	        $.each($("input[name='select[]']:checked"), function(){            
-
 
780
	            selected.push($(this).val());
666
    });
781
	        });
-
 
782
 
-
 
783
	        return selected;        
-
 
784
	    }
-
 
785
 
-
 
786
	    $(document).on('change',"input[name='select[]']",function(){
-
 
787
	        var c = currentSelected();
-
 
788
	        var cc = getLength();
-
 
789
 
-
 
790
	        	
-
 
791
	        if(c.length == cc){
-
 
792
	            if($('[data-action="delete"]').hasClass('hide')){
-
 
793
	                $('[data-action="delete"]').removeClass('hide');
-
 
794
	            }
-
 
795
	            return true;
-
 
796
	        }else{
-
 
797
	            $('input[name="select_all"]').prop('checked', false);
-
 
798
	        }
-
 
799
 
-
 
800
	        if(c.length > 0){
-
 
801
	            if($('[data-action="delete"]').hasClass('hide')){
-
 
802
	                $('[data-action="delete"]').removeClass('hide');
-
 
803
	            }
-
 
804
	        }else{
-
 
805
	            if(!$('[data-action="delete"]').hasClass('hide')){
-
 
806
	                $('[data-action="delete"]').addClass('hide');
-
 
807
	            }
-
 
808
	        }
-
 
809
	    });
-
 
Línea -... Línea 667...
-
 
667
 
-
 
668
    function getLength() {
-
 
669
        return $('[data-type="select"]').length;
-
 
670
    }
-
 
671
 
-
 
672
    function currentSelected() {
-
 
673
        var selected = [];
-
 
674
        $.each($("input[name='select[]']:checked"), function() {
-
 
675
            selected.push($(this).val());
-
 
676
        });
-
 
677
        return selected;
-
 
678
    }
-
 
679
    $(document).on('change', "input[name='select[]']", function() {
-
 
680
        var c = currentSelected();
-
 
681
        var cc = getLength();
-
 
682
        if (c.length == cc) {
-
 
683
            if ($('[data-action="delete"]').hasClass('hide')) {
-
 
684
                $('[data-action="delete"]').removeClass('hide');
-
 
685
            }
-
 
686
            return true;
-
 
687
        } else {
-
 
688
            $('input[name="select_all"]').prop('checked', false);
-
 
689
        }
-
 
690
        if (c.length > 0) {
-
 
691
            if ($('[data-action="delete"]').hasClass('hide')) {
-
 
692
                $('[data-action="delete"]').removeClass('hide');
-
 
693
            }
-
 
694
        } else {
-
 
695
            if (!$('[data-action="delete"]').hasClass('hide')) {
-
 
696
                $('[data-action="delete"]').addClass('hide');
-
 
697
            }
810
 
698
        }
811
	    var form3 = $('#form_sample_3');
699
    });
812
        var error3 = $('.alert-danger', form3);
700
    var form3 = $('#form_sample_3');
813
        var success3 = $('.alert-success', form3);
701
    var error3 = $('.alert-danger', form3);
814
 
702
    var success3 = $('.alert-success', form3);
815
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
703
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
816
 	$( "#form-main" ).on('submit', function() {
-
 
817
		for(var instanceName in CKEDITOR.instances) {
704
    $("#form-main").on('submit', function() {
818
			CKEDITOR.instances[instanceName].updateElement();
705
        for (var instanceName in CKEDITOR.instances) {
819
		}
706
            CKEDITOR.instances[instanceName].updateElement();
820
	})
707
        }
821
	    
708
    })
822
	var validatorForm = $( "#form-main" ).validate( {
709
    var validatorForm = $("#form-main").validate({
823
        ignore: [],
710
        ignore: [],
824
        errorClass: 'help-block',
711
        errorClass: 'help-block',
825
        errorElement: 'span',
712
        errorElement: 'span',
826
		rules: {
713
        rules: {
827
			'form-name':  {
714
            'form-name': {
828
				required: true,
715
                required: true,
829
				minlength: 2,
716
                minlength: 2,
830
				maxlength: 50
717
                maxlength: 50
831
			},
718
            },
832
			'form-description' : {
719
            'form-description': {
833
				required: true,
720
                required: true,
834
			},
721
            },
835
			'form-text' : {
722
            'form-text': {
836
				required: true,
723
                required: true,
837
			},
724
            },
838
			'form-language' : {
725
            'form-language': {
839
				required: true,
726
                required: true,
840
			},
727
            },
841
			'forrm-status' : {
728
            'forrm-status': {
842
				required: true,
729
                required: true,
843
			},
730
            },
844
		},
731
        },
845
        highlight: function (element) {
732
        highlight: function(element) {
846
            $(element).closest('.form-group').addClass('has-error');
733
            $(element).closest('.form-group').addClass('has-error');
847
        },
734
        },
848
        unhighlight: function (element) {
735
        unhighlight: function(element) {
849
            $(element).closest('.form-group').removeClass('has-error');
736
            $(element).closest('.form-group').removeClass('has-error');
850
        },
737
        },
851
        errorPlacement: function (error, element) {
738
        errorPlacement: function(error, element) {
Línea 860... Línea 747...
860
                return;
747
                return;
861
            $('html, body').animate({
748
            $('html, body').animate({
862
                scrollTop: $(validator.errorList[0].element).offset().top - 100
749
                scrollTop: $(validator.errorList[0].element).offset().top - 100
863
            }, 1000);
750
            }, 1000);
864
        },
751
        },
1032
        ignore: [],
885
        ignore: [],
1033
        errorClass: 'help-block',
886
        errorClass: 'help-block',
1034
        errorElement: 'span',
887
        errorElement: 'span',
1035
		rules: {
888
        rules: {
1036
			'section-name':  {
889
            'section-name': {
1037
				required: true,
890
                required: true,
1038
				minlength: 2,
891
                minlength: 2,
1039
				maxlength: 50
892
                maxlength: 50
1040
			},
893
            },
1041
			'section-text' : {
894
            'section-text': {
1042
				required: false,
895
                required: false,
1043
			},
896
            },
1044
			'section-value' : {
897
            'section-value': {
1045
				required: true,
898
                required: true,
1046
				number: true,
899
                number: true,
1047
				min: 1
900
                min: 1
1048
			},
901
            },
1049
		},
902
        },
1050
        highlight: function (element) {
903
        highlight: function(element) {
1051
            $(element).closest('.form-group').addClass('has-error');
904
            $(element).closest('.form-group').addClass('has-error');
1052
        },
905
        },
1053
        unhighlight: function (element) {
906
        unhighlight: function(element) {
1054
            $(element).closest('.form-group').removeClass('has-error');
907
            $(element).closest('.form-group').removeClass('has-error');
1055
        },
908
        },
1056
        errorPlacement: function (error, element) {
909
        errorPlacement: function(error, element) {
1057
            if (element.attr("data-error-container")) {
910
            if (element.attr("data-error-container")) {
1058
                error.appendTo(element.attr("data-error-container"));
911
                error.appendTo(element.attr("data-error-container"));
1059
            } else {
912
            } else {
1060
                error.insertAfter(element);
913
                error.insertAfter(element);
1061
            }
914
            }
Línea 1065... Línea 918...
1065
                return;
918
                return;
1066
            $('html, body').animate({
919
            $('html, body').animate({
1067
                scrollTop: $(validator.errorList[0].element).offset().top - 100
920
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1068
            }, 1000);
921
            }, 1000);
1069
        },
922
        },
1070
		submitHandler: function(form) {
923
        submitHandler: function(form) {
1071
		    // do other things for a valid form
924
            // do other things for a valid form
1072
		    //form.submit();
925
            //form.submit();
1073
 
-
 
1074
		    var slug = $('#form-section #section-slug').val();
926
            var slug = $('#form-section #section-slug').val();
1075
		    if(slug) {
927
            if (slug) {
1076
		    	objFormGenerator.editSection(
928
                objFormGenerator.editSection(
1077
		    		$('#form-section #section-slug').val(), 
929
                    $('#form-section #section-slug').val(),
1078
			    	$('#form-section #section-name').val(), 
930
                    $('#form-section #section-name').val(),
1079
			    	$('#form-section #section-text').val(),
931
                    $('#form-section #section-text').val(),
1080
			    	$('#form-section #section-value').val()
932
                    $('#form-section #section-value').val()
1081
			  	);	
933
                );
1082
		    } else {
934
            } else {
1083
		    	objFormGenerator.addSection(
935
                objFormGenerator.addSection(
1084
		    		$('#form-section #section-name').val(), 
936
                    $('#form-section #section-name').val(),
1085
		    		$('#form-section #section-text').val(),
937
                    $('#form-section #section-text').val(),
1086
		    		$('#form-section #section-value').val()
938
                    $('#form-section #section-value').val()
1087
		    	);	
939
                );
1088
		    }
940
            }
1089
		    
-
 
1090
		    renderData(objFormGenerator.sections);
941
            renderData(objFormGenerator.sections);
1091
			$('#modal-section').modal('hide');
942
            $('#modal-section').modal('hide');
1092
			return false;
943
            return false;
1093
		  }
944
        }
1094
	} );
945
    });
1095
 
-
 
1096
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
946
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
1097
 	$( "#form-question" ).on('submit', function() {
947
    $("#form-question").on('submit', function() {
1098
		for(var instanceName in CKEDITOR.instances) {
948
        for (var instanceName in CKEDITOR.instances) {
1099
			CKEDITOR.instances[instanceName].updateElement();
949
            CKEDITOR.instances[instanceName].updateElement();
1100
		}
950
        }
1101
	})
951
    })
1102
	
-
 
1103
	
-
 
1104
	var validatorFormQuestion = $( "#form-question" ).validate( {
952
    var validatorFormQuestion = $("#form-question").validate({
1105
        ignore: [],
953
        ignore: [],
1106
        errorClass: 'help-block',
954
        errorClass: 'help-block',
1107
        errorElement: 'span',
955
        errorElement: 'span',
1108
		rules: {
956
        rules: {
1109
			'question-text' : {
957
            'question-text': {
1110
				required: true,
958
                required: true,
1111
			},
959
            },
1112
			'question-value' : {
960
            'question-value': {
1113
				required: true,
961
                required: true,
1114
				number: true,
962
                number: true,
1115
				min: 1
963
                min: 1
1116
			},
964
            },
1117
			'question-type':  {
965
            'question-type': {
1118
				required: true,
966
                required: true,
1119
			},
967
            },
1120
			'question-max-length' : {
968
            'question-max-length': {
1121
				required: true,
969
                required: true,
1122
				digits: true,
970
                digits: true,
1123
				min: 0
971
                min: 0
1124
			},
972
            },
1125
			'question-range' : {
973
            'question-range': {
1126
				required: true,
974
                required: true,
1127
				number: true,
975
                number: true,
1128
				min: 1
976
                min: 1
1129
			},
977
            },
1130
		},
978
        },
1131
        highlight: function (element) {
979
        highlight: function(element) {
1132
            $(element).closest('.form-group').addClass('has-error');
980
            $(element).closest('.form-group').addClass('has-error');
1133
        },
981
        },
1134
        unhighlight: function (element) {
982
        unhighlight: function(element) {
1135
            $(element).closest('.form-group').removeClass('has-error');
983
            $(element).closest('.form-group').removeClass('has-error');
1136
        },
984
        },
1137
        errorPlacement: function (error, element) {
985
        errorPlacement: function(error, element) {
1138
            if (element.attr("data-error-container")) {
986
            if (element.attr("data-error-container")) {
1139
                error.appendTo(element.attr("data-error-container"));
987
                error.appendTo(element.attr("data-error-container"));
1140
            } else {
988
            } else {
1141
                error.insertAfter(element);
989
                error.insertAfter(element);
1142
            }
990
            }
1143
        },
991
        },
1144
        invalidHandler: function(form, validator) {
992
        invalidHandler: function(form, validator) {
1145
 
-
 
1146
            
-
 
1147
            if (!validator.numberOfInvalids())
993
            if (!validator.numberOfInvalids())
1148
                return;
994
                return;
1149
            $('html, body').animate({
995
            $('html, body').animate({
1150
                scrollTop: $(validator.errorList[0].element).offset().top - 100
996
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1151
            }, 1000);
997
            }, 1000);
1152
        },
998
        },
1153
		submitHandler: function(form) {
999
        submitHandler: function(form) {
1154
		    
-
 
1155
		
-
 
1156
		    if($('#form-question #question-slug').val()) {
1000
            if ($('#form-question #question-slug').val()) {
1157
		    
-
 
1158
			
-
 
1159
		    	objFormGenerator.editQuestion(
1001
                objFormGenerator.editQuestion(
1160
		    		$('#form-question #question-section').val(), 
1002
                    $('#form-question #question-section').val(),
1161
		    		$('#form-question #question-slug').val(),
1003
                    $('#form-question #question-slug').val(),
1162
		    		$('#form-question #question-text').val(), 
1004
                    $('#form-question #question-text').val(),
1163
		    		$('#form-question #question-value').val(),
1005
                    $('#form-question #question-value').val(),
1164
			    	$('#form-question #question-type').val(),
1006
                    $('#form-question #question-type').val(),
1165
			    	$('#form-question #question-max-length').val(),
1007
                    $('#form-question #question-max-length').val(),
1166
	    			$('#form-question #question-multiline').val(),
1008
                    $('#form-question #question-multiline').val(),
1167
	    			$('#form-question #question-range').val()
1009
                    $('#form-question #question-range').val()
1168
			  	);	
1010
                );
1169
		    } else {
1011
            } else {
1170
			    
-
 
1171
		    	objFormGenerator.addQuestion(
1012
                objFormGenerator.addQuestion(
1172
			    	$('#form-question #question-section').val(), 
1013
                    $('#form-question #question-section').val(),
1173
			    	$('#form-question #question-text').val(), 
1014
                    $('#form-question #question-text').val(),
1174
			    	$('#form-question #question-value').val(),
1015
                    $('#form-question #question-value').val(),
1175
				    $('#form-question #question-type').val(),
1016
                    $('#form-question #question-type').val(),
1176
				    $('#form-question #question-max-length').val(),
1017
                    $('#form-question #question-max-length').val(),
1177
		    		$('#form-question #question-multiline').val(),
1018
                    $('#form-question #question-multiline').val(),
1178
		    		$('#form-question #question-range').val()
1019
                    $('#form-question #question-range').val()
1179
		    	);	
1020
                );
1180
		    }
1021
            }
1181
		    renderData(objFormGenerator.sections);
1022
            renderData(objFormGenerator.sections);
1182
			$('#modal-question').modal('hide');
1023
            $('#modal-question').modal('hide');
1183
			return false;
1024
            return false;
1184
		  }
1025
        }
1185
	} );
1026
    });
1186
 
-
 
1187
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
1027
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
1188
 	$( "#form-option" ).on('submit', function() {
1028
    $("#form-option").on('submit', function() {
1189
		for(var instanceName in CKEDITOR.instances) {
1029
        for (var instanceName in CKEDITOR.instances) {
1190
			CKEDITOR.instances[instanceName].updateElement();
1030
            CKEDITOR.instances[instanceName].updateElement();
1191
		}
1031
        }
1192
	})
1032
    })
1193
	
-
 
1194
	var validatorFormOption = $( "#form-option" ).validate( {
1033
    var validatorFormOption = $("#form-option").validate({
1195
        ignore: [],
1034
        ignore: [],
1196
        errorClass: 'help-block',
1035
        errorClass: 'help-block',
1197
        errorElement: 'span',
1036
        errorElement: 'span',
1198
		rules: {
1037
        rules: {
1199
			'option-text' : {
1038
            'option-text': {
1200
				required: true,
1039
                required: true,
1201
			},
1040
            },
1202
        	'option-value' : {
1041
            'option-value': {
1203
				required: true,
1042
                required: true,
1204
				number: true,
1043
                number: true,
1205
				min: 1
1044
                min: 1
1206
        	}
1045
            }
1207
		},
1046
        },
1208
        highlight: function (element) {
1047
        highlight: function(element) {
1209
            $(element).closest('.form-group').addClass('has-error');
1048
            $(element).closest('.form-group').addClass('has-error');
1210
        },
1049
        },
1211
        unhighlight: function (element) {
1050
        unhighlight: function(element) {
1212
            $(element).closest('.form-group').removeClass('has-error');
1051
            $(element).closest('.form-group').removeClass('has-error');
1213
        },
1052
        },
1214
        errorPlacement: function (error, element) {
1053
        errorPlacement: function(error, element) {
1215
            if (element.attr("data-error-container")) {
1054
            if (element.attr("data-error-container")) {
1216
                error.appendTo(element.attr("data-error-container"));
1055
                error.appendTo(element.attr("data-error-container"));
1217
            } else {
1056
            } else {
1218
                error.insertAfter(element);
1057
                error.insertAfter(element);
1219
            }
1058
            }
Línea 1223... Línea 1062...
1223
                return;
1062
                return;
1224
            $('html, body').animate({
1063
            $('html, body').animate({
1225
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1064
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1226
            }, 1000);
1065
            }, 1000);
1227
        },
1066
        },
1502
                        } else {
1199
                        } else {
-
 
1200
                            $('#form-question #question-max-length').val('0');
1503
                    		$('#form-option #option-correct').parent().show();
1201
                            $('#form-question #question-max-length').parent().hide();
-
 
1202
                            $('#form-question #question-multiline').val('0');
-
 
1203
                            $('#form-question #question-multiline').parent().hide();
1504
                        }
1204
                        }
-
 
1205
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-range') {
-
 
1206
                            $('#form-question #question-range').val(objFormGenerator.sections[i].questions[j].range);
-
 
1207
                            $('#form-question #question-range').parent().show();
-
 
1208
                        } else {
-
 
1209
                            $('#form-question #question-range').val('10');
-
 
1210
                            $('#form-question #question-range').parent().hide();
-
 
1211
                        }
-
 
1212
                        showForm = true;
-
 
1213
                        break;
-
 
1214
                    }
-
 
1215
                }
-
 
1216
                break;
-
 
1217
            }
-
 
1218
        }
-
 
1219
        if (showForm) {
-
 
1220
            $('#modal-question h4[class="modal-title"]').html('LABEL_EDIT LABEL_QUESTION');
-
 
1221
            $('#modal-question').modal('show');
-
 
1222
        }
-
 
1223
    });
-
 
1224
    $('body').on('click', 'button.btn-delete-question', function(e) {
-
 
1225
        e.preventDefault();
-
 
1226
        var slug_section = $(this).data('section');
-
 
1227
        var slug = $(this).data('slug');
-
 
1228
        bootbox.confirm({
-
 
1229
            title: "LABEL_DELETE LABEL_QUESTION",
-
 
1230
            message: "LABEL_QUESTION_DELETE",
-
 
1231
            buttons: {
-
 
1232
                cancel: {
-
 
1233
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
-
 
1234
                },
-
 
1235
                confirm: {
-
 
1236
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
-
 
1237
                }
-
 
1238
            },
-
 
1239
            callback: function(result) {
-
 
1240
                if (result) {
-
 
1241
                    objFormGenerator.deleteQuestion(slug_section, slug);
-
 
1242
                    renderData(objFormGenerator.sections);
-
 
1243
                }
-
 
1244
            }
-
 
1245
        });
1505
                		
1246
    });
-
 
1247
    $('body').on('click', 'button.btn-add-option', function(e) {
-
 
1248
        e.preventDefault();
-
 
1249
        var slug_section = $(this).data('section');
-
 
1250
        var slug_question = $(this).data('question');
-
 
1251
        var showForm = false;
-
 
1252
        for (i = 0; i < objFormGenerator.sections.length; i++) {
-
 
1253
            if (slug_section == objFormGenerator.sections[i].slug_section) {
-
 
1254
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
-
 
1255
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
-
 
1256
                        validatorFormOption.resetForm();
-
 
1257
                        $('#form-option #option-section').val(slug_section);
-
 
1258
                        $('#form-option #option-question').val(slug_question);
-
 
1259
                        $('#form-option #option-slug').val('');
-
 
1260
                        instanceName = 'option-text';
-
 
1261
                        let editor = CKEDITOR.instances[instanceName];
-
 
1262
                        editor.setData('', function() {
-
 
1263
                            editor.focus();
-
 
1264
                        });
-
 
1265
                        $('#form-option #option-correct').val('0');
-
 
1266
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
-
 
1267
                            $('#form-option #option-correct').parent().hide();
-
 
1268
                        } else {
-
 
1269
                            $('#form-option #option-correct').parent().show();
-
 
1270
                        }
1506
                		if(objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1271
                        if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1507
                			$('#form-option #option-value').val('0');
1272
                            $('#form-option #option-value').val('0');
1508
                			$('#form-option #option-value').parent().show();
1273
                            $('#form-option #option-value').parent().show();
1509
                		} else {
1274
                        } else {
1510
                			$('#form-option #option-value').val('1');
1275
                            $('#form-option #option-value').val('1');
1511
                			$('#form-option #option-value').parent().hide();
1276
                            $('#form-option #option-value').parent().hide();
1512
                			
-
 
1513
                       	}
1277
                        }
1514
 
-
 
1515
						   renderData(objFormGenerator.sections);
1278
                        renderData(objFormGenerator.sections);
1516
                		showForm = true;
1279
                        showForm = true;
1517
	    			}
1280
                    }
1518
	    		}
1281
                }
1519
	    	}
1282
            }
1520
	    }
1283
        }
1521
 
-
 
1522
		if(showForm) {
1284
        if (showForm) {
1523
    		$('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
1285
            $('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
1524
    		$('#modal-option').modal('show');
1286
            $('#modal-option').modal('show');
1525
		}
1287
        }
1526
		
-
 
1527
	});
1288
    });
1528
 
-
 
1529
    /**
1289
    /**
1719
JS;
1442
JS;
1720
$this->inlineScript()->captureEnd();
1443
$this->inlineScript()->captureEnd();
1721
?>
1444
?>
Línea 1722... Línea 1445...
1722
 
1445
 
Línea 1781... Línea 1504...
1781
            </div>
1504
            </div>
1782
        </div>
1505
        </div>
1783
    </div>
1506
    </div>
Línea 1784... Línea 1507...
1784
 
1507
 
-
 
1508
    <!-- Create/Edit Form -->
1785
    <!-- Create/Edit Form -->
1509
    <?php
1786
    <?php echo $this->partial('modals/forms.phtml',  array(
1510
    echo $this->partial('modals/forms.phtml', array(
1787
		'status_inactive' => $status_inactive,
1511
        'status_inactive' => $status_inactive,
1788
		'status_active' => $status_active,
1512
        'status_active' => $status_active,
1789
		'lang_es'=>$lang_es,
1513
        'lang_es' => $lang_es,
-
 
1514
        'lang_en' => $lang_en
1790
		'lang_en'=>$lang_en
1515
    ));
1791
		)) ;?>
1516
    ?>
Línea 1792... Línea 1517...
1792
    <!-- Create/Edit Form-->
1517
    <!-- Create/Edit Form-->
Línea 1793... Línea 1518...
1793
 
1518
 
1794
    <!-- Modals -->
1519
    <!-- Modals -->
1795
 
1520
 
Línea 1796... Línea 1521...
1796
    <!-- Section Modal -->
1521
    <!-- Section Modal -->
Línea 1797... Línea 1522...
1797
    <?php echo $this->partial('modals/sections.phtml') ;?>
1522
<?php echo $this->partial('modals/sections.phtml'); ?>
Línea 1798... Línea 1523...
1798
    <!-- End Modal Section -->
1523
    <!-- End Modal Section -->
Línea 1799... Línea 1524...
1799
 
1524
 
Línea 1800... Línea 1525...
1800
    <!-- Question Modal -->
1525
    <!-- Question Modal -->
1801
 
1526
 
Línea 1802... Línea 1527...
1802
	<?php echo $this->partial('modals/questions.phtml') ;?>
1527
<?php echo $this->partial('modals/questions.phtml'); ?>
Línea 1803... Línea 1528...
1803
 
1528
 
1804
	<!-- End Modal Question -->
1529
    <!-- End Modal Question -->