Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 4466 | Rev 4493 | 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');
4459 eleazar 582
                $('#form-main #name').val(response['data']['name']),
4384 eleazar 583
 
584
                /*----------Set Ckeditor ------------*/
4466 eleazar 585
                CKEDITOR.instances.description.setData(response['data']['description']);
586
                CKEDITOR.instances.text.setData(response['data']['text']);
4384 eleazar 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();
4459 eleazar 599
                $('#form-main #name').focus();
4384 eleazar 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
            },
4466 eleazar 672
            'description':{
673
                updateCkeditor:function() {
674
                    CKEDITOR.instances.description.updateElement();
675
                },
4384 eleazar 676
            },
4466 eleazar 677
            'text':{
678
                updateCkeditor:function() {
679
                    CKEDITOR.instances.text.updateElement();
680
                },
4384 eleazar 681
            },
682
            'forrm-status': {
683
                required: true,
684
            },
685
        },
686
        highlight: function(element) {
687
            $(element).closest('.form-group').addClass('has-error');
688
        },
689
        unhighlight: function(element) {
690
            $(element).closest('.form-group').removeClass('has-error');
691
        },
692
        errorPlacement: function(error, element) {
693
            if (element.attr("data-error-container")) {
694
                error.appendTo(element.attr("data-error-container"));
695
            } else {
696
                error.insertAfter(element);
697
            }
698
        },
699
        invalidHandler: function(form, validator) {
700
            if (!validator.numberOfInvalids())
701
                return;
702
            $('html, body').animate({
703
                scrollTop: $(validator.errorList[0].element).offset().top - 100
704
            }, 1000);
705
        },
706
        submitHandler: function(form) {
707
            var error = false;
708
            if (objFormGenerator.sections.length == 0) {
709
                $.fn.showError('ERROR_SECCTIONS');
710
                return false;
711
            } else {
712
                for (i = 0; i < objFormGenerator.sections.length; i++) {
713
                    if (objFormGenerator.sections[i].questions.length == 0) {
714
                        $.fn.showError('ERROR_QUESTIONS'.replace('%s', objFormGenerator.sections[i].name));
715
                        return false;
716
                    }
4429 eleazar 717
                    var valueSection = parseInt(objFormGenerator.sections[i].value);
718
                    var totalValueQuestion = 0;
4384 eleazar 719
                    for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
4429 eleazar 720
                        valueQuestion = parseInt(objFormGenerator.sections[i].questions[j].value);
721
                        totalValueQuestion = totalValueQuestion + valueQuestion;
4384 eleazar 722
                        if (objFormGenerator.sections[i].questions[j].type == 'simple' ||
723
                            objFormGenerator.sections[i].questions[j].type == 'multiple' ||
724
                            objFormGenerator.sections[i].questions[j].type == 'rating-open') {
725
                            var questionNumber = j + 1;
726
                            var numberCorrect = 0;
727
                            if (objFormGenerator.sections[i].questions[j].options.length == 0) {
728
                                $.fn.showError('ERROR_OPTIONS'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
729
                                return false;
730
                            }
731
                            var totalOption = 0;
732
                            var maxOption = 0;
733
                            for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
734
                                if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
735
                                    if (objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
736
                                        numberCorrect++;
737
                                    }
738
                                }
739
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' && objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
740
                                    totalOption = totalOption + parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
741
                                }
742
                                if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
743
                                    if (parseInt(objFormGenerator.sections[i].questions[j].options[k].value) > maxOption) {
744
                                        maxOption = parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
745
                                    }
746
                                }
747
                            }
748
                            if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
749
                                if (numberCorrect == 0) {
750
                                    $.fn.showError('ERROR_OPTIONS_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
751
                                    return false;
752
                                }
753
                                if (
754
                                    objFormGenerator.sections[i].questions[j].type == 'simple' && numberCorrect > 1) {
755
                                    $.fn.showError('ERROR_OPTIONS_DUPLICATE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
756
                                    return false;
757
                                }
758
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' && numberCorrect == 1) {
759
                                    $.fn.showError('ERROR_OPTIONS_ONE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
760
                                    return false;
761
                                }
762
                            }
4429 eleazar 763
                            if (objFormGenerator.sections[i].questions[j].type == 'multiple' && totalOption != valueQuestion) {
764
                                $.fn.showError('ERROR_OPTIONS_SUM_VALUES'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
765
                                return false;
766
                            }
767
                            if (objFormGenerator.sections[i].questions[j].type == 'rating-open' && maxOption > valueQuestion) {
768
                                $.fn.showError('ERROR_OPTIONS_MAX_OPTION'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
769
                                return false;
770
                            }
4384 eleazar 771
                        }
772
                    }
4429 eleazar 773
                    if (valueSection != totalValueQuestion) {
4384 eleazar 774
                        $.fn.showError('ERROR_VALUE_SECTIONS'.replace('%s', objFormGenerator.sections[i].name));
775
                        return false;
4429 eleazar 776
                    }
4384 eleazar 777
                }
778
                var formId = parseInt($('#form-main #form-id').val());
779
                var formContinue = parseInt($('#form-main #form-continue').val());
780
                var data = {
781
                    'id': formId,
4459 eleazar 782
                    'name': $('#form-main #name').val(),
783
                    'description': $('#form-main #description').val(),
784
                    'text': $('#form-main #text').val(),
785
                    'status': $('#form-main #status').val(),
4384 eleazar 786
                    'content': JSON.stringify(objFormGenerator.sections)
787
                }
788
                $.ajax({
789
                    'dataType': 'json',
790
                    'method': 'post',
791
                    'url': $('#form-main').attr('action'),
792
                    'data': data,
793
                }).done(function(response) {
794
                    if (response['success']) {
795
                        $.fn.showSuccess(response['data']);
796
                        if (formContinue == 1) {
797
                            $('#form-main').attr('action',response['action_edit']);
798
                            $('#form-main #form-id').val(response['id']);
799
                            $('#form-main #form-continue').val(0);
800
                        } else {
801
                            $('#row-edit').hide();
802
                            $('#row-forms').show();
803
                        /*---------- Reset Form -------- */
804
                        $('#form-main')[0].reset();
805
                        /*--------Reset Ckeditor ----------*/
4466 eleazar 806
                        CKEDITOR.instances.text.setData('');
807
                        CKEDITOR.instances.description.setData('');
4384 eleazar 808
                        /*--------Reset Sections ----------*/
809
                        clearSectionData();
810
                        /* ------- Refresh Table -----------*/
811
 
812
                        }
813
                        tableForm.fnDraw();
814
                    } else {
815
                        $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
816
                    }
817
                }).fail(function(jqXHR, textStatus, errorThrown) {
818
                    $.fn.showError(textStatus);
819
                });
820
                return false;
821
            }
