Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 151 | Rev 153 | 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
											} else {
710
													$.fn.showError(response['data']);
711
											}
712
									}).fail(function( jqXHR, textStatus, errorThrown) {
713
											$.fn.showError(textStatus);
714
									}).always(function() {
715
											NProgress.done();
716
									});
717
							},
718
					});
719
			},
720
			'aoColumns': [
721
					{ 'mDataProp': 'name' },
722
				{ 'mDataProp': 'language'},
723
					{ 'mDataProp': 'status' },
724
					{ 'mDataProp': 'actions' },
725
		],
726
			'columnDefs': [
727
					{
728
							'targets': 0,
729
							'className' : 'text-vertical-middle',
730
					},
731
					{
732
							'targets': 1,
733
							'className' : 'text-vertical-middle',
734
					},
735
					{
736
							'targets': -2,
737
							'orderable': false,
738
							'className' : 'text-center',
739
								'render' : function ( data, type, row ) {
740
 
741
									checked = data == 'a' ? ' checked="checked" ' : '';
742
									return '<div class="checkbox checkbox-success">' +
743
											'<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
744
											'<label ></label></div>';
745
							}
746
					},
747
					{
748
							'targets': -1,
749
							'orderable': false,
750
							'render' : function ( data, type, row ) {
751
									s = '';
752
 
753
									if(allowEdit) {
123 steven 754
											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 755
									}
756
									if(allowDelete) {
757
											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;';
758
									}
759
									return s;
760
							}
761
					}
762
				],
118 steven 763
	});
764
 
139 geraldo 765
 
118 steven 766
	$('body').on('click', 'a.btn-delete-form',function(e) {
767
		e.preventDefault();
768
		form_id =  $(this).data('id')
769
 
770
		bootbox.confirm({
771
		    title: "LABEL_DELETE LABEL_FORM",
138 geraldo 772
		    message: "LABEL_QUESTION_DELETE",
118 steven 773
		    buttons: {
774
		        cancel: {
775
		            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
776
		        },
777
		        confirm: {
778
		            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
779
		        }
780
		    },
781
		    callback: function (result) {
782
			    if(result) {
783
    		    	$.ajax({
784
    	                'dataType': 'json',
785
    	                'method': 'post',
786
    	                'url' :  'ajax.<?php echo $this->module; ?>.php?action=delete',
787
    	                'data' :{
788
    	                    'form-id' : form_id
789
    	                },
790
    	            }).done(function(response) {
791
 
792
    	                if(response['success']) {
793
    	                	$.fn.showSuccess(response['message']);
794
    	                	tableForm.fnDraw();
795
    	                } else {
141 geraldo 796
    	                	$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
118 steven 797
    	                }
798
    	            }).fail(function( jqXHR, textStatus, errorThrown) {
799
    					$.fn.showError(textStatus);
800
    	            });
801
			    }
802
		    }
803
		});
804
 
805
 
806
    });
807
 
808
    $(document).on('click','[data-action="delete"]',function(){
809
 
810
    	bootbox.confirm({
811
		    title: "LABEL_DELETE LABEL_FORMS_2",
138 geraldo 812
		    message: "LABEL_QUESTION_DELETE",
118 steven 813
		    buttons: {
814
		        cancel: {
815
		            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
816
		        },
817
		        confirm: {
818
		            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
819
		        }
820
		    },
821
		    callback: function (result) {
822
			    if(result) {
823
			    	var d = currentSelected();
824
    		    	$.ajax({
825
    	                'dataType': 'json',
826
    	                'method': 'post',
827
    	                'url' :  'ajax.<?php echo $this->module; ?>.php?action=delete-selected',
828
    	                'data' :{
829
    	                	 selected : d
830
    	                },
831
    	            }).done(function(response) {
832
 
833
    	                if(response['success']) {
834
    	                	$.fn.showSuccess(response['message']);
835
    	                	tableForm.fnDraw();
836
    	                } else {
141 geraldo 837
    	                	$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
118 steven 838
    	                }
839
    	            }).fail(function( jqXHR, textStatus, errorThrown) {
840
    					$.fn.showError(textStatus);
841
    	            });
842
			    }
843
		    }
844
		});
845
 
846
    });
847
 
848
 
849
    $('body').on('switch-change', 'input[type="checkbox"].make-switch-form', function(e) {
850
		e.preventDefault();
851
		e.stopPropagation();
852
 
853
		form_id =  $(this).data('id')
854
		form_status = $(this).prop('checked') ? 'A' : 'D';
855
 
856
		$.ajax({
857
        	'dataType': 'json',
858
            'method': 'post',
859
            'url' :  'ajax.<?php echo $this->module; ?>.php?action=status',
860
            'data' :{
861
            	'form-id' : form_id,
862
            	'form-status' : form_status
863
            },
864
        }).done(function(response) {
865
	        if(response['success']) {
866
	        	$.fn.showSuccess(response['message']);
867
	       } else {
141 geraldo 868
    	       	$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
118 steven 869
            }
870
         }).fail(function( jqXHR, textStatus, errorThrown) {
871
			$.fn.showError(textStatus);
872
        })
873
    });
874
 
124 steven 875
	$('body').on('click', 'button.btn-edit-form',function(e) {
118 steven 876
		e.preventDefault();
877
		form_id =  $(this).data('id')
125 steven 878
    var action = $(this).data('href');
118 steven 879
		$.ajax({
125 steven 880
			'dataType'  : 'json',
881
			'accept'    : 'application/json',
882
			'method'    : 'get',
883
			'url'       :  action,
118 steven 884
		}).done(function(response) {
885
			if(response['success']) {
886
					validatorForm.resetForm();
887
 
150 geraldo 888
					$('#main #id' ).val(response['id']),
889
					$('#main #continue').val('0');
890
					$('#main #name' ).val(response['name']),
118 steven 891
 
892
 
893
					instanceName = 'form-description';
894
					let editor = CKEDITOR.instances[instanceName ];
895
					editor.setData(response['description'], function() {
896
							editor.focus();
897
					});
898
 
899
 
900
					instanceName = 'form-text';
901
					CKEDITOR.instances[instanceName ].setData(response['text']);
902
 
150 geraldo 903
					$('#main #language' ).val(response['language']),
904
					$('#main #status' ).val(response['status']);
118 steven 905
 
906
					objFormGenerator.clear();
126 steven 907
					objFormGenerator.sections = response['sections'] || [];
118 steven 908
					objFormGenerator.render();
909
					$('#row-forms').hide();
910
					$('#row-edit').show();
911
 
150 geraldo 912
					$('#main #name').focus();
118 steven 913
 
914
				} else {
141 geraldo 915
					$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
118 steven 916
				}
917
			}).fail(function( jqXHR, textStatus, errorThrown) {
918
				$.fn.showError(textStatus);
919
			});
920
    });
921
 
