Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 991 Rev 992
Línea 827... Línea 827...
827
                });
827
                });
828
                return false;
828
                return false;
829
            }
829
            }
830
        }
830
        }
831
    });
831
    });
832
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
-
 
833
    $("#form-section").on('submit', function() {
-
 
834
        for (var instanceName in CKEDITOR.instances) {
-
 
835
            CKEDITOR.instances[instanceName].updateElement();
-
 
836
        }
-
 
837
    })
-
 
838
    /**
-
 
839
     * Validate rules form section
-
 
840
     */
-
 
841
    var validatorFormSection = $("#form-section").validate({
-
 
842
        ignore: [],
-
 
843
        errorClass: 'help-block',
-
 
844
        errorElement: 'span',
-
 
845
        rules: {
-
 
846
            'section-name': {
-
 
847
                required: true,
-
 
848
                minlength: 2,
-
 
849
                maxlength: 50
-
 
850
            },
-
 
851
            'section-text': {
-
 
852
                required: false,
-
 
853
            },
-
 
854
            'section-value': {
-
 
855
                required: true,
-
 
856
                number: true,
-
 
857
                min: 1
-
 
858
            },
-
 
859
        },
-
 
860
        highlight: function(element) {
-
 
861
            $(element).closest('.form-group').addClass('has-error');
-
 
862
        },
-
 
863
        unhighlight: function(element) {
-
 
864
            $(element).closest('.form-group').removeClass('has-error');
-
 
865
        },
-
 
866
        errorPlacement: function(error, element) {
-
 
867
            if (element.attr("data-error-container")) {
-
 
868
                error.appendTo(element.attr("data-error-container"));
-
 
869
            } else {
-
 
870
                error.insertAfter(element);
-
 
871
            }
-
 
872
        },
-
 
873
        invalidHandler: function(form, validator) {
-
 
874
            if (!validator.numberOfInvalids())
-
 
875
                return;
-
 
876
            $('html, body').animate({
-
 
877
                scrollTop: $(validator.errorList[0].element).offset().top - 100
-
 
878
            }, 1000);
-
 
879
        },
-
 
880
        submitHandler: function(form) {
-
 
881
            // do other things for a valid form
-
 
882
            //form.submit();
-
 
883
            var slug = $('#form-section #section-slug').val();
-
 
884
            if (slug) {
-
 
885
                objFormGenerator.editSection(
-
 
886
                    $('#form-section #section-slug').val(),
-
 
887
                    $('#form-section #section-name').val(),
-
 
888
                    $('#form-section #section-text').val(),
-
 
889
                    $('#form-section #section-value').val()
-
 
890
                );
-
 
891
            } else {
-
 
892
                objFormGenerator.addSection(
-
 
893
                    $('#form-section #section-name').val(),
-
 
894
                    $('#form-section #section-text').val(),
-
 
895
                    $('#form-section #section-value').val()
-
 
896
                );
-
 
897
            }
-
 
898
            renderSectionData(objFormGenerator.sections);
-
 
899
            $('#modal-section').modal('hide');
-
 
900
            return false;
-
 
901
        }
-
 
902
    });
-
 
903
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
-
 
904
    $("#form-question").on('submit', function() {
-
 
905
        for (var instanceName in CKEDITOR.instances) {
-
 
906
            CKEDITOR.instances[instanceName].updateElement();
-
 
907
        }
-
 
908
    })
-
 
909
    /**
832
    /**
910
     * Validate rules form Questions
833
     * Validate rules form Questions
911
     */
834
     */
912
    var validatorFormQuestion = $("#form-question").validate({
835
    var validatorFormQuestion = $("#form-question").validate({
913
        ignore: [],
836
        ignore: [],
Línea 1050... Línea 973...
1050
            $('#modal-option').modal('hide');
973
            $('#modal-option').modal('hide');
1051
            return false;
974
            return false;
1052
        }
975
        }
1053
    });
976
    });
1054
    /**
977
    /**
1055
     * Clicked on add new section
-
 
1056
     */
-
 
1057
    $('body').on('click', 'button[id="btn-add-section"]', function(e) {
-
 
1058
        e.preventDefault();
-
 
1059
        validatorFormSection.resetForm();
-
 
1060
        $('#form-section #section-slug').val('');
-
 
1061
        $('#form-section #section-name').val('');
-
 
1062
        CKEDITOR.instances['section-text'].setData('');
-
 
1063
        $('#form-section #section-value').val('0');
-
 
1064
        $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
-
 
1065
        $('#modal-section').modal('show');
-
 
1066
    });
-
 
1067
    /**
-
 
1068
     * Clicked on edit section
-
 
1069
     */
-
 