822
        }
823
    });
824
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
825
    $("#form-section").on('submit', function() {
826
        for (var instanceName in CKEDITOR.instances) {
827
            CKEDITOR.instances[instanceName].updateElement();
828
        }
829
    })
830
    /**
831
     * Validate rules form section
832
     */
833
    var validatorFormSection = $("#form-section").validate({
834
        ignore: [],
835
        errorClass: 'help-block',
836
        errorElement: 'span',
837
        rules: {
838
            'section-name': {
839
                required: true,
840
                minlength: 2,
841
                maxlength: 50
842
            },
843
            'section-text': {
844
                required: false,
845
            },
846
            'section-value': {
4429 eleazar 847
                required: true,
4384 eleazar 848
                number: true,
4429 eleazar 849
                min: 1
4384 eleazar 850
            },
851
        },
852
        highlight: function(element) {
853
            $(element).closest('.form-group').addClass('has-error');
854
        },
855
        unhighlight: function(element) {
856
            $(element).closest('.form-group').removeClass('has-error');
857
        },
858
        errorPlacement: function(error, element) {
859
            if (element.attr("data-error-container")) {
860
                error.appendTo(element.attr("data-error-container"));
861
            } else {
862
                error.insertAfter(element);
863
            }
864
        },
865
        invalidHandler: function(form, validator) {
866
            if (!validator.numberOfInvalids())
867
                return;
868
            $('html, body').animate({
869
                scrollTop: $(validator.errorList[0].element).offset().top - 100
870
            }, 1000);
871
        },
872
        submitHandler: function(form) {
873
            // do other things for a valid form
874
            //form.submit();
875
            var slug = $('#form-section #section-slug').val();
876
            if (slug) {
877
                objFormGenerator.editSection(
878
                    $('#form-section #section-slug').val(),
879
                    $('#form-section #section-name').val(),
880
                    $('#form-section #section-text').val(),
4429 eleazar 881
                    $('#form-section #section-value').val()
4384 eleazar 882
                );
883
            } else {
884
                objFormGenerator.addSection(
885
                    $('#form-section #section-name').val(),
886
                    $('#form-section #section-text').val(),
4429 eleazar 887
                    $('#form-section #section-value').val()
4384 eleazar 888
                );
889
            }
890
            renderSectionData(objFormGenerator.sections);
891
            $('#modal-section').modal('hide');
892
            return false;
893
        }
894
    });
895
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
896
    $("#form-question").on('submit', function() {
897
        for (var instanceName in CKEDITOR.instances) {
898
            CKEDITOR.instances[instanceName].updateElement();
899
        }
900
    })
901
    /**
902
     * Validate rules form Questions
903
     */
904
    var validatorFormQuestion = $("#form-question").validate({
905
        ignore: [],
906
        errorClass: 'help-block',
907
        errorElement: 'span',
908
        rules: {
909
            'question-text': {
910
                required: true,
911
            },
912
            'question-value': {
4429 eleazar 913
                required: true,
4384 eleazar 914
                number: true,
915
                min: 1
916
            },
917
            'question-type': {
918
                required: true,
919
            },
920
            'question-max-length': {
921
                required: true,
922
                digits: true,
923
                min: 0
924
            },
925
            'question-range': {
926
                required: true,
927
                number: true,
928
                min: 1
929
            },
930
        },
931
        highlight: function(element) {
932
            $(element).closest('.form-group').addClass('has-error');
933
        },
934
        unhighlight: function(element) {
935
            $(element).closest('.form-group').removeClass('has-error');
936
        },
937
        errorPlacement: function(error, element) {
938
            if (element.attr("data-error-container")) {
939
                error.appendTo(element.attr("data-error-container"));
940
            } else {
941
                error.insertAfter(element);
942
            }
943
        },
944
        invalidHandler: function(form, validator) {
945
            if (!validator.numberOfInvalids())
946
                return;
947
            $('html, body').animate({
948
                scrollTop: $(validator.errorList[0].element).offset().top - 100
949
            }, 1000);
950
        },
951
        submitHandler: function(form) {
952
            if ($('#form-question #question-slug').val()) {
953
                objFormGenerator.editQuestion(
954
                    $('#form-question #question-section').val(),
955
                    $('#form-question #question-slug').val(),
956
                    $('#form-question #question-text').val(),
4429 eleazar 957
                    $('#form-question #question-value').val(),
4384 eleazar 958
                    $('#form-question #question-type').val(),
959
                    $('#form-question #question-max-length').val(),
960
                    $('#form-question #question-multiline').val(),
961
                    $('#form-question #question-range').val()
962
                );
963
            } else {
964
                objFormGenerator.addQuestion(
965
                    $('#form-question #question-section').val(),
966
                    $('#form-question #question-text').val(),
4429 eleazar 967
                    $('#form-question #question-value').val(),
4384 eleazar 968
                    $('#form-question #question-type').val(),
969
                    $('#form-question #question-max-length').val(),
970
                    $('#form-question #question-multiline').val(),
971
                    $('#form-question #question-range').val()
972
                );
973
            }
974
            renderSectionData(objFormGenerator.sections);
975
            $('#modal-question').modal('hide');
976
            return false;
977
        }
978
    });
