Proyectos de Subversion LeadersLinked - Backend

Rev

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