Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 157 | Rev 159 | 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 = [];
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
				{
157 geraldo 86
					if(section_slug !=  this.sections[i].slug_section) {
118 steven 87
						continue;
88
					}
89
 
90
					$('span.section-name' + section_slug).html(this.sections[i].name);
91
 
157 geraldo 92
					let table = 'table-section-question-option' + this.sections[i].slug_section;
118 steven 93
					$('#' + table  + ' tbody').empty();
94
 
157 geraldo 95
					s = '<tr class="tr-section" data-slug="' + this.sections[i].slug_section + '">';
136 geraldo 96
					s = s  + '<td class="text-left">LABEL_SECTION</td>';
118 steven 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>';
157 geraldo 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';
118 steven 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
 
157 geraldo 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);
118 steven 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(
157 geraldo 133
									this.sections[i].slug_section,
134
									this.sections[i].questions[j].slug_question,
118 steven 135
									this.sections[i].questions[j].type,
157 geraldo 136
									this.sections[i].questions[j].options[k].slug_option,
118 steven 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';
136 geraldo 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';
118 steven 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
 
157 geraldo 284
					this.drawSection(this.sections[i].slug_section, this.sections[i].name, this.sections[i].value);
118 steven 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
 
157 geraldo 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);
118 steven 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(
157 geraldo 321
									this.sections[i].slug_section,
322
									this.sections[i].questions[j].slug_question,
118 steven 323
									this.sections[i].questions[j].type,
157 geraldo 324
									this.sections[i].questions[j].options[k].slug_option,
118 steven 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
 
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
				}
364
 
365
				this.sections.push(section);
366
				this.drawSection(slug, name, text);
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
				}
382
				if(renderTable) {
383
					this.renderSection(slug);
384
				}
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();
409
				var slug = 'question' + d.getTime();
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 = {
157 geraldo 424
							'slug_question' : slug,
118 steven 425
								'text' : text,
426
								'value' : value,
427
								'type' : type,
428
								'position' : position,
429
								'maxlength' :maxlength,
430
								'multiline' : multiline,
431
								'range' : range,
432
								'options' : [],
433
							}
434
						this.sections[i].questions.push(question);
435
						renderTable = true;
436
						break;
437
					}
438
				}
439
 
440
				if(renderTable) {
441
					this.renderSection(section_slug);
442
				}
443
			},
444
			this.editQuestion = function(section_slug, question_slug, text, value, type, maxlength, multiline, range)
445
			{
446
				var renderTable = false;
447
				for(i = 0; i < this.sections.length; i++)
448
				{
157 geraldo 449
					if(section_slug == this.sections[i].slug_section) {
118 steven 450
						for(j = 0; j < this.sections[i].questions.length; j++) {
157 geraldo 451
							if(question_slug == this.sections[i].questions[j].slug_question) {
118 steven 452
								this.sections[i].questions[j].text 	= text,
453
								this.sections[i].questions[j].value	= value,
454
								this.sections[i].questions[j].type 	= type;
455
 
456
								if(type == 'open') {
457
									this.sections[i].questions[j].maxlength	= maxlength;
458
									this.sections[i].questions[j].multiline	= multiline;
459
									this.sections[i].questions[j].options	= [];
460
								} else {
461
									this.sections[i].questions[j].maxlength	= 0;
462
									this.sections[i].questions[j].multiline	= 0;
463
								}
464
 
465
									if(type == 'rating-range') {
466
										this.sections[i].questions[j].range = range;
467
									} else {
468
										this.sections[i].questions[j].range = 0;
469
									}
470
								renderTable = true;
471
								break;
472
							}
473
						}
474
					}
475
					if(renderTable) {
476
						break;
477
					}
478
				}
479
				if(renderTable) {
480
					this.renderSection(section_slug);
481
				}
482
			},
483
			this.deleteQuestion = function(section_slug, question_slug)
484
			{
485
				var renderTable = false;
486
				for(i = 0; i < this.sections.length; i++)
487
				{
157 geraldo 488
						if(section_slug == this.sections[i].slug_section) {
118 steven 489
							for(j = 0; j < this.sections[i].questions.length; j++) {
157 geraldo 490
							if(question_slug == this.sections[i].questions[j].slug_question) {
118 steven 491
									this.sections[i].questions.splice(j, 1);
492
										renderTable = true;
493
										break;
494
							}
495
						}
496
					}
497
 
498
					if(renderTable) {
499
						break;
500
					}
501
				}
502
				if(renderTable) {
503
					this.renderSection(section_slug);
504
				}
505
			},
506
			this.addOption = function (section_slug, question_slug, text, correct, value)
507
			{
508
				var d = new Date();
509
				var slug = 'option' + d.getTime();
510
 
511
				var position = 0;
512
				var renderTable = false;
513
				for(i = 0; i < this.sections.length; i++)
514
				{
157 geraldo 515
					if(section_slug == this.sections[i].slug_section) {
118 steven 516
						for(j = 0; j < this.sections[i].questions.length; j++) {
157 geraldo 517
							if(question_slug == this.sections[i].questions[j].slug_question) {
118 steven 518
								$.each(this.sections[i].questions[j].options, function(index, option) {
519
										if(position < option.position) {
520
											position = option.position;
521
										}
522
									});
523
									position++;
524
 
525
									var option = {
157 geraldo 526
										'slug_option' : slug,
118 steven 527
											'text' : text,
528
											'correct' : correct,
529
											'value' : value
530
										}
531
 
532
										this.sections[i].questions[j].options.push(option);
533
									renderTable = true;
534
									break;
535
							}
536
 
537
									if(renderTable) {
538
								break;
539
							}
540
						}
541
					}
542
				}
543
				if(renderTable) {
544
					this.renderSection(section_slug);
545
				}
546
			},