979
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
980
    $("#form-option").on('submit', function() {
981
        for (var instanceName in CKEDITOR.instances) {
982
            CKEDITOR.instances[instanceName].updateElement();
983
        }
984
    })
985
    /**
986
     * Validate rules form options
987
     */
988
    var validatorFormOption = $("#form-option").validate({
989
        ignore: [],
990
        errorClass: 'help-block',
991
        errorElement: 'span',
992
        rules: {
993
            'option-text': {
994
                required: true,
995
            },
996
            'option-value': {
4429 eleazar 997
                required: true,
4384 eleazar 998
                number: true,
999
                min: 1
1000
            }
1001
        },
1002
        highlight: function(element) {
1003
            $(element).closest('.form-group').addClass('has-error');
1004
        },
1005
        unhighlight: function(element) {
1006
            $(element).closest('.form-group').removeClass('has-error');
1007
        },
1008
        errorPlacement: function(error, element) {
1009
            if (element.attr("data-error-container")) {
1010
                error.appendTo(element.attr("data-error-container"));
1011
            } else {
1012
                error.insertAfter(element);
1013
            }
1014
        },
1015
        invalidHandler: function(form, validator) {
1016
            if (!validator.numberOfInvalids())
1017
                return;
1018
            $('html, body').animate({
1019
                scrollTop: $(validator.errorList[0].element).offset().top - 100
1020
            }, 1000);
1021
        },
1022
        submitHandler: function(form) {
1023
            if ($('#form-option #option-slug').val()) {
1024
                objFormGenerator.editOption(
1025
                    $('#form-option #option-section').val(),
1026
                    $('#form-option #option-question').val(),
1027
                    $('#form-option #option-slug').val(),
1028
                    $('#form-option #option-text').val(),
1029
                    $('#form-option #option-correct').val(),
4429 eleazar 1030
                    $('#form-option #option-value').val()
4384 eleazar 1031
                );
1032
            } else {
1033
                objFormGenerator.addOption(
1034
                    $('#form-option #option-section').val(),
1035
                    $('#form-option #option-question').val(),
1036
                    $('#form-option #option-text').val(),
1037
                    $('#form-option #option-correct').val(),
4429 eleazar 1038
                    $('#form-option #option-value').val()
4384 eleazar 1039
                );
1040
            }
1041
            renderSectionData(objFormGenerator.sections);
1042
            $('#modal-option').modal('hide');
1043
            return false;
1044
        }
1045
    });
1046
    /**
1047
     * Clicked on add new section
1048
     */
1049
    $('body').on('click', 'button[id="btn-add-section"]', function(e) {
1050
        e.preventDefault();
1051
        validatorFormSection.resetForm();
1052
        $('#form-section #section-slug').val('');
1053
        $('#form-section #section-name').val('');
1054
        CKEDITOR.instances['section-text'].setData('');
4429 eleazar 1055
        $('#form-section #section-value').val('0');
4384 eleazar 1056
        $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
1057
        $('#modal-section').modal('show');
1058
    });
1059
    /**
1060
     * Clicked on edit section
1061
     */
1062
    $('body').on('click', 'button.btn-edit-section', function(e) {
1063
        e.preventDefault();
1064
        var slug = $(this).data('section');
1065
        var section;
1066
        var showForm = false;
1067
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1068
            section = objFormGenerator.sections[i];
1069
            if (slug == section.slug_section) {
1070
                validatorFormSection.resetForm();
1071
                $('#form-section #section-slug').val(section.slug_section);
1072
                $('#form-section #section-name').val(section.name);
1073
                CKEDITOR.instances['section-text'].setData(section.text);
4429 eleazar 1074
                $('#form-section #section-value').val(section.value);
4384 eleazar 1075
                showForm = true;
1076
                break;
1077
            }
1078
        }
1079
        if (showForm) {
1080
            $('#modal-section h4[class="modal-title"]').html('LABEL_EDIT LABEL_SECTION');
1081
            $('#modal-section').modal('show');
1082
        }
1083
    });
1084
    /**
1085
     * Clicked on remove section
1086
     */
1087
    $('body').on('click', 'button.btn-delete-section', function(e) {
1088
        e.preventDefault();
1089
        var slug = $(this).data('section');
1090
        bootbox.confirm({
1091
            title: "LABEL_DELETE LABEL_SECTION",
1092
            message: "LABEL_QUESTION_DELETE",
1093
            buttons: {
1094
                cancel: {
1095
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1096
                },
1097
                confirm: {
1098
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1099
                }
1100
            },
1101
            callback: function(result) {
1102
                if (result) {
1103
                    objFormGenerator.deleteSection(slug);
1104
                    renderSectionData(objFormGenerator.sections);
1105
                }
1106
            }
1107
        });
1108
    });
1109
    /**
1110
     * Clicked add new question
1111
     */
