Proyectos de Subversion LeadersLinked - Backend

Rev

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

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