547
			this.editOption = function(section_slug, question_slug, option_slug, text, correct, value)
548
			{
549
				var renderTable = false;
550
				for(i = 0; i < this.sections.length; i++)
551
				{
157 geraldo 552
					if(section_slug == this.sections[i].slug_section) {
118 steven 553
						for(j = 0; j < this.sections[i].questions.length; j++) {
157 geraldo 554
							if(question_slug == this.sections[i].questions[j].slug_question) {
118 steven 555
								for(k = 0; k < this.sections[i].questions[j].options.length; k++) {
157 geraldo 556
									if(option_slug == this.sections[i].questions[j].options[k].slug_option) {
118 steven 557
										this.sections[i].questions[j].options[k].text = text;
558
										this.sections[i].questions[j].options[k].correct = correct;
559
										this.sections[i].questions[j].options[k].value = value;
560
										renderTable = true;
561
												break;
562
									}
563
								}
564
							}
565
									if(renderTable) {
566
								break;
567
							}
568
						}
569
					}
570
						if(renderTable) {
571
							break;
572
						}
573
				}
574
 
575
				if(renderTable) {
576
					this.renderSection(section_slug);
577
				}
578
			},
579
			this.deleteOption = function(section_slug, question_slug, option_slug)
580
			{
581
				var renderTable = false;
582
				for(i = 0; i < this.sections.length; i++)
583
				{
157 geraldo 584
						if(section_slug == this.sections[i].slug_section) {
118 steven 585
							for(j = 0; j < this.sections[i].questions.length; j++) {
157 geraldo 586
							if(question_slug == this.sections[i].questions[j].slug_question) {
118 steven 587
								for(k = 0; k < this.sections[i].questions[j].options.length; k++) {
157 geraldo 588
									if(option_slug == this.sections[i].questions[j].options[k].slug_option) {
118 steven 589
										this.sections[i].questions[j].options.splice(k, 1);
590
										renderTable = true;
591
												break;
592
									}
593
								}
594
							}
595
									if(renderTable) {
596
								break;
597
							}
598
						}
599
					}
600
 
601
					if(renderTable) {
602
						break;
603
					}
604
				}
605
				if(renderTable) {
606
					this.renderSection(section_slug);
607
				}
608
			}
609
		}
610
 
611
		function htmlEntities(str) {
612
				return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
613
		}
