Proyectos de Subversion LeadersLinked - Backend

Rev

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