Proyectos de Subversion LeadersLinked - Backend

Rev

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