Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 992 Rev 993
Línea 830... Línea 830...
830
        }
830
        }
831
    });
831
    });
832
    /**
832
    /**
833
     * Validate rules form Questions
833
     * Validate rules form Questions
834
     */
834
     */
835
    var validatorFormQuestion = $("#form-question").validate({
835
    var validatorFormQuestion = $("#form-section").validate({
836
        ignore: [],
836
        ignore: [],
837
        errorClass: 'help-block',
837
        errorClass: 'help-block',
838
        errorElement: 'span',
838
        errorElement: 'span',
839
        rules: {
839
        rules: {
840
            'question-text': {
840
            'question-text': {
Línea 878... Línea 878...
878
            $('html, body').animate({
878
            $('html, body').animate({
879
                scrollTop: $(validator.errorList[0].element).offset().top - 100
879
                scrollTop: $(validator.errorList[0].element).offset().top - 100
880
            }, 1000);
880
            }, 1000);
881
        },
881
        },
882
        submitHandler: function(form) {
882
        submitHandler: function(form) {
883
            if ($('#form-question #question-slug').val()) {
883
            if ($('#form-section #section-id').val()) {
884
                objFormGenerator.editQuestion(
884
                objFormGenerator.editQuestion(
885
                    $('#form-question #question-section').val(),
885
                    $('#form-section #question-section').val(),
886
                    $('#form-question #question-slug').val(),
886
                    $('#form-section #section-id').val(),
887
                    $('#form-question #question-text').val(),
887
                    $('#form-section #question-text').val(),
888
                    $('#form-question #question-value').val(),
888
                    $('#form-section #question-value').val(),
889
                    $('#form-question #question-type').val(),
889
                    $('#form-section #question-type').val(),
890
                    $('#form-question #question-max-length').val(),
890
                    $('#form-section #question-max-length').val(),
891
                    $('#form-question #question-multiline').val(),
891
                    $('#form-section #question-multiline').val(),
892
                    $('#form-question #question-range').val()
892
                    $('#form-section #question-range').val()
893
                );
893
                );
894
            } else {
894
            } else {
895
                objFormGenerator.addQuestion(
895
                objFormGenerator.addQuestion(
896
                    $('#form-question #question-section').val(),
896
                    $('#form-section #question-section').val(),
897
                    $('#form-question #question-text').val(),
897
                    $('#form-section #question-text').val(),
898
                    $('#form-question #question-value').val(),
898
                    $('#form-section #question-value').val(),
899
                    $('#form-question #question-type').val(),
899
                    $('#form-section #question-type').val(),
900
                    $('#form-question #question-max-length').val(),
900
                    $('#form-section #question-max-length').val(),
901
                    $('#form-question #question-multiline').val(),
901
                    $('#form-section #question-multiline').val(),
902
                    $('#form-question #question-range').val()
902
                    $('#form-section #question-range').val()
903
                );
903
                );
904
            }
904
            }
905
            renderSectionData(objFormGenerator.sections);
905
            renderSectionData(objFormGenerator.sections);
906
            $('#modal-question').modal('hide');
906
            $('#modal-section').modal('hide');
907
            return false;
907
            return false;
908
        }
908
        }
909
    });
909
    });
910
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
910
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
911
    $("#form-option").on('submit', function() {
911
    $("#form-option").on('submit', function() {
Línea 975... Línea 975...
975
        }
975
        }
976
    });
976
    });
977
    /**
977
    /**
978
     * Clicked add new question
978
     * Clicked add new question
979
     */
979
     */
