Proyectos de Subversion LeadersLinked - Backend

Rev

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