614
    jQuery( document ).ready(function( $ ) {
615
			var objFormGenerator = new classFormGenerator();
616
	objFormGenerator.render();
122 steven 617
	var allowEdit   = $allowEdit;
618
	var allowDelete = $allowDelete;
146 geraldo 619
 
122 steven 620
	var tableForm = $('#gridTable').dataTable( {
621
			'processing': true,
622
			'serverSide': true,
623
			'searching': true,
624
			'order': [[ 0, 'asc' ]],
625
			'ordering':  true,
626
			'ordenable' : true,
627
			'responsive': true,
628
			'select' : false,
629
			'paging': true,
630
			'pagingType': 'simple_numbers',
631
			'ajax': {
632
				'url' : '$routeDatatable',
633
				'type' : 'get',
634
				'beforeSend': function (request) {
635
						NProgress.start();
636
				},
637
				'dataFilter': function(response) {
638
						var response = jQuery.parseJSON( response );
639
 
640
						var json                = {};
641
						json.recordsTotal       = 0;
642
						json.recordsFiltered    = 0;
643
						json.data               = [];
644
 
645
 
646
						if(response.success) {
647
								json.recordsTotal       = response.data.total;
648
								json.recordsFiltered    = response.data.total;
649
								json.data               = response.data.items;
146 geraldo 650
 
122 steven 651
						} else {
652
								$.fn.showError(response.data)
653
						}
654
 
655
						return JSON.stringify( json );
656
				}
657
			},
658
			'language' : {
659
					'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
660
					'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
661
					'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
662
					'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
663
					'sInfo':           'LABEL_DATATABLE_SINFO',
664
					'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
665
					'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
666
					'sInfoPostFix':    '',
667
					'sSearch':         'LABEL_DATATABLE_SSEARCH',
668
					'sUrl':            '',
669
					'sInfoThousands':  ',',
670
					'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
671
					'oPaginate': {
672
							'sFirst':    'LABEL_DATATABLE_SFIRST',
673
							'sLast':     'LABEL_DATATABLE_SLAST',
674
							'sNext':     'LABEL_DATATABLE_SNEXT',
675
							'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
676
					},
677
					'oAria': {
678
							'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
679
							'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
680
					},
681
			},
682
			'drawCallback': function( settings ) {
683
					NProgress.done();
684
					$('button.btn-delete').confirmation({
685
							rootSelector: 'button.btn-delete',
686
							title : 'LABEL_ARE_YOU_SURE',
687
							singleton : true,
688
							btnOkLabel: 'LABEL_YES',
689
							btnCancelLabel: 'LABEL_NO',
690
							onConfirm: function(value) {
691
									action = $(this).data('href');
692
									NProgress.start();
693
									$.ajax({
694
											'dataType'  : 'json',
695
											'accept'    : 'application/json',
696
											'method'    : 'post',
697
											'url'       :  action,
698
									}).done(function(response) {
699
											if(response['success']) {
700
													$.fn.showSuccess(response['data']);
153 geraldo 701
													gridTable.api().ajax.reload(null, false);
122 steven 702
											} else {
703
													$.fn.showError(response['data']);
704
											}
705
									}).fail(function( jqXHR, textStatus, errorThrown) {
706
											$.fn.showError(textStatus);
707
									}).always(function() {
708
											NProgress.done();
709
									});
710
							},
711
					});
712
			},
713
			'aoColumns': [
714
					{ 'mDataProp': 'name' },
715
				{ 'mDataProp': 'language'},
716
					{ 'mDataProp': 'status' },
717
					{ 'mDataProp': 'actions' },
718
		],
719
			'columnDefs': [
720
					{
721
							'targets': 0,
722
							'className' : 'text-vertical-middle',
723
					},
724
					{
725
							'targets': 1,
726
							'className' : 'text-vertical-middle',
727
					},
728
					{
729
							'targets': -2,
730
							'orderable': false,
731
							'className' : 'text-center',
732
								'render' : function ( data, type, row ) {
733
 
734
									checked = data == 'a' ? ' checked="checked" ' : '';
735
									return '<div class="checkbox checkbox-success">' +
736
											'<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
737
											'<label ></label></div>';
738
							}
739
					},
740
					{
741
							'targets': -1,
742
							'orderable': false,
743
							'render' : function ( data, type, row ) {
744
									s = '';
745
 
746
									if(allowEdit) {
123 steven 747
											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 748
									}
749
									if(allowDelete) {
750
											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;';
751
									}
752
									return s;
753
							}
754
					}
755
				],
118 steven 756
	});
757
 
139 geraldo 758
 
118 steven 759
	$('body').on('click', 'a.btn-delete-form',function(e) {
760
		e.preventDefault();
761
		form_id =  $(this).data('id')
762
 
763
		bootbox.confirm({
764
		    title: "LABEL_DELETE LABEL_FORM",
138 geraldo 765
		    message: "LABEL_QUESTION_DELETE",
118 steven 766
		    buttons: {
767
		        cancel: {
768
		            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
769
		        },
770
		        confirm: {
771
		            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
772
		        }
773
		    },
774
		    callback: function (result) {
775
			    if(result) {
776
    		    	$.ajax({
777
    	                'dataType': 'json',
778
    	                'method': 'post',
779
    	                'url' :  'ajax.<?php echo $this->module; ?>.php?action=delete',
780
    	                'data' :{
781
    	                    'form-id' : form_id
782
    	                },
783
    	            }).done(function(response) {
784
 
785
    	                if(response['success']) {
786
    	                	$.fn.showSuccess(response['message']);
787
    	                	tableForm.fnDraw();
788
    	                } else {
141 geraldo 789
    	                	$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
118 steven 790
    	                }
791
    	            }).fail(function( jqXHR, textStatus, errorThrown) {
792
    					$.fn.showError(textStatus);
793
    	            });
794
			    }
795
		    }
796
		});
797
 
798
 
799
    });
800
 
801
    $(document).on('click','[data-action="delete"]',function(){
802
 
803
    	bootbox.confirm({
804
		    title: "LABEL_DELETE LABEL_FORMS_2",
138 geraldo 805
		    message: "LABEL_QUESTION_DELETE",
118 steven 806
		    buttons: {
807
		        cancel: {
808
		            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
809
		        },
810
		        confirm: {
811
		            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
812
		        }
813
		    },
814
		    callback: function (result) {
815
			    if(result) {
816
			    	var d = currentSelected();
817
    		    	$.ajax({
818
    	                'dataType': 'json',
819
    	                'method': 'post',
820
    	                'url' :  'ajax.<?php echo $this->module; ?>.php?action=delete-selected',
821
    	                'data' :{
822
    	                	 selected : d
823
    	                },
824
    	            }).done(function(response) {
825
 
826
    	                if(response['success']) {
827
    	                	$.fn.showSuccess(response['message']);
828
    	                	tableForm.fnDraw();
829
    	                } else {
141 geraldo 830
    	                	$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
118 steven 831
    	                }
832
    	            }).fail(function( jqXHR, textStatus, errorThrown) {
833
    					$.fn.showError(textStatus);
834
    	            });
835
			    }
836
		    }
837
		});
838
 
839
    });
840
 
841
 
842
    $('body').on('switch-change', 'input[type="checkbox"].make-switch-form', function(e) {
843
		e.preventDefault();
844
		e.stopPropagation();
845
 
846
		form_id =  $(this).data('id')
847
		form_status = $(this).prop('checked') ? 'A' : 'D';
848
 
849
		$.ajax({
850
        	'dataType': 'json',
851
            'method': 'post',
852
            'url' :  'ajax.<?php echo $this->module; ?>.php?action=status',
853
            'data' :{
854
            	'form-id' : form_id,
855
            	'form-status' : form_status
856
            },
857
        }).done(function(response) {
858
	        if(response['success']) {
859
	        	$.fn.showSuccess(response['message']);
860
	       } else {
141 geraldo 861
    	       	$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
118 steven 862
            }
863
         }).fail(function( jqXHR, textStatus, errorThrown) {
864
			$.fn.showError(textStatus);
865
        })
866
    });
867
 
124 steven 868
	$('body').on('click', 'button.btn-edit-form',function(e) {
118 steven 869
		e.preventDefault();
870
		form_id =  $(this).data('id')
125 steven 871
    var action = $(this).data('href');
118 steven 872
		$.ajax({
125 steven 873
			'dataType'  : 'json',
874
			'accept'    : 'application/json',
875
			'method'    : 'get',
876
			'url'       :  action,
118 steven 877
		}).done(function(response) {
878
			if(response['success']) {
879
					validatorForm.resetForm();
880
 
153 geraldo 881
					$('#form-main #form-id' ).val(response['id']),
882
					$('#form-main #form-continue').val('0');
883
					$('#form-main #form-name' ).val(response['name']),
118 steven 884
 
885
 
886
					instanceName = 'form-description';
887
					let editor = CKEDITOR.instances[instanceName ];
888
					editor.setData(response['description'], function() {
889
							editor.focus();
890
					});
891
 
892
 
893
					instanceName = 'form-text';
894
					CKEDITOR.instances[instanceName ].setData(response['text']);
895
 
153 geraldo 896
					$('#form-main #form-language' ).val(response['language']),
897
					$('#form-main #form-status' ).val(response['status']);
118 steven 898
 
899
					objFormGenerator.clear();
126 steven 900
					objFormGenerator.sections = response['sections'] || [];
118 steven 901
					objFormGenerator.render();
902
					$('#row-forms').hide();
903
					$('#row-edit').show();
904
 
153 geraldo 905
					$('#form-main #form-name').focus();
118 steven 906
 
907
				} else {
141 geraldo 908
					$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
118 steven 909
				}
910
			}).fail(function( jqXHR, textStatus, errorThrown) {
911
				$.fn.showError(textStatus);
912
			});
913
    });
914
 
915
	 $(document).on('click','[data-type="select_all"]',function(){
916
 
917
	        if($('input[name="select_all"]:checked').val() == 'all'){
918
	            $('[data-type="select"]').prop('checked', true);
919
	            $('[data-action="delete"]').removeClass('hide');
920
	        }else{
921
	            $('[data-type="select"]').prop('checked', false);
922
	            $('[data-action="delete"]').addClass('hide');
923
	        }
924
	    });
925
 
926
	    function getLength(){
927
	        return $('[data-type="select"]').length;
928
	    }
929
 
930
	    function currentSelected(){
931
	        var selected = [];
932
	        $.each($("input[name='select[]']:checked"), function(){
933
	            selected.push($(this).val());
934
	        });
935
 
936
	        return selected;
937
	    }
938
 
939
	    $(document).on('change',"input[name='select[]']",function(){
940
	        var c = currentSelected();
941
	        var cc = getLength();
942
 
943
 
944
	        if(c.length == cc){
945
	            if($('[data-action="delete"]').hasClass('hide')){
946
	                $('[data-action="delete"]').removeClass('hide');
947
	            }
948
	            return true;
949
	        }else{
950
	            $('input[name="select_all"]').prop('checked', false);
951
	        }
952
 
953
	        if(c.length > 0){
954
	            if($('[data-action="delete"]').hasClass('hide')){
955
	                $('[data-action="delete"]').removeClass('hide');
956
	            }
957
	        }else{
958
	            if(!$('[data-action="delete"]').hasClass('hide')){
959
	                $('[data-action="delete"]').addClass('hide');
960
	            }
961
	        }
962
	    });
963
 
964
	    var form3 = $('#form_sample_3');
965
        var error3 = $('.alert-danger', form3);
966
        var success3 = $('.alert-success', form3);
967
 
968
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
153 geraldo 969
 	$( "#form-main" ).on('submit', function() {
118 steven 970
		for(var instanceName in CKEDITOR.instances) {
971
			CKEDITOR.instances[instanceName].updateElement();
972
		}
973
	})
974
 
153 geraldo 975
	var validatorForm = $( "#form-main" ).validate( {
118 steven 976
        ignore: [],
977
        errorClass: 'help-block',
978
        errorElement: 'span',
979
		rules: {
980
			'form-name':  {
981
				required: true,
982
				minlength: 2,
983
				maxlength: 50
984
			},
985
			'form-description' : {
986
				required: true,
987
			},
988
			'form-text' : {
989
				required: true,
990
			},
991
			'form-language' : {
992
				required: true,
993
			},
994
			'forrm-status' : {
995
				required: true,
996
			},
997
		},
998
        highlight: function (element) {
999
            $(element).closest('.form-group').addClass('has-error');
1000
        },
1001
        unhighlight: function (element) {
1002
            $(element).closest('.form-group').removeClass('has-error');
1003
        },
1004
        errorPlacement: function (error, element) {
1005
            if (element.attr("data-error-container")) {
1006
                error.appendTo(element.attr("data-error-container"));
1007
            } else {
1008
                error.insertAfter(element);
1009
            }
1010
        },
1011
        invalidHandler: function(form, validator) {
1012
            if (!validator.numberOfInvalids())
1013
                return;
1014
            $('html, body').animate({
1015
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1016
            }, 1000);
1017
        },
1018
		submitHandler: function(form) {
140 geraldo 1019
 
118 steven 1020
		    var error = false;
1021
		    if(objFormGenerator.sections.length == 0) {
142 geraldo 1022
		    	$.fn.showError('ERROR_SECCTIONS');
118 steven 1023
		    	error = true;
1024
		    } else {
1025
 
1026
		    	for(i = 0; i < objFormGenerator.sections.length; i++)
1027
		    	{
1028
 
1029
		    		if(objFormGenerator.sections[i].questions.length == 0) {
143 geraldo 1030
		    			$.fn.showError('ERROR_QUESTIONS'.replace('%s', objFormGenerator.sections[i].name ));
118 steven 1031
		    			break;
1032
		    		}
1033
 
1034
		    		var valueSection = parseInt(objFormGenerator.sections[i].value);
1035
		    		var totalValueQuestion = 0;
1036
 
1037
 
1038
		    		for(j = 0; j < objFormGenerator.sections[i].questions.length; j++)
1039
		    		{
1040
		    			valueQuestion = parseInt(objFormGenerator.sections[i].questions[j].value);
1041
		    			totalValueQuestion = totalValueQuestion + valueQuestion;
1042
		    			if(objFormGenerator.sections[i].questions[j].type == 'simple'
1043
			    			|| objFormGenerator.sections[i].questions[j].type == 'multiple'
1044
			    			|| objFormGenerator.sections[i].questions[j].type == 'rating-open' ) {
1045
 
1046
		    				var questionNumber = j + 1;
1047
		    				var numberCorrect = 0;
1048
 
1049
 
1050
		    				if(objFormGenerator.sections[i].questions[j].options.length == 0) {
139 geraldo 1051
 
143 geraldo 1052
								$.fn.showError('ERROR_OPTIONS'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
139 geraldo 1053
								error = true;
154 geraldo 1054
								return false;
118 steven 1055
									break;
1056
		    				}
1057
 
1058
		    				var totalOption = 0;
1059
		    				var maxOption = 0;
1060
		    				for(k = 0;  k < objFormGenerator.sections[i].questions[j].options.length; k++)
1061
		    				{
1062
		    					if(objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple' ) {
1063
    		    					if(objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
1064
    		    						numberCorrect++;
1065
    		    					}
1066
		    					}
1067
 
1068
		    					if(objFormGenerator.sections[i].questions[j].type == 'multiple' && objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
1069
		    						totalOption = totalOption + parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
1070
			    				}
1071
 
1072
		    					if(objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1073
		    						if(parseInt(objFormGenerator.sections[i].questions[j].options[k].value) > maxOption) {
1074
											maxOption = parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
1075
					    			}
1076
			    				}
1077
 
1078
		    				}
1079
 
1080
		    				if(objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple' ) {
1081
 
1082
    		    				if(numberCorrect == 0) {
143 geraldo 1083
    		    					$.fn.showError('ERROR_OPTIONS_CORRECT'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 1084
    		    					error = true;
154 geraldo 1085
									return false;
118 steven 1086
    		    					break;
1087
    		    				}
1088
    		    				if(objFormGenerator.sections[i].questions[j].type == 'simple' && numberCorrect > 1) {
143 geraldo 1089
    		    					$.fn.showError('ERROR_OPTIONS_DUPLICATE_CORRECT'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 1090
    		    					error = true;
154 geraldo 1091
									return false;
118 steven 1092
    		    					break;
1093
    		    				}
1094
    		    				if(objFormGenerator.sections[i].questions[j].type == 'multiple' && numberCorrect == 1) {
143 geraldo 1095
    		    					$.fn.showError('ERROR_OPTIONS_ONE_CORRECT'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 1096
    		    					error = true;
154 geraldo 1097
									return false;
118 steven 1098
    		    					break;
1099
    		    				}
1100
		    				}
1101
 
1102
			 				if(objFormGenerator.sections[i].questions[j].type == 'multiple' && totalOption > valueQuestion ) {
139 geraldo 1103
 
143 geraldo 1104
								$.fn.showError('ERROR_OPTIONS_SUM_VALUES'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 1105
		    					error = true;
154 geraldo 1106
								return false;
118 steven 1107
		    					break;
1108
			    			}
1109
 
1110
		    				if(objFormGenerator.sections[i].questions[j].type == 'rating-open' && maxOption > valueQuestion ) {
143 geraldo 1111
								$.fn.showError('ERROR_OPTIONS_MAX_OPTION'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 1112
		    					error = true;
154 geraldo 1113
								return false;
118 steven 1114
		    					break;
1115
			    			}
1116
						}
1117
 
1118
		    		}
1119
 
1120
		    		if(valueSection != totalValueQuestion) {
143 geraldo 1121
		    			$.fn.showError('ERROR_VALUE_SECTIONS'.replace('%s', objFormGenerator.sections[i].name ));
118 steven 1122
		    			error = true;
154 geraldo 1123
						return false;
118 steven 1124
		    			break;
1125
					}
1126
				}
1127
 
1128
 
1129
 
1130
    			if(error) {
1131
    				return false;
1132
    			} else {
1133
 
1134
 
153 geraldo 1135
    				var formId		= parseInt($('#form-main #form-id' ).val());
1136
    				var formContinue = parseInt($('#form-main #form-continue' ).val());
118 steven 1137
 
1138
    				var data = {
143 geraldo 1139
    	    			'id'	: formId,
153 geraldo 1140
        				'name' : $('#form-main #form-name' ).val(),
1141
        				'description' : $('#form-main #form-description' ).val(),
1142
        				'text' : $('#form-main #form-text' ).val(),
1143
        				'language' : $('#form-main #form-language' ).val(),
1144
        				'status' : $('#form-main #form-status' ).val(),
118 steven 1145
        				'sections' : objFormGenerator.sections
1146
    				}
127 steven 1147
					$.ajax({
1148
						'dataType': 'json',
1149
						'method': 'post',
1150
						'url' :  '$routeAdd',
1151
						'data' : data,
1152
					}).done(function(response) {
1153
						if(response['success']) {
1154
							$.fn.showSuccess(response['message']);
118 steven 1155
							if(formContinue == 1) {
153 geraldo 1156
								$('#form-main #form-id').val(response['form-id']);
1157
								$('#form-main #form-continue').val(0);
118 steven 1158
							} else {
1159
								$('#row-edit').hide();
127 steven 1160
								$('#row-forms').show();
118 steven 1161
							}
1162
							tableForm.fnDraw();
127 steven 1163
						} else {
141 geraldo 1164
							$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
127 steven 1165
						}
1166
					}).fail(function( jqXHR, textStatus, errorThrown) {
118 steven 1167
						$.fn.showError(textStatus);
127 steven 1168
					});
1169
						return false;
118 steven 1170
    			}
1171
			}
1172
 
1173
 
1174
		}
1175
	});
1176
 
1177
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
153 geraldo 1178
 	$( "#form-section" ).on('submit', function() {
118 steven 1179
		for(var instanceName in CKEDITOR.instances) {
1180
			CKEDITOR.instances[instanceName].updateElement();
1181
		}
1182
	})
1183
 
153 geraldo 1184
	var validatorFormSection = $( "#form-section" ).validate( {
118 steven 1185
        ignore: [],
1186
        errorClass: 'help-block',
1187
        errorElement: 'span',
1188
		rules: {
1189
			'section-name':  {
1190
				required: true,
1191
				minlength: 2,
1192
				maxlength: 50
1193
			},
1194
			'section-text' : {
1195
				required: false,
1196
			},
1197
			'section-value' : {
1198
				required: true,
1199
				number: true,
1200
				min: 1
1201
			},
1202
		},
1203
        highlight: function (element) {
1204
            $(element).closest('.form-group').addClass('has-error');
1205
        },
1206
        unhighlight: function (element) {
1207
            $(element).closest('.form-group').removeClass('has-error');
1208
        },
1209
        errorPlacement: function (error, element) {
1210
            if (element.attr("data-error-container")) {
1211
                error.appendTo(element.attr("data-error-container"));
1212
            } else {
1213
                error.insertAfter(element);
1214
            }
1215
        },
1216
        invalidHandler: function(form, validator) {
1217
            if (!validator.numberOfInvalids())
1218
                return;
1219
            $('html, body').animate({
1220
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1221
            }, 1000);
1222
        },
1223
		submitHandler: function(form) {
1224
		    // do other things for a valid form
1225
		    //form.submit();
1226
 
153 geraldo 1227
		    var slug = $('#form-section #section-slug').val();
118 steven 1228
		    if(slug) {
1229
		    	objFormGenerator.editSection(
153 geraldo 1230
		    		$('#form-section #section-slug').val(),
1231
			    	$('#form-section #section-name').val(),
1232
			    	$('#form-section #section-text').val(),
1233
			    	$('#form-section #section-value').val()
118 steven 1234
			  	);
1235
		    } else {
1236
		    	objFormGenerator.addSection(
153 geraldo 1237
		    		$('#form-section #section-name').val(),
1238
		    		$('#form-section #section-text').val(),
1239
		    		$('#form-section #section-value').val()
118 steven 1240
		    	);
1241
		    }
1242
 
157 geraldo 1243
		    renderData(objFormGenerator.sections);
118 steven 1244
 
1245
			$('#modal-section').modal('hide');
1246
			return false;
1247
		  }
1248
	} );
1249
 
1250
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
153 geraldo 1251
 	$( "#form-question" ).on('submit', function() {
118 steven 1252
		for(var instanceName in CKEDITOR.instances) {
1253
			CKEDITOR.instances[instanceName].updateElement();
1254
		}
1255
	})
1256
 
1257
 
153 geraldo 1258
	var validatorFormQuestion = $( "#form-question" ).validate( {
118 steven 1259
        ignore: [],
1260
        errorClass: 'help-block',
1261
        errorElement: 'span',
1262
		rules: {
1263
			'question-text' : {
1264
				required: true,
1265
			},
1266
			'question-value' : {
1267
				required: true,
1268
				number: true,
1269
				min: 1
1270
			},
1271
			'question-type':  {
1272
				required: true,
1273
			},
1274
			'question-max-length' : {
1275
				required: true,
1276
				digits: true,
1277
				min: 0
1278
			},
1279
			'question-range' : {
1280
				required: true,
1281
				number: true,
1282
				min: 1
1283
			},
1284
		},
1285
        highlight: function (element) {
1286
            $(element).closest('.form-group').addClass('has-error');
1287
        },
1288
        unhighlight: function (element) {
1289
            $(element).closest('.form-group').removeClass('has-error');
1290
        },
1291
        errorPlacement: function (error, element) {
1292
            if (element.attr("data-error-container")) {
1293
                error.appendTo(element.attr("data-error-container"));
1294
            } else {
1295
                error.insertAfter(element);
1296
            }
1297
        },
1298
        invalidHandler: function(form, validator) {
1299
 
1300
 
1301
            if (!validator.numberOfInvalids())
1302
                return;
1303
            $('html, body').animate({
1304
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1305
            }, 1000);
1306
        },
1307
		submitHandler: function(form) {
1308
 
139 geraldo 1309
 
153 geraldo 1310
		    if($('#form-question #question-slug').val()) {
118 steven 1311
 
139 geraldo 1312
 
118 steven 1313
		    	objFormGenerator.editQuestion(
153 geraldo 1314
		    		$('#form-question #question-section').val(),
1315
		    		$('#form-question #question-slug').val(),
1316
		    		$('#form-question #question-text').val(),
1317
		    		$('#form-question #question-value').val(),
1318
			    	$('#form-question #question-type').val(),
1319
			    	$('#form-question #question-max-length').val(),
1320
	    			$('#form-question #question-multiline').val(),
1321
	    			$('#form-question #question-range').val()
118 steven 1322
			  	);
1323
		    } else {
1324
 
1325
		    	objFormGenerator.addQuestion(
153 geraldo 1326
			    	$('#form-question #question-section').val(),
1327
			    	$('#form-question #question-text').val(),
1328
			    	$('#form-question #question-value').val(),
1329
				    $('#form-question #question-type').val(),
1330
				    $('#form-question #question-max-length').val(),
1331
		    		$('#form-question #question-multiline').val(),
1332
		    		$('#form-question #question-range').val()
118 steven 1333
		    	);
1334
		    }
157 geraldo 1335
		    renderData(objFormGenerator.sections);
118 steven 1336
			$('#modal-question').modal('hide');
1337
			return false;
1338
		  }
1339
	} );
1340
 
1341
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
153 geraldo 1342
 	$( "#form-option" ).on('submit', function() {
118 steven 1343
		for(var instanceName in CKEDITOR.instances) {
1344
			CKEDITOR.instances[instanceName].updateElement();
1345
		}
1346
	})
1347
 
153 geraldo 1348
	var validatorFormOption = $( "#form-option" ).validate( {
118 steven 1349
        ignore: [],
1350
        errorClass: 'help-block',
1351
        errorElement: 'span',
1352
		rules: {
1353
			'option-text' : {
1354
				required: true,
1355
			},
1356
        	'option-value' : {
1357
				required: true,
1358
				number: true,
1359
				min: 1
1360
        	}
1361
		},
1362
        highlight: function (element) {
1363
            $(element).closest('.form-group').addClass('has-error');
1364
        },
1365
        unhighlight: function (element) {
1366
            $(element).closest('.form-group').removeClass('has-error');
1367
        },
1368
        errorPlacement: function (error, element) {
1369
            if (element.attr("data-error-container")) {
1370
                error.appendTo(element.attr("data-error-container"));
1371
            } else {
1372
                error.insertAfter(element);
1373
            }
1374
        },
1375
        invalidHandler: function(form, validator) {
1376
            if (!validator.numberOfInvalids())
1377
                return;
1378
            $('html, body').animate({
1379
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1380
            }, 1000);
1381
        },
1382
		submitHandler: function(form) {
1383
 
1384
 
153 geraldo 1385
		    if($('#form-option #option-slug').val()) {
118 steven 1386
		    	objFormGenerator.editOption(
153 geraldo 1387
		    		$('#form-option #option-section').val(),
1388
		    		$('#form-option #option-question').val(),
1389
		    		$('#form-option #option-slug').val(),
1390
		    		$('#form-option #option-text').val(),
1391
		    		$('#form-option #option-correct').val(),
1392
		    		$('#form-option #option-value').val()
118 steven 1393
			  	);
1394
		    } else {
1395
		    	objFormGenerator.addOption(
153 geraldo 1396
			    	$('#form-option #option-section').val(),
1397
			    	$('#form-option #option-question').val(),
1398
			    	$('#form-option #option-text').val(),
1399
			    	$('#form-option #option-correct').val(),
1400
			    	$('#form-option #option-value').val()
118 steven 1401
		    	);
1402
		    }
157 geraldo 1403
			renderData(objFormGenerator.sections);
118 steven 1404
			$('#modal-option').modal('hide');
1405
			return false;
1406
		  }
1407
	} );
1408
 
1409
	$('body').on('click', 'button[id="btn-add-section"]', function(e){
1410
		e.preventDefault();
1411
 
1412
		validatorFormSection.resetForm();
153 geraldo 1413
		$('#form-section #section-slug').val('');
1414
		$('#form-section #section-name').val('');
118 steven 1415
 
1416
		instanceName = 'section-text';
1417
		let editor = CKEDITOR.instances[instanceName ];
143 geraldo 1418
		editor.setData('', function() {
118 steven 1419
		    editor.focus();
1420
		});
1421
 
1422
 
153 geraldo 1423
		$('#form-section #section-value').val('0');
136 geraldo 1424
		$('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
118 steven 1425
		$('#modal-section').modal('show');
1426
	});
1427
 
1428
	$('body').on('click', 'button.btn-edit-section', function(e){
1429
	    e.preventDefault();
1430
 
1431
	    var slug = $(this).data('slug');
1432
	    var section;
1433
	    var showForm = false;
1434
 
1435
	    for(i = 0; i < objFormGenerator.sections.length; i++) {
1436
	        section = objFormGenerator.sections[i];
1437
 
1438
	    	if(slug == section.slug) {
1439
 
1440
				validatorFormSection.resetForm();
153 geraldo 1441
	    		$('#form-section #section-slug').val(section.slug);
1442
	    		$('#form-section #section-name').val(section.name);
118 steven 1443
 
1444
	    		instanceName = 'section-text';
1445
	    		let editor = CKEDITOR.instances[instanceName ];
1446
	    		editor.setData( section.text, function() {
1447
	    		    editor.focus();
1448
	    		});
1449
 
153 geraldo 1450
				$('#form-section #section-value').val(section.value);
156 geraldo 1451
 
157 geraldo 1452
 
118 steven 1453
				showForm = true;
1454
				break;
1455
	    	}
1456
	    }
1457
 
1458
	    if(showForm) {
136 geraldo 1459
	    	$('#modal-section h4[class="modal-title"]').html('LABEL_EDIT LABEL_SECTION');
118 steven 1460
			$('#modal-section').modal('show');
1461
	    }
1462
 
1463
	});
1464
 
1465
	$('body').on('click', 'button.btn-delete-section', function(e){
1466
		e.preventDefault();
1467
		var slug = $(this).data('slug');
1468
 
1469
		bootbox.confirm({
138 geraldo 1470
		    title: "LABEL_DELETE LABEL_SECTION",
1471
		    message: "LABEL_QUESTION_DELETE",
118 steven 1472
		    buttons: {
1473
		        cancel: {
1474
		            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1475
		        },
1476
		        confirm: {
1477
		            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1478
		        }
1479
		    },
1480
		    callback: function (result) {
1481
		    	if (result) {
1482
					objFormGenerator.deleteSection(slug);
157 geraldo 1483
					renderData(objFormGenerator.sections);
118 steven 1484
				}
1485
		    }
1486
		});
1487
 
1488
 
1489
 
1490
	});
1491
 
1492
 
1493
	$('body').on('click', 'button.btn-add-question', function(e){
1494
		e.preventDefault();
1495
 
1496
		validatorFormQuestion.resetForm();
1497
		var slug = $(this).data('slug');
1498
 
153 geraldo 1499
		$('#form-question #question-section').val(slug);
1500
		$('#form-question #question-slug').val('');
118 steven 1501
 
1502
		instanceName = 'question-text';
1503
		let editor = CKEDITOR.instances[instanceName ];
143 geraldo 1504
		editor.setData('', function() {
118 steven 1505
		    editor.focus();
1506
		});
1507
 
1508
 
153 geraldo 1509
		$('#form-question #question-value').val('0');
1510
		$('#form-question #question-type').val($('#form-question #question-type option:first').val());
118 steven 1511
 
153 geraldo 1512
		$('#form-question #question-max-length').val('0');
1513
		$('#form-question #question-max-length').parent().show();
118 steven 1514
 
153 geraldo 1515
		$('#form-question #question-multiline').val('0');
1516
		$('#form-question #question-multiline').parent().show();
118 steven 1517
 
153 geraldo 1518
		$('#form-question #question-range').val('10');
1519
		$('#form-question #question-range').parent().hide();
118 steven 1520
 
136 geraldo 1521
		$('#modal-question h4[class="modal-title"]').html('LABEL_ADD LABEL_QUESTION');
118 steven 1522
		$('#modal-question').modal('show');
1523
 
1524
	});
1525
 
1526
 
1527
 
1528
	$('body').on('click', 'button.btn-edit-question', function(e){
1529
	    e.preventDefault();
1530
 
1531
	    var slug_section	= $(this).data('section');
1532
	    var slug 			= $(this).data('slug');
1533
	    var showForm 		= false;
1534
 
1535
	    for(i = 0; i < objFormGenerator.sections.length; i++) {
1536
 
157 geraldo 1537
	    	if(slug_section == objFormGenerator.sections[i].slug_section) {
118 steven 1538
 
1539
	    		for(j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1540
 
157 geraldo 1541
	    			if(slug == objFormGenerator.sections[i].questions[j].slug_question) {
118 steven 1542
	    				validatorFormQuestion.resetForm();
1543
 
157 geraldo 1544
	    				$('#form-question #question-section').val(objFormGenerator.sections[i].slug_section);
1545
	    				$('#form-question #question-slug').val(objFormGenerator.sections[i].questions[j].slug_question);
118 steven 1546
 
1547
	    	    		instanceName = 'question-text';
1548
	    	    		let editor = CKEDITOR.instances[instanceName ];
1549
	    	    		editor.setData( objFormGenerator.sections[i].questions[j].text, function() {
1550
	    	    		    editor.focus();
1551
	    	    		});
1552
 
1553
 
153 geraldo 1554
	        			$('#form-question #question-value').val(objFormGenerator.sections[i].questions[j].value);
1555
	        			$('#form-question #question-type').val(objFormGenerator.sections[i].questions[j].type);
118 steven 1556
 
1557
 
1558
 
1559
	        			if(objFormGenerator.sections[i].questions[j].type == 'open') {
153 geraldo 1560
		        			$('#form-question #question-max-length').val(objFormGenerator.sections[i].questions[j].maxlength);
1561
		        			$('#form-question #question-max-length').parent().show();
118 steven 1562
 
153 geraldo 1563
		        			$('#form-question #question-multiline').val(objFormGenerator.sections[i].questions[j].multiline);
1564
							$('#form-question #question-multiline').parent().show();
118 steven 1565
	        			} else {
153 geraldo 1566
		        			$('#form-question #question-max-length').val('0');
1567
		        			$('#form-question #question-max-length').parent().hide();
118 steven 1568
 
153 geraldo 1569
		        			$('#form-question #question-multiline').val('0');
1570
							$('#form-question #question-multiline').parent().hide();
118 steven 1571
	        			}
1572
 
1573
	        			if(objFormGenerator.sections[i].questions[j].type == 'rating-range') {
153 geraldo 1574
	            			$('#form-question #question-range').val(objFormGenerator.sections[i].questions[j].range);
1575
		        			$('#form-question #question-range').parent().show();
118 steven 1576
 
1577
	        			} else {
153 geraldo 1578
	            			$('#form-question #question-range').val('10');
1579
		        			$('#form-question #question-range').parent().hide();
118 steven 1580
		        		}
1581
 
156 geraldo 1582
						console.log(objFormGenerator);
1583
 
118 steven 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
	 */
1688
	//const renderData = (data) => $("#rows").html($("#sectionTemplate").render(data));
1689
 
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>