Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 117 Rev 118
Línea 377... Línea 377...
377
 
377
 
378
        CKEDITOR.replace('description');
378
        CKEDITOR.replace('description');
379
        CKEDITOR.replace('text');
379
        CKEDITOR.replace('text');
380
    });
380
    });
-
 
381
JS;
-
 
382
echo <<<JS
-
 
383
		const classFormGenerator = function() {
-
 
384
			this.id 				= 0,
-
 
385
			this.table				= '',
-
 
386
			this.name 				= '',
-
 
387
			this.text 				= '',
-
 
388
			this.status				= 'a',
-
 
389
			this.sections 			= [],
-
 
390
			this.clear = function() 
-
 
391
			{
-
 
392
				this.sections = [];
-
 
393
				this.render();
-
 
394
			},
-
 
395
			this.renderSection = function(section_slug)
-
 
396
			{
-
 
397
			
-
 
398
				var s = '';
-
 
399
				for(i = 0; i < this.sections.length; i++)
-
 
400
				{
-
 
401
					if(section_slug !=  this.sections[i].slug) {
-
 
402
						continue;
-
 
403
					}
-
 
404
 
-
 
405
					$('span.section-name' + section_slug).html(this.sections[i].name);
-
 
406
 
-
 
407
					let table = 'table-section-question-option' + this.sections[i].slug; 
-
 
408
					$('#' + table  + ' tbody').empty();
-
 
409
					
-
 
410
					s = '<tr class="tr-section" data-slug="' + this.sections[i].slug + '">';
-
 
411
					s = s  + '<td class="text-left">Seccion</td>';
-
 
412
					s = s  + '<td class="text-left">' + this.sections[i].name +  '</td>';
-
 
413
					s = s  + '<td class="text-right">' + this.sections[i].value + '</td>';
-
 
414
					s = s  + '<td>&nbsp</td>';
-
 
415
					s = s  + '<td>';
-
 
416
					s = s  + '<button class="btn btn-default btn-edit-section" data-slug="' + this.sections[i].slug + '" data-toggle="tooltip" title="LABEL_EDIT LABEL_SECTION"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_SECTION </button>&nbsp';
-
 
417
					s = s  + '<button class="btn btn-default btn-delete-section" data-slug="' + this.sections[i].slug + '" data-toggle="tooltip" title="LABEL_DELETE LABEL_SECTION"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_SECTION </button>&nbsp';
-
 
418
					s = s  + '<button class="btn btn-default btn-add-question" data-slug="' + this.sections[i].slug + '" data-toggle="tooltip" title="LABEL_ADD LABEL_QUESTION"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_ADD LABEL_QUESTION </button>&nbsp';
-
 
419
					s = s  + '</td>';
-
 
420
					s = s  + '</tr>';
-
 
421
					$('#' + table + ' tbody').append(s);
-
 
422
					
-
 
423
					
-
 
424
 
-
 
425
					for(j = 0; j < this.sections[i].questions.length; j++)
-
 
426
					{
-
 
427
						this.sections[i].questions[j].position = j;
-
 
428
 
-
 
429
						this.drawQuestion( this.sections[i].slug, this.sections[i].questions[j].slug, this.sections[i].questions[j].text, this.sections[i].questions[j].value , this.sections[i].questions[j].type);
-
 
430
						if(this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple'|| this.sections[i].questions[j].type == 'rating-open') {
-
 
431
							
-
 
432
								
-
 
433
							this.sections[i].questions[j].options.sort(function(a, b) {
-
 
434
										if (a.position > b.position) {
-
 
435
												return 1;
-
 
436
										}
-
 
437
										if (a.position < b.position) {
-
 
438
											return -1;
-
 
439
										}
-
 
440
										return 0;
-
 
441
									});
-
 
442
								
-
 
443
							
-
 
444
							for(k = 0; k < this.sections[i].questions[j].options.length; k++)
-
 
445
							{
-
 
446
								this.sections[i].questions[j].options[k].position = j;
-
 
447
								this.drawOption(
-
 
448
									this.sections[i].slug, 
-
 
449
									this.sections[i].questions[j].slug,  
-
 
450
									this.sections[i].questions[j].type, 
-
 
451
									this.sections[i].questions[j].options[k].slug, 
-
 
452
									this.sections[i].questions[j].options[k].text, 
-
 
453
									this.sections[i].questions[j].options[k].type, 
-
 
454
									this.sections[i].questions[j].options[k].correct, 
-
 
455
									this.sections[i].questions[j].options[k].value
-
 
456
								);
-
 
457
							}
-
 
458
						}
-
 
459
					}
-
 
460
				}
-
 
461
				
-
 
462
				$('[data-toggle="tooltip"]').tooltip();
-
 
463
			},
-
 
464
			this.drawSection = function(section_slug, section_name, section_value)
-
 
465
			{
-
 
466
				let table = 'table-section-question-option' + section_slug; 
-
 
467
				let collapse = 'collapse-' + section_slug;
-
 
468
 
-
 
469
				s = '<div class="panel panel-default" id="panel' + section_slug + '">';
-
 
470
				s = s + '	<div class="panel-heading">';
-
 
471
				s = s + '		<h4 class="panel-title">';
-
 
472
				s = s + '			<a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" href="#' + collapse + '"><span class="section-name' + section_slug + '">' + section_name + '</span></a>';
-
 
473
				s = s + '		</h4>';
-
 
474
				s = s + '	</div>';
-
 
475
				s = s + '	<div id="' + collapse + '" class="panel-collapse collapse">';
-
 
476
				s = s + '		<div class="panel-body">';
-
 
477
				s = s + '			<div class="table-responsive">';
-
 
478
				s = s + '				<table class="table table-bordered" id="' + table + '">';
-
 
479
				s = s + '					<thead>';
-
 
480
				s = s + '						<tr>';
-
 
481
				s = s + '							<th>LABEL_ELEMENT</th>';
-
 
482
				s = s + '							<th>LABEL_TEXT</th>';
-
 
483
				s = s + '							<th>LABEL_VALUE</th>';
-
 
484
				s = s + '							<th>LABEL_TYPE</th>';
-
 
485
				s = s + '							<th>LABEL_ACTIONS</th>';
-
 
486
				s = s + '						</tr>';
-
 
487
				s = s + '					</thead>';
-
 
488
				s = s + '					<tbody>';
-
 
489
				s = s + '					</tbody>';					
-
 
490
				s = s + '				</table>';
-
 
491
				s = s + '			</div>';
-
 
492
				s = s + '		</div>';
-
 
493
				s = s + '	</div>';
-
 
494
				s = s + '</div>';
-
 
495
 
-
 
496
				$('#accordion').append(s);
-
 
497
 
-
 
498
 
-
 
499
				s = '<tr class="tr-section" data-slug="' + section_slug + '">';
-
 
500
				s = s  + '<td class="text-left">LABEL_SECTION</td>';
-
 
501
				s = s  + '<td class="text-left">' + section_name +  '</td>';
-
 
502
				s = s  + '<td class="text-right">' + section_value + '</td>';
-
 
503
				s = s  + '<td>&nbsp</td>';
-
 
504
				s = s  + '<td>';
-
 
505
				s = s  + '<button class="btn btn-default btn-edit-section" data-slug="' + section_slug + '" data-toggle="tooltip" title="LABEL_EDIT LABEL_SECTION"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_SECTION </button>&nbsp';
-
 
506
				s = s  + '<button class="btn btn-default btn-delete-section" data-slug="' + section_slug + '" data-toggle="tooltip" title="LABEL_DELETE LABEL_SECTION"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_SECTION </button>&nbsp';
-
 
507
				s = s  + '<button class="btn btn-default btn-add-question" data-slug="' + section_slug + '" data-toggle="tooltip" title="LABEL_ADD LABEL_SECTION"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_ADD LABEL_SECTION </button>&nbsp';
-
 
508
				s = s  + '</td>';
-
 
509
				s = s  + '</tr>';
-
 
510
				$('#' + table + ' tbody').append(s);
-
 
511
			},
-
 
512
 
-
 
513
			this.drawQuestion = function(section_slug, question_slug, question_text, question_value, question_type)
-
 
514
			{
-
 
515
				
-
 
516
				
-
 
517
				s = '<tr class="tr-question" data-slug="' + question_slug + '">';
-
 
518
				s = s  + '<td class="text-left">--LABEL_QUESTION</td>';
-
 
519
				s = s  + '<td class="text-left">' + question_text +  '</td>';
-
 
520
				s = s  + '<td class="text-right"><font color="red">' + question_value + '</font></td>';
-
 
521
				s = s  + '<td>' + question_type.substr(0,1).toUpperCase() + question_type.substr(1) +  '</td>';
-
 
522
				s = s  + '<td>';
-
 
523
				s = s  + '<button class="btn btn-default btn-edit-question" data-section="' + section_slug + '" data-slug="' + question_slug + '" data-toggle="tooltip" title="LABEL_EDIT LABEL_QUESTION"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_QUESTION</button>&nbsp';
-
 
524
				s = s  + '<button class="btn btn-default btn-delete-question" data-section="' + section_slug + '" data-slug="' + question_slug + '" data-toggle="tooltip" title="LABEL_DELETE LABEL_QUESTION"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_QUESTION</button>&nbsp';
-
 
525
				if(question_type == 'simple' || question_type == 'multiple' || question_type == 'rating-open') {
-
 
526
					s = s  + '<button class="btn btn-default btn-add-option" data-section="' + section_slug + '" data-slug="' + question_slug + '" data-toggle="tooltip" title="LABEL_ADD LABEL_OPTION"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_ADD LABEL_OPTION</button>&nbsp';
-
 
527
				}
-
 
528
				
-
 
529
				s = s  + '</td>';
-
 
530
 
-
 
531
				let table = 'table-section-question-option' + section_slug; 
-
 
532
				$('#' + table + ' tbody').append(s);
-
 
533
			},
-
 
534
 
-
 
535
			this.drawOption = function(section_slug, question_slug,  question_type, option_slug, option_text, option_type, option_correct, option_value)
-
 
536
			{
-
 
537
				
-
 
538
				
-
 
539
				s = '<tr class="tr-option" data-slug="' + option_slug + '">';
-
 
540
				s = s  + '<td class="text-left">---LABEL_OPTION</td>';
-
 
541
				s = s  + '<td class="text-left">' + option_text +  '</td>';
-
 
542
				if(question_type == 'multiple' || question_type == 'rating-open') {
-
 
543
 
-
 
544
					if(question_type == 'multiple') {
-
 
545
						if(option_correct == 1) {
-
 
546
							s = s  + '<td class="text-right">' + option_value + '</td>';
-
 
547
						} else {
-
 
548
							s = s  + '<td>&nbsp</td>';
-
 
549
						}
-
 
550
					} else {
-
 
551
						s = s  + '<td class="text-right">' + option_value + '</td>';
-
 
552
					}	
-
 
553
				} else {
-
 
554
					s = s  + '<td>&nbsp</td>';
-
 
555
				}
-
 
556
 
-
 
557
				if(question_type == 'simple' || question_type == 'multiple') {
-
 
558
					if(option_correct == 1) {
-
 
559
						s = s  + '<td class="text-left"><font color="green">LABEL_CORRECT</font></td>';
-
 
560
					} else {
-
 
561
						s = s  + '<td class="text-left"><font color="red">LABEL_FAIL</font></td>';
-
 
562
						
-
 
563
					}
-
 
564
				} else {
-
 
565
					s = s  + '<td>&nbsp</td>';
-
 
566
				}
-
 
567
				
-
 
568
				
-
 
569
				s = s  + '<td>';
-
 
570
				s = s  + '<button class="btn btn-default btn-edit-option" data-section="' + section_slug + '" data-question="' + question_slug + '" data-slug="' + option_slug + '" data-toggle="tooltip" title="LABEL_EDIT LABEL_OPTION"><i class="fa fa-edit" aria-hidden="true"></i></button>&nbsp';
-
 
571
				s = s  + '<button class="btn btn-default btn-delete-option" data-section="' + section_slug + '" data-question="' + question_slug + '" data-slug="' + option_slug + '" data-toggle="tooltip" title="LABEL_DELETE LABEL_OPTION"><i class="fa fa-ban" aria-hidden="true"></i></button>&nbsp';
-
 
572
				s = s  + '</td>';
-
 
573
 
-
 
574
				let table = 'table-section-question-option' + section_slug; 
-
 
575
				$('#' + table + ' tbody').append(s);
-
 
576
 
-
 
577
			},
-
 
578
			
-
 
579
			this.render = function() 
-
 
580
			{
-
 
581
				$('#accordion').empty();
-
 
582
 
-
 
583
				this.sections.sort(function(a, b) {
-
 
584
					if (a.position > b.position) {
-
 
585
							return 1;
-
 
586
					}
-
 
587
					if (a.position < b.position) {
-
 
588
						return -1;
-
 
589
					}
-
 
590
					return 0;
-
 
591
				});
-
 
592
				
-
 
593
				var s = '';
-
 
594
				for(i = 0; i < this.sections.length; i++)
-
 
595
				{
-
 
596
					this.sections[i].position = i;
-
 
597
 
-
 
598
 
-
 
599
					this.drawSection(this.sections[i].slug, this.sections[i].name, this.sections[i].value);
-
 
600
					
-
 
601
					
-
 
602
					this.sections[i].questions.sort(function(a, b) {
-
 
603
						if (a.position > b.position) {
-
 
604
								return 1;
-
 
605
						}
-
 
606
						if (a.position < b.position) {
-
 
607
							return -1;
-
 
608
						}
-
 
609
						return 0;
-
 
610
					});
-
 
611
					
-
 
612
					
-
 
613
					for(j = 0; j < this.sections[i].questions.length; j++)
-
 
614
					{
-
 
615
						this.sections[i].questions[j].position = j;
-
 
616
 
-
 
617
						this.drawQuestion( this.sections[i].slug, this.sections[i].questions[j].slug, this.sections[i].questions[j].text, this.sections[i].questions[j].value , this.sections[i].questions[j].type);
-
 
618
						if(this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple'|| this.sections[i].questions[j].type == 'rating-open') {
-
 
619
							
-
 
620
								
-
 
621
							this.sections[i].questions[j].options.sort(function(a, b) {
-
 
622
										if (a.position > b.position) {
-
 
623
												return 1;
-
 
624
										}
-
 
625
										if (a.position < b.position) {
-
 
626
											return -1;
-
 
627
										}
-
 
628
										return 0;
-
 
629
									});
-
 
630
								
-
 
631
							
-
 
632
							for(k = 0; k < this.sections[i].questions[j].options.length; k++)
-
 
633
							{
-
 
634
								this.sections[i].questions[j].options[k].position = j;
-
 
635
								this.drawOption(
-
 
636
									this.sections[i].slug, 
-
 
637
									this.sections[i].questions[j].slug,  
-
 
638
									this.sections[i].questions[j].type, 
-
 
639
									this.sections[i].questions[j].options[k].slug, 
-
 
640
									this.sections[i].questions[j].options[k].text, 
-
 
641
									this.sections[i].questions[j].options[k].type, 
-
 
642
									this.sections[i].questions[j].options[k].correct, 
-
 
643
									this.sections[i].questions[j].options[k].value
-
 
644
								);
-
 
645
							}
-
 
646
						}
-
 
647
 
-
 
648
					}
-
 
649
					
-
 
650
					
-
 
651
				}
-
 
652
 
-
 
653
				
-
 
654
				$('[data-toggle="tooltip"]').tooltip();
-
 
655
 
-
 
656
			},
-
 
657
 
-
 
658
			this.addSection = function (name, text, value)
-
 
659
			{
-
 
660
				var d = new Date();
-
 
661
					var slug = 'section' + d.getTime();
-
 
662
					
-
 
663
					var position = 0;
-
 
664
					$.each(this.sections, function(index, section) {
-
 
665
						if(position < section.position) {
-
 
666
							position = section.position;
-
 
667
						}
-
 
668
					});
-
 
669
					position++;
-
 
670
 
-
 
671
				var section = {
-
 
672
					'slug' 		: slug,
-
 
673
					'name' 		: name,
-
 
674
					'text' 		: text,
-
 
675
					'value' 	: value,
-
 
676
					'position' 	: position,
-
 
677
					'questions' : [],
-
 
678
				}
-
 
679
 
-
 
680
				this.sections.push(section);
-
 
681
				this.drawSection(slug, name, text);
-
 
682
			},
-
 
683
			this.editSection = function (slug, name, text, value)
-
 
684
			{
-
 
685
				var renderTable = false;
-
 
686
				for(i = 0; i < this.sections.length; i++) 
-
 
687
				{
-
 
688
						if(slug == this.sections[i].slug) {
-
 
689
							this.sections[i].name = name;
-
 
690
							this.sections[i].text = text;
-
 
691
							this.sections[i].value = value;
-
 
692
							renderTable = true;
-
 
693
							
-
 
694
							break;
-
 
695
						}
-
 
696
				}
-
 
697
				if(renderTable) {
-
 
698
					this.renderSection(slug);
-
 
699
				}
-
 
700
 
-
 
701
				
-
 
702
			},
-
 
703
			this.deleteSection = function(slug)
-
 
704
			{
-
 
705
				var renderTable = false;
-
 
706
				for(i = 0; i < this.sections.length; i++) 
-
 
707
				{
-
 
708
						if(slug == this.sections[i].slug) {
-
 
709
							this.sections.splice(i, 1);
-
 
710
							
-
 
711
							renderTable = true;
-
 
712
							break;
-
 
713
					}
-
 
714
 
-
 
715
				
-
 
716
				}
-
 
717
				if(renderTable) {
-
 
718
					$('#panel' + slug).remove();
-
 
719
				}
-
 
720
			},
-
 
721
			this.addQuestion = function (section_slug, text, value, type, maxlength, multiline, range) 
-
 
722
			{
-
 
723
				var d = new Date();
-
 
724
				var slug = 'question' + d.getTime();
-
 
725
					
-
 
726
				var position = 0;
-
 
727
				var renderTable = false;
-
 
728
				for(i = 0; i < this.sections.length; i++)
-
 
729
				{
-
 
730
					if(section_slug == this.sections[i].slug) {
-
 
731
						$.each(this.sections[i].questions, function(index, question) {
-
 
732
							if(position < question.position) {
-
 
733
								position = question.position;
-
 
734
							}
-
 
735
						});
-
 
736
						position++;
-
 
737
							
-
 
738
						var question = {
-
 
739
							'slug' : slug,
-
 
740
								'text' : text,
-
 
741
								'value' : value,
-
 
742
								'type' : type,
-
 
743
								'position' : position,
-
 
744
								'maxlength' :maxlength,
-
 
745
								'multiline' : multiline,
-
 
746
								'range' : range,
-
 
747
								'options' : [],
-
 
748
							}
-
 
749
 
-
 
750
						this.sections[i].questions.push(question);
-
 
751
						renderTable = true;
-
 
752
						break;
-
 
753
					}
-
 
754
				}
-
 
755
					
-
 
756
				if(renderTable) {
-
 
757
					this.renderSection(section_slug);
-
 
758
				}
-
 
759
			},
-
 
760
			this.editQuestion = function(section_slug, question_slug, text, value, type, maxlength, multiline, range) 
-
 
761
			{
-
 
762
				var renderTable = false;
-
 
763
				for(i = 0; i < this.sections.length; i++)
-
 
764
				{
-
 
765
					if(section_slug == this.sections[i].slug) {
-
 
766
						for(j = 0; j < this.sections[i].questions.length; j++) {
-
 
767
							if(question_slug == this.sections[i].questions[j].slug) {
-
 
768
								this.sections[i].questions[j].text 	= text,
-
 
769
								this.sections[i].questions[j].value	= value,
-
 
770
								this.sections[i].questions[j].type 	= type;
-
 
771
									
-
 
772
								if(type == 'open') {
-
 
773
									this.sections[i].questions[j].maxlength	= maxlength;
-
 
774
									this.sections[i].questions[j].multiline	= multiline;
-
 
775
									this.sections[i].questions[j].options	= [];
-
 
776
								} else {
-
 
777
									this.sections[i].questions[j].maxlength	= 0;
-
 
778
									this.sections[i].questions[j].multiline	= 0;
-
 
779
								}
-
 
780
 
-
 
781
									if(type == 'rating-range') {
-
 
782
										this.sections[i].questions[j].range = range;
-
 
783
									} else {
-
 
784
										this.sections[i].questions[j].range = 0;
-
 
785
									}
-
 
786
								renderTable = true;
-
 
787
								break;
-
 
788
							}
-
 
789
						}
-
 
790
					}
-
 
791
					if(renderTable) {
-
 
792
						break;
-
 
793
					}
-
 
794
				}
-
 
795
				if(renderTable) {
-
 
796
					this.renderSection(section_slug);
-
 
797
				}
-
 
798
			},
-
 
799
			this.deleteQuestion = function(section_slug, question_slug)
-
 
800
			{
-
 
801
				var renderTable = false;
-
 
802
				for(i = 0; i < this.sections.length; i++) 
-
 
803
				{
-
 
804
						if(section_slug == this.sections[i].slug) {
-
 
805
							for(j = 0; j < this.sections[i].questions.length; j++) {
-
 
806
							if(question_slug == this.sections[i].questions[j].slug) {
-
 
807
									this.sections[i].questions.splice(j, 1);
-
 
808
										renderTable = true;
-
 
809
										break;
-
 
810
							}
-
 
811
						}
-
 
812
					}
-
 
813
						
-
 
814
					if(renderTable) {
-
 
815
						break;
-
 
816
					}
-
 
817
				}
-
 
818
				if(renderTable) {
-
 
819
					this.renderSection(section_slug);
-
 
820
				}
-
 
821
			},
-
 
822
			this.addOption = function (section_slug, question_slug, text, correct, value) 
-
 
823
			{
-
 
824
				var d = new Date();
-
 
825
				var slug = 'option' + d.getTime();
-
 
826
				
-
 
827
				var position = 0;
-
 
828
				var renderTable = false;
-
 
829
				for(i = 0; i < this.sections.length; i++)
-
 
830
				{
-
 
831
					if(section_slug == this.sections[i].slug) {
-
 
832
						for(j = 0; j < this.sections[i].questions.length; j++) {
-
 
833
							if(question_slug == this.sections[i].questions[j].slug) {
-
 
834
								$.each(this.sections[i].questions[j].options, function(index, option) {
-
 
835
										if(position < option.position) {
-
 
836
											position = option.position;
-
 
837
										}
-
 
838
									});
-
 
839
									position++;
-
 
840
										
-
 
841
									var option = {
-
 
842
										'slug' : slug,
-
 
843
											'text' : text,
-
 
844
											'correct' : correct,
-
 
845
											'value' : value
-
 
846
										}
-
 
847
 
-
 
848
										this.sections[i].questions[j].options.push(option);
-
 
849
									renderTable = true;
-
 
850
									break;
-
 
851
							}
-
 
852
								
-
 
853
									if(renderTable) {
-
 
854
								break;
-
 
855
							}
-
 
856
						}
-
 
857
					}
-
 
858
				}
-
 
859
				if(renderTable) {
-
 
860
					this.renderSection(section_slug);
-
 
861
				}
-
 
862
			},
-
 
863
			this.editOption = function(section_slug, question_slug, option_slug, text, correct, value) 
-
 
864
			{
-
 
865
				var renderTable = false;
-
 
866
				for(i = 0; i < this.sections.length; i++)
-
 
867
				{
-
 
868
					if(section_slug == this.sections[i].slug) {
-
 
869
						for(j = 0; j < this.sections[i].questions.length; j++) {
-
 
870
							if(question_slug == this.sections[i].questions[j].slug) {
-
 
871
								for(k = 0; k < this.sections[i].questions[j].options.length; k++) {
-
 
872
									if(option_slug == this.sections[i].questions[j].options[k].slug) {
-
 
873
										this.sections[i].questions[j].options[k].text = text;
-
 
874
										this.sections[i].questions[j].options[k].correct = correct;
-
 
875
										this.sections[i].questions[j].options[k].value = value;
-
 
876
										renderTable = true;
-
 
877
												break;
-
 
878
									}
-
 
879
								}
-
 
880
							}
-
 
881
									if(renderTable) {
-
 
882
								break;
-
 
883
							}
-
 
884
						}
-
 
885
					}
-
 
886
						if(renderTable) {
-
 
887
							break;
-
 
888
						}
-
 
889
				}
-
 
890
					
-
 
891
				if(renderTable) {
-
 
892
					this.renderSection(section_slug);
-
 
893
				}
-
 
894
			},
-
 
895
			this.deleteOption = function(section_slug, question_slug, option_slug)
-
 
896
			{
-
 
897
				var renderTable = false;
-
 
898
				for(i = 0; i < this.sections.length; i++) 
-
 
899
				{
-
 
900
						if(section_slug == this.sections[i].slug) {
-
 
901
							for(j = 0; j < this.sections[i].questions.length; j++) {
-
 
902
							if(question_slug == this.sections[i].questions[j].slug) {
-
 
903
								for(k = 0; k < this.sections[i].questions[j].options.length; k++) {
-
 
904
									if(option_slug == this.sections[i].questions[j].options[k].slug) {
-
 
905
										this.sections[i].questions[j].options.splice(k, 1);
-
 
906
										renderTable = true;
-
 
907
												break;
-
 
908
									}
-
 
909
								}
-
 
910
							}
-
 
911
									if(renderTable) {
-
 
912
								break;
-
 
913
							}
-
 
914
						}
-
 
915
					}
-
 
916
						
-
 
917
					if(renderTable) {
-
 
918
						break;
-
 
919
					}
-
 
920
				}
-
 
921
				if(renderTable) {
-
 
922
					this.renderSection(section_slug);
-
 
923
				}
-
 
924
			}
-
 
925
		}