1112
    $('body').on('click', 'button.btn-add-question', function(e) {
1113
        e.preventDefault();
1114
        validatorFormQuestion.resetForm();
1115
        var slug = $(this).data('section');
1116
        $('#form-question #question-section').val(slug);
1117
        $('#form-question #question-slug').val('');
1118
        CKEDITOR.instances['question-text'].setData('');
4429 eleazar 1119
        $('#form-question #question-value').val('0');
4384 eleazar 1120
        $('#form-question #question-type').val($('#form-question #question-type option:first').val());
1121
        $('#form-question #question-max-length').val('0');
1122
        $('#form-question #question-max-length').parent().show();
1123
        $('#form-question #question-multiline').val('0');
1124
        $('#form-question #question-multiline').parent().show();
1125
        $('#form-question #question-range').val('10');
1126
        $('#form-question #question-range').parent().hide();
1127
        $('#modal-question h4[class="modal-title"]').html('LABEL_ADD LABEL_QUESTION');
1128
        $('#modal-question').modal('show');
1129
    });
1130
    /**
1131
     * Clicked edit question
1132
     */
1133
    $('body').on('click', 'button.btn-edit-question', function(e) {
1134
        e.preventDefault();
1135
        var slug_section = $(this).data('section');
1136
        var slug = $(this).data('question');
1137
        var showForm = false;
1138
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1139
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1140
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1141
                    if (slug == objFormGenerator.sections[i].questions[j].slug_question) {
1142
                        validatorFormQuestion.resetForm();
1143
                        $('#form-question #question-section').val(objFormGenerator.sections[i].slug_section);
1144
                        $('#form-question #question-slug').val(objFormGenerator.sections[i].questions[j].slug_question);
1145
                        CKEDITOR.instances['question-text'].setData(objFormGenerator.sections[i].questions[j].text);
4429 eleazar 1146
                        $('#form-question #question-value').val(objFormGenerator.sections[i].questions[j].value);
4384 eleazar 1147
                        $('#form-question #question-type').val(objFormGenerator.sections[i].questions[j].type);
1148
                        if (objFormGenerator.sections[i].questions[j].type == 'open') {
1149
                            $('#form-question #question-max-length').val(objFormGenerator.sections[i].questions[j].maxlength);
1150
                            $('#form-question #question-max-length').parent().show();
1151
                            $('#form-question #question-multiline').val(objFormGenerator.sections[i].questions[j].multiline);
1152
                            $('#form-question #question-multiline').parent().show();
1153
                        } else {
1154
                            $('#form-question #question-max-length').val('0');
1155
                            $('#form-question #question-max-length').parent().hide();
1156
                            $('#form-question #question-multiline').val('0');
1157
                            $('#form-question #question-multiline').parent().hide();
1158
                        }
1159
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-range') {
1160
                            $('#form-question #question-range').val(objFormGenerator.sections[i].questions[j].range);
1161
                            $('#form-question #question-range').parent().show();
1162
                        } else {
1163
                            $('#form-question #question-range').val('10');
1164
                            $('#form-question #question-range').parent().hide();
1165
                        }
1166
                        showForm = true;
1167
                        break;
1168
                    }
1169
                }
1170
                break;
1171
            }
1172
        }
1173
        if (showForm) {
1174
            $('#modal-question h4[class="modal-title"]').html('LABEL_EDIT LABEL_QUESTION');
1175
            $('#modal-question').modal('show');
1176
        }
1177
    });
1178
    /**
1179
     * Clicked remove question
1180
     */
1181
    $('body').on('click', 'button.btn-delete-question', function(e) {
1182
        e.preventDefault();
1183
        var slug_section = $(this).data('section');
1184
        var slug = $(this).data('question');
1185
        bootbox.confirm({
1186
            title: "LABEL_DELETE LABEL_QUESTION",
1187
            message: "LABEL_QUESTION_DELETE",
1188
            buttons: {
1189
                cancel: {
1190
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1191
                },
1192
                confirm: {
1193
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1194
                }
1195
            },
1196
            callback: function(result) {
1197
                if (result) {
1198
                    objFormGenerator.deleteQuestion(slug_section, slug);
1199
                    renderSectionData(objFormGenerator.sections);
1200
                }
1201
            }
1202
        });
1203
    });
1204
    /**
1205
     * Clicked add new Option
1206
     */
1207
    $('body').on('click', 'button.btn-add-option', function(e) {
1208
        e.preventDefault();
1209
        var slug_section = $(this).data('section');
1210
        var slug_question = $(this).data('question');
1211
        var showForm = false;
1212
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1213
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1214
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1215
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1216
                        validatorFormOption.resetForm();
1217
                        $('#form-option #option-section').val(slug_section);
1218
                        $('#form-option #option-question').val(slug_question);
1219
                        $('#form-option #option-slug').val('');
1220
                        CKEDITOR.instances['option-text'].setData('', function() {
1221
                            editor.focus();
1222
                        });
1223
                        $('#form-option #option-correct').val('0');
1224
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1225
                            $('#form-option #option-correct').parent().hide();
1226
                        } else {
1227
                            $('#form-option #option-correct').parent().show();
1228
                        }
4429 eleazar 1229
                        if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
4384 eleazar 1230
                            $('#form-option #option-value').val('0');
1231
                            $('#form-option #option-value').parent().show();
1232
                        } else {
1233
                            $('#form-option #option-value').val('1');
1234
                            $('#form-option #option-value').parent().hide();
4429 eleazar 1235
                        }
4384 eleazar 1236
                        renderSectionData(objFormGenerator.sections);
1237
                        $('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
1238
                        $('#modal-option').modal('show');
1239
                        return true;
1240
                    }
1241
                }
1242
            }
1243
        }
1244
    });
1245
    /**
1246
     * Clicked edit option
1247
     */