980
    $('body').on('click', 'button.btn-add-question', function(e) {
980
    $('body').on('click', 'button.btn-add-section', function(e) {
981
        e.preventDefault();
981
        e.preventDefault();
982
        validatorFormQuestion.resetForm();
982
        validatorFormQuestion.resetForm();
983
        var slug = $(this).data('section');
-
 
984
        $('#form-question #question-section').val(slug);
-
 
985
        $('#form-question #question-slug').val('');
983
        $('#form-section #section-id').val('');
986
        CKEDITOR.instances['question-text'].setData('');
984
        CKEDITOR.instances['question-text'].setData('');
987
        $('#form-question #question-value').val('0');
-
 
988
        $('#form-question #question-type').val($('#form-question #question-type option:first').val());
985
        $('#form-section #question-type').val($('#form-section #question-type option:first').val());
989
        $('#form-question #question-max-length').val('0');
986
        $('#form-section #question-max-length').val('0');
990
        $('#form-question #question-max-length').parent().show();
987
        $('#form-section #question-max-length').parent().show();
991
        $('#form-question #question-multiline').val('0');
988
        $('#form-section #question-multiline').val('0');
992
        $('#form-question #question-multiline').parent().show();
989
        $('#form-section #question-multiline').parent().show();
993
        $('#form-question #question-range').val('10');
-
 
994
        $('#form-question #question-range').parent().hide();
-
 
995
        $('#modal-question h4[class="modal-title"]').html('LABEL_ADD LABEL_QUESTION');
990
        $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
996
        $('#modal-question').modal('show');
991
        $('#modal-section').modal('show');
997
    });
992
    });
998
    /**
993
    /**
999
     * Clicked edit question
994
     * Clicked edit question
1000
     */
995
     */
1001
    $('body').on('click', 'button.btn-edit-question', function(e) {
996
    $('body').on('click', 'button.btn-edit-section', function(e) {
1002
        e.preventDefault();
997
        e.preventDefault();
1003
        var slug_section = $(this).data('section');
998
        var slug_section = $(this).data('section');
1004
        var slug = $(this).data('question');
999
        var slug = $(this).data('question');
1005
        var showForm = false;
1000
        var showForm = false;
1006
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1001
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1007
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1002
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1008
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1003
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1009
                    if (slug == objFormGenerator.sections[i].questions[j].slug_question) {
1004
                    if (slug == objFormGenerator.sections[i].questions[j].slug_question) {
1010
                        validatorFormQuestion.resetForm();
1005
                        validatorFormQuestion.resetForm();
1011
                        $('#form-question #question-section').val(objFormGenerator.sections[i].slug_section);
1006
                        $('#form-section #question-section').val(objFormGenerator.sections[i].slug_section);
1012
                        $('#form-question #question-slug').val(objFormGenerator.sections[i].questions[j].slug_question);
1007
                        $('#form-section #section-id').val(objFormGenerator.sections[i].questions[j].slug_question);
1013
                        CKEDITOR.instances['question-text'].setData(objFormGenerator.sections[i].questions[j].text);
1008
                        CKEDITOR.instances['question-text'].setData(objFormGenerator.sections[i].questions[j].text);
1014
                        $('#form-question #question-value').val(objFormGenerator.sections[i].questions[j].value);
1009
                        $('#form-section #question-value').val(objFormGenerator.sections[i].questions[j].value);
1015
                        $('#form-question #question-type').val(objFormGenerator.sections[i].questions[j].type);
1010
                        $('#form-section #question-type').val(objFormGenerator.sections[i].questions[j].type);
1016
                        if (objFormGenerator.sections[i].questions[j].type == 'open') {
1011
                        if (objFormGenerator.sections[i].questions[j].type == 'open') {
1017
                            $('#form-question #question-max-length').val(objFormGenerator.sections[i].questions[j].maxlength);
1012
                            $('#form-section #question-max-length').val(objFormGenerator.sections[i].questions[j].maxlength);
1018
                            $('#form-question #question-max-length').parent().show();
1013
                            $('#form-section #question-max-length').parent().show();
1019
                            $('#form-question #question-multiline').val(objFormGenerator.sections[i].questions[j].multiline);
1014
                            $('#form-section #question-multiline').val(objFormGenerator.sections[i].questions[j].multiline);
1020
                            $('#form-question #question-multiline').parent().show();
1015
                            $('#form-section #question-multiline').parent().show();
1021
                        } else {
1016
                        } else {
1022
                            $('#form-question #question-max-length').val('0');
1017
                            $('#form-section #question-max-length').val('0');
1023
                            $('#form-question #question-max-length').parent().hide();
1018
                            $('#form-section #question-max-length').parent().hide();
1024
                            $('#form-question #question-multiline').val('0');
1019
                            $('#form-section #question-multiline').val('0');
1025
                            $('#form-question #question-multiline').parent().hide();
1020
                            $('#form-section #question-multiline').parent().hide();
1026
                        }
1021
                        }
1027
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-range') {
1022
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-range') {
1028
                            $('#form-question #question-range').val(objFormGenerator.sections[i].questions[j].range);
1023
                            $('#form-section #question-range').val(objFormGenerator.sections[i].questions[j].range);
1029
                            $('#form-question #question-range').parent().show();
1024
                            $('#form-section #question-range').parent().show();
1030
                        } else {
1025
                        } else {
1031
                            $('#form-question #question-range').val('10');
1026
                            $('#form-section #question-range').val('10');
1032
                            $('#form-question #question-range').parent().hide();
1027
                            $('#form-section #question-range').parent().hide();
1033
                        }
1028
                        }
1034
                        showForm = true;
1029
                        showForm = true;
1035
                        break;
1030
                        break;
1036
                    }
1031
                    }
1037
                }
1032
                }
