Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 203 | Rev 205 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 203 Rev 204
Línea 77... Línea 77...
77
        this.sections = [],
77
        this.sections = [],
78
        this.clear = function() {
78
        this.clear = function() {
79
            this.sections = [];
79
            this.sections = [];
80
            this.render();
80
            this.render();
81
        },
81
        },
-
 
82
        /**
-
 
83
         * Render array sections
-
 
84
         */
82
        this.renderSection = function(slug_section) {
85
        this.renderSection = function(slug_section) {
83
            var s = '';
86
            var s = '';
84
            for (i = 0; i < this.sections.length; i++) {
87
            for (i = 0; i < this.sections.length; i++) {
85
                if (slug_section != this.sections[i].slug_section) {
88
                if (slug_section != this.sections[i].slug_section) {
86
                    continue;
89
                    continue;
Línea 145... Línea 148...
145
                    }
148
                    }
146
                }
149
                }
147
            }
150
            }
148
            $('[data-toggle="tooltip"]').tooltip();
151
            $('[data-toggle="tooltip"]').tooltip();
149
        },
152
        },
-
 
153
        /**
-
 
154
         * Add element to section array 
-
 
155
         */
150
        this.addSection = function(name, text, value) {
156
        this.addSection = function(name, text, value) {
151
            var d = new Date();
157
            var d = new Date();
152
            var slug = 'section' + d.getTime();
158
            var slug = 'section' + d.getTime();
153
            var position = 0;
159
            var position = 0;
154
            $.each(this.sections, function(index, section) {
160
            $.each(this.sections, function(index, section) {
Línea 165... Línea 171...
165
                'position': position,
171
                'position': position,
166
                'questions': [],
172
                'questions': [],
167
            }
173
            }
168
            this.sections.push(section);
174
            this.sections.push(section);
169
        },
175
        },
-
 
176
         /**
-
 
177
         * Edit element to section array 
-
 
178
         */
170
        this.editSection = function(slug, name, text, value) {
179
        this.editSection = function(slug, name, text, value) {
171
            var renderTable = false;
180
            var renderTable = false;
172
            for (i = 0; i < this.sections.length; i++) {
181
            for (i = 0; i < this.sections.length; i++) {
173
                if (slug == this.sections[i].slug_section) {
182
                if (slug == this.sections[i].slug_section) {
174
                    this.sections[i].name = name;
183
                    this.sections[i].name = name;
Línea 180... Línea 189...
180
            }
189
            }
181
            if (renderTable) {
190
            if (renderTable) {
182
                this.renderSection(slug);
191
                this.renderSection(slug);
183
            }
192
            }
184
        },
193
        },
-
 
194
         /**
-
 
195
         * Remove element to section array
-
 
196
         */
185
        this.deleteSection = function(slug) {
197
        this.deleteSection = function(slug) {
186
            var renderTable = false;
198
            var renderTable = false;
187
            for (i = 0; i < this.sections.length; i++) {
199
            for (i = 0; i < this.sections.length; i++) {
188
                if (slug == this.sections[i].slug_section) {
200
                if (slug == this.sections[i].slug_section) {
189
                    this.sections.splice(i, 1);
201
                    this.sections.splice(i, 1);
Línea 193... Línea 205...
193
            }
205
            }
194
            if (renderTable) {
206
            if (renderTable) {
195
                $('#panel' + slug).remove();
207
                $('#panel' + slug).remove();
196
            }
208
            }
197
        },
209
        },
-
 
210
         /**
-
 
211
         * Add element to question array
-
 
212
         */
198
        this.addQuestion = function(slug_section, text, value, type, maxlength, multiline, range) {
213
        this.addQuestion = function(slug_section, text, value, type, maxlength, multiline, range) {
199
            var d = new Date();
214
            var d = new Date();
200
            var slug_question = 'question' + d.getTime();
215
            var slug_question = 'question' + d.getTime();
201
            var position = 0;
216
            var position = 0;
202
            var renderTable = false;
217
            var renderTable = false;
Línea 227... Línea 242...
227
            }
242
            }
228
            if (renderTable) {
243
            if (renderTable) {
229
                this.renderSection(slug_section);
244
                this.renderSection(slug_section);
230
            }
245
            }
231
        },
246
        },
-
 
247
         /**
-
 
248
         * Add element to question array
-
 
249
         */
232
        this.editQuestion = function(slug_section, slug_question, text, value, type, maxlength, multiline, range) {
250
        this.editQuestion = function(slug_section, slug_question, text, value, type, maxlength, multiline, range) {
233
            var renderTable = false;
251
            var renderTable = false;
234
            for (i = 0; i < this.sections.length; i++) {
252
            for (i = 0; i < this.sections.length; i++) {
235
                if (slug_section == this.sections[i].slug_section) {
253
                if (slug_section == this.sections[i].slug_section) {
236
                    for (j = 0; j < this.sections[i].questions.length; j++) {
254
                    for (j = 0; j < this.sections[i].questions.length; j++) {
Línea 262... Línea 280...
262
            }
280
            }
263
            if (renderTable) {
281
            if (renderTable) {
264
                this.renderSection(slug_section);
282
                this.renderSection(slug_section);
265
            }
283
            }
266
        },
284
        },
-
 
285
        /**
-
 
286
         * Remove element to question array
-
 
287
         */
267
        this.deleteQuestion = function(slug_section, slug_question) {
288
        this.deleteQuestion = function(slug_section, slug_question) {
268
            var renderTable = false;
289
            var renderTable = false;
269
            for (i = 0; i < this.sections.length; i++) {
290
            for (i = 0; i < this.sections.length; i++) {
270
                if (slug_section == this.sections[i].slug_section) {
291
                if (slug_section == this.sections[i].slug_section) {
271
                    for (j = 0; j < this.sections[i].questions.length; j++) {
292
                    for (j = 0; j < this.sections[i].questions.length; j++) {
Línea 282... Línea 303...
282
            }
303
            }
283
            if (renderTable) {
304
            if (renderTable) {
284
                this.renderSection(slug_section);
305
                this.renderSection(slug_section);
285
            }
306
            }
286
        },
307
        },
-
 
308
        /**
-
 
309
         * Add element to option array
-
 
310
         */
287
        this.addOption = function(slug_section, slug_question, text, correct, value) {
311
        this.addOption = function(slug_section, slug_question, text, correct, value) {
288
            var d = new Date();
312
            var d = new Date();
289
            var slug_option = 'option' + d.getTime();
313
            var slug_option = 'option' + d.getTime();
290
            var position = 0;
314
            var position = 0;
291
            var renderTable = false;
315
            var renderTable = false;
Línea 319... Línea 343...
319
            }
343
            }
320
            if (renderTable) {
344
            if (renderTable) {
321
                this.renderSection(slug_section);
345
                this.renderSection(slug_section);
322
            }
346
            }
323
        },
347
        },
-
 
348
        /**
-
 
349
         * Edit element to option array
-
 
350
         */
324
        this.editOption = function(slug_section, slug_question, option_slug, text, correct, value) {
351
        this.editOption = function(slug_section, slug_question, option_slug, text, correct, value) {
325
            var renderTable = false;
352
            var renderTable = false;
326
            for (i = 0; i < this.sections.length; i++) {
353
            for (i = 0; i < this.sections.length; i++) {
327
                if (slug_section == this.sections[i].slug_section) {
354
                if (slug_section == this.sections[i].slug_section) {
328
                    for (j = 0; j < this.sections[i].questions.length; j++) {
355
                    for (j = 0; j < this.sections[i].questions.length; j++) {
Línea 348... Línea 375...
348
            }
375
            }
349
            if (renderTable) {
376
            if (renderTable) {
350
                this.renderSection(slug_section);
377
                this.renderSection(slug_section);
351
            }
378
            }
352
        },
379
        },
-
 
380
        /**
-
 
381
         * Remove element to option array
-
 
382
         */
353
        this.deleteOption = function(slug_section, slug_question, option_slug) {
383
        this.deleteOption = function(slug_section, slug_question, option_slug) {
354
            var renderTable = false;
384
            var renderTable = false;
355
            for (i = 0; i < this.sections.length; i++) {
385
            for (i = 0; i < this.sections.length; i++) {
356
                if (slug_section == this.sections[i].slug_section) {
386
                if (slug_section == this.sections[i].slug_section) {
357
                    for (j = 0; j < this.sections[i].questions.length; j++) {
387
                    for (j = 0; j < this.sections[i].questions.length; j++) {
Línea 385... Línea 415...
385
jQuery(document).ready(function($) {
415
jQuery(document).ready(function($) {
386
    var objFormGenerator = new classFormGenerator();
416
    var objFormGenerator = new classFormGenerator();
387
    objFormGenerator.render();
417
    objFormGenerator.render();
388
    var allowEdit = $allowEdit;
418
    var allowEdit = $allowEdit;
389
    var allowDelete = $allowDelete;
419
    var allowDelete = $allowDelete;
-
 
420
    /**
-
 
421
     * Get rows and set data table
-
 
422
     */
390
    var tableForm = $('#gridTable').dataTable({
423
    var tableForm = $('#gridTable').dataTable({
391
        'processing': true,
424
        'processing': true,
392
        'serverSide': true,
425
        'serverSide': true,
393
        'searching': true,
426
        'searching': true,
394
        'order': [
427
        'order': [
Línea 523... Línea 556...
523
                    return s;
556
                    return s;
524
                }
557
                }
525
            }
558
            }
526
        ],
559
        ],
527
    });
560
    });
-
 
561
    /**
-
 
562
     * Clicked on edit form
528
    
563
     */
529
    $('body').on('click', 'button.btn-edit-form', function(e) {
564
    $('body').on('click', 'button.btn-edit-form', function(e) {
530
        e.preventDefault();
565
        e.preventDefault();
531
        form_id = $(this).data('id')
566
        form_id = $(this).data('id')
532
        var action = $(this).data('href');
567
        var action = $(this).data('href');
533
        $.ajax({
568
        $.ajax({
Línea 539... Línea 574...
539
            if (response['success']) {
574
            if (response['success']) {
540
                validatorForm.resetForm();
575
                validatorForm.resetForm();
541
                $('#form-main').attr('action', action);
576
                $('#form-main').attr('action', action);
542
                $('.btn-form-save-continue').hide();
577
                $('.btn-form-save-continue').hide();
543
                $('#form-main #form-id').val(response['data']['id']),
578
                $('#form-main #form-id').val(response['data']['id']),
544
                $('#form-main #form-continue').val('0');
579
                    $('#form-main #form-continue').val('0');
545
                $('#form-main #form-name').val(response['data']['name']),
580
                $('#form-main #form-name').val(response['data']['name']),
546
                 
-
 
547
 
-
 
548
                /*----------Set Ckeditor ------------*/
581
                    /*----------Set Ckeditor ------------*/
549
                CKEDITOR.instances['form-description'].setData(response['data']['description']);
582
                    CKEDITOR.instances['form-description'].setData(response['data']['description']);
550
                CKEDITOR.instances['form-text'].setData(response['data']['text']);
583
                CKEDITOR.instances['form-text'].setData(response['data']['text']);
551
 
-
 
552
 
-
 
553
                $('#form-main #form-language').val(response['data']['language']),
584
                $('#form-main #form-language').val(response['data']['language']),
554
                $('#form-main #form-status').val(response['data']['status']);
585
                    $('#form-main #form-status').val(response['data']['status']);
555
 
-
 
556
                objFormGenerator.clear();
586
                objFormGenerator.clear();
557
                objFormGenerator.sections = response['data']['content'] || [];
587
                objFormGenerator.sections = response['data']['content'] || [];
558
                objFormGenerator.render();
588
                objFormGenerator.render();
559
                renderSectionData(objFormGenerator.sections);
589
                renderSectionData(objFormGenerator.sections);
560
                $('#row-forms').hide();
590
                $('#row-forms').hide();
Línea 616... Línea 646...
616
    $("#form-main").on('submit', function() {
646
    $("#form-main").on('submit', function() {
617
        for (var instanceName in CKEDITOR.instances) {
647
        for (var instanceName in CKEDITOR.instances) {
618
            CKEDITOR.instances[instanceName].updateElement();
648
            CKEDITOR.instances[instanceName].updateElement();
619
        }
649
        }
620
    })
650
    })
-
 
651
    /**
-
 
652
     * Validate rules form 
-
 
653
     */
621
    var validatorForm = $("#form-main").validate({
654
    var validatorForm = $("#form-main").validate({
622
        ignore: [],
655
        ignore: [],
623
        errorClass: 'help-block',
656
        errorClass: 'help-block',
624
        errorElement: 'span',
657
        errorElement: 'span',
625
        rules: {
658
        rules: {
Línea 663... Línea 696...
663
        },
696
        },
664
        submitHandler: function(form) {
697
        submitHandler: function(form) {
665
            var error = false;
698
            var error = false;
666
            if (objFormGenerator.sections.length == 0) {
699
            if (objFormGenerator.sections.length == 0) {
667
                $.fn.showError('ERROR_SECCTIONS');
700
                $.fn.showError('ERROR_SECCTIONS');
668
                error = true;
701
                return false;
669
            } else {
702
            } else {
670
                for (i = 0; i < objFormGenerator.sections.length; i++) {
703
                for (i = 0; i < objFormGenerator.sections.length; i++) {
671
                    if (objFormGenerator.sections[i].questions.length == 0) {
704
                    if (objFormGenerator.sections[i].questions.length == 0) {
672
                        $.fn.showError('ERROR_QUESTIONS'.replace('%s', objFormGenerator.sections[i].name));
705
                        $.fn.showError('ERROR_QUESTIONS'.replace('%s', objFormGenerator.sections[i].name));
673
                        break;
706
                        return false;
674
                    }
707
                    }
675
                    var valueSection = parseInt(objFormGenerator.sections[i].value);
708
                    var valueSection = parseInt(objFormGenerator.sections[i].value);
676
                    var totalValueQuestion = 0;
709
                    var totalValueQuestion = 0;
677
                    for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
710
                    for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
678
                        valueQuestion = parseInt(objFormGenerator.sections[i].questions[j].value);
711
                        valueQuestion = parseInt(objFormGenerator.sections[i].questions[j].value);
Línea 682... Línea 715...
682
                            objFormGenerator.sections[i].questions[j].type == 'rating-open') {
715
                            objFormGenerator.sections[i].questions[j].type == 'rating-open') {
683
                            var questionNumber = j + 1;
716
                            var questionNumber = j + 1;
684
                            var numberCorrect = 0;
717
                            var numberCorrect = 0;
685
                            if (objFormGenerator.sections[i].questions[j].options.length == 0) {
718
                            if (objFormGenerator.sections[i].questions[j].options.length == 0) {
686
                                $.fn.showError('ERROR_OPTIONS'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
719
                                $.fn.showError('ERROR_OPTIONS'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
687
                                error = true;
-
 
688
                                return false;
720
                                return false;
689
                                break;
-
 
690
                            }
721
                            }
691
                            var totalOption = 0;
722
                            var totalOption = 0;
692
                            var maxOption = 0;
723
                            var maxOption = 0;
693
                            for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
724
                            for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
694
                                if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
725
                                if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
Línea 706... Línea 737...
706
                                }
737
                                }
707
                            }
738
                            }
708
                            if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
739
                            if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
709
                                if (numberCorrect == 0) {
740
                                if (numberCorrect == 0) {
710
                                    $.fn.showError('ERROR_OPTIONS_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
741
                                    $.fn.showError('ERROR_OPTIONS_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
711
                                    error = true;
-
 
712
                                    return false;
742
                                    return false;
713
                                    break;
-
 
714
                                }
743
                                }
715
                                if (objFormGenerator.sections[i].questions[j].type == 'simple' && numberCorrect > 1) {
744
                                if (objFormGenerator.sections[i].questions[j].type == 'simple' && numberCorrect > 1) {
716
                                    $.fn.showError('ERROR_OPTIONS_DUPLICATE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
745
                                    $.fn.showError('ERROR_OPTIONS_DUPLICATE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
717
                                    error = true;
-
 
718
                                    return false;
746
                                    return false;
719
                                    break;
-
 
720
                                }
747
                                }
721
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' && numberCorrect == 1) {
748
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' && numberCorrect == 1) {
722
                                    $.fn.showError('ERROR_OPTIONS_ONE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
749
                                    $.fn.showError('ERROR_OPTIONS_ONE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
723
                                    error = true;
-
 
724
                                    return false;
750
                                    return false;
725
                                    break;
-
 
726
                                }
751
                                }
727
                            }
752
                            }
728
                            if (objFormGenerator.sections[i].questions[j].type == 'multiple' && totalOption > valueQuestion) {
753
                            if (objFormGenerator.sections[i].questions[j].type == 'multiple' && totalOption > valueQuestion) {
729
                                $.fn.showError('ERROR_OPTIONS_SUM_VALUES'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
754
                                $.fn.showError('ERROR_OPTIONS_SUM_VALUES'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
730
                                error = true;
-
 
731
                                return false;
755
                                return false;
732
                                break;
-
 
733
                            }
756
                            }
734
                            if (objFormGenerator.sections[i].questions[j].type == 'rating-open' && maxOption > valueQuestion) {
757
                            if (objFormGenerator.sections[i].questions[j].type == 'rating-open' && maxOption > valueQuestion) {
735
                                $.fn.showError('ERROR_OPTIONS_MAX_OPTION'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
758
                                $.fn.showError('ERROR_OPTIONS_MAX_OPTION'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
736
                                error = true;
-
 
737
                                return false;
759
                                return false;
738
                                break;
-
 
739
                            }
760
                            }
740
                        }
761
                        }
741
                    }
762
                    }
742
                    if (valueSection != totalValueQuestion) {
763
                    if (valueSection != totalValueQuestion) {
743
                        $.fn.showError('ERROR_VALUE_SECTIONS'.replace('%s', objFormGenerator.sections[i].name));
764
                        $.fn.showError('ERROR_VALUE_SECTIONS'.replace('%s', objFormGenerator.sections[i].name));
744
                        error = true;
-
 
745
                        return false;
765
                        return false;
746
                        break;
-
 
747
                    }
766
                    }
748
                }
767
                }
749
                if (error) {
-
 
750
                    return false;
-
 
751
                } else {
-
 
752
                    var formId = parseInt($('#form-main #form-id').val());
768
                var formId = parseInt($('#form-main #form-id').val());
753
                    var formContinue = parseInt($('#form-main #form-continue').val());
769
                var formContinue = parseInt($('#form-main #form-continue').val());
754
                    var data = {
770
                var data = {
755
                        'id': formId,
771
                    'id': formId,
756
                        'name': $('#form-main #form-name').val(),
772
                    'name': $('#form-main #form-name').val(),
757
                        'description': $('#form-main #form-description').val(),
773
                    'description': $('#form-main #form-description').val(),
758
                        'text': $('#form-main #form-text').val(),
774
                    'text': $('#form-main #form-text').val(),
759
                        'language': $('#form-main #form-language').val(),
775
                    'language': $('#form-main #form-language').val(),
760
                        'status': $('#form-main #form-status').val(),
776
                    'status': $('#form-main #form-status').val(),
761
                        'content': JSON.stringify(objFormGenerator.sections)
777
                    'content': JSON.stringify(objFormGenerator.sections)
762
                    }
778
                }
763
                    $.ajax({
779
                $.ajax({
764
                        'dataType': 'json',
780
                    'dataType': 'json',
765
                        'method': 'post',
781
                    'method': 'post',
766
                        'url': $('#form-main').attr('action'),
782
                    'url': $('#form-main').attr('action'),
767
                        'data': data,
783
                    'data': data,
768
                    }).done(function(response) {
784
                }).done(function(response) {
769
                        if (response['success']) {
785
                    if (response['success']) {
770
                            $.fn.showSuccess(response['data']);
786
                        $.fn.showSuccess(response['data']);
771
                            if (formContinue == 1) {
787
                        if (formContinue == 1) {
772
                                $('#form-main #form-id').val(response['form-id']);
788
                            $('#form-main #form-id').val(response['form-id']);
773
                                $('#form-main #form-continue').val(0);
789
                            $('#form-main #form-continue').val(0);
774
                            } else {
-
 
775
                                $('#row-edit').hide();
-
 
776
                                $('#row-forms').show();
-
 
777
                            }
-
 
778
 
-
 
779
                            /*---------- Reset Form -------- */
-
 
780
                            $('#form-main')[0].reset();
-
 
781
        
-
 
782
                            /*--------Reset Ckeditor ----------*/
-
 
783
                            CKEDITOR.instances['form-text'].setData('');
-
 
784
                            CKEDITOR.instances['form-description'].setData('');
-
 
785
 
-
 
786
                            /*--------Reset Sections ----------*/
-
 
787
                            clearSectionData();
-
 
788
 
-
 
789
                            /* ------- Refresh Table -----------*/
-
 
790
                            tableForm.fnDraw();
-
 
791
 
-
 
792
                        } else {
790
                        } else {
-
 
791
                            $('#row-edit').hide();
793
                            $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
792
                            $('#row-forms').show();
794
                        }
793
                        }
-
 
794
                        /*---------- Reset Form -------- */
-
 
795
                        $('#form-main')[0].reset();
-
 
796
                        /*--------Reset Ckeditor ----------*/
795
                    }).fail(function(jqXHR, textStatus, errorThrown) {
797
                        CKEDITOR.instances['form-text'].setData('');
-
 
798
                        CKEDITOR.instances['form-description'].setData('');
-
 
799
                        /*--------Reset Sections ----------*/
796
                        $.fn.showError(textStatus);
800
                        clearSectionData();
-
 
801
                        /* ------- Refresh Table -----------*/
-
 
802
                        tableForm.fnDraw();
-
 
803
                    } else {
-
 
804
                        $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
797
                    });
805
                    }
-
 
806
                }).fail(function(jqXHR, textStatus, errorThrown) {
798
                    return false;
807
                    $.fn.showError(textStatus);
799
                }
808
                });
-
 
809
                return false;
800
            }
810
            }
801
        }
811
        }
802
    });
812
    });
803
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
813
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
804
    $("#form-section").on('submit', function() {
814
    $("#form-section").on('submit', function() {
805
        for (var instanceName in CKEDITOR.instances) {
815
        for (var instanceName in CKEDITOR.instances) {
806
            CKEDITOR.instances[instanceName].updateElement();
816
            CKEDITOR.instances[instanceName].updateElement();
807
        }
817
        }
808
    })
818
    })
-
 
819
    /**
-
 
820
     * Validate rules form section
-
 
821
     */
809
    var validatorFormSection = $("#form-section").validate({
822
    var validatorFormSection = $("#form-section").validate({
810
        ignore: [],
823
        ignore: [],
811
        errorClass: 'help-block',
824
        errorClass: 'help-block',
812
        errorElement: 'span',
825
        errorElement: 'span',
813
        rules: {
826
        rules: {
Línea 872... Línea 885...
872
    $("#form-question").on('submit', function() {
885
    $("#form-question").on('submit', function() {
873
        for (var instanceName in CKEDITOR.instances) {
886
        for (var instanceName in CKEDITOR.instances) {
874
            CKEDITOR.instances[instanceName].updateElement();
887
            CKEDITOR.instances[instanceName].updateElement();
875
        }
888
        }
876
    })
889
    })
-
 
890
    /**
-
 
891
     * Validate rules form Questions
-
 
892
     */
877
    var validatorFormQuestion = $("#form-question").validate({
893
    var validatorFormQuestion = $("#form-question").validate({
878
        ignore: [],
894
        ignore: [],
879
        errorClass: 'help-block',
895
        errorClass: 'help-block',
880
        errorElement: 'span',
896
        errorElement: 'span',
881
        rules: {
897
        rules: {
Línea 953... Línea 969...
953
    $("#form-option").on('submit', function() {
969
    $("#form-option").on('submit', function() {
954
        for (var instanceName in CKEDITOR.instances) {
970
        for (var instanceName in CKEDITOR.instances) {
955
            CKEDITOR.instances[instanceName].updateElement();
971
            CKEDITOR.instances[instanceName].updateElement();
956
        }
972
        }
957
    })
973
    })
-
 
974
    /**
-
 
975
     * Validate rules form options
-
 
976
     */
958
    var validatorFormOption = $("#form-option").validate({
977
    var validatorFormOption = $("#form-option").validate({
959
        ignore: [],
978
        ignore: [],
960
        errorClass: 'help-block',
979
        errorClass: 'help-block',
961
        errorElement: 'span',
980
        errorElement: 'span',
962
        rules: {
981
        rules: {
Línea 1011... Línea 1030...
1011
            renderSectionData(objFormGenerator.sections);
1030
            renderSectionData(objFormGenerator.sections);
1012
            $('#modal-option').modal('hide');
1031
            $('#modal-option').modal('hide');
1013
            return false;
1032
            return false;
1014
        }
1033
        }
1015
    });
1034
    });
-
 
1035
    /**
-
 
1036
     * Clicked on add new section
-
 
1037
     */
1016
    $('body').on('click', 'button[id="btn-add-section"]', function(e) {
1038
    $('body').on('click', 'button[id="btn-add-section"]', function(e) {
1017
        e.preventDefault();
1039
        e.preventDefault();
1018
        validatorFormSection.resetForm();
1040
        validatorFormSection.resetForm();
1019
        $('#form-section #section-slug').val('');
1041
        $('#form-section #section-slug').val('');
1020
        $('#form-section #section-name').val('');
1042
        $('#form-section #section-name').val('');
1021
        CKEDITOR.instances['section-text'].setData('');
1043
        CKEDITOR.instances['section-text'].setData('');
1022
        $('#form-section #section-value').val('0');
1044
        $('#form-section #section-value').val('0');
1023
        $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
1045
        $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
1024
        $('#modal-section').modal('show');
1046
        $('#modal-section').modal('show');
1025
    });
1047
    });
-
 
1048
    /**
-
 
1049
     * Clicked on edit section
-
 
1050
     */
1026
    $('body').on('click', 'button.btn-edit-section', function(e) {
1051
    $('body').on('click', 'button.btn-edit-section', function(e) {
1027
        e.preventDefault();
1052
        e.preventDefault();
1028
        var slug = $(this).data('section');
1053
        var slug = $(this).data('section');
1029
        var section;
1054
        var section;
1030
        var showForm = false;
1055
        var showForm = false;
Línea 1043... Línea 1068...
1043
        if (showForm) {
1068
        if (showForm) {
1044
            $('#modal-section h4[class="modal-title"]').html('LABEL_EDIT LABEL_SECTION');
1069
            $('#modal-section h4[class="modal-title"]').html('LABEL_EDIT LABEL_SECTION');
1045
            $('#modal-section').modal('show');
1070
            $('#modal-section').modal('show');
1046
        }
1071
        }
1047
    });
1072
    });
-
 
1073
    /**
-
 
1074
     * Clicked on remove section
-
 
1075
     */
1048
    $('body').on('click', 'button.btn-delete-section', function(e) {
1076
    $('body').on('click', 'button.btn-delete-section', function(e) {
1049
        e.preventDefault();
1077
        e.preventDefault();
1050
        var slug = $(this).data('section');
1078
        var slug = $(this).data('section');
1051
        bootbox.confirm({
1079
        bootbox.confirm({
1052
            title: "LABEL_DELETE LABEL_SECTION",
1080
            title: "LABEL_DELETE LABEL_SECTION",
Línea 1065... Línea 1093...
1065
                    renderSectionData(objFormGenerator.sections);
1093
                    renderSectionData(objFormGenerator.sections);
1066
                }
1094
                }
1067
            }
1095
            }
1068
        });
1096
        });
1069
    });
1097
    });
-
 
1098
    /**
-
 
1099
     * Clicked add new question
-
 
1100
     */
1070
    $('body').on('click', 'button.btn-add-question', function(e) {
1101
    $('body').on('click', 'button.btn-add-question', function(e) {
1071
        e.preventDefault();
1102
        e.preventDefault();
1072
        validatorFormQuestion.resetForm();
1103
        validatorFormQuestion.resetForm();
1073
        var slug = $(this).data('section');
1104
        var slug = $(this).data('section');
1074
        $('#form-question #question-section').val(slug);
1105
        $('#form-question #question-section').val(slug);
Línea 1083... Línea 1114...
1083
        $('#form-question #question-range').val('10');
1114
        $('#form-question #question-range').val('10');
1084
        $('#form-question #question-range').parent().hide();
1115
        $('#form-question #question-range').parent().hide();
1085
        $('#modal-question h4[class="modal-title"]').html('LABEL_ADD LABEL_QUESTION');
1116
        $('#modal-question h4[class="modal-title"]').html('LABEL_ADD LABEL_QUESTION');
1086
        $('#modal-question').modal('show');
1117
        $('#modal-question').modal('show');
1087
    });
1118
    });
-
 
1119
    /**
-
 
1120
     * Clicked edit question
-
 
1121
     */
1088
    $('body').on('click', 'button.btn-edit-question', function(e) {
1122
    $('body').on('click', 'button.btn-edit-question', function(e) {
1089
        e.preventDefault();
1123
        e.preventDefault();
1090
        var slug_section = $(this).data('section');
1124
        var slug_section = $(this).data('section');
1091
        var slug = $(this).data('question');
1125
        var slug = $(this).data('question');
1092
        var showForm = false;
1126
        var showForm = false;
Línea 1128... Línea 1162...
1128
        if (showForm) {
1162
        if (showForm) {
1129
            $('#modal-question h4[class="modal-title"]').html('LABEL_EDIT LABEL_QUESTION');
1163
            $('#modal-question h4[class="modal-title"]').html('LABEL_EDIT LABEL_QUESTION');
1130
            $('#modal-question').modal('show');
1164
            $('#modal-question').modal('show');
1131
        }
1165
        }
1132
    });
1166
    });
-
 
1167
    /**
-
 
1168
     * Clicked remove question
-
 
1169
     */
1133
    $('body').on('click', 'button.btn-delete-question', function(e) {
1170
    $('body').on('click', 'button.btn-delete-question', function(e) {
1134
        e.preventDefault();
1171
        e.preventDefault();
1135
        var slug_section = $(this).data('section');
1172
        var slug_section = $(this).data('section');
1136
        var slug = $(this).data('question');
1173
        var slug = $(this).data('question');
1137
        bootbox.confirm({
1174
        bootbox.confirm({
Línea 1151... Línea 1188...
1151
                    renderSectionData(objFormGenerator.sections);
1188
                    renderSectionData(objFormGenerator.sections);
1152
                }
1189
                }
1153
            }
1190
            }
1154
        });
1191
        });
1155
    });
1192
    });
-
 
1193
    /**
-
 
1194
     * Clicked add new Option
1156
     
1195
     */
1157
    $('body').on('click', 'button.btn-add-option', function(e) {
1196
    $('body').on('click', 'button.btn-add-option', function(e) {
1158
        e.preventDefault();
1197
        e.preventDefault();
1159
        var slug_section = $(this).data('section');
1198
        var slug_section = $(this).data('section');
1160
        var slug_question = $(this).data('question');
1199
        var slug_question = $(this).data('question');
1161
        var showForm = false;
1200
        var showForm = false;
Línea 1165... Línea 1204...
1165
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1204
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1166
                        validatorFormOption.resetForm();
1205
                        validatorFormOption.resetForm();
1167
                        $('#form-option #option-section').val(slug_section);
1206
                        $('#form-option #option-section').val(slug_section);
1168
                        $('#form-option #option-question').val(slug_question);
1207
                        $('#form-option #option-question').val(slug_question);
1169
                        $('#form-option #option-slug').val('');
1208
                        $('#form-option #option-slug').val('');
1170
 
-
 
1171
                        CKEDITOR.instances['option-text'].setData('', function() {
1209
                        CKEDITOR.instances['option-text'].setData('', function() {
1172
                            editor.focus();
1210
                            editor.focus();
1173
                        });
1211
                        });
1174
 
-
 
1175
                        $('#form-option #option-correct').val('0');
1212
                        $('#form-option #option-correct').val('0');
1176
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1213
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1177
                            $('#form-option #option-correct').parent().hide();
1214
                            $('#form-option #option-correct').parent().hide();
1178
                        } else {
1215
                        } else {
1179
                            $('#form-option #option-correct').parent().show();
1216
                            $('#form-option #option-correct').parent().show();
Línea 1194... Línea 1231...
1194
        if (showForm) {
1231
        if (showForm) {
1195
            $('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
1232
            $('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
1196
            $('#modal-option').modal('show');
1233
            $('#modal-option').modal('show');
1197
        }
1234
        }
1198
    });
1235
    });
-
 
1236
    /**
-
 
1237
     * Clicked edit option
1199
 
1238
     */
1200
    $('body').on('click', 'button.btn-edit-option', function(e) {
1239
    $('body').on('click', 'button.btn-edit-option', function(e) {
1201
        e.preventDefault();
1240
        e.preventDefault();
1202
        var slug_section = $(this).data('section');
1241
        var slug_section = $(this).data('section');
1203
        var slug_question = $(this).data('question');
1242
        var slug_question = $(this).data('question');
1204
        var slug = $(this).data('slug');
1243
        var slug = $(this).data('slug');
Línea 1211... Línea 1250...
1211
                            if (slug == objFormGenerator.sections[i].questions[j].options[k].slug_option) {
1250
                            if (slug == objFormGenerator.sections[i].questions[j].options[k].slug_option) {
1212
                                validatorFormOption.resetForm();
1251
                                validatorFormOption.resetForm();
1213
                                $('#form-option #option-section').val(objFormGenerator.sections[i].slug_section);
1252
                                $('#form-option #option-section').val(objFormGenerator.sections[i].slug_section);
1214
                                $('#form-option #option-question').val(objFormGenerator.sections[i].questions[j].slug_question);
1253
                                $('#form-option #option-question').val(objFormGenerator.sections[i].questions[j].slug_question);
1215
                                $('#form-option #option-slug').val(objFormGenerator.sections[i].questions[j].options[k].slug_option);
1254
                                $('#form-option #option-slug').val(objFormGenerator.sections[i].questions[j].options[k].slug_option);
1216
                                CKEDITOR.instances['option-text'].setData(objFormGenerator.sections[i].questions[j].options[k].text, 
1255
                                CKEDITOR.instances['option-text'].setData(objFormGenerator.sections[i].questions[j].options[k].text,
1217
                                function() {
1256
                                    function() {
1218
                                    editor.focus();
1257
                                        editor.focus();
1219
                                });
1258
                                    });
1220
                                $('#form-option #option-correct').val(objFormGenerator.sections[i].questions[j].options[k].correct);
1259
                                $('#form-option #option-correct').val(objFormGenerator.sections[i].questions[j].options[k].correct);
1221
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'simple') {
1260
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'simple') {
1222
                                    $('#form-option #option-correct').parent().show();
1261
                                    $('#form-option #option-correct').parent().show();
1223
                                } else {
1262
                                } else {
1224
                                    $('#form-option #option-correct').parent().hide();
1263
                                    $('#form-option #option-correct').parent().hide();
Línea 1246... Línea 1285...
1246
        if (showForm) {
1285
        if (showForm) {
1247
            $('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
1286
            $('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
1248
            $('#modal-option').modal('show');
1287
            $('#modal-option').modal('show');
1249
        }
1288
        }
1250
    });
1289
    });
-
 
1290
    /**
-
 
1291
     * Clicked remove option
-
 
1292
     */
1251
    $('body').on('click', 'button.btn-delete-option', function(e) {
1293
    $('body').on('click', 'button.btn-delete-option', function(e) {
1252
        e.preventDefault();
1294
        e.preventDefault();
1253
        var slug_section = $(this).data('section');
1295
        var slug_section = $(this).data('section');
1254
        var slug_question = $(this).data('question');
1296
        var slug_question = $(this).data('question');
1255
        var slug = $(this).data('slug');
1297
        var slug = $(this).data('slug');
Línea 1270... Línea 1312...
1270
                    renderSectionData(objFormGenerator.sections);
1312
                    renderSectionData(objFormGenerator.sections);
1271
                }
1313
                }
1272
            }
1314
            }
1273
        });
1315
        });
1274
    })
1316
    })
-
 
1317
    /**
-
 
1318
     * Format input number (Form Section) 
-
 
1319
     */
1275
    $('#form-section #section-value').inputNumberFormat({
1320
    $('#form-section #section-value').inputNumberFormat({
1276
        'decimal': 2
1321
        'decimal': 2
1277
    });
1322
    });
-
 
1323
    /**
-
 
1324
     * Format input number (Form Question) 
-
 
1325
     */
1278
    $('#form-question #question-value').inputNumberFormat({
1326
    $('#form-question #question-value').inputNumberFormat({
1279
        'decimal': 2
1327
        'decimal': 2
1280
    });
1328
    });
-
 
1329
    /**
-
 
1330
     * Format input number (Form Question) 
-
 
1331
     */
1281
    $('#form-question #question-max-length').inputNumberFormat({
1332
    $('#form-question #question-max-length').inputNumberFormat({
1282
        'decimal': 0
1333
        'decimal': 0
1283
    });
1334
    });
-
 
1335
    /**
-
 
1336
     * Format input number (Form Option) 
-
 
1337
     */
1284
    $('#form-option #option-value').inputNumberFormat({
1338
    $('#form-option #option-value').inputNumberFormat({
1285
        'decimal': 2
1339
        'decimal': 2
1286
    });
1340
    });
-
 
1341
    /**
-
 
1342
     * Detect when updating question status and hide/Show options
-
 
1343
     */
1287
    $('#form-question #question-type').change(function(e) {
1344
    $('#form-question #question-type').change(function(e) {
1288
        e.preventDefault();
1345
        e.preventDefault();
1289
        if ($('#form-question #question-type').val() == 'open') {
1346
        if ($('#form-question #question-type').val() == 'open') {
1290
            $('#form-question #question-max-length').parent().show();
1347
            $('#form-question #question-max-length').parent().show();
1291
            $('#form-question #question-multiline').parent().show();
1348
            $('#form-question #question-multiline').parent().show();
Línea 1300... Línea 1357...
1300
            $('#form-question #question-range').parent().show();
1357
            $('#form-question #question-range').parent().show();
1301
        } else {
1358
        } else {
1302
            $('#form-question #question-range').parent().hide();
1359
            $('#form-question #question-range').parent().hide();
1303
        }
1360
        }
1304
    });
1361
    });
-
 
1362
    /**
-
 
1363
     * Clicked new Form
-
 
1364
     */
1305
    $('button.btn-add-form').click(function(e) {
1365
    $('button.btn-add-form').click(function(e) {
1306
        e.preventDefault();
1366
        e.preventDefault();
1307
        objFormGenerator.clear();
1367
        objFormGenerator.clear();
1308
        objFormGenerator.render();
1368
        objFormGenerator.render();
1309
        validatorForm.resetForm();
1369
        validatorForm.resetForm();
1310
        clearSectionData();
1370
        clearSectionData();
1311
 
-
 
1312
        $('.btn-form-save-continue').show();
1371
        $('.btn-form-save-continue').show();
1313
 
-
 
1314
        $('#form-main').attr('action', '$routeAdd');
1372
        $('#form-main').attr('action', '$routeAdd');
1315
 
-
 
1316
        $('#form-main #form-id').val('0');
1373
        $('#form-main #form-id').val('0');
1317
        $('#form-main #form-continue').val('0');
1374
        $('#form-main #form-continue').val('0');
1318
        $('#form-main #form-name').val('');
1375
        $('#form-main #form-name').val('');
1319
 
-
 
1320
        $('#form-main #form-language').val('$lang_es'),
1376
        $('#form-main #form-language').val('$lang_es'),
1321
        $('#form-main #form-status').val('$status_inactive');
1377
            $('#form-main #form-status').val('$status_inactive');
1322
 
-
 
1323
        $('#row-forms').hide();
1378
        $('#row-forms').hide();
1324
        $('#row-edit').show();
1379
        $('#row-edit').show();
1325
        $('#form-main #form-name').focus();
1380
        $('#form-main #form-name').focus();
1326
 
-
 
1327
    });
1381
    });
-
 
1382
    /**
-
 
1383
     * Clicked cancel new/edit Form
-
 
1384
     */
1328
    $('button.btn-edit-cancel').click(function(e) {
1385
    $('button.btn-edit-cancel').click(function(e) {
1329
        e.preventDefault();
1386
        e.preventDefault();
1330
        $('#row-edit').hide();
1387
        $('#row-edit').hide();
1331
        $('#row-forms').show();
1388
        $('#row-forms').show();
1332
    });
1389
    });
-
 
1390
    /**
-
 
1391
     * Clicked save and continue new Form
-
 
1392
     */
1333
    $('button.btn-form-save-continue').click(function(e) {
1393
    $('button.btn-form-save-continue').click(function(e) {
1334
        e.preventDefault();
1394
        e.preventDefault();
1335
        $('#form-main #form-continue').val('1')
1395
        $('#form-main #form-continue').val('1')
1336
        $('#form-main').submit();
1396
        $('#form-main').submit();
1337
    });
1397
    });
-
 
1398
    /**
-
 
1399
     * Clicked save and close new/edit Form
-
 
1400
     */
1338
    $('button.btn-form-save-close').click(function(e) {
1401
    $('button.btn-form-save-close').click(function(e) {
1339
        e.preventDefault();
1402
        e.preventDefault();
1340
        $('#form-main #form-continue').val('0')
1403
        $('#form-main #form-continue').val('0')
1341
        $('#form-main').submit();
1404
        $('#form-main').submit();
1342
    });
1405
    });
-
 
1406
    /**
-
 
1407
     * Modal Settings
-
 
1408
     */
1343
    $('#modal-section, #modal-question, #modal-option').modal({
1409
    $('#modal-section, #modal-question, #modal-option').modal({
1344
        backdrop: 'static',
1410
        backdrop: 'static',
1345
        keyboard: false,
1411
        keyboard: false,
1346
        show: false
1412
        show: false
1347
    });
1413
    });
1348
 
-
 
1349
    /**
1414
    /**
1350
    * Get Question type
1415
     * Get Question type
1351
    */
1416
     */
1352
    const getQuestionTypeBySlug = (slug_section, slug_question) => {
1417
    const getQuestionTypeBySlug = (slug_section, slug_question) => {
1353
         for (i = 0; i < objFormGenerator.sections.length; i++) {
1418
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1354
             if (slug_section == objFormGenerator.sections[i].slug_section) {
1419
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1355
                 for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1420
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1356
                     if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1421
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1357
                         return objFormGenerator.sections[i].questions[j].type;
1422
                        return objFormGenerator.sections[i].questions[j].type;
1358
                     }
1423
                    }
1359
                 }
1424
                }
1360
             }
1425
            }
1361
         }
1426
        }
1362
    }
1427
    }
1363
        
-
 
1364
    /**
1428
    /**
1365
    * Render Sections data
1429
     * Render Sections data
1366
    */
1430
     */
1367
    const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
1431
    const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
1368
         getType: getQuestionTypeBySlug
1432
        getType: getQuestionTypeBySlug
1369
    }));
1433
    }));
1370
     
-
 
1371
    /**
1434
    /**
1372
    * Clear Div Section data 
1435
     * Clear Div Section data 
1373
    */
1436
     */
1374
    const clearSectionData = () => $("#rows").html(''); 
1437
    const clearSectionData = () => $("#rows").html('');
1375
 
-
 
1376
    /**
1438
    /**
1377
    * Click on refresh button
1439
     * Clicked refresh button
1378
    */
1440
     */
1379
    $('button.btn-refresh').click(function(e) {
1441
    $('button.btn-refresh').click(function(e) {
1380
        tableForm.fnDraw(); 
1442
        tableForm.fnDraw();
1381
    });
1443
    });
1382
});
1444
});
1383
JS;
1445
JS;
1384
$this->inlineScript()->captureEnd();
1446
$this->inlineScript()->captureEnd();
1385
?>
1447
?>