1248
    $('body').on('click', 'button.btn-edit-option', function(e) {
1249
        e.preventDefault();
1250
        var slug_section = $(this).data('section');
1251
        var slug_question = $(this).data('question');
1252
        var slug = $(this).data('slug');
1253
        var showForm = false;
1254
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1255
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1256
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1257
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1258
                        for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
1259
                            if (slug == objFormGenerator.sections[i].questions[j].options[k].slug_option) {
1260
                                validatorFormOption.resetForm();
1261
                                $('#form-option #option-section').val(objFormGenerator.sections[i].slug_section);
1262
                                $('#form-option #option-question').val(objFormGenerator.sections[i].questions[j].slug_question);
1263
                                $('#form-option #option-slug').val(objFormGenerator.sections[i].questions[j].options[k].slug_option);
1264
                                CKEDITOR.instances['option-text'].setData(objFormGenerator.sections[i].questions[j].options[k].text,
1265
                                    function() {
1266
                                        editor.focus();
1267
                                    });
1268
                                $('#form-option #option-correct').val(objFormGenerator.sections[i].questions[j].options[k].correct);
1269
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'simple') {
1270
                                    $('#form-option #option-correct').parent().show();
1271
                                } else {
1272
                                    $('#form-option #option-correct').parent().hide();
1273
                                }
4429 eleazar 1274
                                $('#form-option #option-value').val(objFormGenerator.sections[i].questions[j].options[k].value);
4384 eleazar 1275
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1276
                                    $('#form-option #option-value').parent().show();
1277
                                } else {
1278
                                    $('#form-option #option-value').parent().hide();
4429 eleazar 1279
                                }
4384 eleazar 1280
                                showForm = true;
1281
                                break;
1282
                            }
1283
                        }
1284
                    }
1285
                    if (showForm) {
1286
                        break;
1287
                    }
1288
                }
1289
            }
1290
            if (showForm) {
1291
                break;
1292
            }
1293
        }
1294
        if (showForm) {
1295
            $('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
1296
            $('#modal-option').modal('show');
1297
        }
1298
    });
1299
    /**
1300
     * Clicked remove option
1301
     */
1302
    $('body').on('click', 'button.btn-delete-option', function(e) {
1303
        e.preventDefault();
1304
        var slug_section = $(this).data('section');
1305
        var slug_question = $(this).data('question');
1306
        var slug = $(this).data('slug');
1307
        bootbox.confirm({
1308
            title: "LABEL_DELETE LABEL_OPTION",
1309
            message: "LABEL_QUESTION_DELETE",
1310
            buttons: {
1311
                cancel: {
1312
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1313
                },
1314
                confirm: {
1315
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1316
                }
1317
            },
1318
            callback: function(result) {
1319
                if (result) {
1320
                    objFormGenerator.deleteOption(slug_section, slug_question, slug);
1321
                    renderSectionData(objFormGenerator.sections);
1322
                }
1323
            }
1324
        });
1325
    })
1326
    /**
1327
     * Format input number (Form Section)
1328
     */
1329
    $('#form-section #section-value').inputNumberFormat({
1330
        'decimal': 2
1331
    });
1332
    /**
1333
     * Format input number (Form Question)
1334
     */
1335
    $('#form-question #question-value').inputNumberFormat({
1336
        'decimal': 2
1337
    });
1338
    /**
1339
     * Format input number (Form Question)
1340
     */
1341
    $('#form-question #question-max-length').inputNumberFormat({
1342
        'decimal': 0
1343
    });
1344
    /**
1345
     * Format input number (Form Option)
1346
     */
1347
    $('#form-option #option-value').inputNumberFormat({
1348
        'decimal': 2
1349
    });
1350
    /**
1351
     * Detect when updating question status and hide/Show options
1352
     */
1353
    $('#form-question #question-type').change(function(e) {
1354
        e.preventDefault();
1355
        if ($('#form-question #question-type').val() == 'open') {
1356
            $('#form-question #question-max-length').parent().show();
1357
            $('#form-question #question-multiline').parent().show();
1358
        } else {
1359
            $('#form-question #question-max-length').val('0');
1360
            $('#form-question #question-max-length').parent().hide();
1361
            $('#form-question #question-multiline').val('0');
1362
            $('#form-question #question-multiline').parent().hide();
1363
        }
1364
        $('#form-question #question-range').val('10');
1365
        if ($('#form-question #question-type').val() == 'rating-range') {
1366
            $('#form-question #question-range').parent().show();
1367
        } else {
1368
            $('#form-question #question-range').parent().hide();
1369
        }
1370
    });
1371
    /**
1372
     * Clicked new Form
1373
     */
1374
    $('button.btn-add-form').click(function(e) {
1375
        e.preventDefault();
1376
        objFormGenerator.clear();
1377
        objFormGenerator.render();
1378
        validatorForm.resetForm();
1379
        clearSectionData();
1380
        $('#form-main').attr('action', '$routeAdd');
1381
        $('#form-main #form-id').val('0');
1382
        $('#form-main #form-continue').val('0');
4459 eleazar 1383
        $('#form-main #name').val('');
1384
        $('#form-main #status').val('$status_inactive');
4466 eleazar 1385
        CKEDITOR.instances.text.setData('');
1386
        CKEDITOR.instances.description.setData('');
4384 eleazar 1387
        $('#row-forms').hide();
1388
        $('#row-edit').show();
4459 eleazar 1389
        $('#form-main #name').focus();
4384 eleazar 1390
    });
1391
    /**
1392
     * Clicked cancel new/edit Form
1393
     */
1394
    $('button.btn-edit-cancel').click(function(e) {
1395
        e.preventDefault();
1396
        $('#row-edit').hide();
1397
        $('#row-forms').show();
1398
    });
1399
    /**
1400
     * Clicked save and continue new Form
1401
     */
1402
    $('button.btn-form-save-continue').click(function(e) {
1403
        e.preventDefault();
1404
        $('#form-main #form-continue').val('1')
1405
        $('#form-main').submit();
1406
    });
1407
    /**
1408
     * Clicked save and close new/edit Form
1409
     */