-
 
926
 
-
 
927
		function htmlEntities(str) {
-
 
928
				return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
-
 
929
		}
-
 
930
    jQuery( document ).ready(function( $ ) {
-
 
931
			var objFormGenerator = new classFormGenerator();
-
 
932
	objFormGenerator.render();
-
 
933
 
-
 
934
	
-
 
935
	var tableForm = $('#table-form').dataTable({
-
 
936
		select :true,
-
 
937
        bProcessing: true,
-
 
938
        bServerSide: true,
-
 
939
        sAjaxSource: "ajax.<?php echo $this->module; ?>.php?action=gridview",
-
 
940
        fnServerData: function (sSource, aoData, fnCallback) {
-
 
941
         	$.ajax({
-
 
942
               	dataType: 'json',
-
 
943
                type: "POST",
-
 
944
                url: sSource,
-
 
945
                data: aoData,
-
 
946
                success: fnCallback
-
 
947
          	});
-
 
948
        },
-
 
949
        aaSorting : [],
-
 
950
        aoColumns: [
-
 
951
					{sName: "checkbox", sTitle : '<input type="checkbox" value="all" data-type="select_all" name="select_all" id="select_all">',bSortable:false,bSearchable:false},
-
 
952
					{sName: "name", sTitle: 'LABEL_FIRST_NAME'},
-
 
953
					{sName: "language", sTitle: 'LABEL_LANGUAGE'},
-
 
954
					{sName: "added_on", sTitle : 'LABEL_ADDED_ON'},
-
 
955
					{sName: "status", sTitle: 'LABEL_STATUS', bSortable:false, bSearchable:false},
-
 
956
					{sName: "operation", sTitle: 'LABEL_OPERATION', bSortable: false, bSearchable: false},
-
 
957
         ],
-
 
958
        //  fnServerParams: function(aoData){
-
 
959
        //  	setTitle(aoData, this)
-
 
960
        //  },
-
 
961
         fnDrawCallback: function(oSettings) {
-
 
962
         		$('.make-switch-form').bootstrapSwitch();
-
 
963
            $('.make-switch-form').bootstrapSwitch('setOnClass', 'success');
-
 
964
            $('.make-switch-form').bootstrapSwitch('setOffClass', 'danger');
-
 
965
         }
-
 
966
	});
-
 
967
 
-
 
968
	$('body').on('click', 'a.btn-delete-form',function(e) {
-
 
969
		e.preventDefault();
-
 
970
		form_id =  $(this).data('id')
-
 
971
		
-
 
972
		bootbox.confirm({
-
 
973
		    title: "LABEL_DELETE LABEL_FORM",
-
 
974
		    message: "LABEL_ARE_YOU_SURE",
-
 
975
		    buttons: {
-
 
976
		        cancel: {
-
 
977
		            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
-
 
978
		        },
-
 
979
		        confirm: {
-
 
980
		            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
-
 
981
		        }
-
 
982
		    },
-
 
983
		    callback: function (result) {
-
 
984
			    if(result) {
-
 
985
    		    	$.ajax({
-
 
986
    	                'dataType': 'json',
-
 
987
    	                'method': 'post',
-
 
988
    	                'url' :  'ajax.<?php echo $this->module; ?>.php?action=delete',
-
 
989
    	                'data' :{
-
 
990
    	                    'form-id' : form_id
-
 
991
    	                },
-
 
992
    	            }).done(function(response) {
-
 
993
    
-
 
994
    	                if(response['success']) {
-
 
995
    	                	$.fn.showSuccess(response['message']);
-
 
996
    	                	tableForm.fnDraw();
-
 
997
    	                } else {
-
 
998
    	                	$.fn.showError(response['message']);
-
 
999
    	                }
-
 
1000
    	            }).fail(function( jqXHR, textStatus, errorThrown) {
-
 
1001
    					$.fn.showError(textStatus);
-
 
1002
    	            });
-
 
1003
			    }
-
 
1004
		    }
-
 
1005
		});
-
 
1006
		
-
 
1007
 
-
 
1008
    });
-
 
1009
 
-
 
1010
    $(document).on('click','[data-action="delete"]',function(){
-
 
1011
 
-
 
1012
    	bootbox.confirm({
-
 
1013
		    title: "LABEL_DELETE LABEL_FORMS_2",
-
 
1014
		    message: "LABEL_ARE_YOU_SURE",
-
 
1015
		    buttons: {
-
 
1016
		        cancel: {
-
 
1017
		            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
-
 
1018
		        },
-
 
1019
		        confirm: {
-
 
1020
		            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
-
 
1021
		        }
-
 
1022
		    },
-
 
1023
		    callback: function (result) {
-
 
1024
			    if(result) {
-
 
1025
			    	var d = currentSelected();	
-
 
1026
    		    	$.ajax({
-
 
1027
    	                'dataType': 'json',
-
 
1028
    	                'method': 'post',
-
 
1029
    	                'url' :  'ajax.<?php echo $this->module; ?>.php?action=delete-selected',
-
 
1030
    	                'data' :{
-
 
1031
    	                	 selected : d
-
 
1032
    	                },
-
 
1033
    	            }).done(function(response) {
-
 
1034
    
-
 
1035
    	                if(response['success']) {
-
 
1036
    	                	$.fn.showSuccess(response['message']);
-
 
1037
    	                	tableForm.fnDraw();
-
 
1038
    	                } else {
-
 
1039
    	                	$.fn.showError(response['message']);
-
 
1040
    	                }
-
 
1041
    	            }).fail(function( jqXHR, textStatus, errorThrown) {
-
 
1042
    					$.fn.showError(textStatus);
-
 
1043
    	            });
-
 
1044
			    }
-
 
1045
		    }
-
 
1046
		});
-
 
1047
        
-
 
1048
    });
-
 
1049
 
-
 
1050
 
-
 
1051
    $('body').on('switch-change', 'input[type="checkbox"].make-switch-form', function(e) {
-
 
1052
		e.preventDefault();
-
 
1053
		e.stopPropagation();
-
 
1054
 
-
 
1055
		form_id =  $(this).data('id')
-
 
1056
		form_status = $(this).prop('checked') ? 'A' : 'D';
-
 
1057
		
-
 
1058
        
-
 
1059
		$.ajax({
-
 
1060
        	'dataType': 'json',
-
 
1061
            'method': 'post',
-
 
1062
            'url' :  'ajax.<?php echo $this->module; ?>.php?action=status',
-
 
1063
            'data' :{
-
 
1064
            	'form-id' : form_id,
-
 
1065
            	'form-status' : form_status
-
 
1066
            },
-
 
1067
        }).done(function(response) {
-
 
1068
	        if(response['success']) {
-
 
1069
	        	$.fn.showSuccess(response['message']);
-
 
1070
	       } else {
-
 
1071
    	       	$.fn.showError(response['message']);
-
 
1072
            }
-
 
1073
         }).fail(function( jqXHR, textStatus, errorThrown) {
-
 
1074
			$.fn.showError(textStatus);
-
 
1075
        })
-
 
1076
    }); 
-
 
1077
 
-
 
1078
	$('body').on('click', 'a.btn-edit-form',function(e) {
-
 
1079
		e.preventDefault();
-
 
1080
		form_id =  $(this).data('id')
-
 
1081
        
-
 
1082
		$.ajax({
-
 
1083
			'dataType': 'json',
-
 
1084
			'method': 'post',
-
 
1085
			'url' :  '/test/method-one',
-
 
1086
			'data' :{
-
 
1087
				'form-id' : form_id
-
 
1088
			},
-
 
1089
		}).done(function(response) {
-
 
1090
			if(response['success']) {
-
 
1091
					validatorForm.resetForm();
-
 
1092
 
-
 
1093
					$('#form-main #form-id' ).val(response['id']),
-
 
1094
					$('#form-main #form-continue').val('0');
-
 
1095
					$('#form-main #form-name' ).val(response['name']),
-
 
1096
 
-
 
1097
 
-
 
1098
					instanceName = 'form-description'; 
-
 
1099
					let editor = CKEDITOR.instances[instanceName ];
-
 
1100
					editor.setData(response['description'], function() {
-
 
1101
							editor.focus();
-
 
1102
					});
-
 
1103
					
-
 
1104
					
-
 
1105
					instanceName = 'form-text'; 
-
 
1106
					CKEDITOR.instances[instanceName ].setData(response['text']);
-
 
1107
 
-
 
1108
					$( '#form-main #form-language' ).val(response['language']),
-
 
1109
					$( '#form-main #form-status' ).val(response['status']);
-
 
1110
 
-
 
1111
					objFormGenerator.clear();
-
 
1112
					objFormGenerator.sections = response['sections'];
-
 
1113
					objFormGenerator.render();
-
 
1114
					$('#row-forms').hide();
-
 
1115
					$('#row-edit').show();
-
 
1116
 
-
 
1117
					$('#form-main #form-name').focus();
-
 
1118
					
-
 
1119
				} else {
-
 
1120
					$.fn.showError(response['message']);
-
 
1121
				}
-
 
1122
			}).fail(function( jqXHR, textStatus, errorThrown) {
-
 
1123
				$.fn.showError(textStatus);
-
 
1124
			});
-
 
1125
    });
-
 
1126
 
-
 
1127
	 $(document).on('click','[data-type="select_all"]',function(){
-
 
1128
 
-
 
1129
	        if($('input[name="select_all"]:checked').val() == 'all'){
-
 
1130
	            $('[data-type="select"]').prop('checked', true);
-
 
1131
	            $('[data-action="delete"]').removeClass('hide');    
-
 
1132
	        }else{
-
 
1133
	            $('[data-type="select"]').prop('checked', false);    
-
 
1134
	            $('[data-action="delete"]').addClass('hide');
-
 
1135
	        }
-
 
1136
	    });
-
 
1137
 
-
 
1138
	    function getLength(){
-
 
1139
	        return $('[data-type="select"]').length;
-
 
1140
	    }
-
 
1141
 
-
 
1142
	    function currentSelected(){
-
 
1143
	        var selected = [];
-
 
1144
	        $.each($("input[name='select[]']:checked"), function(){            
-
 
1145
	            selected.push($(this).val());
-
 
1146
	        });
-
 
1147
 
-
 
1148
	        return selected;        
-
 
1149
	    }
-
 
1150
 
-
 
1151
	    $(document).on('change',"input[name='select[]']",function(){
-
 
1152
	        var c = currentSelected();
-
 
1153
	        var cc = getLength();
-
 
1154
 
-
 
1155
	        	
-
 
1156
	        if(c.length == cc){
-
 
1157
	            if($('[data-action="delete"]').hasClass('hide')){
-
 
1158
	                $('[data-action="delete"]').removeClass('hide');
-
 
1159
	            }
-
 
1160
	            return true;
-
 
1161
	        }else{
-
 
1162
	            $('input[name="select_all"]').prop('checked', false);
-
 
1163
	        }
-
 
1164
 
-
 
1165
	        if(c.length > 0){
-
 
1166
	            if($('[data-action="delete"]').hasClass('hide')){
-
 
1167
	                $('[data-action="delete"]').removeClass('hide');
-
 
1168
	            }
-
 
1169
	        }else{
-
 
1170
	            if(!$('[data-action="delete"]').hasClass('hide')){
-
 
1171
	                $('[data-action="delete"]').addClass('hide');
-
 
1172
	            }
-
 
1173
	        }
-
 
1174
	    });
-
 
1175
 
-
 
1176
	    var form3 = $('#form_sample_3');
-
 
1177
        var error3 = $('.alert-danger', form3);
-
 
1178
        var success3 = $('.alert-success', form3);
-
 
1179
 
-
 
1180
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
-
 
1181
 	$( "#form-main" ).on('submit', function() {
-
 
1182
		for(var instanceName in CKEDITOR.instances) {
-
 
1183
			CKEDITOR.instances[instanceName].updateElement();
-
 
1184
		}
-
 
1185
	})
-
 
1186
	    
-
 
1187
	var validatorForm = $( "#form-main" ).validate( {
-
 
1188
        ignore: [],
-
 
1189
        errorClass: 'help-block',
-
 
1190
        errorElement: 'span',
-
 
1191
		rules: {
-
 
1192
			'form-name':  {
-
 
1193
				required: true,
-
 
1194
				minlength: 2,
-
 
1195
				maxlength: 50
-
 
1196
			},
-
 
1197
			'form-description' : {
-
 
1198
				required: true,
-
 
1199
			},
-
 
1200
			'form-text' : {
-
 
1201
				required: true,
-
 
1202
			},
-
 
1203
			'form-language' : {
-
 
1204
				required: true,
-
 
1205
			},
-
 
1206
			'forrm-status' : {
-
 
1207
				required: true,
-
 
1208
			},
-
 
1209
		},
-
 
1210
        highlight: function (element) {
-
 
1211
            $(element).closest('.form-group').addClass('has-error');
-
 
1212
        },
-
 
1213
        unhighlight: function (element) {
-
 
1214
            $(element).closest('.form-group').removeClass('has-error');
-
 
1215
        },
-
 
1216
        errorPlacement: function (error, element) {
-
 
1217
            if (element.attr("data-error-container")) {
-
 
1218
                error.appendTo(element.attr("data-error-container"));
-
 
1219
            } else {
-
 
1220
                error.insertAfter(element);
-
 
1221
            }
-
 
1222
        },
-
 
1223
        invalidHandler: function(form, validator) {
-
 
1224
            if (!validator.numberOfInvalids())
-
 
1225
                return;
-
 
1226
            $('html, body').animate({
-
 
1227
                scrollTop: $(validator.errorList[0].element).offset().top - 100
-
 
1228
            }, 1000);
-
 
1229
        },
-
 
1230
		submitHandler: function(form) {
-
 
1231
		    // do other things for a valid form
-
 
1232
		    //form.submit();
-
 
1233
 
-
 
1234
		    
-
 
1235
		    var error = false;
-
 
1236
		    if(objFormGenerator.sections.length == 0) {
-
 
1237
		    	$.fn.showError('There are no sections');
-
 
1238
		    	error = true;
-
 
1239
		    } else {
-
 
1240
		    	
-
 
1241
		    	for(i = 0; i < objFormGenerator.sections.length; i++) 
-
 
1242
		    	{
-
 
1243
		    		
-
 
1244
		    		if(objFormGenerator.sections[i].questions.length == 0) {
-
 
1245
		    			$.fn.showError('El "' + objFormGenerator.sections[i].name + '" no tiene preguntas');
-
 
1246
		    			break;
-
 
1247
		    		}
-
 
1248
		    		
-
 
1249
		    		var valueSection = parseInt(objFormGenerator.sections[i].value);
-
 
1250
		    		var totalValueQuestion = 0;
-
 
1251
		    		
-
 
1252
		    		
-
 
1253
		    		for(j = 0; j < objFormGenerator.sections[i].questions.length; j++)
-
 
1254
		    		{
-
 
1255
		    			valueQuestion = parseInt(objFormGenerator.sections[i].questions[j].value);
-
 
1256
		    			totalValueQuestion = totalValueQuestion + valueQuestion;
-
 
1257
		    			if(objFormGenerator.sections[i].questions[j].type == 'simple' 
-
 
1258
			    			|| objFormGenerator.sections[i].questions[j].type == 'multiple' 
-
 
1259
			    			|| objFormGenerator.sections[i].questions[j].type == 'rating-open' ) {
-
 
1260
		    				
-
 
1261
		    				var questionNumber = j + 1;
-
 
1262
		    				var numberCorrect = 0;
-
 
1263
		    				
-
 
1264
		    				
-
 
1265
		    				if(objFormGenerator.sections[i].questions[j].options.length == 0) {
-
 
1266
		    					$.fn.showError('El "' + objFormGenerator.sections[i].name + '" seccion, La pregunta #' + questionNumber + ' no tiene opciones');
-
 
1267
									error = true;
-
 
1268
									break;
-
 
1269
		    				}
-
 
1270
 
-
 
1271
		    				
-
 
1272
		    				var totalOption = 0;
-
 
1273
		    				var maxOption = 0;
-
 
1274
		    				for(k = 0;  k < objFormGenerator.sections[i].questions[j].options.length; k++)
-
 
1275
		    				{
-
 
1276
		    					if(objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple' ) {
-
 
1277
    		    					if(objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
-
 
1278
    		    						numberCorrect++;
-
 
1279
    		    					}
-
 
1280
		    					}
-
 
1281
 
-
 
1282
		    					if(objFormGenerator.sections[i].questions[j].type == 'multiple' && objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
-
 
1283
		    						totalOption = totalOption + parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
-
 
1284
			    				}
-
 
1285
 
-
 
1286
		    					if(objFormGenerator.sections[i].questions[j].type == 'rating-open') {
-
 
1287
		    						if(parseInt(objFormGenerator.sections[i].questions[j].options[k].value) > maxOption) {
-
 
1288
											maxOption = parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
-
 
1289
					    			}
-
 
1290
			    				}
-
 
1291
			    				
-
 
1292
		    				}
-
 
1293
 
-
 
1294
		    				if(objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple' ) {
-
 
1295
		    				
-
 
1296
    		    				if(numberCorrect == 0) {
-
 
1297
    		    					$.fn.showError('El "' + objFormGenerator.sections[i].name + '" seccion, La pregunta #' + questionNumber + ' no tiene una opcion correcta');
-
 
1298
    		    					error = true;
-
 
1299
    		    					break;
-
 
1300
    		    				}
-
 
1301
    		    				if(objFormGenerator.sections[i].questions[j].type == 'simple' && numberCorrect > 1) {
-
 
1302
    		    					$.fn.showError('El "' + objFormGenerator.sections[i].name + '" seccion, La pregunta #' + questionNumber + ' tiene más de una opción correcta');
-
 
1303
    		    					error = true;
-
 
1304
    		    					break;
-
 
1305
    		    				}
-
 
1306
    		    				if(objFormGenerator.sections[i].questions[j].type == 'multiple' && numberCorrect == 1) {
-
 
1307
    		    					$.fn.showError('El "' + objFormGenerator.sections[i].name + '" seccion, La pregunta #' + questionNumber + ' solo tiene una opción correcta');
-
 
1308
    		    					error = true;
-
 
1309
    		    					break;
-
 
1310
    		    				}
-
 
1311
		    				}
-
 
1312
 
-
 
1313
			    			//console.log('totalOption = ' + totalOption + ' valueQuestion = ' + valueQuestion );
-
 
1314
			    			
-
 
1315
			 				if(objFormGenerator.sections[i].questions[j].type == 'multiple' && totalOption > valueQuestion ) {
-
 
1316
		     					$.fn.showError('El "' + objFormGenerator.sections[i].name + '" seccion, La pregunta #' + questionNumber + ' la suma de los valores de las opciones es mayor que el valor de la pregunta');
-
 
1317
		    					error = true;
-
 
1318
		    					break;
-
 
1319
			    			}
-
 
1320
 
-
 
1321
							//console.log('maxOption = ' + maxOption + ' valueQuestion = ' + valueQuestion );
-
 
1322
			    			
-
 
1323
		    				if(objFormGenerator.sections[i].questions[j].type == 'rating-open' && maxOption > valueQuestion ) {
-
 
1324
		     					$.fn.showError('El "' + objFormGenerator.sections[i].name + '" seccion, La pregunta #' + questionNumber + ' ');
-
 
1325
		    					error = true;
-
 
1326
		    					break;
-
 
1327
			    			}
-
 
1328
						}
-
 
1329
 
-
 
1330
	
-
 
1331
		    		}
-
 
1332
 
-
 
1333
		    		if(valueSection != totalValueQuestion) {
-
 
1334
		    			$.fn.showError('El "' + objFormGenerator.sections[i].name + '" sección y las preguntas no son las mismas');
-
 
1335
		    			error = true;
-
 
1336
		    			break;
-
 
1337
					}
-
 
1338
				}
-
 
1339
 
-
 
1340
				
-
 
1341
 
-
 
1342
    			if(error) {
-
 
1343
    				return false;
-
 
1344
    			} else {
-
 
1345
 
-
 
1346
 
-
 
1347
    				var formId		= parseInt($( '#form-main #form-id' ).val());
-
 
1348
    				var formContinue = parseInt($( '#form-main #form-continue' ).val());
-
 
1349
        			
-
 
1350
    				var data = {
-
 
1351
    	    			'form-id'	: formId,
-
 
1352
        				'form-name' : $( '#form-main #form-name' ).val(),
-
 
1353
        				'form-description' : $( '#form-main #form-description' ).val(),
-
 
1354
        				'form-text' : $( '#form-main #form-text' ).val(),
-
 
1355
        				'form-language' : $( '#form-main #form-language' ).val(),
-
 
1356
        				'form-status' : $( '#form-main #form-status' ).val(),
-
 
1357
        				'sections' : objFormGenerator.sections
-
 
1358
    				}
-
 
1359
    				
-
 
1360
 
-
 
1361
    				$.ajax({
-
 
1362
                        'dataType': 'json',
-
 
1363
                        'method': 'post',
-
 
1364
                        'url' :  '/test/method-one',
-
 
1365
                        'data' : data,
-
 
1366
                    }).done(function(response) {
-
 
1367
 
-
 
1368
                        if(response['success']) {
-
 
1369
                        	$.fn.showSuccess(response['message']);
-
 
1370
							if(formContinue == 1) {
-
 
1371
								$('#form-main #form-id').val(response['form-id']);
-
 
1372
								$('#form-main #form-continue').val(0);
-
 
1373
							} else {
-
 
1374
								$('#row-edit').hide();
-
 
1375
                        		$('#row-forms').show();
-
 
1376
							}
-
 
1377
 
-
 
1378
 
-
 
1379
							tableForm.fnDraw();
-
 
1380
                        	
-
 
1381
                        } else {
-
 
1382
                        	$.fn.showError(response['message']);
-
 
1383
                        }
-
 
1384
                    }).fail(function( jqXHR, textStatus, errorThrown) {
-
 
1385
						$.fn.showError(textStatus);
-
 
1386
                    });
-
 
1387
 
-
 
1388
                    return false;
-
 
1389
 
-
 
1390
    				
-
 
1391
    			}
-
 
1392
			}
-
 
1393
 
-
 
1394
 
-
 
1395
		}
-
 
1396
	});
-
 
1397
 
-
 
1398
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
-
 
1399
 	$( "#form-section" ).on('submit', function() {
-
 
1400
		for(var instanceName in CKEDITOR.instances) {
-
 
1401
			CKEDITOR.instances[instanceName].updateElement();
-
 
1402
		}
-
 
1403
	})
-
 
1404
	
-
 
1405
	var validatorFormSection = $( "#form-section" ).validate( {
-
 
1406
        ignore: [],
-
 
1407
        errorClass: 'help-block',
-
 
1408
        errorElement: 'span',
-
 
1409
		rules: {
-
 
1410
			'section-name':  {
-
 
1411
				required: true,
-
 
1412
				minlength: 2,
-
 
1413
				maxlength: 50
-
 
1414
			},
-
 
1415
			'section-text' : {
-
 
1416
				required: false,
-
 
1417
			},
-
 
1418
			'section-value' : {
-
 
1419
				required: true,
-
 
1420
				number: true,
-
 
1421
				min: 1
-
 
1422
			},
-
 
1423
		},
-
 
1424
        highlight: function (element) {
-
 
1425
            $(element).closest('.form-group').addClass('has-error');
-
 
1426
        },
-
 
1427
        unhighlight: function (element) {
-
 
1428
            $(element).closest('.form-group').removeClass('has-error');
-
 
1429
        },
-
 
1430
        errorPlacement: function (error, element) {
-
 
1431
            if (element.attr("data-error-container")) {
-
 
1432
                error.appendTo(element.attr("data-error-container"));
-
 
1433
            } else {
-
 
1434
                error.insertAfter(element);
-
 
1435
            }
-
 
1436
        },
-
 
1437
        invalidHandler: function(form, validator) {
-
 
1438
            if (!validator.numberOfInvalids())
-
 
1439
                return;
-
 
1440
            $('html, body').animate({
-
 
1441
                scrollTop: $(validator.errorList[0].element).offset().top - 100
-
 
1442
            }, 1000);
-
 
1443
        },
-
 
1444
		submitHandler: function(form) {
-
 
1445
		    // do other things for a valid form
-
 
1446
		    //form.submit();
-
 
1447
 
-
 
1448
		    var slug = $('#form-section #section-slug').val();
-
 
1449
		    if(slug) {
-
 
1450
		    	objFormGenerator.editSection(
-
 
1451
		    		$('#form-section #section-slug').val(), 
-
 
1452
			    	$('#form-section #section-name').val(), 
-
 
1453
			    	$('#form-section #section-text').val(),
-
 
1454
			    	$('#form-section #section-value').val()
-
 
1455
			  	);	
-
 
1456
		    } else {
-
 
1457
		    	objFormGenerator.addSection(
-
 
1458
		    		$('#form-section #section-name').val(), 
-
 
1459
		    		$('#form-section #section-text').val(),
-
 
1460
		    		$('#form-section #section-value').val()
-
 
1461
		    	);	
-
 
1462
		    }
-
 
1463
		    
-
 
1464
		    
-
 
1465
		    
-
 
1466
			$('#modal-section').modal('hide');
-
 
1467
			return false;
-
 
1468
		  }
-
 
1469
	} );
-
 
1470
 
-
 
1471
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
-
 
1472
 	$( "#form-question" ).on('submit', function() {
-
 
1473
		for(var instanceName in CKEDITOR.instances) {
-
 
1474
			CKEDITOR.instances[instanceName].updateElement();
-
 
1475
		}
-
 
1476
	})
-
 
1477
	
-
 
1478
	
-
 
1479
	var validatorFormQuestion = $( "#form-question" ).validate( {
-
 
1480
        ignore: [],
-
 
1481
        errorClass: 'help-block',
-
 
1482
        errorElement: 'span',
-
 
1483
		rules: {
-
 
1484
			'question-text' : {
-
 
1485
				required: true,
-
 
1486
			},
-
 
1487
			'question-value' : {
-
 
1488
				required: true,
-
 
1489
				number: true,
-
 
1490
				min: 1
-
 
1491
			},
-
 
1492
			'question-type':  {
-
 
1493
				required: true,
-
 
1494
			},
-
 
1495
			'question-max-length' : {
-
 
1496
				required: true,
-
 
1497
				digits: true,
-
 
1498
				min: 0
-
 
1499
			},
-
 
1500
			'question-range' : {
-
 
1501
				required: true,
-
 
1502
				number: true,
-
 
1503
				min: 1
-
 
1504
			},
-
 
1505
		},
-
 
1506
        highlight: function (element) {
-
 
1507
            $(element).closest('.form-group').addClass('has-error');
-
 
1508
        },
-
 
1509
        unhighlight: function (element) {
-
 
1510
            $(element).closest('.form-group').removeClass('has-error');
-
 
1511
        },
-
 
1512
        errorPlacement: function (error, element) {
-
 
1513
            if (element.attr("data-error-container")) {
-
 
1514
                error.appendTo(element.attr("data-error-container"));
-
 
1515
            } else {
-
 
1516
                error.insertAfter(element);
-
 
1517
            }
-
 
1518
        },
-
 
1519
        invalidHandler: function(form, validator) {
-
 
1520
 
-
 
1521
			//console.log(validator);
-
 
1522
            
-
 
1523
            if (!validator.numberOfInvalids())
-
 
1524
                return;
-
 
1525
            $('html, body').animate({
-
 
1526
                scrollTop: $(validator.errorList[0].element).offset().top - 100
-
 
1527
            }, 1000);
-
 
1528
        },
-
 
1529
		submitHandler: function(form) {
-
 
1530
		    // do other things for a valid form
-
 
1531
		    //form.submit();
-
 
1532
		    
-
 
1533
		    /*console.log('submitHandler');
-
 
1534
		    console.log('question-section = ' + $('#form-question #question-section').val()); 
-
 
1535
		    console.log('question-text = ' + $('#form-question #question-text').val());
-
 
1536
		    console.log('question-value = ' + $('#form-question #question-value').val());
-
 
1537
		    console.log('question-type = ' + $('#form-question #question-type').val());
-
 
1538
		    console.log('question-max-length = ' + $('#form-question #question-max-length').val());
-
 
1539
		    console.log('question-multiline = ' + $('#form-question #question-multiline').val());
-
 
1540
		    console.log('question-range = ' + $('#form-question #question-range').val());*/
-
 
1541
 
-
 
1542
		    
-
 
1543
 
-
 
1544
		    if($('#form-question #question-slug').val()) {
-
 
1545
		    	console.log('editQuestion');
-
 
1546
			    
-
 
1547
		    	objFormGenerator.editQuestion(
-
 
1548
		    		$('#form-question #question-section').val(), 
-
 
1549
		    		$('#form-question #question-slug').val(),
-
 
1550
		    		$('#form-question #question-text').val(), 
-
 
1551
		    		$('#form-question #question-value').val(),
-
 
1552
			    	$('#form-question #question-type').val(),
-
 
1553
			    	$('#form-question #question-max-length').val(),
-
 
1554
	    			$('#form-question #question-multiline').val(),
-
 
1555
	    			$('#form-question #question-range').val()
-
 
1556
			  	);	
-
 
1557
		    } else {
-
 
1558
		    	console.log('addQuestion');
-
 
1559
			    
-
 
1560
		    	objFormGenerator.addQuestion(
-
 
1561
			    	$('#form-question #question-section').val(), 
-
 
1562
			    	$('#form-question #question-text').val(), 
-
 
1563
			    	$('#form-question #question-value').val(),
-
 
1564
				    $('#form-question #question-type').val(),
-
 
1565
				    $('#form-question #question-max-length').val(),
-
 
1566
		    		$('#form-question #question-multiline').val(),
-
 
1567
		    		$('#form-question #question-range').val()
-
 
1568
		    	);	
-
 
1569
		    }
-
 
1570
		    
-
 
1571
			$('#modal-question').modal('hide');
-
 
1572
			return false;
-
 
1573
		  }
-
 
1574
	} );
-
 
1575
 
-
 
1576
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
-
 
1577
 	$( "#form-option" ).on('submit', function() {
-
 
1578
		for(var instanceName in CKEDITOR.instances) {
-
 
1579
			CKEDITOR.instances[instanceName].updateElement();
-
 
1580
		}
-
 
1581
	})
-
 
1582
	
-
 
1583
	var validatorFormOption = $( "#form-option" ).validate( {
-
 
1584
        ignore: [],
-
 
1585
        errorClass: 'help-block',
-
 
1586
        errorElement: 'span',
-
 
1587
		rules: {
-
 
1588
			'option-text' : {
-
 
1589
				required: true,
-
 
1590
			},
-
 
1591
        	'option-value' : {
-
 
1592
				required: true,
-
 
1593
				number: true,
-
 
1594
				min: 1
-
 
1595
        	}
-
 
1596
		},
-
 
1597
        highlight: function (element) {
-
 
1598
            $(element).closest('.form-group').addClass('has-error');
-
 
1599
        },
-
 
1600
        unhighlight: function (element) {
-
 
1601
            $(element).closest('.form-group').removeClass('has-error');
-
 
1602
        },
-
 
1603
        errorPlacement: function (error, element) {
-
 
1604
            if (element.attr("data-error-container")) {
-
 
1605
                error.appendTo(element.attr("data-error-container"));
-
 
1606
            } else {
-
 
1607
                error.insertAfter(element);
-
 
1608
            }
-
 
1609
        },
-
 
1610
        invalidHandler: function(form, validator) {
-
 
1611
            if (!validator.numberOfInvalids())
-
 
1612
                return;
-
 
1613
            $('html, body').animate({
-
 
1614
                scrollTop: $(validator.errorList[0].element).offset().top - 100
-
 
1615
            }, 1000);
-
 
1616
        },
-
 
1617
		submitHandler: function(form) {
-
 
1618
		    // do other things for a valid form
-
 
1619
		    //form.submit();
-
 
1620
		    
-
 
1621
 
-
 
1622
		    if($('#form-option #option-slug').val()) {
-
 
1623
		    	objFormGenerator.editOption(
-
 
1624
		    		$('#form-option #option-section').val(), 
-
 
1625
		    		$('#form-option #option-question').val(), 
-
 
1626
		    		$('#form-option #option-slug').val(),
-
 
1627
		    		$('#form-option #option-text').val(), 
-
 
1628
		    		$('#form-option #option-correct').val(),
-
 
1629
		    		$('#form-option #option-value').val()
-
 
1630
			  	);	
-
 
1631
		    } else {
-
 
1632
		    	objFormGenerator.addOption(
-
 
1633
			    	$('#form-option #option-section').val(), 
-
 
1634
			    	$('#form-option #option-question').val(), 
-
 
1635
			    	$('#form-option #option-text').val(), 
-
 
1636
			    	$('#form-option #option-correct').val(),
-
 
1637
			    	$('#form-option #option-value').val()
-
 
1638
		    	);	
-
 
1639
		    }
-
 
1640
 
-
 
1641
 
-
 
1642
		    
-
 
1643
		    
-
 
1644
			$('#modal-option').modal('hide');
-
 
1645
			return false;
-
 
1646
		  }
-
 
1647
	} );
-
 
1648
	
-
 
1649
	$('body').on('click', 'button[id="btn-add-section"]', function(e){
-
 
1650
		e.preventDefault();
-
 
1651
		
-
 
1652
		validatorFormSection.resetForm();
-
 
1653
		$('#form-section #section-slug').val('');
-
 
1654
		$('#form-section #section-name').val('');
-
 
1655
 
-
 
1656
		instanceName = 'section-text'; 
-
 
1657
		let editor = CKEDITOR.instances[instanceName ];
-
 
1658
		editor.setData( '', function() {
-
 
1659
		    editor.focus();
-
 
1660
		});
-
 
1661
 
-
 
1662
	
-
 
1663
		$('#form-section #section-value').val('0');
-
 
1664
		$('#modal-section h4[class="modal-title"]').html('New Section');
-
 
1665
		$('#modal-section').modal('show');
-
 
1666
	});
-
 
1667
	
-
 
1668
	$('body').on('click', 'button.btn-edit-section', function(e){
-
 
1669
	    e.preventDefault();
-
 
1670
	    
-
 
1671
	    var slug = $(this).data('slug');
-
 
1672
	    var section;
-
 
1673
	    var showForm = false;
-
 
1674
	    
-
 
1675
	    for(i = 0; i < objFormGenerator.sections.length; i++) {
-
 
1676
	        section = objFormGenerator.sections[i];
-
 
1677
	    	
-
 
1678
	    	if(slug == section.slug) {
-
 
1679
 
-
 
1680
		    	//console.log('btn-edit-section');
-
 
1681
		    	//console.log(section);
-
 
1682
 
-
 
1683
				validatorFormSection.resetForm();
-
 
1684
	    		$('#form-section #section-slug').val(section.slug);
-
 
1685
	    		$('#form-section #section-name').val(section.name);
-
 
1686
	
-
 
1687
	    		instanceName = 'section-text'; 
-
 
1688
	    		let editor = CKEDITOR.instances[instanceName ];
-
 
1689
	    		editor.setData( section.text, function() {
-
 
1690
	    		    editor.focus();
-
 
1691
	    		});
-
 
1692
	    	    		
-
 
1693
				$('#form-section #section-value').val(section.value);
-
 
1694
				
-
 
1695
				showForm = true;
-
 
1696
				break;
-
 
1697
	    	}
-
 
1698
	    }
-
 
1699
	    
-
 
1700
	    if(showForm) {
-
 
1701
	    	$('#modal-section h4[class="modal-title"]').html('Edit Section');
-
 
1702
			$('#modal-section').modal('show');
-
 
1703
	    }
-
 
1704
	    
-
 
1705
	});
-
 
1706
	
-
 
1707
	$('body').on('click', 'button.btn-delete-section', function(e){
-
 
1708
		e.preventDefault();
-
 
1709
		var slug = $(this).data('slug');
-
 
1710
 
-
 
1711
		bootbox.confirm({
-
 
1712
		    title: "LABEL_DELETE LABEL_SECTION?",
-
 
1713
		    message: "LABEL_ARE_YOU_SURE",
-
 
1714
		    buttons: {
-
 
1715
		        cancel: {
-
 
1716
		            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
-
 
1717
		        },
-
 
1718
		        confirm: {
-
 
1719
		            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
-
 
1720
		        }
-
 
1721
		    },
-
 
1722
		    callback: function (result) {
-
 
1723
		    	if (result) {
-
 
1724
					objFormGenerator.deleteSection(slug);
-
 
1725
				}
-
 
1726
		    }
-
 
1727
		});
-
 
1728
		
-
 
1729
 
-
 
1730
	
-
 
1731
	});
-
 
1732
	
-
 
1733
	
-
 
1734
	$('body').on('click', 'button.btn-add-question', function(e){
-
 
1735
		e.preventDefault();
-
 
1736
		
-
 
1737
		validatorFormQuestion.resetForm();
-
 
1738
		var slug = $(this).data('slug');
-
 
1739
		
-
 
1740
		$('#form-question #question-section').val(slug);
-
 
1741
		$('#form-question #question-slug').val('');
-
 
1742
 
-
 
1743
		instanceName = 'question-text'; 
-
 
1744
		let editor = CKEDITOR.instances[instanceName ];
-
 
1745
		editor.setData( '', function() {
-
 
1746
		    editor.focus();
-
 
1747
		});
-
 
1748
 
-
 
1749
 
-
 
1750
		$('#form-question #question-value').val('0');
-
 
1751
		$('#form-question #question-type').val($('#form-question #question-type option:first').val());
-
 
1752
		
-
 
1753
		$('#form-question #question-max-length').val('0');
-
 
1754
		$('#form-question #question-max-length').parent().show();
-
 
1755
		
-
 
1756
		$('#form-question #question-multiline').val('0');
-
 
1757
		$('#form-question #question-multiline').parent().show();
-
 
1758
 
-
 
1759
		$('#form-question #question-range').val('10');
-
 
1760
		$('#form-question #question-range').parent().hide();
-
 
1761
		
-
 
1762
		$('#modal-question h4[class="modal-title"]').html('New Question');
-
 
1763
		$('#modal-question').modal('show');
-
 
1764
		
-
 
1765
	});
-
 
1766
	
-
 
1767
 
-
 
1768
	
-
 
1769
	$('body').on('click', 'button.btn-edit-question', function(e){
-
 
1770
	    e.preventDefault();
-
 
1771
	    
-
 
1772
	    var slug_section	= $(this).data('section');
-
 
1773
	    var slug 			= $(this).data('slug');
-
 
1774
	    var showForm 		= false;
-
 
1775
	    
-
 
1776
	    for(i = 0; i < objFormGenerator.sections.length; i++) {
-
 
1777
	    	
-
 
1778
	    	if(slug_section == objFormGenerator.sections[i].slug) {
-
 
1779
	    		
-
 
1780
	    		for(j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
-
 
1781
	    			
-
 
1782
	    			if(slug == objFormGenerator.sections[i].questions[j].slug) {
-
 
1783
	    				validatorFormQuestion.resetForm();
-
 
1784
	    				
-
 
1785
	    				$('#form-question #question-section').val(objFormGenerator.sections[i].slug);
-
 
1786
	    				$('#form-question #question-slug').val(objFormGenerator.sections[i].questions[j].slug);
-
 
1787
 
-
 
1788
	    	    		instanceName = 'question-text'; 
-
 
1789
	    	    		let editor = CKEDITOR.instances[instanceName ];
-
 
1790
	    	    		editor.setData( objFormGenerator.sections[i].questions[j].text, function() {
-
 
1791
	    	    		    editor.focus();
-
 
1792
	    	    		});
-
 
1793
 
-
 
1794
 
-
 
1795
	        			$('#form-question #question-value').val(objFormGenerator.sections[i].questions[j].value);
-
 
1796
	        			$('#form-question #question-type').val(objFormGenerator.sections[i].questions[j].type);
-
 
1797
	        			
-
 
1798
	        			
-
 
1799
	        
-
 
1800
	        			if(objFormGenerator.sections[i].questions[j].type == 'open') {
-
 
1801
		        			$('#form-question #question-max-length').val(objFormGenerator.sections[i].questions[j].maxlength);
-
 
1802
		        			$('#form-question #question-max-length').parent().show();
-
 
1803
		        			
-
 
1804
		        			$('#form-question #question-multiline').val(objFormGenerator.sections[i].questions[j].multiline);
-
 
1805
							$('#form-question #question-multiline').parent().show();
-
 
1806
	        			} else {
-
 
1807
		        			$('#form-question #question-max-length').val('0');
-
 
1808
		        			$('#form-question #question-max-length').parent().hide();
-
 
1809
		        			
-
 
1810
		        			$('#form-question #question-multiline').val('0');
-
 
1811
							$('#form-question #question-multiline').parent().hide();
-
 
1812
	        			}
-
 
1813
 
-
 
1814
	        			if(objFormGenerator.sections[i].questions[j].type == 'rating-range') {
-
 
1815
	            			$('#form-question #question-range').val(objFormGenerator.sections[i].questions[j].range);
-
 
1816
		        			$('#form-question #question-range').parent().show();
-
 
1817
 
-
 
1818
	        			} else {
-
 
1819
	            			$('#form-question #question-range').val('10');
-
 
1820
		        			$('#form-question #question-range').parent().hide();
-
 
1821
		        		}
-
 
1822
 
-
 
1823
    					showForm = true;
-
 
1824
    					break;
-
 
1825
	    				
-
 
1826
	    			}
-
 
1827
	    			
-
 
1828
	    		}
-
 
1829
	    		
-
 
1830
	    		break;
-
 
1831
	    	}
-
 
1832
	    }
-
 
1833
	    
-
 
1834
	    if(showForm) {
-
 
1835
	    	$('#modal-question h4[class="modal-title"]').html('LABEL_EDIT LABEL_QUESTION');
-
 
1836
				$('#modal-question').modal('show');
-
 
1837
	    }
-
 
1838
	    
-
 
1839
	});
-
 
1840
	
-
 
1841
	
-
 
1842
	
-
 
1843
	
-
 
1844
	$('body').on('click', 'button.btn-delete-question', function(e){
-
 
1845
		e.preventDefault();
-
 
1846
		
-
 
1847
		var slug_section	= $(this).data('section');
-
 
1848
		var slug 			= $(this).data('slug');
-
 
1849
 
-
 
1850
		bootbox.confirm({
-
 
1851
			title: "LABEL_DELETE LABEL_QUESTION?",
-
 
1852
			message: "LABEL_ARE_YOU_SURE",
-
 
1853
			buttons: {
-
 
1854
				cancel: {
-
 
1855
   					label: '<i class="fa fa-times"></i> LABEL_CANCEL'
-
 
1856
    			},
-
 
1857
			    confirm: {
-
 
1858
			    	label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
-
 
1859
			    }
-
 
1860
			},
-
 
1861
			callback: function (result) {
-
 
1862
				if (result) {
-
 
1863
					objFormGenerator.deleteQuestion(slug_section, slug);
-
 
1864
				}
-
 
1865
			}
-
 
1866
		});		    
-
 
1867
	});
-
 
1868
	
-
 
1869
	
-
 
1870
	$('body').on('click', 'button.btn-add-option', function(e){
-
 
1871
		e.preventDefault();
-
 
1872
	    var slug_section	= $(this).data('section');
-
 
1873
		var slug_question 	= $(this).data('slug');
-
 
1874
		var showForm 		= false;
-
 
1875
 
-
 
1876
	    for(i = 0; i < objFormGenerator.sections.length; i++) {
-
 
1877
	    	if(slug_section == objFormGenerator.sections[i].slug) {
-
 
1878
	    		for(j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
-
 
1879
	    			if(slug_question == objFormGenerator.sections[i].questions[j].slug) {
-
 
1880
 
-
 
1881
                		validatorFormOption.resetForm();
-
 
1882
                		$('#form-option #option-section').val(slug_section);
-
 
1883
                		$('#form-option #option-question').val(slug_question);
-
 
1884
                		$('#form-option #option-slug').val('');
-
 
1885
						
-
 
1886
                		instanceName = 'option-text'; 
-
 
1887
	    	    		let editor = CKEDITOR.instances[instanceName ];
-
 
1888
	    	    		editor.setData( '', function() {
-
 
1889
	    	    		    editor.focus();
-
 
1890
	    	    		});
-
 
1891
 
-
 
1892
 
-
 
1893
	    	    		$('#form-option #option-correct').val('0');
-
 
1894
                		if(objFormGenerator.sections[i].questions[j].type == 'rating-open') {
-
 
1895
                    		$('#form-option #option-correct').parent().hide();
-
 
1896
                        } else {
-
 
1897
                    		$('#form-option #option-correct').parent().show();
-
 
1898
                        }
-
 
1899
                		
-
 
1900
                		if(objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
-
 
1901
                			$('#form-option #option-value').val('0');
-
 
1902
                			$('#form-option #option-value').parent().show();
-
 
1903
                		} else {
-
 
1904
                			$('#form-option #option-value').val('1');
-
 
1905
                			$('#form-option #option-value').parent().hide();
-
 
1906
                			
-
 
1907
                       	}
-
 
1908
                		showForm = true;
-
 
1909
	    			}
-
 
1910
	    		}
-
 
1911
	    	}
-
 
1912
	    }
-
 
1913
 
-
 
1914
		if(showForm) {
-
 
1915
    		$('#modal-option h4[class="modal-title"]').html('New Option');
-
 
1916
    		$('#modal-option').modal('show');
-
 
1917
		}
-
 
1918
		
-
 
1919
	});
-
 
1920
	
-
 
1921
 
-
 
1922
	
-
 
1923
	$('body').on('click', 'button.btn-edit-option', function(e){
-
 
1924
	    e.preventDefault();
-
 
1925
	    
-
 
1926
	    var slug_section	= $(this).data('section');
-
 
1927
	    var slug_question	= $(this).data('question');
-
 
1928
	    var slug 			= $(this).data('slug');
-
 
1929
	    var showForm 		= false;
-
 
1930
	    
-
 
1931
	    for(i = 0; i < objFormGenerator.sections.length; i++) {
-
 
1932
	    	if(slug_section == objFormGenerator.sections[i].slug) {
-
 
1933
	    		for(j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
-
 
1934
	    			if(slug_question == objFormGenerator.sections[i].questions[j].slug) {
-
 
1935
	    				for(k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
-
 
1936
	    					if(slug == objFormGenerator.sections[i].questions[j].options[k].slug) {
-
 
1937
	    						validatorFormOption.resetForm();
-
 
1938
	    						$('#form-option #option-section').val(objFormGenerator.sections[i].slug);
-
 
1939
	    						$('#form-option #option-question').val(objFormGenerator.sections[i].questions[j].slug);
-
 
1940
    		    				$('#form-option #option-slug').val(objFormGenerator.sections[i].questions[j].options[k].slug);
-
 
1941
 
-
 
1942
    		    				instanceName = 'option-text'; 
-
 
1943
    		    	    		let editor = CKEDITOR.instances[instanceName ];
-
 
1944
    		    	    		editor.setData( objFormGenerator.sections[i].questions[j].options[k].text, function() {
-
 
1945
    		    	    		    editor.focus();
-
 
1946
    		    	    		});
-
 
1947
    	    		    	    		
-
 
1948
    		    				
-
 
1949
    		    				$('#form-option #option-correct').val(objFormGenerator.sections[i].questions[j].options[k].correct);
-
 
1950
    		    				if(objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'simple') {
-
 
1951
    		    					$('#form-option #option-correct').parent().show();
-
 
1952
    		    				} else {
-
 
1953
    		    					$('#form-option #option-correct').parent().hide();
-
 
1954
            		    		}
-
 
1955
 
-
 
1956
    		    				$('#form-option #option-value').val(objFormGenerator.sections[i].questions[j].options[k].value);
-
 
1957
 
-
 
1958
								if(objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
-
 
1959
    		    					$('#form-option #option-value').parent().show();
-
 
1960
								} else {
-
 
1961
									$('#form-option #option-value').parent().hide();
-
 
1962
								}
-
 
1963
 
-
 
1964
 
-
 
1965
								
-
 
1966
    		    				showForm = true;
-
 
1967
    	    					break;
-
 
1968
	    					}
-
 
1969
	    				}
-
 
1970
	    			}
-
 
1971
	    			if(showForm) {
-
 
1972
		    			break;
-
 
1973
		    		}
-
 
1974
	    		}
-
 
1975
	    	}
-
 
1976
			if(showForm) {
-
 
1977
    			break;
-
 
1978
    		}
-
 
1979
	    }
-
 
1980
	    
-
 
1981
	    if(showForm) {
-
 
1982
	    	$('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
-
 
1983
				$('#modal-option').modal('show');
-
 
1984
	    }
-
 
1985
	});
-
 
1986
	
-
 
1987
	$('body').on('click', 'button.btn-delete-option', function(e){
-
 
1988
		e.preventDefault();
-
 
1989
		var slug_section	= $(this).data('section');
-
 
1990
		var slug_question	= $(this).data('question');
-
 
1991
		    var slug 			= $(this).data('slug');
-
 
1992
 
-
 
1993
 
-
 
1994
		bootbox.confirm({
-
 
1995
			title: "LABEL_DELETE LABEL_OPTION?",
-
 
1996
			message: "LABEL_ARE_YOU_SURE",
-
 
1997
			buttons: {
-
 
1998
				cancel: {
-
 
1999
	   				label: '<i class="fa fa-times"></i> LABEL_CANCEL'
-
 
2000
	    		},
-
 
2001
				confirm: {
-
 
2002
					label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
-
 
2003
				}
-
 
2004
			},
-
 
2005
			callback: function (result) {
-
 
2006
				if (result) {
-
 
2007
					objFormGenerator.deleteOption(slug_section, slug_question, slug);
-
 
2008
				}
-
 
2009
			}
-
 
2010
		});			    
-
 
2011
	})
-
 
2012
 
-
 
2013
	$('#form-section #section-value').inputNumberFormat({'decimal' : 2});
-
 
2014
 
-
 
2015
	$('#form-question #question-value').inputNumberFormat({'decimal' : 2});
-
 
2016
	$('#form-question #question-max-length').inputNumberFormat({'decimal' : 0});
-
 
2017
 
-
 
2018
	$('#form-option #option-value').inputNumberFormat({'decimal' : 2});
-
 
2019
	
-
 
2020
	$('#form-question #question-type').change(function(e) {
-
 
2021
		e.preventDefault();
-
 
2022
		
-
 
2023
		if($('#form-question #question-type').val() == 'open') {
-
 
2024
			$('#form-question #question-max-length').parent().show();
-
 
2025
			$('#form-question #question-multiline').parent().show();
-
 
2026
			
-
 
2027
		} else {
-
 
2028
			$('#form-question #question-max-length').val('0');
-
 
2029
			$('#form-question #question-max-length').parent().hide();
-
 
2030
 
-
 
2031
			$('#form-question #question-multiline').val('0');
-
 
2032
			$('#form-question #question-multiline').parent().hide();
-
 
2033
		}
-
 
2034
 
-
 
2035
		$('#form-question #question-range').val('10');
-
 
2036
		if($('#form-question #question-type').val() == 'rating-range') {
-
 
2037
			$('#form-question #question-range').parent().show();
-
 
2038
		} else {
-
 
2039
			$('#form-question #question-range').parent().hide();
-
 
2040
		}
-
 
2041
 
-
 
2042
 
-
 
2043
		
-
 
2044
	});
-
 
2045
 
-
 
2046
	$('button.btn-add-form').click(function(e) {
-
 
2047
		e.preventDefault();
-
 
2048
 
-
 
2049
		objFormGenerator.clear();
-
 
2050
		objFormGenerator.render();
-
 
2051
		validatorForm.resetForm();
-
 
2052
 
-
 
2053
		$('#form-main #form-id').val('0');
-
 
2054
		$('#form-main #form-continue').val('0');
-
 
2055
		$('#form-main #form-name').val('');
-
 
2056
 
-
 
2057
		instanceName = 'form-text'; 
-
 
2058
		let editor = CKEDITOR.instances[instanceName ];
-
 
2059
		editor.setData('', function() {
-
 
2060
		    editor.focus();
-
 
2061
		});
-
 
2062
 
-
 
2063
 
-
 
2064
		instanceName = 'form-description'; 
-
 
2065
		CKEDITOR.instances[instanceName ].setData('');
-
 
2066
		
-
 
2067
		$( '#form-main #form-language' ).val('EN'),
-
 
2068
		$( '#form-main #form-status' ).val('D');
-
 
2069
		
-
 
2070
		$('#row-forms').hide();
-
 
2071
		$('#row-edit').show();
-
 
2072
		$('#form-main #form-name').focus();
-
 
2073
 
-
 
2074
        /*$('html, body').animate({
-
 
2075
            scrollTop: $('#form-main #form-name').offset().top - 100
-
 
2076
        }, 1000);*/
-
 
2077
	});
-
 
2078
 
-
 
2079
	$('button.btn-edit-cancel').click(function(e) {
-
 
2080
		e.preventDefault();
-
 
2081
		$('#row-edit').hide();
-
 
2082
		$('#row-forms').show();
-
 
2083
		
-
 
2084
	});
-
 
2085
 
-
 
2086
 
-
 
2087
	$('button.btn-form-save-continue').click(function(e) {
-
 
2088
		e.preventDefault();
-
 
2089
		$('#form-main #form-continue').val('1')
-
 
2090
		$('#form-main').submit();
-
 
2091
	});
-
 
2092
	
-
 
2093
	$('button.btn-form-save-close').click(function(e) {
-
 
2094
		e.preventDefault();
-
 
2095
		$('#form-main #form-continue').val('0')
-
 
2096
		$('#form-main').submit();
-
 
2097
		
-
 
2098
	});
-
 
2099
 
-
 
2100
	$('#modal-section, #modal-question, #modal-option').modal({
-
 
2101
			backdrop: 'static',
-
 
2102
			keyboard: false,
-
 
2103
			show: false
-
 
2104
		});
-
 
2105
	});
381
JS;
2106
JS;
382
$this->inlineScript()->captureEnd();
2107
$this->inlineScript()->captureEnd();
-
 
2108
?>
-
 
2109
 
Línea 383... Línea 2110...
383
?>
2110
 
384
  
2111
  
385
<!-- Content Header (Page header) -->
2112
<!-- Content Header (Page header) -->
386
<section class="content-header">
2113
<section class="content-header">