Proyectos de Subversion LeadersLinked - Backend

Rev

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