Proyectos de Subversion LeadersLinked - Backend

Rev

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