922
	 $(document).on('click','[data-type="select_all"]',function(){
923
 
924
	        if($('input[name="select_all"]:checked').val() == 'all'){
925
	            $('[data-type="select"]').prop('checked', true);
926
	            $('[data-action="delete"]').removeClass('hide');
927
	        }else{
928
	            $('[data-type="select"]').prop('checked', false);
929
	            $('[data-action="delete"]').addClass('hide');
930
	        }
931
	    });
932
 
933
	    function getLength(){
934
	        return $('[data-type="select"]').length;
935
	    }
936
 
937
	    function currentSelected(){
938
	        var selected = [];
939
	        $.each($("input[name='select[]']:checked"), function(){
940
	            selected.push($(this).val());
941
	        });
942
 
943
	        return selected;
944
	    }
945
 
946
	    $(document).on('change',"input[name='select[]']",function(){
947
	        var c = currentSelected();
948
	        var cc = getLength();
949
 
950
 
951
	        if(c.length == cc){
952
	            if($('[data-action="delete"]').hasClass('hide')){
953
	                $('[data-action="delete"]').removeClass('hide');
954
	            }
955
	            return true;
956
	        }else{
957
	            $('input[name="select_all"]').prop('checked', false);
958
	        }
959
 
960
	        if(c.length > 0){
961
	            if($('[data-action="delete"]').hasClass('hide')){
962
	                $('[data-action="delete"]').removeClass('hide');
963
	            }
964
	        }else{
965
	            if(!$('[data-action="delete"]').hasClass('hide')){
966
	                $('[data-action="delete"]').addClass('hide');
967
	            }
968
	        }
969
	    });
970
 
971
	    var form3 = $('#form_sample_3');
972
        var error3 = $('.alert-danger', form3);
973
        var success3 = $('.alert-success', form3);
974
 
975
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
150 geraldo 976
 	$( "#main" ).on('submit', function() {
118 steven 977
		for(var instanceName in CKEDITOR.instances) {
978
			CKEDITOR.instances[instanceName].updateElement();
979
		}
980
	})
981
 
