Proyectos de Subversion LeadersLinked - Backend

Rev

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