Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
135 geraldo 1
<?php
2
$acl = $this->viewModel()->getRoot()->getVariable('acl');
3
$currentUser = $this->currentUserHelper();
115 efrain 4
 
5
$roleName = $currentUser->getUserTypeId();
6
 
135 geraldo 7
$routeAdd = $this->url('self-evaluation/forms/add');
115 efrain 8
$routeDatatable = $this->url('self-evaluation/forms');
9
$routeDashboard = $this->url('dashboard');
10
 
135 geraldo 11
$allowAdd = $acl->isAllowed($roleName, 'self-evaluation/forms/add') ? 1 : 0;
12
$allowEdit = $acl->isAllowed($roleName, 'self-evaluation/forms/edit') ? 1 : 0;
13
$allowDelete = $acl->isAllowed($roleName, 'self-evaluation/forms/delete') ? 1 : 0;
115 efrain 14
 
15
 
16
$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));
17
 
18
 
19
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
20
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
21
 
22
 
23
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
24
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
25
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
26
 
27
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
28
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
29
 
30
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
31
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
32
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
33
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
34
 
35
 
36
$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.min.css'));
37
$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css'));
38
 
39
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/select2.full.min.js'));
40
 
41
$this->inlineScript()->appendFile($this->basePath('plugins/moment/moment-with-locales.min.js'));
42
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css'));
43
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'));
44
 
45
 
46
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
47
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
48
 
49
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
50
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
120 steven 51
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-input-number/input-number-format.jquery.js'));
115 efrain 52
 
137 geraldo 53
// bootbox Alert //
54
$this->inlineScript()->appendFile($this->basePath('plugins/bootbox/bootbox.min.js'));
55
 
158 geraldo 56
// JsRender //
57
$this->inlineScript()->appendFile($this->basePath('plugins/jsrender/jsrender.min.js'));
58
 
115 efrain 59
$status_active = \LeadersLinked\Model\CompanySelfEvaluationForm::STATUS_ACTIVE;
144 geraldo 60
$status_inactive = \LeadersLinked\Model\CompanySelfEvaluationForm::STATUS_INACTIVE;
115 efrain 61
 
144 geraldo 62
$lang_es = \LeadersLinked\Model\CompanySelfEvaluationForm::LANGUAGE_SPANISH;
63
$lang_en = \LeadersLinked\Model\CompanySelfEvaluationForm::LANGUAGE_ENGLISH;
153 geraldo 64
 
154 geraldo 65
 
115 efrain 66
$this->inlineScript()->captureStart();
67
echo <<<JS
118 steven 68
		const classFormGenerator = function() {
69
			this.id 				= 0,
70
			this.table				= '',
71
			this.name 				= '',
72
			this.text 				= '',
73
			this.status				= 'a',
74
			this.sections 			= [],
75
			this.clear = function()
76
			{
77
				this.sections = [];
163 geraldo 78
			}
118 steven 79
			this.addSection = function (name, text, value)
80
			{
81
				var d = new Date();
82
					var slug = 'section' + d.getTime();
83
 
84
					var position = 0;
85
					$.each(this.sections, function(index, section) {
86
						if(position < section.position) {
87
							position = section.position;
88
						}
89
					});
90
					position++;
91
 
92
				var section = {
157 geraldo 93
					'slug_section' 		: slug,
118 steven 94
					'name' 		: name,
95
					'text' 		: text,
96
					'value' 	: value,
97
					'position' 	: position,
98
					'questions' : [],
99
				}
100
				this.sections.push(section);
101
			},
102
			this.editSection = function (slug, name, text, value)
103
			{
104
				var renderTable = false;
105
				for(i = 0; i < this.sections.length; i++)
106
				{
157 geraldo 107
						if(slug == this.sections[i].slug_section) {
118 steven 108
							this.sections[i].name = name;
109
							this.sections[i].text = text;
110
							this.sections[i].value = value;
111
							renderTable = true;
112
 
113
							break;
114
						}
115
				}
116
 
117
 
118
			},
119
			this.deleteSection = function(slug)
120
			{
121
				var renderTable = false;
122
				for(i = 0; i < this.sections.length; i++)
123
				{
157 geraldo 124
						if(slug == this.sections[i].slug_section) {
118 steven 125
							this.sections.splice(i, 1);
126
 
127
							renderTable = true;
128
							break;
129
					}
130
 
131
 
132
				}
133
				if(renderTable) {
134
					$('#panel' + slug).remove();
135
				}
136
			},
137
			this.addQuestion = function (section_slug, text, value, type, maxlength, multiline, range)
138
			{
139
				var d = new Date();
163 geraldo 140
				var slug_question = 'question' + d.getTime();
118 steven 141
 
142
				var position = 0;
143
				var renderTable = false;
144
				for(i = 0; i < this.sections.length; i++)
145
				{
157 geraldo 146
					if(section_slug == this.sections[i].slug_section) {
118 steven 147
						$.each(this.sections[i].questions, function(index, question) {
148
							if(position < question.position) {
149
								position = question.position;
150
							}
151
						});
152
						position++;
153
 
154
						var question = {
163 geraldo 155
							'section_slug': section_slug,
156
							'slug_question' : slug_question,
118 steven 157
								'text' : text,
158
								'value' : value,
159
								'type' : type,
160
								'position' : position,
161
								'maxlength' :maxlength,
162
								'multiline' : multiline,
163
								'range' : range,
164
								'options' : [],
165
							}
166
						this.sections[i].questions.push(question);
167
						renderTable = true;
168
						break;
169
					}
170
				}
171
 
172
			},
173
			this.editQuestion = function(section_slug, question_slug, text, value, type, maxlength, multiline, range)
174
			{
175
				var renderTable = false;
176
				for(i = 0; i < this.sections.length; i++)
177
				{
157 geraldo 178
					if(section_slug == this.sections[i].slug_section) {
118 steven 179
						for(j = 0; j < this.sections[i].questions.length; j++) {
157 geraldo 180
							if(question_slug == this.sections[i].questions[j].slug_question) {
118 steven 181
								this.sections[i].questions[j].text 	= text,
182
								this.sections[i].questions[j].value	= value,
183
								this.sections[i].questions[j].type 	= type;
184
 
185
								if(type == 'open') {
186
									this.sections[i].questions[j].maxlength	= maxlength;
187
									this.sections[i].questions[j].multiline	= multiline;
188
									this.sections[i].questions[j].options	= [];
189
								} else {
190
									this.sections[i].questions[j].maxlength	= 0;
191
									this.sections[i].questions[j].multiline	= 0;
192
								}
193
 
194
									if(type == 'rating-range') {
195
										this.sections[i].questions[j].range = range;
196
									} else {
197
										this.sections[i].questions[j].range = 0;
198
									}
199
								renderTable = true;
200
								break;
201
							}
202
						}
203
					}
204
					if(renderTable) {
205
						break;
206
					}
207
				}
208
			},
209
			this.deleteQuestion = function(section_slug, question_slug)
210
			{
211
				var renderTable = false;
212
				for(i = 0; i < this.sections.length; i++)
213
				{
157 geraldo 214
						if(section_slug == this.sections[i].slug_section) {
118 steven 215
							for(j = 0; j < this.sections[i].questions.length; j++) {
157 geraldo 216
							if(question_slug == this.sections[i].questions[j].slug_question) {
118 steven 217
									this.sections[i].questions.splice(j, 1);
218
										renderTable = true;
219
										break;
220
							}
221
						}
222
					}
223
 
224
					if(renderTable) {
225
						break;
226
					}
227
				}
228
			},
229
			this.addOption = function (section_slug, question_slug, text, correct, value)
230
			{
231
				var d = new Date();
163 geraldo 232
				var slug_option = 'option' + d.getTime();
118 steven 233
 
234
				var position = 0;
235
				var renderTable = false;
236
				for(i = 0; i < this.sections.length; i++)
237
				{
157 geraldo 238
					if(section_slug == this.sections[i].slug_section) {
118 steven 239
						for(j = 0; j < this.sections[i].questions.length; j++) {
157 geraldo 240
							if(question_slug == this.sections[i].questions[j].slug_question) {
118 steven 241
								$.each(this.sections[i].questions[j].options, function(index, option) {
242
										if(position < option.position) {
243
											position = option.position;
244
										}
245
									});
246
									position++;
247
 
248
									var option = {
163 geraldo 249
										'slug_section' : slug_section,
250
										'slug_question' : slug_question,
251
										'slug_option' : slug_option,
118 steven 252
											'text' : text,
253
											'correct' : correct,
254
											'value' : value
255
										}
256
 
257
										this.sections[i].questions[j].options.push(option);
258
									renderTable = true;
259
									break;
260
							}
261
 
262
									if(renderTable) {
263
								break;
264
							}
265
						}
266
					}
267
				}
268
			},
269
			this.editOption = function(section_slug, question_slug, option_slug, text, correct, value)
270
			{
271
				var renderTable = false;
272
				for(i = 0; i < this.sections.length; i++)
273
				{
157 geraldo 274
					if(section_slug == this.sections[i].slug_section) {
118 steven 275
						for(j = 0; j < this.sections[i].questions.length; j++) {
157 geraldo 276
							if(question_slug == this.sections[i].questions[j].slug_question) {
118 steven 277
								for(k = 0; k < this.sections[i].questions[j].options.length; k++) {
157 geraldo 278
									if(option_slug == this.sections[i].questions[j].options[k].slug_option) {
118 steven 279
										this.sections[i].questions[j].options[k].text = text;
280
										this.sections[i].questions[j].options[k].correct = correct;
281
										this.sections[i].questions[j].options[k].value = value;
282
										renderTable = true;
283
												break;
284
									}
285
								}
286
							}
287
									if(renderTable) {
288
								break;
289
							}
290
						}
291
					}
292
						if(renderTable) {
293
							break;
294
						}
295
				}
163 geraldo 296
 
118 steven 297
			},
298
			this.deleteOption = function(section_slug, question_slug, option_slug)
299
			{
300
				var renderTable = false;
301
				for(i = 0; i < this.sections.length; i++)
302
				{
157 geraldo 303
						if(section_slug == this.sections[i].slug_section) {
118 steven 304
							for(j = 0; j < this.sections[i].questions.length; j++) {
157 geraldo 305
							if(question_slug == this.sections[i].questions[j].slug_question) {
118 steven 306
								for(k = 0; k < this.sections[i].questions[j].options.length; k++) {
157 geraldo 307
									if(option_slug == this.sections[i].questions[j].options[k].slug_option) {
118 steven 308
										this.sections[i].questions[j].options.splice(k, 1);
309
										renderTable = true;
310
												break;
311
									}
312
								}
313
							}
314
									if(renderTable) {
315
								break;
316
							}
317
						}
318
					}
319
 
320
					if(renderTable) {
321
						break;
322
					}
323
				}
324
			}
325
		}