1070
    $('body').on('click', 'button.btn-edit-section', function(e) {
-
 
1071
        e.preventDefault();
-
 
1072
        var slug = $(this).data('section');
-
 
1073
        var section;
-
 
1074
        var showForm = false;
-
 
1075
        for (i = 0; i < objFormGenerator.sections.length; i++) {
-
 
1076
            section = objFormGenerator.sections[i];
-
 
1077
            if (slug == section.slug_section) {
-
 
1078
                validatorFormSection.resetForm();
-
 
1079
                $('#form-section #section-slug').val(section.slug_section);
-
 
1080
                $('#form-section #section-name').val(section.name);
-
 
1081
                CKEDITOR.instances['section-text'].setData(section.text);
-
 
1082
                $('#form-section #section-value').val(section.value);
-
 
1083
                showForm = true;
-
 
1084
                break;
-
 
1085
            }
-
 
1086
        }
-
 
1087
        if (showForm) {
-
 
1088
            $('#modal-section h4[class="modal-title"]').html('LABEL_EDIT LABEL_SECTION');
-
 
1089
            $('#modal-section').modal('show');
-
 
1090
        }
-
 
1091
    });
-
 
1092
    /**
-
 
1093
     * Clicked on remove section
-
 
1094
     */
-
 
1095
    $('body').on('click', 'button.btn-delete-section', function(e) {
-
 
1096
        e.preventDefault();
-
 
1097
        var slug = $(this).data('section');
-
 
1098
        bootbox.confirm({
-
 
1099
            title: "LABEL_DELETE LABEL_SECTION",
-
 
1100
            message: "LABEL_QUESTION_DELETE",
-
 
1101
            buttons: {
-
 
1102
                cancel: {
-
 
1103
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
-
 
1104
                },
-
 
1105
                confirm: {
-
 
1106
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
-
 
1107
                }
-
 
1108
            },
-
 
1109
            callback: function(result) {
-
 
1110
                if (result) {
-
 
1111
                    objFormGenerator.deleteSection(slug);
-
 
1112
                    renderSectionData(objFormGenerator.sections);
-
 
1113
                }
-
 
1114
            }
-
 
1115
        });
-
 
1116
    });
-
 
1117
    /**
-
 
1118
     * Clicked add new question
978
     * Clicked add new question
1119
     */
979
     */
1120
    $('body').on('click', 'button.btn-add-question', function(e) {
980
    $('body').on('click', 'button.btn-add-question', function(e) {
1121
        e.preventDefault();
981
        e.preventDefault();
1122
        validatorFormQuestion.resetForm();
982
        validatorFormQuestion.resetForm();
Línea 1330... Línea 1190...
1330
                }
1190
                }
1331
            }
1191
            }
1332
        });
1192
        });
1333
    })
1193
    })
1334
    /**
1194
    /**
1335
     * Format input number (Form Section) 
-
 
1336
     */
-
 
1337
    $('#form-section #section-value').inputNumberFormat({
-
 
1338
        'decimal': 2
-
 
1339
    });
-
 
1340
    /**
-
 
1341
     * Format input number (Form Question) 
-
 
1342
     */
-
 
1343
    $('#form-question #question-value').inputNumberFormat({
-
 
1344
        'decimal': 2
-
 
1345
    });
-
 
1346
    /**
-
 
1347
     * Format input number (Form Question) 
-
 
1348
     */
-
 
1349
    $('#form-question #question-max-length').inputNumberFormat({
-
 
1350
        'decimal': 0
-
 
1351
    });
-
 
1352
    /**
-
 
1353
     * Format input number (Form Option) 
-
 
1354
     */
-
 
1355
    $('#form-option #option-value').inputNumberFormat({
-
 
1356
        'decimal': 2
-
 
1357
    });
-
 
1358
    /**
-
 
1359
     * Detect when updating question status and hide/Show options
-
 
1360
     */
-
 
1361
    $('#form-question #question-type').change(function(e) {
-
 
1362
        e.preventDefault();
-
 
1363
        if ($('#form-question #question-type').val() == 'open') {
-
 
1364
            $('#form-question #question-max-length').parent().show();
-
 
1365
            $('#form-question #question-multiline').parent().show();
-
 
1366
        } else {
-
 
1367
            $('#form-question #question-max-length').val('0');
-
 
1368
            $('#form-question #question-max-length').parent().hide();
-
 
1369
            $('#form-question #question-multiline').val('0');
-
 
1370
            $('#form-question #question-multiline').parent().hide();
-
 
1371
        }
-
 
1372
        $('#form-question #question-range').val('10');
-
 
1373
        if ($('#form-question #question-type').val() == 'rating-range') {
-
 
1374
            $('#form-question #question-range').parent().show();
-
 
1375
        } else {
-
 
1376
            $('#form-question #question-range').parent().hide();
-
 
1377
        }
-
 
1378
    });
-
 
1379
    /**
-
 
1380
     * Clicked new Form
1195
     * Clicked new Form
1381
     */
1196
     */
1382
    $('button.btn-add-form').click(function(e) {
1197
    $('button.btn-add-form').click(function(e) {
1383
        e.preventDefault();
1198
        e.preventDefault();
1384
        objFormGenerator.clear();
1199
        objFormGenerator.clear();