Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 117 | Rev 119 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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