326
 
327
		function htmlEntities(str) {
328
				return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
329
		}
330
    jQuery( document ).ready(function( $ ) {
331
			var objFormGenerator = new classFormGenerator();
332
	objFormGenerator.render();
122 steven 333
	var allowEdit   = $allowEdit;
334
	var allowDelete = $allowDelete;
146 geraldo 335
 
122 steven 336
	var tableForm = $('#gridTable').dataTable( {
337
			'processing': true,
338
			'serverSide': true,
339
			'searching': true,
340
			'order': [[ 0, 'asc' ]],
341
			'ordering':  true,
342
			'ordenable' : true,
343
			'responsive': true,
344
			'select' : false,
345
			'paging': true,
346
			'pagingType': 'simple_numbers',
347
			'ajax': {
348
				'url' : '$routeDatatable',
349
				'type' : 'get',
350
				'beforeSend': function (request) {
351
						NProgress.start();
352
				},
353
				'dataFilter': function(response) {
354
						var response = jQuery.parseJSON( response );
355
 
356
						var json                = {};
357
						json.recordsTotal       = 0;
358
						json.recordsFiltered    = 0;
359
						json.data               = [];
360
 
361
 
362
						if(response.success) {
363
								json.recordsTotal       = response.data.total;
364
								json.recordsFiltered    = response.data.total;
365
								json.data               = response.data.items;
146 geraldo 366
 
122 steven 367
						} else {
368
								$.fn.showError(response.data)
369
						}
370
 
371
						return JSON.stringify( json );
372
				}
373
			},
374
			'language' : {
375
					'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
376
					'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
377
					'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
378
					'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
379
					'sInfo':           'LABEL_DATATABLE_SINFO',
380
					'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
381
					'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
382
					'sInfoPostFix':    '',
383
					'sSearch':         'LABEL_DATATABLE_SSEARCH',
384
					'sUrl':            '',
385
					'sInfoThousands':  ',',
386
					'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
387
					'oPaginate': {
388
							'sFirst':    'LABEL_DATATABLE_SFIRST',
389
							'sLast':     'LABEL_DATATABLE_SLAST',
390
							'sNext':     'LABEL_DATATABLE_SNEXT',
391
							'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
392
					},
393
					'oAria': {
394
							'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
395
							'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
396
					},
397
			},
398
			'drawCallback': function( settings ) {
399
					NProgress.done();
400
					$('button.btn-delete').confirmation({
401
							rootSelector: 'button.btn-delete',
402
							title : 'LABEL_ARE_YOU_SURE',
403
							singleton : true,
404
							btnOkLabel: 'LABEL_YES',
405
							btnCancelLabel: 'LABEL_NO',
406
							onConfirm: function(value) {
407
									action = $(this).data('href');
408
									NProgress.start();
409
									$.ajax({
410
											'dataType'  : 'json',
411
											'accept'    : 'application/json',
412
											'method'    : 'post',
413
											'url'       :  action,
414
									}).done(function(response) {
415
											if(response['success']) {
416
													$.fn.showSuccess(response['data']);
153 geraldo 417
													gridTable.api().ajax.reload(null, false);
122 steven 418
											} else {
419
													$.fn.showError(response['data']);
420
											}
421
									}).fail(function( jqXHR, textStatus, errorThrown) {
422
											$.fn.showError(textStatus);
423
									}).always(function() {
424
											NProgress.done();
425
									});
426
							},
427
					});
428
			},
429
			'aoColumns': [
430
					{ 'mDataProp': 'name' },
431
				{ 'mDataProp': 'language'},
432
					{ 'mDataProp': 'status' },
433
					{ 'mDataProp': 'actions' },
434
		],
435
			'columnDefs': [
436
					{
437
							'targets': 0,
438
							'className' : 'text-vertical-middle',
439
					},
440
					{
441
							'targets': 1,
442
							'className' : 'text-vertical-middle',
443
					},
444
					{
445
							'targets': -2,
446
							'orderable': false,
447
							'className' : 'text-center',
448
								'render' : function ( data, type, row ) {
449
 
450
									checked = data == 'a' ? ' checked="checked" ' : '';
451
									return '<div class="checkbox checkbox-success">' +
452
											'<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
453
											'<label ></label></div>';
454
							}
455
					},
456
					{
457
							'targets': -1,
458
							'orderable': false,
459
							'render' : function ( data, type, row ) {
460
									s = '';
461
 
462
									if(allowEdit) {
123 steven 463
											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;';
122 steven 464
									}
465
									if(allowDelete) {
466
											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;';
467
									}
468
									return s;
469
							}
470
					}
471
				],
118 steven 472
	});
473
 
139 geraldo 474
 
118 steven 475
	$('body').on('click', 'a.btn-delete-form',function(e) {
476
		e.preventDefault();
477
		form_id =  $(this).data('id')
478
 
479
		bootbox.confirm({
480
		    title: "LABEL_DELETE LABEL_FORM",
138 geraldo 481
		    message: "LABEL_QUESTION_DELETE",
118 steven 482
		    buttons: {
483
		        cancel: {
484
		            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
485
		        },
486
		        confirm: {
487
		            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
488
		        }
489
		    },
490
		    callback: function (result) {
491
			    if(result) {
492
    		    	$.ajax({
493
    	                'dataType': 'json',
494
    	                'method': 'post',
495
    	                'url' :  'ajax.<?php echo $this->module; ?>.php?action=delete',
496
    	                'data' :{
497
    	                    'form-id' : form_id
498
    	                },
499
    	            }).done(function(response) {
500
 
501
    	                if(response['success']) {
502
    	                	$.fn.showSuccess(response['message']);
503
    	                	tableForm.fnDraw();
504
    	                } else {
141 geraldo 505
    	                	$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
118 steven 506
    	                }
507
    	            }).fail(function( jqXHR, textStatus, errorThrown) {
508
    					$.fn.showError(textStatus);
509
    	            });
510
			    }
511
		    }
512
		});
513
 
514
 
515
    });
516
 
517
    $(document).on('click','[data-action="delete"]',function(){
518
 
519
    	bootbox.confirm({
520
		    title: "LABEL_DELETE LABEL_FORMS_2",
138 geraldo 521
		    message: "LABEL_QUESTION_DELETE",
118 steven 522
		    buttons: {
523
		        cancel: {
524
		            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
525
		        },
526
		        confirm: {
527
		            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
528
		        }
529
		    },
530
		    callback: function (result) {
531
			    if(result) {
532
			    	var d = currentSelected();
533
    		    	$.ajax({
534
    	                'dataType': 'json',
535
    	                'method': 'post',
536
    	                'url' :  'ajax.<?php echo $this->module; ?>.php?action=delete-selected',
537
    	                'data' :{
538
    	                	 selected : d
539
    	                },
540
    	            }).done(function(response) {
541
 
542
    	                if(response['success']) {
543
    	                	$.fn.showSuccess(response['message']);
544
    	                	tableForm.fnDraw();
545
    	                } else {
141 geraldo 546
    	                	$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
118 steven 547
    	                }
548
    	            }).fail(function( jqXHR, textStatus, errorThrown) {
549
    					$.fn.showError(textStatus);
550
    	            });
551
			    }
552
		    }
553
		});
554
 
555
    });
556
 
557
 
558
    $('body').on('switch-change', 'input[type="checkbox"].make-switch-form', function(e) {
559
		e.preventDefault();
560
		e.stopPropagation();
561
 
562
		form_id =  $(this).data('id')
563
		form_status = $(this).prop('checked') ? 'A' : 'D';
564
 
565
		$.ajax({
566
        	'dataType': 'json',
567
            'method': 'post',
568
            'url' :  'ajax.<?php echo $this->module; ?>.php?action=status',
569
            'data' :{
570
            	'form-id' : form_id,
571
            	'form-status' : form_status
572
            },
573
        }).done(function(response) {
574
	        if(response['success']) {
575
	        	$.fn.showSuccess(response['message']);
576
	       } else {
141 geraldo 577
    	       	$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
118 steven 578
            }
579
         }).fail(function( jqXHR, textStatus, errorThrown) {
580
			$.fn.showError(textStatus);
581
        })
582
    });
583
 
124 steven 584
	$('body').on('click', 'button.btn-edit-form',function(e) {
118 steven 585
		e.preventDefault();
586
		form_id =  $(this).data('id')
125 steven 587
    var action = $(this).data('href');
118 steven 588
		$.ajax({
125 steven 589
			'dataType'  : 'json',
590
			'accept'    : 'application/json',
591
			'method'    : 'get',
592
			'url'       :  action,
118 steven 593
		}).done(function(response) {
594
			if(response['success']) {
595
					validatorForm.resetForm();
596
 
153 geraldo 597
					$('#form-main #form-id' ).val(response['id']),
598
					$('#form-main #form-continue').val('0');
599
					$('#form-main #form-name' ).val(response['name']),
118 steven 600
 
601
 
602
					instanceName = 'form-description';
603
					let editor = CKEDITOR.instances[instanceName ];
604
					editor.setData(response['description'], function() {
605
							editor.focus();
606
					});
607
 
608
 
609
					instanceName = 'form-text';
610
					CKEDITOR.instances[instanceName ].setData(response['text']);
611
 
153 geraldo 612
					$('#form-main #form-language' ).val(response['language']),
613
					$('#form-main #form-status' ).val(response['status']);
118 steven 614
 
615
					objFormGenerator.clear();
126 steven 616
					objFormGenerator.sections = response['sections'] || [];
118 steven 617
					objFormGenerator.render();
618
					$('#row-forms').hide();
619
					$('#row-edit').show();
620
 
153 geraldo 621
					$('#form-main #form-name').focus();
118 steven 622
 
623
				} else {
141 geraldo 624
					$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
118 steven 625
				}
626
			}).fail(function( jqXHR, textStatus, errorThrown) {
627
				$.fn.showError(textStatus);
628
			});
629
    });
630
 
631
	 $(document).on('click','[data-type="select_all"]',function(){
632
 
633
	        if($('input[name="select_all"]:checked').val() == 'all'){
634
	            $('[data-type="select"]').prop('checked', true);
635
	            $('[data-action="delete"]').removeClass('hide');
636
	        }else{
637
	            $('[data-type="select"]').prop('checked', false);
638
	            $('[data-action="delete"]').addClass('hide');
639
	        }
640
	    });
641
 
642
	    function getLength(){
643
	        return $('[data-type="select"]').length;
644
	    }
645
 
646
	    function currentSelected(){
647
	        var selected = [];
648
	        $.each($("input[name='select[]']:checked"), function(){
649
	            selected.push($(this).val());
650
	        });
651
 
652
	        return selected;
653
	    }
654
 
655
	    $(document).on('change',"input[name='select[]']",function(){
656
	        var c = currentSelected();
657
	        var cc = getLength();
658
 
659
 
660
	        if(c.length == cc){
661
	            if($('[data-action="delete"]').hasClass('hide')){
662
	                $('[data-action="delete"]').removeClass('hide');
663
	            }
664
	            return true;
665
	        }else{
666
	            $('input[name="select_all"]').prop('checked', false);
667
	        }
668
 
669
	        if(c.length > 0){
670
	            if($('[data-action="delete"]').hasClass('hide')){
671
	                $('[data-action="delete"]').removeClass('hide');
672
	            }
673
	        }else{
674
	            if(!$('[data-action="delete"]').hasClass('hide')){
675
	                $('[data-action="delete"]').addClass('hide');
676
	            }
677
	        }
678
	    });
679
 
680
	    var form3 = $('#form_sample_3');
681
        var error3 = $('.alert-danger', form3);
682
        var success3 = $('.alert-success', form3);
683
 
684
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
153 geraldo 685
 	$( "#form-main" ).on('submit', function() {
118 steven 686
		for(var instanceName in CKEDITOR.instances) {
687
			CKEDITOR.instances[instanceName].updateElement();
688
		}
689
	})
690
 
153 geraldo 691
	var validatorForm = $( "#form-main" ).validate( {
118 steven 692
        ignore: [],
693
        errorClass: 'help-block',
694
        errorElement: 'span',
695
		rules: {
696
			'form-name':  {
697
				required: true,
698
				minlength: 2,
699
				maxlength: 50
700
			},
701
			'form-description' : {
702
				required: true,
703
			},
704
			'form-text' : {
705
				required: true,
706
			},
707
			'form-language' : {
708
				required: true,
709
			},
710
			'forrm-status' : {
711
				required: true,
712
			},
713
		},
714
        highlight: function (element) {
715
            $(element).closest('.form-group').addClass('has-error');
716
        },
717
        unhighlight: function (element) {
718
            $(element).closest('.form-group').removeClass('has-error');
719
        },
720
        errorPlacement: function (error, element) {
721
            if (element.attr("data-error-container")) {
722
                error.appendTo(element.attr("data-error-container"));
723
            } else {
724
                error.insertAfter(element);
725
            }
726
        },
727
        invalidHandler: function(form, validator) {
728
            if (!validator.numberOfInvalids())
729
                return;
730
            $('html, body').animate({
731
                scrollTop: $(validator.errorList[0].element).offset().top - 100
732
            }, 1000);
733
        },
734
		submitHandler: function(form) {
140 geraldo 735
 
118 steven 736
		    var error = false;
737
		    if(objFormGenerator.sections.length == 0) {
142 geraldo 738
		    	$.fn.showError('ERROR_SECCTIONS');
118 steven 739
		    	error = true;
740
		    } else {
741
 
742
		    	for(i = 0; i < objFormGenerator.sections.length; i++)
743
		    	{
744
 
745
		    		if(objFormGenerator.sections[i].questions.length == 0) {
143 geraldo 746
		    			$.fn.showError('ERROR_QUESTIONS'.replace('%s', objFormGenerator.sections[i].name ));
118 steven 747
		    			break;
748
		    		}
749
 
750
		    		var valueSection = parseInt(objFormGenerator.sections[i].value);
751
		    		var totalValueQuestion = 0;
752
 
753
 
754
		    		for(j = 0; j < objFormGenerator.sections[i].questions.length; j++)
755
		    		{
756
		    			valueQuestion = parseInt(objFormGenerator.sections[i].questions[j].value);
757
		    			totalValueQuestion = totalValueQuestion + valueQuestion;
758
		    			if(objFormGenerator.sections[i].questions[j].type == 'simple'
759
			    			|| objFormGenerator.sections[i].questions[j].type == 'multiple'
760
			    			|| objFormGenerator.sections[i].questions[j].type == 'rating-open' ) {
761
 
762
		    				var questionNumber = j + 1;
763
		    				var numberCorrect = 0;
764
 
765
 
766
		    				if(objFormGenerator.sections[i].questions[j].options.length == 0) {
139 geraldo 767
 
143 geraldo 768
								$.fn.showError('ERROR_OPTIONS'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
139 geraldo 769
								error = true;
154 geraldo 770
								return false;
118 steven 771
									break;
772
		    				}
773
 
774
		    				var totalOption = 0;
775
		    				var maxOption = 0;
776
		    				for(k = 0;  k < objFormGenerator.sections[i].questions[j].options.length; k++)
777
		    				{
778
		    					if(objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple' ) {
779
    		    					if(objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
780
    		    						numberCorrect++;
781
    		    					}
782
		    					}
783
 
784
		    					if(objFormGenerator.sections[i].questions[j].type == 'multiple' && objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
785
		    						totalOption = totalOption + parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
786
			    				}
787
 
788
		    					if(objFormGenerator.sections[i].questions[j].type == 'rating-open') {
789
		    						if(parseInt(objFormGenerator.sections[i].questions[j].options[k].value) > maxOption) {
790
											maxOption = parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
791
					    			}
792
			    				}
793
 
794
		    				}
795
 
796
		    				if(objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple' ) {
797
 
798
    		    				if(numberCorrect == 0) {
143 geraldo 799
    		    					$.fn.showError('ERROR_OPTIONS_CORRECT'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 800
    		    					error = true;
154 geraldo 801
									return false;
118 steven 802
    		    					break;
803
    		    				}
804
    		    				if(objFormGenerator.sections[i].questions[j].type == 'simple' && numberCorrect > 1) {
143 geraldo 805
    		    					$.fn.showError('ERROR_OPTIONS_DUPLICATE_CORRECT'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 806
    		    					error = true;
154 geraldo 807
									return false;
118 steven 808
    		    					break;
809
    		    				}
810
    		    				if(objFormGenerator.sections[i].questions[j].type == 'multiple' && numberCorrect == 1) {
143 geraldo 811
    		    					$.fn.showError('ERROR_OPTIONS_ONE_CORRECT'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 812
    		    					error = true;
154 geraldo 813
									return false;
118 steven 814
    		    					break;
815
    		    				}
816
		    				}
817
 
818
			 				if(objFormGenerator.sections[i].questions[j].type == 'multiple' && totalOption > valueQuestion ) {
139 geraldo 819
 
143 geraldo 820
								$.fn.showError('ERROR_OPTIONS_SUM_VALUES'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 821
		    					error = true;
154 geraldo 822
								return false;
118 steven 823
		    					break;
824
			    			}
825
 
826
		    				if(objFormGenerator.sections[i].questions[j].type == 'rating-open' && maxOption > valueQuestion ) {
143 geraldo 827
								$.fn.showError('ERROR_OPTIONS_MAX_OPTION'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 828
		    					error = true;
154 geraldo 829
								return false;
118 steven 830
		    					break;
831
			    			}
832
						}
833
 
834
		    		}
835
 
836
		    		if(valueSection != totalValueQuestion) {
143 geraldo 837
		    			$.fn.showError('ERROR_VALUE_SECTIONS'.replace('%s', objFormGenerator.sections[i].name ));
118 steven 838
		    			error = true;
154 geraldo 839
						return false;
118 steven 840
		    			break;
841
					}
842
				}
843
 
844
 
845
 
846
    			if(error) {
847
    				return false;
848
    			} else {
849
 
850
 
153 geraldo 851
    				var formId		= parseInt($('#form-main #form-id' ).val());
852
    				var formContinue = parseInt($('#form-main #form-continue' ).val());
118 steven 853
 
854
    				var data = {
143 geraldo 855
    	    			'id'	: formId,
153 geraldo 856
        				'name' : $('#form-main #form-name' ).val(),
857
        				'description' : $('#form-main #form-description' ).val(),
858
        				'text' : $('#form-main #form-text' ).val(),
859
        				'language' : $('#form-main #form-language' ).val(),
860
        				'status' : $('#form-main #form-status' ).val(),
118 steven 861
        				'sections' : objFormGenerator.sections
862
    				}
127 steven 863
					$.ajax({
864
						'dataType': 'json',
865
						'method': 'post',
866
						'url' :  '$routeAdd',
867
						'data' : data,
868
					}).done(function(response) {
869
						if(response['success']) {
870
							$.fn.showSuccess(response['message']);
118 steven 871
							if(formContinue == 1) {
153 geraldo 872
								$('#form-main #form-id').val(response['form-id']);
873
								$('#form-main #form-continue').val(0);
118 steven 874
							} else {
875
								$('#row-edit').hide();
127 steven 876
								$('#row-forms').show();
118 steven 877
							}
878
							tableForm.fnDraw();
127 steven 879
						} else {
141 geraldo 880
							$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
127 steven 881
						}
882
					}).fail(function( jqXHR, textStatus, errorThrown) {
118 steven 883
						$.fn.showError(textStatus);
127 steven 884
					});
885
						return false;
118 steven 886
    			}
887
			}
888
 
889
 
890
		}
891
	});
892
 
893
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
153 geraldo 894
 	$( "#form-section" ).on('submit', function() {
118 steven 895
		for(var instanceName in CKEDITOR.instances) {
896
			CKEDITOR.instances[instanceName].updateElement();
897
		}
898
	})
899
 
153 geraldo 900
	var validatorFormSection = $( "#form-section" ).validate( {
118 steven 901
        ignore: [],
902
        errorClass: 'help-block',
903
        errorElement: 'span',
904
		rules: {
905
			'section-name':  {
906
				required: true,
907
				minlength: 2,
908
				maxlength: 50
909
			},
910
			'section-text' : {
911
				required: false,
912
			},
913
			'section-value' : {
914
				required: true,
915
				number: true,
916
				min: 1
917
			},
918
		},
919
        highlight: function (element) {
920
            $(element).closest('.form-group').addClass('has-error');
921
        },
922
        unhighlight: function (element) {
923
            $(element).closest('.form-group').removeClass('has-error');
924
        },
925
        errorPlacement: function (error, element) {
926
            if (element.attr("data-error-container")) {
927
                error.appendTo(element.attr("data-error-container"));
928
            } else {
929
                error.insertAfter(element);
930
            }
931
        },
932
        invalidHandler: function(form, validator) {
933
            if (!validator.numberOfInvalids())
934
                return;
935
            $('html, body').animate({
936
                scrollTop: $(validator.errorList[0].element).offset().top - 100
937
            }, 1000);
938
        },
939
		submitHandler: function(form) {
940
		    // do other things for a valid form
941
		    //form.submit();
942
 
153 geraldo 943
		    var slug = $('#form-section #section-slug').val();
118 steven 944
		    if(slug) {
945
		    	objFormGenerator.editSection(
153 geraldo 946
		    		$('#form-section #section-slug').val(),
947
			    	$('#form-section #section-name').val(),
948
			    	$('#form-section #section-text').val(),
949
			    	$('#form-section #section-value').val()
118 steven 950
			  	);
951
		    } else {
952
		    	objFormGenerator.addSection(
153 geraldo 953
		    		$('#form-section #section-name').val(),
954
		    		$('#form-section #section-text').val(),
955
		    		$('#form-section #section-value').val()
118 steven 956
		    	);
957
		    }
958
 
157 geraldo 959
		    renderData(objFormGenerator.sections);
118 steven 960
			$('#modal-section').modal('hide');
961
			return false;
962
		  }
963
	} );
964
 
965
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
153 geraldo 966
 	$( "#form-question" ).on('submit', function() {
118 steven 967
		for(var instanceName in CKEDITOR.instances) {
968
			CKEDITOR.instances[instanceName].updateElement();
969
		}
970
	})
971
 
972
 
153 geraldo 973
	var validatorFormQuestion = $( "#form-question" ).validate( {
118 steven 974
        ignore: [],
975
        errorClass: 'help-block',
976
        errorElement: 'span',
977
		rules: {
978
			'question-text' : {
979
				required: true,
980
			},
981
			'question-value' : {
982
				required: true,
983
				number: true,
984
				min: 1
985
			},
986
			'question-type':  {
987
				required: true,
988
			},
989
			'question-max-length' : {
990
				required: true,
991
				digits: true,
992
				min: 0
993
			},
994
			'question-range' : {
995
				required: true,
996
				number: true,
997
				min: 1
998
			},
999
		},
1000
        highlight: function (element) {
1001
            $(element).closest('.form-group').addClass('has-error');
1002
        },
1003
        unhighlight: function (element) {
1004
            $(element).closest('.form-group').removeClass('has-error');
1005
        },
1006
        errorPlacement: function (error, element) {
1007
            if (element.attr("data-error-container")) {
1008
                error.appendTo(element.attr("data-error-container"));
1009
            } else {
1010
                error.insertAfter(element);
1011
            }
1012
        },
1013
        invalidHandler: function(form, validator) {
1014
 
1015
 
1016
            if (!validator.numberOfInvalids())
1017
                return;
1018
            $('html, body').animate({
1019
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1020
            }, 1000);
1021
        },
1022
		submitHandler: function(form) {
1023
 
139 geraldo 1024
 
153 geraldo 1025
		    if($('#form-question #question-slug').val()) {
118 steven 1026
 
139 geraldo 1027
 
118 steven 1028
		    	objFormGenerator.editQuestion(
153 geraldo 1029
		    		$('#form-question #question-section').val(),
1030
		    		$('#form-question #question-slug').val(),
1031
		    		$('#form-question #question-text').val(),
1032
		    		$('#form-question #question-value').val(),
1033
			    	$('#form-question #question-type').val(),
1034
			    	$('#form-question #question-max-length').val(),
1035
	    			$('#form-question #question-multiline').val(),
1036
	    			$('#form-question #question-range').val()
118 steven 1037
			  	);
1038
		    } else {
1039
 
1040
		    	objFormGenerator.addQuestion(
153 geraldo 1041
			    	$('#form-question #question-section').val(),
1042
			    	$('#form-question #question-text').val(),
1043
			    	$('#form-question #question-value').val(),
1044
				    $('#form-question #question-type').val(),
1045
				    $('#form-question #question-max-length').val(),
1046
		    		$('#form-question #question-multiline').val(),
1047
		    		$('#form-question #question-range').val()
118 steven 1048
		    	);
1049
		    }
157 geraldo 1050
		    renderData(objFormGenerator.sections);
118 steven 1051
			$('#modal-question').modal('hide');
1052
			return false;
1053
		  }
1054
	} );
1055
 
1056
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
153 geraldo 1057
 	$( "#form-option" ).on('submit', function() {
118 steven 1058
		for(var instanceName in CKEDITOR.instances) {
1059
			CKEDITOR.instances[instanceName].updateElement();
1060
		}
1061
	})
1062
 
153 geraldo 1063
	var validatorFormOption = $( "#form-option" ).validate( {
118 steven 1064
        ignore: [],
1065
        errorClass: 'help-block',
1066
        errorElement: 'span',
1067
		rules: {
1068
			'option-text' : {
1069
				required: true,
1070
			},
1071
        	'option-value' : {
1072
				required: true,
1073
				number: true,
1074
				min: 1
1075
        	}
1076
		},
1077
        highlight: function (element) {
1078
            $(element).closest('.form-group').addClass('has-error');
1079
        },
1080
        unhighlight: function (element) {
1081
            $(element).closest('.form-group').removeClass('has-error');
1082
        },
1083
        errorPlacement: function (error, element) {
1084
            if (element.attr("data-error-container")) {
1085
                error.appendTo(element.attr("data-error-container"));
1086
            } else {
1087
                error.insertAfter(element);
1088
            }
1089
        },
1090
        invalidHandler: function(form, validator) {
1091
            if (!validator.numberOfInvalids())
1092
                return;
1093
            $('html, body').animate({
1094
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1095
            }, 1000);
1096
        },
1097
		submitHandler: function(form) {
1098
 
1099
 
153 geraldo 1100
		    if($('#form-option #option-slug').val()) {
118 steven 1101
		    	objFormGenerator.editOption(
153 geraldo 1102
		    		$('#form-option #option-section').val(),
1103
		    		$('#form-option #option-question').val(),
1104
		    		$('#form-option #option-slug').val(),
1105
		    		$('#form-option #option-text').val(),
1106
		    		$('#form-option #option-correct').val(),
1107
		    		$('#form-option #option-value').val()
118 steven 1108
			  	);
1109
		    } else {
1110
		    	objFormGenerator.addOption(
153 geraldo 1111
			    	$('#form-option #option-section').val(),
1112
			    	$('#form-option #option-question').val(),
1113
			    	$('#form-option #option-text').val(),
1114
			    	$('#form-option #option-correct').val(),
1115
			    	$('#form-option #option-value').val()
118 steven 1116
		    	);
1117
		    }
157 geraldo 1118
			renderData(objFormGenerator.sections);
118 steven 1119
			$('#modal-option').modal('hide');
1120
			return false;
1121
		  }
1122
	} );
1123
 
1124
	$('body').on('click', 'button[id="btn-add-section"]', function(e){
1125
		e.preventDefault();
1126
 
1127
		validatorFormSection.resetForm();
153 geraldo 1128
		$('#form-section #section-slug').val('');
1129
		$('#form-section #section-name').val('');
118 steven 1130
 
1131
		instanceName = 'section-text';
1132
		let editor = CKEDITOR.instances[instanceName ];
143 geraldo 1133
		editor.setData('', function() {
118 steven 1134
		    editor.focus();
1135
		});
1136
 
1137
 
153 geraldo 1138
		$('#form-section #section-value').val('0');
136 geraldo 1139
		$('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
118 steven 1140
		$('#modal-section').modal('show');
1141
	});
1142
 
1143
	$('body').on('click', 'button.btn-edit-section', function(e){
1144
	    e.preventDefault();
1145
 
1146
	    var slug = $(this).data('slug');
1147
	    var section;
1148
	    var showForm = false;
1149
 
1150
	    for(i = 0; i < objFormGenerator.sections.length; i++) {
1151
	        section = objFormGenerator.sections[i];
1152
 
1153
	    	if(slug == section.slug) {
1154
 
1155
				validatorFormSection.resetForm();
153 geraldo 1156
	    		$('#form-section #section-slug').val(section.slug);
1157
	    		$('#form-section #section-name').val(section.name);
118 steven 1158
 
1159
	    		instanceName = 'section-text';
1160
	    		let editor = CKEDITOR.instances[instanceName ];
1161
	    		editor.setData( section.text, function() {
1162
	    		    editor.focus();
1163
	    		});
1164
 
153 geraldo 1165
				$('#form-section #section-value').val(section.value);
156 geraldo 1166
 
157 geraldo 1167
 
118 steven 1168
				showForm = true;
1169
				break;
1170
	    	}
1171
	    }
1172
 
1173
	    if(showForm) {
136 geraldo 1174
	    	$('#modal-section h4[class="modal-title"]').html('LABEL_EDIT LABEL_SECTION');
118 steven 1175
			$('#modal-section').modal('show');
1176
	    }
1177
 
1178
	});
1179
 
1180
	$('body').on('click', 'button.btn-delete-section', function(e){
1181
		e.preventDefault();
1182
		var slug = $(this).data('slug');
1183
 
1184
		bootbox.confirm({
138 geraldo 1185
		    title: "LABEL_DELETE LABEL_SECTION",
1186
		    message: "LABEL_QUESTION_DELETE",
118 steven 1187
		    buttons: {
1188
		        cancel: {
1189
		            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1190
		        },
1191
		        confirm: {
1192
		            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1193
		        }
1194
		    },
1195
		    callback: function (result) {
1196
		    	if (result) {
1197
					objFormGenerator.deleteSection(slug);
157 geraldo 1198
					renderData(objFormGenerator.sections);
118 steven 1199
				}
1200
		    }
1201
		});
1202
 
1203
 
1204
 
1205
	});
1206
 
1207
 
1208
	$('body').on('click', 'button.btn-add-question', function(e){
1209
		e.preventDefault();
1210
 
1211
		validatorFormQuestion.resetForm();
1212
		var slug = $(this).data('slug');
1213
 
153 geraldo 1214
		$('#form-question #question-section').val(slug);
1215
		$('#form-question #question-slug').val('');
118 steven 1216
 
1217
		instanceName = 'question-text';
1218
		let editor = CKEDITOR.instances[instanceName ];
143 geraldo 1219
		editor.setData('', function() {
118 steven 1220
		    editor.focus();
1221
		});
1222
 
1223
 
153 geraldo 1224
		$('#form-question #question-value').val('0');
1225
		$('#form-question #question-type').val($('#form-question #question-type option:first').val());
118 steven 1226
 
153 geraldo 1227
		$('#form-question #question-max-length').val('0');
1228
		$('#form-question #question-max-length').parent().show();
118 steven 1229
 
153 geraldo 1230
		$('#form-question #question-multiline').val('0');
1231
		$('#form-question #question-multiline').parent().show();
118 steven 1232
 
153 geraldo 1233
		$('#form-question #question-range').val('10');
1234
		$('#form-question #question-range').parent().hide();
118 steven 1235
 
136 geraldo 1236
		$('#modal-question h4[class="modal-title"]').html('LABEL_ADD LABEL_QUESTION');
118 steven 1237
		$('#modal-question').modal('show');
1238
 
1239
	});
1240
 
1241
 
1242
 
1243
	$('body').on('click', 'button.btn-edit-question', function(e){
1244
	    e.preventDefault();
1245
 
1246
	    var slug_section	= $(this).data('section');
1247
	    var slug 			= $(this).data('slug');
1248
	    var showForm 		= false;
1249
 
1250
	    for(i = 0; i < objFormGenerator.sections.length; i++) {
1251
 
157 geraldo 1252
	    	if(slug_section == objFormGenerator.sections[i].slug_section) {
118 steven 1253
 
1254
	    		for(j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1255
 
157 geraldo 1256
	    			if(slug == objFormGenerator.sections[i].questions[j].slug_question) {
118 steven 1257
	    				validatorFormQuestion.resetForm();
1258
 
157 geraldo 1259
	    				$('#form-question #question-section').val(objFormGenerator.sections[i].slug_section);
1260
	    				$('#form-question #question-slug').val(objFormGenerator.sections[i].questions[j].slug_question);
118 steven 1261
 
1262
	    	    		instanceName = 'question-text';
1263
	    	    		let editor = CKEDITOR.instances[instanceName ];
1264
	    	    		editor.setData( objFormGenerator.sections[i].questions[j].text, function() {
1265
	    	    		    editor.focus();
1266
	    	    		});
1267
 
1268
 
153 geraldo 1269
	        			$('#form-question #question-value').val(objFormGenerator.sections[i].questions[j].value);
1270
	        			$('#form-question #question-type').val(objFormGenerator.sections[i].questions[j].type);
118 steven 1271
 
1272
 
1273
 
1274
	        			if(objFormGenerator.sections[i].questions[j].type == 'open') {
153 geraldo 1275
		        			$('#form-question #question-max-length').val(objFormGenerator.sections[i].questions[j].maxlength);
1276
		        			$('#form-question #question-max-length').parent().show();
118 steven 1277
 
153 geraldo 1278
		        			$('#form-question #question-multiline').val(objFormGenerator.sections[i].questions[j].multiline);
1279
							$('#form-question #question-multiline').parent().show();
118 steven 1280
	        			} else {
153 geraldo 1281
		        			$('#form-question #question-max-length').val('0');
1282
		        			$('#form-question #question-max-length').parent().hide();
118 steven 1283
 
153 geraldo 1284
		        			$('#form-question #question-multiline').val('0');
1285
							$('#form-question #question-multiline').parent().hide();
118 steven 1286
	        			}
1287
 
1288
	        			if(objFormGenerator.sections[i].questions[j].type == 'rating-range') {
153 geraldo 1289
	            			$('#form-question #question-range').val(objFormGenerator.sections[i].questions[j].range);
1290
		        			$('#form-question #question-range').parent().show();
118 steven 1291
 
1292
	        			} else {
153 geraldo 1293
	            			$('#form-question #question-range').val('10');
1294
		        			$('#form-question #question-range').parent().hide();
118 steven 1295
		        		}
1296
 
1297
    					showForm = true;
1298
    					break;
1299
 
1300
	    			}
1301
 
1302
	    		}
1303
 
1304
	    		break;
1305
	    	}
1306
	    }
1307
 
1308
	    if(showForm) {
1309
	    	$('#modal-question h4[class="modal-title"]').html('LABEL_EDIT LABEL_QUESTION');
1310
				$('#modal-question').modal('show');
1311
	    }
1312
 
1313
	});
1314
 
1315
 
1316
 
1317
 
1318
	$('body').on('click', 'button.btn-delete-question', function(e){
1319
		e.preventDefault();
1320
 
1321
		var slug_section	= $(this).data('section');
1322
		var slug 			= $(this).data('slug');
1323
 
1324
		bootbox.confirm({
138 geraldo 1325
			title: "LABEL_DELETE LABEL_QUESTION",
1326
			message: "LABEL_QUESTION_DELETE",
118 steven 1327
			buttons: {
1328
				cancel: {
1329
   					label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1330
    			},
1331
			    confirm: {
1332
			    	label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1333
			    }
1334
			},
1335
			callback: function (result) {
1336
				if (result) {
1337
					objFormGenerator.deleteQuestion(slug_section, slug);
157 geraldo 1338
					renderData(objFormGenerator.sections);
118 steven 1339
				}
1340
			}
1341
		});
1342
	});
1343
 
1344
 
1345
	$('body').on('click', 'button.btn-add-option', function(e){
1346
		e.preventDefault();
1347
	    var slug_section	= $(this).data('section');
1348
		var slug_question 	= $(this).data('slug');
1349
		var showForm 		= false;
1350
 
1351
	    for(i = 0; i < objFormGenerator.sections.length; i++) {
157 geraldo 1352
	    	if(slug_section == objFormGenerator.sections[i].slug_section) {
118 steven 1353
	    		for(j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
157 geraldo 1354
	    			if(slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
118 steven 1355
 
1356
                		validatorFormOption.resetForm();
153 geraldo 1357
                		$('#form-option #option-section').val(slug_section);
1358
                		$('#form-option #option-question').val(slug_question);
1359
                		$('#form-option #option-slug').val('');
118 steven 1360
 
1361
                		instanceName = 'option-text';
1362
	    	    		let editor = CKEDITOR.instances[instanceName ];
143 geraldo 1363
	    	    		editor.setData('', function() {
118 steven 1364
	    	    		    editor.focus();
1365
	    	    		});
1366
 
1367
 
153 geraldo 1368
	    	    		$('#form-option #option-correct').val('0');
118 steven 1369
                		if(objFormGenerator.sections[i].questions[j].type == 'rating-open') {
153 geraldo 1370
                    		$('#form-option #option-correct').parent().hide();
118 steven 1371
                        } else {
153 geraldo 1372
                    		$('#form-option #option-correct').parent().show();
118 steven 1373
                        }
1374
 
1375
                		if(objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
153 geraldo 1376
                			$('#form-option #option-value').val('0');
1377
                			$('#form-option #option-value').parent().show();
118 steven 1378
                		} else {
153 geraldo 1379
                			$('#form-option #option-value').val('1');
1380
                			$('#form-option #option-value').parent().hide();
118 steven 1381
 
1382
                       	}
156 geraldo 1383
 
157 geraldo 1384
						   renderData(objFormGenerator.sections);
118 steven 1385
                		showForm = true;
1386
	    			}
1387
	    		}
1388
	    	}
1389
	    }
1390
 
1391
		if(showForm) {
139 geraldo 1392
    		$('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
118 steven 1393
    		$('#modal-option').modal('show');
1394
		}
1395
 
1396
	});
157 geraldo 1397
 
1398
    /**
1399
	 * Render Sections data
1400
	 */
159 geraldo 1401
	const renderData = (data) => $("#rows").html($("#sectionTemplate").render(data));
157 geraldo 1402
 
159 geraldo 1403
	//const renderData = (data) => console.log(data);
118 steven 1404
 
1405
 
1406
 
1407
	$('body').on('click', 'button.btn-edit-option', function(e){
1408
	    e.preventDefault();
1409
 
1410
	    var slug_section	= $(this).data('section');
1411
	    var slug_question	= $(this).data('question');
1412
	    var slug 			= $(this).data('slug');
1413
	    var showForm 		= false;
1414
 
1415
	    for(i = 0; i < objFormGenerator.sections.length; i++) {
157 geraldo 1416
	    	if(slug_section == objFormGenerator.sections[i].slug_section) {
118 steven 1417
	    		for(j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
157 geraldo 1418
	    			if(slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
118 steven 1419
	    				for(k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
157 geraldo 1420
	    					if(slug == objFormGenerator.sections[i].questions[j].options[k].slug_option) {
118 steven 1421
	    						validatorFormOption.resetForm();
157 geraldo 1422
	    						$('#form-option #option-section').val(objFormGenerator.sections[i].slug_section);
1423
	    						$('#form-option #option-question').val(objFormGenerator.sections[i].questions[j].slug_question);
1424
    		    				$('#form-option #option-slug').val(objFormGenerator.sections[i].questions[j].options[k].slug_option);
118 steven 1425
 
1426
    		    				instanceName = 'option-text';
1427
    		    	    		let editor = CKEDITOR.instances[instanceName ];
1428
    		    	    		editor.setData( objFormGenerator.sections[i].questions[j].options[k].text, function() {
1429
    		    	    		    editor.focus();
1430
    		    	    		});
1431
 
1432
 
153 geraldo 1433
    		    				$('#form-option #option-correct').val(objFormGenerator.sections[i].questions[j].options[k].correct);
118 steven 1434
    		    				if(objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'simple') {
153 geraldo 1435
    		    					$('#form-option #option-correct').parent().show();
118 steven 1436
    		    				} else {
153 geraldo 1437
    		    					$('#form-option #option-correct').parent().hide();
118 steven 1438
            		    		}
1439
 
153 geraldo 1440
    		    				$('#form-option #option-value').val(objFormGenerator.sections[i].questions[j].options[k].value);
118 steven 1441
 
1442
								if(objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
153 geraldo 1443
    		    					$('#form-option #option-value').parent().show();
118 steven 1444
								} else {
153 geraldo 1445
									$('#form-option #option-value').parent().hide();
118 steven 1446
								}
1447
 
1448
 
1449
 
1450
    		    				showForm = true;
1451
    	    					break;
1452
	    					}
1453
	    				}
1454
	    			}
1455
	    			if(showForm) {
1456
		    			break;
1457
		    		}
1458
	    		}
1459
	    	}
1460
			if(showForm) {
1461
    			break;
1462
    		}
1463
	    }
1464
 
1465
	    if(showForm) {
1466
	    	$('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
1467
				$('#modal-option').modal('show');
1468
	    }
1469
	});
1470
 
1471
	$('body').on('click', 'button.btn-delete-option', function(e){
1472
		e.preventDefault();
1473
		var slug_section	= $(this).data('section');
1474
		var slug_question	= $(this).data('question');
1475
		    var slug 			= $(this).data('slug');
1476
 
1477
 
1478
		bootbox.confirm({
138 geraldo 1479
			title: "LABEL_DELETE LABEL_OPTION",
1480
			message: "LABEL_QUESTION_DELETE",
118 steven 1481
			buttons: {
1482
				cancel: {
1483
	   				label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1484
	    		},
1485
				confirm: {
1486
					label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1487
				}
1488
			},
1489
			callback: function (result) {
1490
				if (result) {
1491
					objFormGenerator.deleteOption(slug_section, slug_question, slug);
157 geraldo 1492
					renderData(objFormGenerator.sections);
118 steven 1493
				}
1494
			}
1495
		});
1496
	})
1497
 
153 geraldo 1498
	$('#form-section #section-value').inputNumberFormat({'decimal' : 2});
118 steven 1499
 
153 geraldo 1500
	$('#form-question #question-value').inputNumberFormat({'decimal' : 2});
1501
	$('#form-question #question-max-length').inputNumberFormat({'decimal' : 0});
118 steven 1502
 
153 geraldo 1503
	$('#form-option #option-value').inputNumberFormat({'decimal' : 2});
118 steven 1504
 
153 geraldo 1505
	$('#form-question #question-type').change(function(e) {
118 steven 1506
		e.preventDefault();
1507
 
153 geraldo 1508
		if($('#form-question #question-type').val() == 'open') {
1509
			$('#form-question #question-max-length').parent().show();
1510
			$('#form-question #question-multiline').parent().show();
118 steven 1511
 
1512
		} else {
153 geraldo 1513
			$('#form-question #question-max-length').val('0');
1514
			$('#form-question #question-max-length').parent().hide();
118 steven 1515
 
153 geraldo 1516
			$('#form-question #question-multiline').val('0');
1517
			$('#form-question #question-multiline').parent().hide();
118 steven 1518
		}
1519
 
153 geraldo 1520
		$('#form-question #question-range').val('10');
1521
		if($('#form-question #question-type').val() == 'rating-range') {
1522
			$('#form-question #question-range').parent().show();
118 steven 1523
		} else {
153 geraldo 1524
			$('#form-question #question-range').parent().hide();
118 steven 1525
		}
1526
 
1527
 
1528
 
1529
	});
1530
 
1531
	$('button.btn-add-form').click(function(e) {
1532
		e.preventDefault();
1533
 
1534
		objFormGenerator.clear();
1535
		objFormGenerator.render();
1536
		validatorForm.resetForm();
1537
 
153 geraldo 1538
		$('#form-main #form-id').val('0');
1539
		$('#form-main #form-continue').val('0');
1540
		$('#form-main #form-name').val('');
118 steven 1541
 
1542
		instanceName = 'form-text';
1543
		let editor = CKEDITOR.instances[instanceName ];
1544
		editor.setData('', function() {
1545
		    editor.focus();
1546
		});
1547
 
1548
 
1549
		instanceName = 'form-description';
1550
		CKEDITOR.instances[instanceName ].setData('');
1551
 
153 geraldo 1552
		$('#form-main #form-language' ).val('$lang_es'),
1553
		$('#form-main #form-status' ).val('$status_inactive');
118 steven 1554
 
1555
		$('#row-forms').hide();
1556
		$('#row-edit').show();
153 geraldo 1557
		$('#form-main #form-name').focus();
118 steven 1558
 
1559
	});
1560
 
1561
	$('button.btn-edit-cancel').click(function(e) {
1562
		e.preventDefault();
1563
		$('#row-edit').hide();
1564
		$('#row-forms').show();
1565
 
1566
	});
1567
 
1568
 
1569
	$('button.btn-form-save-continue').click(function(e) {
1570
		e.preventDefault();
153 geraldo 1571
		$('#form-main #form-continue').val('1')
1572
		$('#form-main').submit();
118 steven 1573
	});
1574
 
1575
	$('button.btn-form-save-close').click(function(e) {
1576
		e.preventDefault();
153 geraldo 1577
		$('#form-main #form-continue').val('0')
1578
		$('#form-main').submit();
118 steven 1579
 
1580
	});
1581
 
1582
	$('#modal-section, #modal-question, #modal-option').modal({
1583
			backdrop: 'static',
1584
			keyboard: false,
1585
			show: false
1586
		});
1587
	});
1588
JS;
115 efrain 1589
$this->inlineScript()->captureEnd();
1590
?>
118 steven 1591
 
121 steven 1592
<style type="text/css">
135 geraldo 1593
    tbody input[type="checkbox"]{
1594
        margin-left: 14px;
1595
    }
1596
    .panel-heading .accordion-toggle:after {
1597
        /* symbol for "opening" panels */
1598
        display: inline-block;
1599
        font: normal normal normal 14px/1 FontAwesome;
1600
        font-size: inherit;
1601
        content: "\f077" ;
1602
        float: right;        /* adjust as needed */
1603
        color: grey;         /* adjust as needed */
1604
        text-rendering: auto;
1605
        -webkit-font-smoothing: antialiased;
1606
    }
1607
    .panel-heading .accordion-toggle.collapsed:after {
1608
        /* symbol for "collapsed" panels */
1609
        content: "\f078";    /* adjust as needed, taken from bootstrap.css */
1610
    }
121 steven 1611
</style>
115 efrain 1612
<!-- Content Header (Page header) -->
1613
<section class="content-header">
135 geraldo 1614
    <div class="container-fluid">
1615
        <div class="row mb-2">
1616
            <div class="col-sm-12">
1617
                <h1>LABEL_SELF_EVALUATION_FORMS</h1>
1618
            </div>
1619
        </div>
145 geraldo 1620
    </div>
1621
    <!-- /.container-fluid -->
115 efrain 1622
</section>
1623
<section class="content">
135 geraldo 1624
    <div class="container-fluid" id="row-forms">
1625
        <div class="row">
1626
            <div class="col-12">
145 geraldo 1627
                <div class="card">
135 geraldo 1628
                    <div class="card-body">
153 geraldo 1629
                        <table id="gridTable" class="table   table-hover">
1630
                            <thead>
1631
                                <tr>
1632
                                    <th>LABEL_NAME</th>
1633
                                    <th>LABEL_LANGUAGE</th>
1634
                                    <th>LABEL_ACTIVE</th>
1635
                                    <th>LABEL_ACTIONS</th>
1636
                                </tr>
1637
                            </thead>
155 geraldo 1638
                            <tbody></tbody>
153 geraldo 1639
                        </table>
135 geraldo 1640
                    </div>
1641
                    <div class="card-footer clearfix">
1642
                        <div style="float:right;">
1643
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
1644
                            <?php if ($allowAdd) : ?>
1645
                                <button type="button" class="btn btn-primary btn-add-form"><i class="fa fa-plus"></i> LABEL_ADD </button>
1646
                            <?php endif; ?>
1647
                        </div>
1648
                    </div>
1649
                </div>
145 geraldo 1650
            </div>
1651
        </div>
135 geraldo 1652
    </div>
154 geraldo 1653
 
155 geraldo 1654
    <!-- Create/Edit Form -->
154 geraldo 1655
    <?php echo $this->partial('modals/forms.phtml',  array(
1656
		'status_inactive' => $status_inactive,
1657
		'status_active' => $status_active,
1658
		'lang_es'=>$lang_es,
1659
		'lang_en'=>$lang_en
1660
		)) ;?>
155 geraldo 1661
    <!-- Create/Edit Form-->
154 geraldo 1662
 
135 geraldo 1663
    <!-- Modals -->
153 geraldo 1664
 
135 geraldo 1665
    <!-- Section Modal -->
153 geraldo 1666
    <?php echo $this->partial('modals/sections.phtml') ;?>
135 geraldo 1667
    <!-- End Modal Section -->
153 geraldo 1668
 
135 geraldo 1669
    <!-- Question Modal -->
156 geraldo 1670
 
153 geraldo 1671
	<?php echo $this->partial('modals/questions.phtml') ;?>
156 geraldo 1672
 
153 geraldo 1673
	<!-- End Modal Question -->
1674
 
1675
    <!-- Modal Options -->
156 geraldo 1676
 
153 geraldo 1677
	<?php echo $this->partial('modals/options.phtml') ;?>
135 geraldo 1678
    <!-- End Modal Options -->
153 geraldo 1679
 
135 geraldo 1680
    <!-- End Modals -->
153 geraldo 1681
 
119 steven 1682
</section>