1410
    $('button.btn-form-save-close').click(function(e) {
1411
        e.preventDefault();
1412
        $('#form-main #form-continue').val('0')
1413
        $('#form-main').submit();
1414
    });
1415
    /**
1416
     * Modal Settings
1417
     */
1418
    $('#modal-section, #modal-question, #modal-option').modal({
1419
        backdrop: 'static',
1420
        keyboard: false,
1421
        show: false
1422
    });
1423
    /**
1424
     * Get Question type
1425
     */
1426
    const getQuestionTypeBySlug = (slug_section, slug_question) => {
1427
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1428
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1429
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1430
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1431
                        return objFormGenerator.sections[i].questions[j].type;
1432
                    }
1433
                }
1434
            }
1435
        }
1436
    }
1437
    /**
1438
     * Remove Html Tags
1439
     */
1440
    const removeTags = (str) => str.toString().replace( /(<([^>]+)>)/ig, '')
1441
    /**
1442
     * Render Sections data
1443
     */
1444
    const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
1445
        getType: getQuestionTypeBySlug,
1446
        removeTags: removeTags
1447
    }));
1448
 
1449
 
1450
    /**
1451
     * Clear Div Section data
1452
     */
1453
    const clearSectionData = () => $("#rows").html('');
1454
    /**
1455
     * Clicked refresh button
1456
     */
1457
    $('button.btn-refresh').click(function(e) {
1458
        tableForm.fnDraw();
1459
    });
4466 eleazar 1460
 
1461
    CKEDITOR.replace('description');
1462
    CKEDITOR.replace('text');
4384 eleazar 1463
 
1464
});
1465
JS;
1466
$this->inlineScript()->captureEnd();
1467
?>
1468
 
1469
<!-- Content Header (Page header) -->
1470
<section class="content-header">
1471
    <div class="container-fluid">
1472
        <div class="row mb-2">
1473
            <div class="col-sm-12">
1474
                <h1>LABEL_SELF_EVALUATION_FORMS</h1>
1475
            </div>
1476
        </div>
1477
    </div>
1478
    <!-- /.container-fluid -->
1479
</section>
1480
<section class="content">
1481
    <div class="container-fluid" id="row-forms">
1482
        <div class="row">
1483
            <div class="col-12">
1484
                <div class="card">
1485
                    <div class="card-body">
1486
                        <table id="gridTable" class="table   table-hover">
1487
                            <thead>
1488
                                <tr>
1489
                                    <th>LABEL_NAME</th>
1490
                                    <th>LABEL_ACTIVE</th>
1491
                                    <th>LABEL_ACTIONS</th>
1492
                                </tr>
1493
                            </thead>
1494
                            <tbody></tbody>
1495
                        </table>
1496
                    </div>
1497
                    <div class="card-footer clearfix">
1498
                        <div style="float:right;">
1499
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
1500
                            <?php if ($allowAdd) : ?>
1501
                                <button type="button" class="btn btn-primary btn-add-form"><i class="fa fa-plus"></i> LABEL_ADD </button>
1502
                            <?php endif; ?>
1503
                        </div>
1504
                    </div>
1505
                </div>
1506
            </div>
1507
        </div>
1508
    </div>
1509
 
1510
    <!-- Create/Edit Form -->
1511
 
1512
    <div class="row" id="row-edit" style="display: none">
1513
        <div class="col-xs-12 col-md-12">
1514
            <form action="#" name="form-main" id="form-main">
1515
                <input type="hidden" name="form-id" id="form-id" value="0" />
1516
                <input type="hidden" name="form-continue" id="form-continue" value="0" />
4450 eleazar 1517
                <?php
1518
                     //$form = $this->formAdd;
1519
                     $form->setAttributes([
1520
                         'method' => 'post',
1521
                         'name' => 'form-main',
1522
                         'action' => $routeAdd,
1523
                         'id' => 'form-main'
1524
                     ]);
1525
                     $form->prepare();
1526
                     echo $this->form()->openTag($form);
1527
                ?>
1528
               <div class="form-group">
1529
                    <?php
1530
                    $element = $form->get('name');
1531
                    $element->setOptions(['label' => 'LABEL_FIRST_NAME']);
1532
                    $element->setAttributes(['class' => 'form-control']);
1533
                    echo $this->formLabel($element);
1534
                    echo $this->formText($element);
1535
                    ?>
4384 eleazar 1536
                </div>
1537
                <div class="form-group">
4450 eleazar 1538
                        <?php
1539
                        $element = $form->get('description');
1540
                        $element->setOptions(['label' => 'LABEL_DESCRPTION']);
1541
                        $element->setAttributes(['class' => 'form-control']);
1542
                        echo $this->formLabel($element);
4468 eleazar 1543
                        echo $this->formTextArea($element);
4450 eleazar 1544
                        ?>
4384 eleazar 1545
                </div>
1546
                <div class="form-group">
4450 eleazar 1547
                        <?php
1548
                        $element = $form->get('text');
1549
                        $element->setOptions(['label' => 'LABEL_TEXT']);
1550
                        $element->setAttributes(['class' => 'form-control']);
1551
                        echo $this->formLabel($element);
4468 eleazar 1552
                        echo $this->formTextArea($element);
4450 eleazar 1553
                        ?>
4384 eleazar 1554
                </div>
1555
                <div class="form-group">
4450 eleazar 1556
                        <?php
1557
                        $element = $form->get('status');
1558
                        $element->setAttributes(['class' => 'form-control']);
1559
                        $element->setOptions(['label' => 'LABEL_STATUS']);
1560
                        echo $this->formLabel($element);
1561
                        echo $this->formSelect($element);
1562
                        ?>
1563
                    </div>
4384 eleazar 1564
                <br/>