150 geraldo 982
	var validatorForm = $( "#main" ).validate( {
118 steven 983
        ignore: [],
984
        errorClass: 'help-block',
985
        errorElement: 'span',
986
		rules: {
987
			'form-name':  {
988
				required: true,
989
				minlength: 2,
990
				maxlength: 50
991
			},
992
			'form-description' : {
993
				required: true,
994
			},
995
			'form-text' : {
996
				required: true,
997
			},
998
			'form-language' : {
999
				required: true,
1000
			},
1001
			'forrm-status' : {
1002
				required: true,
1003
			},
1004
		},
1005
        highlight: function (element) {
1006
            $(element).closest('.form-group').addClass('has-error');
1007
        },
1008
        unhighlight: function (element) {
1009
            $(element).closest('.form-group').removeClass('has-error');
1010
        },
1011
        errorPlacement: function (error, element) {
1012
            if (element.attr("data-error-container")) {
1013
                error.appendTo(element.attr("data-error-container"));
1014
            } else {
1015
                error.insertAfter(element);
1016
            }
1017
        },
1018
        invalidHandler: function(form, validator) {
1019
            if (!validator.numberOfInvalids())
1020
                return;
1021
            $('html, body').animate({
1022
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1023
            }, 1000);
1024
        },
1025
		submitHandler: function(form) {
140 geraldo 1026
 
118 steven 1027
		    var error = false;
1028
		    if(objFormGenerator.sections.length == 0) {
142 geraldo 1029
		    	$.fn.showError('ERROR_SECCTIONS');
118 steven 1030
		    	error = true;
1031
		    } else {
1032
 
1033
		    	for(i = 0; i < objFormGenerator.sections.length; i++)
1034
		    	{
1035
 
1036
		    		if(objFormGenerator.sections[i].questions.length == 0) {
143 geraldo 1037
		    			$.fn.showError('ERROR_QUESTIONS'.replace('%s', objFormGenerator.sections[i].name ));
118 steven 1038
		    			break;
1039
		    		}
1040
 
1041
		    		var valueSection = parseInt(objFormGenerator.sections[i].value);
1042
		    		var totalValueQuestion = 0;
1043
 
1044
 
1045
		    		for(j = 0; j < objFormGenerator.sections[i].questions.length; j++)
1046
		    		{
1047
		    			valueQuestion = parseInt(objFormGenerator.sections[i].questions[j].value);
1048
		    			totalValueQuestion = totalValueQuestion + valueQuestion;
1049
		    			if(objFormGenerator.sections[i].questions[j].type == 'simple'
1050
			    			|| objFormGenerator.sections[i].questions[j].type == 'multiple'
1051
			    			|| objFormGenerator.sections[i].questions[j].type == 'rating-open' ) {
1052
 
1053
		    				var questionNumber = j + 1;
1054
		    				var numberCorrect = 0;
1055
 
1056
 
1057
		    				if(objFormGenerator.sections[i].questions[j].options.length == 0) {
139 geraldo 1058
 
143 geraldo 1059
								$.fn.showError('ERROR_OPTIONS'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
139 geraldo 1060
								error = true;
118 steven 1061
									break;
1062
		    				}
1063
 
1064
		    				var totalOption = 0;
1065
		    				var maxOption = 0;
1066
		    				for(k = 0;  k < objFormGenerator.sections[i].questions[j].options.length; k++)
1067
		    				{
1068
		    					if(objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple' ) {
1069
    		    					if(objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
1070
    		    						numberCorrect++;
1071
    		    					}
1072
		    					}
1073
 
1074
		    					if(objFormGenerator.sections[i].questions[j].type == 'multiple' && objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
1075
		    						totalOption = totalOption + parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
1076
			    				}
1077
 
1078
		    					if(objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1079
		    						if(parseInt(objFormGenerator.sections[i].questions[j].options[k].value) > maxOption) {
1080
											maxOption = parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
1081
					    			}
1082
			    				}
1083
 
1084
		    				}
1085
 
1086
		    				if(objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple' ) {
1087
 
1088
    		    				if(numberCorrect == 0) {
143 geraldo 1089
    		    					$.fn.showError('ERROR_OPTIONS_CORRECT'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 1090
    		    					error = true;
1091
    		    					break;
1092
    		    				}
1093
    		    				if(objFormGenerator.sections[i].questions[j].type == 'simple' && numberCorrect > 1) {
143 geraldo 1094
    		    					$.fn.showError('ERROR_OPTIONS_DUPLICATE_CORRECT'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 1095
    		    					error = true;
1096
    		    					break;
1097
    		    				}
1098
    		    				if(objFormGenerator.sections[i].questions[j].type == 'multiple' && numberCorrect == 1) {
143 geraldo 1099
    		    					$.fn.showError('ERROR_OPTIONS_ONE_CORRECT'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 1100
    		    					error = true;
1101
    		    					break;
1102
    		    				}
1103
		    				}
1104
 
1105
			 				if(objFormGenerator.sections[i].questions[j].type == 'multiple' && totalOption > valueQuestion ) {
139 geraldo 1106
 
143 geraldo 1107
								$.fn.showError('ERROR_OPTIONS_SUM_VALUES'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 1108
		    					error = true;
1109
		    					break;
1110
			    			}
1111
 
1112
		    				if(objFormGenerator.sections[i].questions[j].type == 'rating-open' && maxOption > valueQuestion ) {
143 geraldo 1113
								$.fn.showError('ERROR_OPTIONS_MAX_OPTION'.replace('%s', objFormGenerator.sections[i].name ).replace('%n', questionNumber));
118 steven 1114
		    					error = true;
1115
		    					break;
1116
			    			}
1117
						}
1118
 
1119
		    		}
1120
 
1121
		    		if(valueSection != totalValueQuestion) {
143 geraldo 1122
		    			$.fn.showError('ERROR_VALUE_SECTIONS'.replace('%s', objFormGenerator.sections[i].name ));
118 steven 1123
		    			error = true;
1124
		    			break;
1125
					}
1126
				}
1127
 
1128
 
1129
 
1130
    			if(error) {
1131
    				return false;
1132
    			} else {
1133
 
1134
 
150 geraldo 1135
    				var formId		= parseInt($('#main #id' ).val());
1136
    				var formContinue = parseInt($('#main #continue' ).val());
118 steven 1137
 
1138
    				var data = {
143 geraldo 1139
    	    			'id'	: formId,
150 geraldo 1140
        				'name' : $('#main #name' ).val(),
1141
        				'description' : $('#main #description' ).val(),
1142
        				'text' : $('#main #text' ).val(),
1143
        				'language' : $('#main #language' ).val(),
1144
        				'status' : $('#main #status' ).val(),
118 steven 1145
        				'sections' : objFormGenerator.sections
1146
    				}
127 steven 1147
					$.ajax({
1148
						'dataType': 'json',
1149
						'method': 'post',
1150
						'url' :  '$routeAdd',
1151
						'data' : data,
1152
					}).done(function(response) {
1153
						if(response['success']) {
1154
							$.fn.showSuccess(response['message']);
118 steven 1155
							if(formContinue == 1) {
150 geraldo 1156
								$('#main #id').val(response['form-id']);
1157
								$('#main #continue').val(0);
118 steven 1158
							} else {
1159
								$('#row-edit').hide();
127 steven 1160
								$('#row-forms').show();
118 steven 1161
							}
1162
							tableForm.fnDraw();
127 steven 1163
						} else {
141 geraldo 1164
							$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
127 steven 1165
						}
1166
					}).fail(function( jqXHR, textStatus, errorThrown) {
118 steven 1167
						$.fn.showError(textStatus);
127 steven 1168
					});
1169
						return false;
118 steven 1170
    			}
1171
			}
1172
 
1173
 
1174
		}
1175
	});
1176
 
1177
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
150 geraldo 1178
 	$( "#section" ).on('submit', function() {
118 steven 1179
		for(var instanceName in CKEDITOR.instances) {
1180
			CKEDITOR.instances[instanceName].updateElement();
1181
		}
1182
	})
1183
 
150 geraldo 1184
	var validatorFormSection = $( "#section" ).validate( {
118 steven 1185
        ignore: [],
1186
        errorClass: 'help-block',
1187
        errorElement: 'span',
1188
		rules: {
1189
			'section-name':  {
1190
				required: true,
1191
				minlength: 2,
1192
				maxlength: 50
1193
			},
1194
			'section-text' : {
1195
				required: false,
1196
			},
1197
			'section-value' : {
1198
				required: true,
1199
				number: true,
1200
				min: 1
1201
			},
1202
		},
1203
        highlight: function (element) {
1204
            $(element).closest('.form-group').addClass('has-error');
1205
        },
1206
        unhighlight: function (element) {
1207
            $(element).closest('.form-group').removeClass('has-error');
1208
        },
1209
        errorPlacement: function (error, element) {
1210
            if (element.attr("data-error-container")) {
1211
                error.appendTo(element.attr("data-error-container"));
1212
            } else {
1213
                error.insertAfter(element);
1214
            }
1215
        },
1216
        invalidHandler: function(form, validator) {
1217
            if (!validator.numberOfInvalids())
1218
                return;
1219
            $('html, body').animate({
1220
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1221
            }, 1000);
1222
        },
1223
		submitHandler: function(form) {
1224
		    // do other things for a valid form
1225
		    //form.submit();
1226
 
150 geraldo 1227
		    var slug = $('#section #section-slug').val();
118 steven 1228
		    if(slug) {
1229
		    	objFormGenerator.editSection(
150 geraldo 1230
		    		$('#section #section-slug').val(),
1231
			    	$('#section #section-name').val(),
1232
			    	$('#section #section-text').val(),
1233
			    	$('#section #section-value').val()
118 steven 1234
			  	);
1235
		    } else {
1236
		    	objFormGenerator.addSection(
150 geraldo 1237
		    		$('#section #section-name').val(),
1238
		    		$('#section #section-text').val(),
1239
		    		$('#section #section-value').val()
118 steven 1240
		    	);
1241
		    }
1242
 
1243
 
1244
 
1245
			$('#modal-section').modal('hide');
1246
			return false;
1247
		  }
1248
	} );
1249
 
1250
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
150 geraldo 1251
 	$( "#question" ).on('submit', function() {
118 steven 1252
		for(var instanceName in CKEDITOR.instances) {
1253
			CKEDITOR.instances[instanceName].updateElement();
1254
		}
1255
	})
1256
 
1257
 
150 geraldo 1258
	var validatorFormQuestion = $( "#question" ).validate( {
118 steven 1259
        ignore: [],
1260
        errorClass: 'help-block',
1261
        errorElement: 'span',
1262
		rules: {
1263
			'question-text' : {
1264
				required: true,
1265
			},
1266
			'question-value' : {
1267
				required: true,
1268
				number: true,
1269
				min: 1
1270
			},
1271
			'question-type':  {
1272
				required: true,
1273
			},
1274
			'question-max-length' : {
1275
				required: true,
1276
				digits: true,
1277
				min: 0
1278
			},
1279
			'question-range' : {
1280
				required: true,
1281
				number: true,
1282
				min: 1
1283
			},
1284
		},
1285
        highlight: function (element) {
1286
            $(element).closest('.form-group').addClass('has-error');
1287
        },
1288
        unhighlight: function (element) {
1289
            $(element).closest('.form-group').removeClass('has-error');
1290
        },
1291
        errorPlacement: function (error, element) {
1292
            if (element.attr("data-error-container")) {
1293
                error.appendTo(element.attr("data-error-container"));
1294
            } else {
1295
                error.insertAfter(element);
1296
            }
1297
        },
1298
        invalidHandler: function(form, validator) {
1299
 
1300
 
1301
            if (!validator.numberOfInvalids())
1302
                return;
1303
            $('html, body').animate({
1304
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1305
            }, 1000);
1306
        },
1307
		submitHandler: function(form) {
1308
 
139 geraldo 1309
 
150 geraldo 1310
		    if($('#question #question-slug').val()) {
118 steven 1311
 
139 geraldo 1312
 
118 steven 1313
		    	objFormGenerator.editQuestion(
150 geraldo 1314
		    		$('#question #question-section').val(),
1315
		    		$('#question #question-slug').val(),
1316
		    		$('#question #question-text').val(),
1317
		    		$('#question #question-value').val(),
1318
			    	$('#question #question-type').val(),
1319
			    	$('#question #question-max-length').val(),
1320
	    			$('#question #question-multiline').val(),
1321
	    			$('#question #question-range').val()
118 steven 1322
			  	);
1323
		    } else {
1324
 
1325
		    	objFormGenerator.addQuestion(
150 geraldo 1326
			    	$('#question #question-section').val(),
1327
			    	$('#question #question-text').val(),
1328
			    	$('#question #question-value').val(),
1329
				    $('#question #question-type').val(),
1330
				    $('#question #question-max-length').val(),
1331
		    		$('#question #question-multiline').val(),
1332
		    		$('#question #question-range').val()
118 steven 1333
		    	);
1334
		    }
1335
 
1336
			$('#modal-question').modal('hide');
1337
			return false;
1338
		  }
1339
	} );
1340
 
1341
	//IMPORTANT: update CKEDITOR textarea with actual content before submit
150 geraldo 1342
 	$( "#option" ).on('submit', function() {
118 steven 1343
		for(var instanceName in CKEDITOR.instances) {
1344
			CKEDITOR.instances[instanceName].updateElement();
1345
		}
1346
	})
1347
 
150 geraldo 1348
	var validatorFormOption = $( "#option" ).validate( {
118 steven 1349
        ignore: [],
1350
        errorClass: 'help-block',
1351
        errorElement: 'span',
1352
		rules: {
1353
			'option-text' : {
1354
				required: true,
1355
			},
1356
        	'option-value' : {
1357
				required: true,
1358
				number: true,
1359
				min: 1
1360
        	}
1361
		},
1362
        highlight: function (element) {
1363
            $(element).closest('.form-group').addClass('has-error');
1364
        },
1365
        unhighlight: function (element) {
1366
            $(element).closest('.form-group').removeClass('has-error');
1367
        },
1368
        errorPlacement: function (error, element) {
1369
            if (element.attr("data-error-container")) {
1370
                error.appendTo(element.attr("data-error-container"));
1371
            } else {
1372
                error.insertAfter(element);
1373
            }
1374
        },
1375
        invalidHandler: function(form, validator) {
1376
            if (!validator.numberOfInvalids())
1377
                return;
1378
            $('html, body').animate({
1379
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1380
            }, 1000);
1381
        },
1382
		submitHandler: function(form) {
1383
 
1384
 
150 geraldo 1385
		    if($('#option #option-slug').val()) {
118 steven 1386
		    	objFormGenerator.editOption(
150 geraldo 1387
		    		$('#option #option-section').val(),
1388
		    		$('#option #option-question').val(),
1389
		    		$('#option #option-slug').val(),
1390
		    		$('#option #option-text').val(),
1391
		    		$('#option #option-correct').val(),
1392
		    		$('#option #option-value').val()
118 steven 1393
			  	);
1394
		    } else {
1395
		    	objFormGenerator.addOption(
150 geraldo 1396
			    	$('#option #option-section').val(),
1397
			    	$('#option #option-question').val(),
1398
			    	$('#option #option-text').val(),
1399
			    	$('#option #option-correct').val(),
1400
			    	$('#option #option-value').val()
118 steven 1401
		    	);
1402
		    }
1403
 
1404
			$('#modal-option').modal('hide');
1405
			return false;
1406
		  }
1407
	} );
1408
 
1409
	$('body').on('click', 'button[id="btn-add-section"]', function(e){
1410
		e.preventDefault();
1411
 
1412
		validatorFormSection.resetForm();
150 geraldo 1413
		$('#section #section-slug').val('');
1414
		$('#section #section-name').val('');
118 steven 1415
 
1416
		instanceName = 'section-text';
1417
		let editor = CKEDITOR.instances[instanceName ];
143 geraldo 1418
		editor.setData('', function() {
118 steven 1419
		    editor.focus();
1420
		});
1421
 
1422
 
150 geraldo 1423
		$('#section #section-value').val('0');
136 geraldo 1424
		$('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
118 steven 1425
		$('#modal-section').modal('show');
1426
	});
1427
 
1428
	$('body').on('click', 'button.btn-edit-section', function(e){
1429
	    e.preventDefault();
1430
 
1431
	    var slug = $(this).data('slug');
1432
	    var section;
1433
	    var showForm = false;
1434
 
1435
	    for(i = 0; i < objFormGenerator.sections.length; i++) {
1436
	        section = objFormGenerator.sections[i];
1437
 
1438
	    	if(slug == section.slug) {
1439
 
1440
				validatorFormSection.resetForm();
150 geraldo 1441
	    		$('#section #section-slug').val(section.slug);
1442
	    		$('#section #section-name').val(section.name);
118 steven 1443
 
1444
	    		instanceName = 'section-text';
1445
	    		let editor = CKEDITOR.instances[instanceName ];
1446
	    		editor.setData( section.text, function() {
1447
	    		    editor.focus();
1448
	    		});
1449
 
150 geraldo 1450
				$('#section #section-value').val(section.value);
118 steven 1451
 
1452
				showForm = true;
1453
				break;
1454
	    	}
1455
	    }
1456
 
1457
	    if(showForm) {
136 geraldo 1458
	    	$('#modal-section h4[class="modal-title"]').html('LABEL_EDIT LABEL_SECTION');
118 steven 1459
			$('#modal-section').modal('show');
1460
	    }
1461
 
1462
	});
1463
 
1464
	$('body').on('click', 'button.btn-delete-section', function(e){
1465
		e.preventDefault();
1466
		var slug = $(this).data('slug');
1467
 
1468
		bootbox.confirm({
138 geraldo 1469
		    title: "LABEL_DELETE LABEL_SECTION",
1470
		    message: "LABEL_QUESTION_DELETE",
118 steven 1471
		    buttons: {
1472
		        cancel: {
1473
		            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1474
		        },
1475
		        confirm: {
1476
		            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1477
		        }
1478
		    },
1479
		    callback: function (result) {
1480
		    	if (result) {
1481
					objFormGenerator.deleteSection(slug);
1482
				}
1483
		    }
1484
		});
1485
 
1486
 
1487
 
1488
	});
1489
 
1490
 
1491
	$('body').on('click', 'button.btn-add-question', function(e){
1492
		e.preventDefault();
1493
 
1494
		validatorFormQuestion.resetForm();
1495
		var slug = $(this).data('slug');
1496
 
150 geraldo 1497
		$('#question #question-section').val(slug);
1498
		$('#question #question-slug').val('');
118 steven 1499
 
1500
		instanceName = 'question-text';
1501
		let editor = CKEDITOR.instances[instanceName ];
143 geraldo 1502
		editor.setData('', function() {
118 steven 1503
		    editor.focus();
1504
		});
1505
 
1506
 
150 geraldo 1507
		$('#question #question-value').val('0');
1508
		$('#question #question-type').val($('#question #question-type option:first').val());
118 steven 1509
 
150 geraldo 1510
		$('#question #question-max-length').val('0');
1511
		$('#question #question-max-length').parent().show();
118 steven 1512
 
150 geraldo 1513
		$('#question #question-multiline').val('0');
1514
		$('#question #question-multiline').parent().show();
118 steven 1515
 
150 geraldo 1516
		$('#question #question-range').val('10');
1517
		$('#question #question-range').parent().hide();
118 steven 1518
 
136 geraldo 1519
		$('#modal-question h4[class="modal-title"]').html('LABEL_ADD LABEL_QUESTION');
118 steven 1520
		$('#modal-question').modal('show');
1521
 
1522
	});
1523
 
1524
 
1525
 
1526
	$('body').on('click', 'button.btn-edit-question', function(e){
1527
	    e.preventDefault();
1528
 
1529
	    var slug_section	= $(this).data('section');
1530
	    var slug 			= $(this).data('slug');
1531
	    var showForm 		= false;
1532
 
1533
	    for(i = 0; i < objFormGenerator.sections.length; i++) {
1534
 
1535
	    	if(slug_section == objFormGenerator.sections[i].slug) {
1536
 
1537
	    		for(j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1538
 
1539
	    			if(slug == objFormGenerator.sections[i].questions[j].slug) {
1540
	    				validatorFormQuestion.resetForm();
1541
 
150 geraldo 1542
	    				$('#question #question-section').val(objFormGenerator.sections[i].slug);
1543
	    				$('#question #question-slug').val(objFormGenerator.sections[i].questions[j].slug);
118 steven 1544
 
1545
	    	    		instanceName = 'question-text';
1546
	    	    		let editor = CKEDITOR.instances[instanceName ];
1547
	    	    		editor.setData( objFormGenerator.sections[i].questions[j].text, function() {
1548
	    	    		    editor.focus();
1549
	    	    		});
1550
 
1551
 
150 geraldo 1552
	        			$('#question #question-value').val(objFormGenerator.sections[i].questions[j].value);
1553
	        			$('#question #question-type').val(objFormGenerator.sections[i].questions[j].type);
118 steven 1554
 
1555
 
1556
 
1557
	        			if(objFormGenerator.sections[i].questions[j].type == 'open') {
150 geraldo 1558
		        			$('#question #question-max-length').val(objFormGenerator.sections[i].questions[j].maxlength);
1559
		        			$('#question #question-max-length').parent().show();
118 steven 1560
 
150 geraldo 1561
		        			$('#question #question-multiline').val(objFormGenerator.sections[i].questions[j].multiline);
1562
							$('#question #question-multiline').parent().show();
118 steven 1563
	        			} else {
150 geraldo 1564
		        			$('#question #question-max-length').val('0');
1565
		        			$('#question #question-max-length').parent().hide();
118 steven 1566
 
150 geraldo 1567
		        			$('#question #question-multiline').val('0');
1568
							$('#question #question-multiline').parent().hide();
118 steven 1569
	        			}
1570
 
1571
	        			if(objFormGenerator.sections[i].questions[j].type == 'rating-range') {
150 geraldo 1572
	            			$('#question #question-range').val(objFormGenerator.sections[i].questions[j].range);
1573
		        			$('#question #question-range').parent().show();
118 steven 1574
 
1575
	        			} else {
150 geraldo 1576
	            			$('#question #question-range').val('10');
1577
		        			$('#question #question-range').parent().hide();
118 steven 1578
		        		}
1579
 
1580
    					showForm = true;
1581
    					break;
1582
 
1583
	    			}
1584
 
1585
	    		}
1586
 
1587
	    		break;
1588
	    	}
1589
	    }
1590
 
1591
	    if(showForm) {
1592
	    	$('#modal-question h4[class="modal-title"]').html('LABEL_EDIT LABEL_QUESTION');
1593
				$('#modal-question').modal('show');
1594
	    }
1595
 
1596
	});
1597
 
1598
 
1599
 
1600
 
1601
	$('body').on('click', 'button.btn-delete-question', function(e){
1602
		e.preventDefault();
1603
 
1604
		var slug_section	= $(this).data('section');
1605
		var slug 			= $(this).data('slug');
1606
 
1607
		bootbox.confirm({
138 geraldo 1608
			title: "LABEL_DELETE LABEL_QUESTION",
1609
			message: "LABEL_QUESTION_DELETE",
118 steven 1610
			buttons: {
1611
				cancel: {
1612
   					label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1613
    			},
1614
			    confirm: {
1615
			    	label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1616
			    }
1617
			},
1618
			callback: function (result) {
1619
				if (result) {
1620
					objFormGenerator.deleteQuestion(slug_section, slug);
1621
				}
1622
			}
1623
		});
1624
	});
1625
 
1626
 
1627
	$('body').on('click', 'button.btn-add-option', function(e){
1628
		e.preventDefault();
1629
	    var slug_section	= $(this).data('section');
1630
		var slug_question 	= $(this).data('slug');
1631
		var showForm 		= false;
1632
 
1633
	    for(i = 0; i < objFormGenerator.sections.length; i++) {
1634
	    	if(slug_section == objFormGenerator.sections[i].slug) {
1635
	    		for(j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1636
	    			if(slug_question == objFormGenerator.sections[i].questions[j].slug) {
1637
 
1638
                		validatorFormOption.resetForm();
150 geraldo 1639
                		$('#option #option-section').val(slug_section);
1640
                		$('#option #option-question').val(slug_question);
1641
                		$('#option #option-slug').val('');
118 steven 1642
 
1643
                		instanceName = 'option-text';
1644
	    	    		let editor = CKEDITOR.instances[instanceName ];
143 geraldo 1645
	    	    		editor.setData('', function() {
118 steven 1646
	    	    		    editor.focus();
1647
	    	    		});
1648
 
1649
 
150 geraldo 1650
	    	    		$('#option #option-correct').val('0');
118 steven 1651
                		if(objFormGenerator.sections[i].questions[j].type == 'rating-open') {
150 geraldo 1652
                    		$('#option #option-correct').parent().hide();
118 steven 1653
                        } else {
150 geraldo 1654
                    		$('#option #option-correct').parent().show();
118 steven 1655
                        }
1656
 
1657
                		if(objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
150 geraldo 1658
                			$('#option #option-value').val('0');
1659
                			$('#option #option-value').parent().show();
118 steven 1660
                		} else {
150 geraldo 1661
                			$('#option #option-value').val('1');
1662
                			$('#option #option-value').parent().hide();
118 steven 1663
 
1664
                       	}
1665
                		showForm = true;
1666
	    			}
1667
	    		}
1668
	    	}
1669
	    }
1670
 
1671
		if(showForm) {
139 geraldo 1672
    		$('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
118 steven 1673
    		$('#modal-option').modal('show');
1674
		}
1675
 
1676
	});
1677
 
1678
 
1679
 
1680
	$('body').on('click', 'button.btn-edit-option', function(e){
1681
	    e.preventDefault();
1682
 
1683
	    var slug_section	= $(this).data('section');
1684
	    var slug_question	= $(this).data('question');
1685
	    var slug 			= $(this).data('slug');
1686
	    var showForm 		= false;
1687
 
1688
	    for(i = 0; i < objFormGenerator.sections.length; i++) {
1689
	    	if(slug_section == objFormGenerator.sections[i].slug) {
1690
	    		for(j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1691
	    			if(slug_question == objFormGenerator.sections[i].questions[j].slug) {
1692
	    				for(k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
1693
	    					if(slug == objFormGenerator.sections[i].questions[j].options[k].slug) {
1694
	    						validatorFormOption.resetForm();
150 geraldo 1695
	    						$('#option #option-section').val(objFormGenerator.sections[i].slug);
1696
	    						$('#option #option-question').val(objFormGenerator.sections[i].questions[j].slug);
1697
    		    				$('#option #option-slug').val(objFormGenerator.sections[i].questions[j].options[k].slug);
118 steven 1698
 
1699
    		    				instanceName = 'option-text';
1700
    		    	    		let editor = CKEDITOR.instances[instanceName ];
1701
    		    	    		editor.setData( objFormGenerator.sections[i].questions[j].options[k].text, function() {
1702
    		    	    		    editor.focus();
1703
    		    	    		});
1704
 
1705
 
150 geraldo 1706
    		    				$('#option #option-correct').val(objFormGenerator.sections[i].questions[j].options[k].correct);
118 steven 1707
    		    				if(objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'simple') {
150 geraldo 1708
    		    					$('#option #option-correct').parent().show();
118 steven 1709
    		    				} else {
150 geraldo 1710
    		    					$('#option #option-correct').parent().hide();
118 steven 1711
            		    		}
1712
 
150 geraldo 1713
    		    				$('#option #option-value').val(objFormGenerator.sections[i].questions[j].options[k].value);
118 steven 1714
 
1715
								if(objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
150 geraldo 1716
    		    					$('#option #option-value').parent().show();
118 steven 1717
								} else {
150 geraldo 1718
									$('#option #option-value').parent().hide();
118 steven 1719
								}
1720
 
1721
 
1722
 
1723
    		    				showForm = true;
1724
    	    					break;
1725
	    					}
1726
	    				}
1727
	    			}
1728
	    			if(showForm) {
1729
		    			break;
1730
		    		}
1731
	    		}
1732
	    	}
1733
			if(showForm) {
1734
    			break;
1735
    		}
1736
	    }
1737
 
1738
	    if(showForm) {
1739
	    	$('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
1740
				$('#modal-option').modal('show');
1741
	    }
1742
	});
1743
 
1744
	$('body').on('click', 'button.btn-delete-option', function(e){
1745
		e.preventDefault();
1746
		var slug_section	= $(this).data('section');
1747
		var slug_question	= $(this).data('question');
1748
		    var slug 			= $(this).data('slug');
1749
 
1750
 
1751
		bootbox.confirm({
138 geraldo 1752
			title: "LABEL_DELETE LABEL_OPTION",
1753
			message: "LABEL_QUESTION_DELETE",
118 steven 1754
			buttons: {
1755
				cancel: {
1756
	   				label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1757
	    		},
1758
				confirm: {
1759
					label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1760
				}
1761
			},
1762
			callback: function (result) {
1763
				if (result) {
1764
					objFormGenerator.deleteOption(slug_section, slug_question, slug);
1765
				}
1766
			}
1767
		});
1768
	})
1769
 
150 geraldo 1770
	$('#section #section-value').inputNumberFormat({'decimal' : 2});
118 steven 1771
 
150 geraldo 1772
	$('#question #question-value').inputNumberFormat({'decimal' : 2});
1773
	$('#question #question-max-length').inputNumberFormat({'decimal' : 0});
118 steven 1774
 
150 geraldo 1775
	$('#option #option-value').inputNumberFormat({'decimal' : 2});
118 steven 1776
 
150 geraldo 1777
	$('#question #question-type').change(function(e) {
118 steven 1778
		e.preventDefault();
1779
 
150 geraldo 1780
		if($('#question #question-type').val() == 'open') {
1781
			$('#question #question-max-length').parent().show();
1782
			$('#question #question-multiline').parent().show();
118 steven 1783
 
1784
		} else {
150 geraldo 1785
			$('#question #question-max-length').val('0');
1786
			$('#question #question-max-length').parent().hide();
118 steven 1787
 
150 geraldo 1788
			$('#question #question-multiline').val('0');
1789
			$('#question #question-multiline').parent().hide();
118 steven 1790
		}
1791
 
150 geraldo 1792
		$('#question #question-range').val('10');
1793
		if($('#question #question-type').val() == 'rating-range') {
1794
			$('#question #question-range').parent().show();
118 steven 1795
		} else {
150 geraldo 1796
			$('#question #question-range').parent().hide();
118 steven 1797
		}
1798
 
1799
 
1800
 
1801
	});
1802
 
1803
	$('button.btn-add-form').click(function(e) {
1804
		e.preventDefault();
1805
 
1806
		objFormGenerator.clear();
1807
		objFormGenerator.render();
1808
		validatorForm.resetForm();
1809
 
150 geraldo 1810
		$('#main #id').val('0');
1811
		$('#main #continue').val('0');
1812
		$('#main #name').val('');
118 steven 1813
 
1814
		instanceName = 'form-text';
1815
		let editor = CKEDITOR.instances[instanceName ];
1816
		editor.setData('', function() {
1817
		    editor.focus();
1818
		});
1819
 
1820
 
1821
		instanceName = 'form-description';
1822
		CKEDITOR.instances[instanceName ].setData('');
1823
 
150 geraldo 1824
		$('#main #language' ).val('$lang_es'),
1825
		$('#main #status' ).val('$status_inactive');
118 steven 1826
 
1827
		$('#row-forms').hide();
1828
		$('#row-edit').show();
150 geraldo 1829
		$('#main #name').focus();
118 steven 1830
 
1831
	});
1832
 
1833
	$('button.btn-edit-cancel').click(function(e) {
1834
		e.preventDefault();
1835
		$('#row-edit').hide();
1836
		$('#row-forms').show();
1837
 
1838
	});
1839
 
1840
 
1841
	$('button.btn-form-save-continue').click(function(e) {
1842
		e.preventDefault();
150 geraldo 1843
		$('#main #continue').val('1')
1844
		$('#main').submit();
118 steven 1845
	});
1846
 
1847
	$('button.btn-form-save-close').click(function(e) {
1848
		e.preventDefault();
150 geraldo 1849
		$('#main #continue').val('0')
1850
		$('#main').submit();
118 steven 1851
 
1852
	});
1853
 
1854
	$('#modal-section, #modal-question, #modal-option').modal({
1855
			backdrop: 'static',
1856
			keyboard: false,
1857
			show: false
1858
		});
1859
	});
1860
JS;
115 efrain 1861
$this->inlineScript()->captureEnd();
1862
?>
118 steven 1863
 
121 steven 1864
<style type="text/css">
135 geraldo 1865
    tbody input[type="checkbox"]{
1866
        margin-left: 14px;
1867
    }
1868
    .panel-heading .accordion-toggle:after {
1869
        /* symbol for "opening" panels */
1870
        display: inline-block;
1871
        font: normal normal normal 14px/1 FontAwesome;
1872
        font-size: inherit;
1873
        content: "\f077" ;
1874
        float: right;        /* adjust as needed */
1875
        color: grey;         /* adjust as needed */
1876
        text-rendering: auto;
1877
        -webkit-font-smoothing: antialiased;
1878
    }
1879
    .panel-heading .accordion-toggle.collapsed:after {
1880
        /* symbol for "collapsed" panels */
1881
        content: "\f078";    /* adjust as needed, taken from bootstrap.css */
1882
    }
121 steven 1883
</style>
146 geraldo 1884
 
1885
<script id="formTmpl" type="text/x-jsrender">
150 geraldo 1886
<tr>
1887
   <td>{{:name}}</td>
1888
   <td>{{:language}}</td>
1889
   <td>
1890
      <div class="checkbox checkbox-success">
1891
         {{if status =='a' }}
1892
         <input class="styled" type="checkbox" checked="checked" disabled="disabled">
1893
         {{/if}}
1894
         {{if status !='a' }}
1895
         <input class="styled" type="checkbox"  disabled="disabled">
1896
         {{/if}}
1897
         <label></label>
1898
      </div>
1899
   </td>
1900
   <td>
151 geraldo 1901
   <?php if ($allowAdd) : ?>
150 geraldo 1902
      <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>
151 geraldo 1903
	  <?php endif; ?>
1904
	  <?php if ($allowDelete) : ?>
150 geraldo 1905
      <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>
151 geraldo 1906
	  <?php endif; ?>
150 geraldo 1907
   </td>
146 geraldo 1908
</tr>
150 geraldo 1909
</script>
146 geraldo 1910
 
115 efrain 1911
<!-- Content Header (Page header) -->
1912
<section class="content-header">
135 geraldo 1913
    <div class="container-fluid">
1914
        <div class="row mb-2">
1915
            <div class="col-sm-12">
1916
                <h1>LABEL_SELF_EVALUATION_FORMS</h1>
1917
            </div>
1918
        </div>
145 geraldo 1919
    </div>
1920
    <!-- /.container-fluid -->
115 efrain 1921
</section>
1922
<section class="content">
135 geraldo 1923
    <div class="container-fluid" id="row-forms">
1924
        <div class="row">
1925
            <div class="col-12">
145 geraldo 1926
                <div class="card">
135 geraldo 1927
                    <div class="card-body">
146 geraldo 1928
 
152 geraldo 1929
					<table  id="gridTable" class="table table-hover">
146 geraldo 1930
                            <thead>
1931
                                <tr>
1932
                                    <th>LABEL_NAME</th>
1933
                                    <th>LABEL_LANGUAGE</th>
1934
                                    <th>LABEL_ACTIVE</th>
1935
                                    <th>LABEL_ACTIONS</th>
1936
                                </tr>
1937
                            </thead>
1938
                            <tbody id="rows"></tbody>
1939
                        </table>
135 geraldo 1940
                    </div>
1941
                    <div class="card-footer clearfix">
1942
                        <div style="float:right;">
1943
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
1944
                            <?php if ($allowAdd) : ?>
1945
                                <button type="button" class="btn btn-primary btn-add-form"><i class="fa fa-plus"></i> LABEL_ADD </button>
1946
                            <?php endif; ?>
1947
                        </div>
1948
                    </div>
1949
                </div>
145 geraldo 1950
            </div>
1951
        </div>
135 geraldo 1952
    </div>
1953
    <!-- Row Edit -->
1954
    <div class="row" id="row-edit" style="display: none">
1955
        <div class="col-xs-12 col-md-12">
1956
            <form action="#" name="form-main" id="form-main">
1957
                <input type="hidden" name="form-id" id="form-id" value="0" />
1958
                <input type="hidden" name="form-continue" id="form-continue" value="0" />
1959
                <div class="form-group">
1960
                    <label for="form-name">LABEL_FIRST_NAME</label>
1961
                    <input type="text" name="form-name" id="form-name" class="form-control" maxlength="50" />
1962
                </div>
1963
                <div class="form-group">
1964
                    <label for="form-description">LABEL_DESCRIPTION</label>
1965
                    <!--  ckeditor -->
1966
                    <textarea  name="form-description" id="form-description" rows="5" class="ckeditor form-control"></textarea>
1967
                </div>
1968
                <div class="form-group">
1969
                    <label for="form-text">LABEL_TEXT</label>
1970
                    <!--  ckeditor -->
1971
                    <textarea  name="form-text" id="form-text" rows="5" class="ckeditor form-control"></textarea>
1972
                </div>
1973
                <div class="form-group">
1974
                    <label for="form-language">LABEL_LANGUAGES</label>
1975
                    <select name="form-language" id="form-language" class="form-control">
145 geraldo 1976
                        <option value="<?php echo $lang_en; ?>">LABEL_ENGLISH</option>
1977
                        <option value="<?php echo $lang_es; ?>">LABEL_SPANISH</option>
135 geraldo 1978
                    </select>
1979
                </div>
1980
                <div class="form-group">
1981
                    <label for="form-status">LABEL_STATUS</label>
1982
                    <select name="form-status" id="form-status" class="form-control">
145 geraldo 1983
                        <option value="<?php echo $status_inactive; ?>">LABEL_INACTIVE</option>
1984
                        <option value="<?php echo $status_active; ?>">LABEL_ACTIVE</option>
135 geraldo 1985
                    </select>
1986
                </div>
1987
                <br/>
1988
                <div class="row">
1989
                    <div class="col-xs-12 col-md-12 text-right">
1990
                        <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>
1991
                    </div>
1992
                </div>
1993
                <br />
1994
                <div class="row">
1995
                    <div class="col-xs-12 col-md-12">
145 geraldo 1996
                        <div class="panel-group" id="accordion"></div>
135 geraldo 1997
                    </div>
145 geraldo 1998
                </div>
135 geraldo 1999
                <div class="form-group">
2000
                    <button type="submit" form="form-main" class="btn btn-info btn-form-save-continue">LABEL_SAVE & LABEL_CONTINUE</button>
2001
                    <button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE & LABEL_CLOSE</button>
2002
                    <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
2003
                </div>
2004
            </form>
2005
        </div>
2006
    </div>
2007
    <!-- End Row Edit -->
2008
    <!-- Modals -->
2009
    <!-- Section Modal -->
2010
    <div  id="modal-section" class="modal" tabindex="-1" role="dialog">
139 geraldo 2011
        <div class="modal-dialog modal-lg" role="document">
135 geraldo 2012
            <form action="#" name="form-section" id="form-section">
2013
                <input type="hidden" name="section-slug" id="section-slug" value="" />
2014
                <div class="modal-content">
2015
                    <div class="modal-header">
139 geraldo 2016
                        <h4 class="modal-title">LABEL_ADD LABEL_SECTION</h4>
2017
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
136 geraldo 2018
                            <span aria-hidden="true">&times;</span>
2019
                        </button>
135 geraldo 2020
                    </div>
2021
                    <div class="modal-body">
2022
                        <div class="form-group">
2023
                            <label for="section-name">LABEL_FIRST_NAME</label>
2024
                            <input type="text" name="section-name" id="section-name" class="form-control" maxlength="50" value="" />
2025
                        </div>
2026
                        <div class="form-group">
2027
                            <label for="section-text">LABEL_TEXT</label>
2028
                            <!--  ckeditor -->
2029
                            <textarea  name="section-text" id="section-text" rows="5" class="ckeditor form-control"></textarea>
2030
                        </div>
2031
                        <div class="form-group">
2032
                            <label for="section-value">LABEL_VALUE</label>
2033
                            <input type="text" name="section-value" id="section-value"  class="form-control" value="0" />
2034
                        </div>
2035
                    </div>
2036
                    <div class="modal-footer">
2037
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
2038
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
2039
                    </div>
2040
                </div>
2041
            </form>
2042
        </div>
2043
    </div>
2044
    <!-- End Modal Section -->
2045
    <!-- Question Modal -->
2046
    <div  id="modal-question" class="modal" tabindex="-1" role="dialog">
139 geraldo 2047
        <div class="modal-dialog modal-lg" role="document">
135 geraldo 2048
            <form action="#" name="form-question" id="form-question">
2049
                <input type="hidden" name="question-section" id="question-section" />
2050
                <input type="hidden" name="question-slug" id="question-slug" />
2051
                <div class="modal-content">
2052
                    <div class="modal-header">
2053
                        <h4 class="modal-title">LABEL_ADD LABEL_QUESTION</h4>
2054
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
2055
                            <span aria-hidden="true">&times;</span>
2056
                        </button>
2057
                    </div>
2058
                    <div class="modal-body">
2059
                        <div class="form-group">
2060
                            <label for="question-text">LABEL_TEXT</label>
2061
                            <!--  ckeditor -->
2062
                            <textarea  name="question-text" id="question-text" rows="5" class="ckeditor form-control"></textarea>
2063
                        </div>
2064
                        <div class="form-group">
2065
                            <label for="question-value">LABEL_VALUE</label>
2066
                            <input type="text" name="question-value" id="question-value"  class="form-control" />
2067
                        </div>
2068
                        <div class="form-group">
2069
                            <label for="question-type">LABEL_TYPE</label>
2070
                            <select name="question-type" id="question-type" class="form-control">
2071
                                <option value="open">LABEL_OPEN</option>
2072
                                <option value="simple">Simple</option>
2073
                                <option value="multiple">Multiple</option>
2074
                                <option value="rating-open">LABEL_RATING_OPEN</option>
2075
                                <option value="rating-range">LABEL_RATING_RANGE</option>
2076
                            </select>
2077
                        </div>
2078
                        <div class="form-group">
2079
                            <label for="question-max-length">LABEL_MAXLENGTH</label>
2080
                            <input type="text" name="question-max-length" id="question-max-length"  class="form-control" />
2081
                        </div>
2082
                        <div class="form-group">
2083
                            <label for="question-multiline">LABEL_MULTI_LINE</label>
2084
                            <select name="question-multiline" id="question-multiline" class="form-control">
2085
                                <option value="1">LABEL_YES</option>
145 geraldo 2086
                                <option value="0">LABEL_NOT</option>
135 geraldo 2087
                            </select>
2088
                        </div>
2089
                        <div class="form-group">
2090
                            <label for="question-range">LABEL_RANGE</label>
2091
                            <select name="question-range" id="question-range" class="form-control">
2092
                                <option value="10">1-10</option>
2093
                                <option value="6">1-6</option>
2094
                                <option value="5">1-5</option>
2095
                            </select>
2096
                        </div>
2097
                    </div>
2098
                    <div class="modal-footer">
2099
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
2100
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
2101
                    </div>
2102
                </div>
2103
            </form>
2104
        </div>
2105
    </div>
2106
    <!-- End Modal Question -->
2107
    <!-- MOdal Options -->
2108
    <div  id="modal-option" class="modal" tabindex="-1" role="dialog">
139 geraldo 2109
        <div class="modal-dialog modal-lg" role="document">
135 geraldo 2110
            <form action="#" name="form-option" id="form-option">
2111
                <input type="hidden" name="option-section" id="option-section" value="" />
2112
                <input type="hidden" name="option-question" id="option-question" value="" />
2113
                <input type="hidden" name="option-slug" id="option-slug" value="" />
2114
                <div class="modal-content">
2115
                    <div class="modal-header">
2116
                        <h4 class="modal-title">LABEL_OPTION</h4>
2117
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
2118
                            <span aria-hidden="true">&times;</span>
2119
                        </button>
2120
                    </div>
2121
                    <div class="modal-body">
2122
                        <div class="form-group">
2123
                            <label for="option-text">LABEL_TEXT</label>
2124
                            <!--  ckeditor -->
2125
                            <textarea  name="option-text" id="option-text" rows="5" class="ckeditor form-control"></textarea>
2126
                        </div>
2127
                        <div class="form-group">
2128
                            <label for="option-correct">LABEL_ANSWER_CORRECT</label>
2129
                            <select name="option-correct" id="option-correct" class="form-control">
2130
                                <option value="1">LABEL_YES</option>
145 geraldo 2131
                                <option value="0">LABEL_NOT</option>
135 geraldo 2132
                            </select>
2133
                        </div>
2134
                        <div class="form-group">
2135
                            <label for="option-value">LABEL_VALUE</label>
2136
                            <input type="text" name="option-value" id="option-value" class="form-control" />
2137
                        </div>
2138
                    </div>
2139
                    <div class="modal-footer">
2140
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
2141
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
2142
                    </div>
2143
                </div>
2144
            </form>
2145
        </div>
2146
    </div>
2147
    <!-- End Modal Options -->
2148
    <!-- End Modals -->
119 steven 2149
</section>