Proyectos de Subversion LeadersLinked - Backend

Rev

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