Proyectos de Subversion LeadersLinked - Backend

Rev

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