1565
                <div class="row">
1566
                    <div class="col-xs-12 col-md-12 text-right">
1567
                        <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>
1568
                    </div>
1569
                </div>
1570
                <br />
1571
                <div class="row">
1572
                    <div class="col-xs-12 col-md-12">
1573
                        <div class="panel-group" id="rows"></div>
1574
                    </div>
1575
                </div>
1576
                <div class="form-group">
1577
                    <button type="submit" form="form-main" class="btn btn-info btn-form-save-continue">LABEL_SAVE & LABEL_CONTINUE</button>
1578
                    <button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE & LABEL_CLOSE</button>
1579
                    <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
1580
                </div>
1581
            </form>
1582
        </div>
1583
    </div>
1584
 
1585
    <!-- Create/Edit Form-->
1586
 
1587
    <!-- Section Modal -->
1588
    <div  id="modal-section" class="modal" tabindex="-1" role="dialog">
1589
        <div class="modal-dialog modal-lg" role="document">
1590
            <form action="#" name="form-section" id="form-section">
1591
                <input type="hidden" name="section-slug" id="section-slug" value="" />
1592
                <div class="modal-content">
1593
                    <div class="modal-header">
1594
                        <h4 class="modal-title">LABEL_ADD LABEL_SECTION</h4>
1595
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1596
                            <span aria-hidden="true">&times;</span>
1597
                        </button>
1598
                    </div>
1599
                    <div class="modal-body">
1600
                        <div class="form-group">
1601
                            <label for="section-name">LABEL_FIRST_NAME</label>
1602
                            <input type="text" name="section-name" id="section-name" class="form-control" maxlength="50" value="" />
1603
                        </div>
1604
                        <div class="form-group">
1605
                            <label for="section-text">LABEL_TEXT</label>
1606
                            <!--  ckeditor -->
1607
                            <textarea  name="section-text" id="section-text" rows="5" class="ckeditor form-control"></textarea>
1608
                        </div>
1609
                        <div class="form-group">
4429 eleazar 1610
                            <label for="section-value">LABEL_VALUE</label>
1611
                            <input type="text" name="section-value" id="section-value"  class="form-control" value="0" />
4384 eleazar 1612
                        </div>
1613
                    </div>
1614
                    <div class="modal-footer">
1615
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
1616
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1617
                    </div>
1618
                </div>
1619
            </form>
1620
        </div>
1621
    </div>
1622
    <!-- End Modal Section -->
1623
 
1624
    <!-- Question Modal -->
1625
 
1626
    <div  id="modal-question" class="modal" tabindex="-1" role="dialog">
1627
        <div class="modal-dialog modal-lg" role="document">
1628
            <form action="#" name="form-question" id="form-question">
1629
                <input type="hidden" name="question-section" id="question-section" />
1630
                <input type="hidden" name="question-slug" id="question-slug" />
1631
                <div class="modal-content">
1632
                    <div class="modal-header">
1633
                        <h4 class="modal-title">LABEL_ADD LABEL_QUESTION</h4>
1634
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1635
                            <span aria-hidden="true">&times;</span>
1636
                        </button>
1637
                    </div>
1638
                    <div class="modal-body">
1639
                        <div class="form-group">
1640
                            <label for="question-text">LABEL_TEXT</label>
1641
                            <!--  ckeditor -->
1642
                            <textarea  name="question-text" id="question-text" rows="5" class="ckeditor form-control"></textarea>
1643
                        </div>
1644
                        <div class="form-group">
4429 eleazar 1645
                            <label for="question-value">LABEL_VALUE</label>
1646
                            <input type="text" name="question-value" id="question-value"  class="form-control" />
4384 eleazar 1647
                        </div>
1648
                        <div class="form-group">
1649
                            <label for="question-type">LABEL_TYPE</label>
1650
                            <select name="question-type" id="question-type" class="form-control">
1651
                                <option value="open">LABEL_OPEN</option>
1652
                                <option value="simple">Simple</option>
1653
                                <option value="multiple">Multiple</option>
1654
                                <option value="rating-open">LABEL_RATING_OPEN</option>
1655
                                <option value="rating-range">LABEL_RATING_RANGE</option>
1656
                            </select>
1657
                        </div>
1658
                        <div class="form-group">
1659
                            <label for="question-max-length">LABEL_MAXLENGTH</label>
1660
                            <input type="text" name="question-max-length" id="question-max-length"  class="form-control" />
1661
                        </div>
1662
                        <div class="form-group">
1663
                            <label for="question-multiline">LABEL_MULTI_LINE</label>
1664
                            <select name="question-multiline" id="question-multiline" class="form-control">
1665
                                <option value="1">LABEL_YES</option>
1666
                                <option value="0">LABEL_NOT</option>
1667
                            </select>
1668
                        </div>
1669
                        <div class="form-group">
1670
                            <label for="question-range">LABEL_RANGE</label>
1671
                            <select name="question-range" id="question-range" class="form-control">
1672
                                <option value="10">1-10</option>
1673
                                <option value="6">1-6</option>
1674
                                <option value="5">1-5</option>
1675
                            </select>
1676
                        </div>
1677
                    </div>
1678
                    <div class="modal-footer">
1679
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
1680
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1681
                    </div>
1682
                </div>
1683
            </form>
1684
        </div>
1685
    </div>
1686
 
1687
    <!-- End Modal Question -->
1688
 
1689
    <!-- Modal Options -->
1690
 
1691
    <div  id="modal-option" class="modal" tabindex="-1" role="dialog">
1692
        <div class="modal-dialog modal-lg" role="document">
1693
            <form action="#" name="form-option" id="form-option">
1694
                <input type="hidden" name="option-section" id="option-section" value="" />
1695
                <input type="hidden" name="option-question" id="option-question" value="" />