1038
                break;
1033
                break;
1039
            }
1034
            }
1040
        }
1035
        }
1041
        if (showForm) {
1036
        if (showForm) {
1042
            $('#modal-question h4[class="modal-title"]').html('LABEL_EDIT LABEL_QUESTION');
1037
            $('#modal-section h4[class="modal-title"]').html('LABEL_EDIT LABEL_SECTION');
1043
            $('#modal-question').modal('show');
1038
            $('#modal-section').modal('show');
1044
        }
1039
        }
1045
    });
1040
    });
1046
    /**
1041
    /**
1047
     * Clicked remove question
1042
     * Clicked remove question
1048
     */
1043
     */
1049
    $('body').on('click', 'button.btn-delete-question', function(e) {
1044
    $('body').on('click', 'button.btn-delete-section', function(e) {
1050
        e.preventDefault();
1045
        e.preventDefault();
1051
        var slug_section = $(this).data('section');
1046
        var slug_section = $(this).data('section');
1052
        var slug = $(this).data('question');
1047
        var slug = $(this).data('question');
1053
        bootbox.confirm({
1048
        bootbox.confirm({
1054
            title: "LABEL_DELETE LABEL_QUESTION",
1049
            title: "LABEL_DELETE LABEL_SECTION",
1055
            message: "LABEL_QUESTION_DELETE",
1050
            message: "LABEL_SECTION_DELETE",
1056
            buttons: {
1051
            buttons: {
1057
                cancel: {
1052
                cancel: {
1058
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1053
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1059
                },
1054
                },
1060
                confirm: {
1055
                confirm: {
Línea 1172... Línea 1167...
1172
        var slug_section = $(this).data('section');
1167
        var slug_section = $(this).data('section');
1173
        var slug_question = $(this).data('question');
1168
        var slug_question = $(this).data('question');
1174
        var slug = $(this).data('slug');
1169
        var slug = $(this).data('slug');
1175
        bootbox.confirm({
1170
        bootbox.confirm({
1176
            title: "LABEL_DELETE LABEL_OPTION",
1171
            title: "LABEL_DELETE LABEL_OPTION",
1177
            message: "LABEL_QUESTION_DELETE",
1172
            message: "LABEL_SECTION_DELETE",
1178
            buttons: {
1173
            buttons: {
1179
                cancel: {
1174
                cancel: {
1180
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1175
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1181
                },
1176
                },
1182
                confirm: {
1177
                confirm: {
Línea 1233... Línea 1228...
1233
        $('#form-main').submit();
1228
        $('#form-main').submit();
1234
    });
1229
    });
1235
    /**
1230
    /**
1236
     * Modal Settings
1231
     * Modal Settings
1237
     */
1232
     */
1238
    $('#modal-section, #modal-question, #modal-option').modal({
1233
    $('#modal-section, #modal-section, #modal-option').modal({
1239
        backdrop: 'static',
1234
        backdrop: 'static',
1240
        keyboard: false,
1235
        keyboard: false,
1241
        show: false
1236
        show: false
1242
    });
1237
    });
1243
    /**
1238
    /**
Línea 1360... Línea 1355...
1360
 
1355
 
Línea 1361... Línea 1356...
1361
  
1356
  
1362
 
1357
 
1363
    <!-- Question Modal -->
1358
    <!-- Question Modal -->
1364
 
1359
 
1365
    <div  id="modal-question" class="modal" tabindex="-1" role="dialog">
1360
    <div  id="modal-section" class="modal" tabindex="-1" role="dialog">
1366
        <div class="modal-dialog modal-lg" role="document">
1361
        <div class="modal-dialog modal-lg" role="document">
1367
            <form action="#" name="form-question" id="form-question">
1362
            <form action="#" name="form-section" id="form-section">
1368
                <input type="hidden" name="question-section" id="question-section" />
1363
                <input type="hidden" name="question-section" id="question-section" />
1369
                <input type="hidden" name="question-slug" id="question-slug" />
1364
                <input type="hidden" name="section-id" id="section-id" />
1370
                <div class="modal-content">
1365
                <div class="modal-content">
1371
                    <div class="modal-header">
1366
                    <div class="modal-header">
1372
                        <h4 class="modal-title">LABEL_ADD LABEL_QUESTION</h4>
1367
                        <h4 class="modal-title">LABEL_ADD LABEL_SECTION</h4>
1373
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1368
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
Línea 1480... Línea 1475...
1480
                                <td>{{:value}}</td>
1475
                                <td>{{:value}}</td>
1481
                                <td></td>
1476
                                <td></td>
1482
                                <td>
1477
                                <td>
1483
                                    <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>
1478
                                    <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>
1484
                                    <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> 
1479
                                    <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> 
1485
                                    <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> 
1480
                                    <button class="btn btn-default btn-add-question" data-section="{{:slug_section}}" data-toggle="tooltip"  data-original-title="LABEL_ADD  LABEL_SECTION"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_ADD  LABEL_SECTION </button> 
1486
                                </td>
1481
                                </td>
1487
                            </tr>
1482
                            </tr>
1488
                            {{for questions}}
1483
                            {{for questions}}
1489
                            <tr class="tr-question">
1484
                            <tr class="tr-question">
1490
                                <td class="text-left">--LABEL_QUESTION</td>
1485
                                <td class="text-left">--LABEL_SECTION</td>
1491
                                <td class="text-left">
1486
                                <td class="text-left">
1492
                                    {{:~removeTags(text)}}
1487
                                    {{:~removeTags(text)}}
1493
                                </td>
1488
                                </td>
1494
                                <td><font color="red">{{:value}}</font></td>
1489
                                <td><font color="red">{{:value}}</font></td>
1495
                                <td class="text-capitalize">
1490
                                <td class="text-capitalize">
Línea 1498... Línea 1493...
1498
                                    {{if type == 'multiple'}} Multiple {{/if}}
1493
                                    {{if type == 'multiple'}} Multiple {{/if}}
1499
                                    {{if type == 'rating-open'}} LABEL_RATING_OPEN {{/if}}
1494
                                    {{if type == 'rating-open'}} LABEL_RATING_OPEN {{/if}}
1500
                                    {{if type == 'rating-range'}} LABEL_RATING_RANGE {{/if}}
1495
                                    {{if type == 'rating-range'}} LABEL_RATING_RANGE {{/if}}
1501
                                </td>
1496
                                </td>
1502
                                <td>
1497
                                <td>
1503
                                    <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> 
1498
                                    <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_SECTION"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_SECTION</button> 
1504
                                    <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> 
1499
                                    <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_SECTION"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_SECTION</button> 
Línea 1505... Línea 1500...
1505
                                  
1500
                                  
1506
                                    {{if type == 'simple' || type == 'rating-open' || type=='multiple' }}
1501
                                    {{if type == 'simple' || type == 'rating-open' || type=='multiple' }}
1507
                                    <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> 
1502
                                    <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>