Proyectos de Subversion LeadersLinked - Backend

Rev

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