1696
                <input type="hidden" name="option-slug" id="option-slug" value="" />
1697
                <div class="modal-content">
1698
                    <div class="modal-header">
1699
                        <h4 class="modal-title">LABEL_OPTION</h4>
1700
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1701
                            <span aria-hidden="true">&times;</span>
1702
                        </button>
1703
                    </div>
1704
                    <div class="modal-body">
1705
                        <div class="form-group">
1706
                            <label for="option-text">LABEL_TEXT</label>
1707
                            <!--  ckeditor -->
1708
                            <textarea  name="option-text" id="option-text" rows="5" class="ckeditor form-control"></textarea>
1709
                        </div>
1710
                        <div class="form-group">
1711
                            <label for="option-correct">LABEL_ANSWER_CORRECT</label>
1712
                            <select name="option-correct" id="option-correct" class="form-control">
1713
                                <option value="1">LABEL_YES</option>
1714
                                <option value="0">LABEL_NOT</option>
1715
                            </select>
1716
                        </div>
1717
                        <div class="form-group">
1718
                            <label for="option-value">LABEL_VALUE</label>
1719
                            <input type="text" name="option-value" id="option-value" class="form-control" />
1720
                        </div>
1721
                    </div>
1722
                    <div class="modal-footer">
1723
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
1724
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1725
                    </div>
1726
                </div>
1727
            </form>
1728
        </div>
1729
    </div>
1730
 
1731
    <!-- End Modal Options -->
1732
 
1733
    <!---Template Sections --->
1734
    <script id="sectionTemplate" type="text/x-jsrender">
1735
    <div class="panel panel-default" id="panel-{{:slug_section}}">
1736
        <div class="panel-heading">
1737
            <h4 class="panel-title">
1738
                <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:slug_section}}" href="#collapse-{{:slug_section}}">
1739
                    <span class="section-name{{:slug_section}}">
1740
                        {{:name}}
1741
                    </span>
1742
                </a>
1743
            </h4>
1744
        </div>
1745
        <div id="collapse-{{:slug_section}}" class="panel-collapse in collapse show">
1746
            <div class="panel-body">
1747
                <div class="table-responsive">
1748
                    <table class="table table-bordered">
1749
                        <thead>
1750
                            <tr>
1751
                                <th style="width: 10%;">LABEL_ELEMENT</th>
1752
                                <th style="width: 50%;">LABEL_TEXT</th>
4429 eleazar 1753
                                <th style="width: 10%;">LABEL_VALUE</th>
4384 eleazar 1754
                                <th style="width: 10%;">LABEL_TYPE</th>
1755
                                <th style="width: 20%;">LABEL_ACTIONS</th>
1756
                            </tr>
1757
                        </thead>
1758
                        <tbody>
1759
                            <tr class="tr-section">
1760
                                <td class="text-left">LABEL_SECTION</td>
1761
                                <td class="text-left">{{:name}}</td>
4429 eleazar 1762
                                <td>{{:value}}</td>
4384 eleazar 1763
                                <td></td>
1764
                                <td>
1765
                                    <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>
1766
                                    <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>
1767
                                    <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>
1768
                                </td>
1769
                            </tr>
1770
                            {{for questions}}
1771
                            <tr class="tr-question">
1772
                                <td class="text-left">--LABEL_QUESTION</td>
1773
                                <td class="text-left">
1774
                                    {{:~removeTags(text)}}
1775
                                </td>
4429 eleazar 1776
                                <td><font color="red">{{:value}}</font></td>
4384 eleazar 1777
                                <td class="text-capitalize">
1778
                                    {{if type == 'open'}} LABEL_OPEN {{/if}}
1779
                                    {{if type == 'simple'}} Simple {{/if}}
1780
                                    {{if type == 'multiple'}} Multiple {{/if}}
1781
                                    {{if type == 'rating-open'}} LABEL_RATING_OPEN {{/if}}
1782
                                    {{if type == 'rating-range'}} LABEL_RATING_RANGE {{/if}}
1783
                                </td>
1784
                                <td>
1785
                                    <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>
1786
                                    <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>
1787
 
1788
                                    {{if type == 'simple' || type == 'rating-open' || type=='multiple' }}
1789
                                    <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>
1790
                                    {{/if}}
1791
 
1792
                                </td>
1793
                            </tr>
1794
                            {{for options}}
1795
                            <tr class="tr-option">
1796
                                <td class="text-left">---LABEL_OPTION</td>
1797
                                <td class="text-left">
1798
                                    {{:~removeTags(text)}}
1799
                                </td>
1800
                                <td>
1801
 
1802
                                    {{if ~getType( slug_section, slug_question) == 'multiple' || ~getType( slug_section, slug_question) == 'rating-open'  }}
4429 eleazar 1803
                                    {{:value}}
4384 eleazar 1804
                                    {{/if}}
1805
                                </td>
1806
                                <td class="text-left">
1807
                                    {{if ~getType( slug_section, slug_question) != 'rating-open'}}
1808
                                    {{if correct == 1}}
1809
                                    <font color="green">LABEL_CORRECT</font>
1810
                                    {{/if}}
1811
                                    {{if correct == 0}}
1812
                                    <font color="red">LABEL_FAIL</font>
1813
                                    {{/if}}
1814
                                    {{/if}}
1815
                                </td>
1816
                                <td>
1817
                                    <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>
1818
                                    <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>
1819
                                </td>
1820
                            </tr>
1821
                            {{/for}}
1822
                            {{/for}}
1823
                        </tbody>
1824
                    </table>
1825
                </div>
1826
            </div>
1827
        </div>
1828
    </div>
1829
    </script>
1830
 
1831
    <!-- End Template Sections-->
1832
 
1833
</section>