Proyectos de Subversion LeadersLinked - Backend

Rev

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