<commit_before>﻿$(document).ready(function () {

    

    $("#textTemplate-modal-button").click(function () {
        
        if (isMainCont == "True") {
            $("#main-template-number-select").val("current");
            $("#mainTemplatesModal").appendTo("body").modal("show").find('.modal-content').draggable();
            loadTopHeadText();
        }
        else {
            //loadSelectData();
            loadTextData();
            $("#templatesModal").appendTo("body").modal("show").find('.modal-content').draggable();
        }
       
    });

    $("#template-number-select").bind("change", function () {
        loadTextData();
    });
    $("#main-template-number-select").bind("change", function () {
        loadPrologText();
        loadEpilogText();
        loadTopHeadText();
        loadModuleText();
    });
    $("#save-template-changes").click(function () {
        var text = {};
        text["Contract_type"] = $("#document-type-text").val();
        text["Title"] = $("#title-text").val();
        //text["Page_head"] = $("#page-head-text").val();
        text["Page_head"] = tinymce.get('page-head-text').getContent();
        //text["Document_foot"] = $("#document-foot-text").val();
        text["Document_foot"] = tinymce.get('document-foot-text').getContent();
        text["Document_foot_title"] = $("#bodytitle").val(),
        text["Delivery_maint_title"] = $("#deluhtitle").val(),
        //text["Delivery_maint_text"] = $("#deluhtext").val()
        text["Delivery_maint_text"] = tinymce.get('deluhtext').getContent();
        text["Contract_id"] = contractId;
        text["Customer"] = customerName;
        text["Page_foot"] = "";
        text["Document_head"] = "";


        $.ajax({
            "url": serverPrefix + "CustomerContract/SaveContractText/",
            "type": "POST",
            "data": {
                "customer": customerName,
                "contract-id": contractId,
                "json": JSON.stringify(text)
            },
            "success": function (data) {
                

                if (data > 0) {

                    console.log("success");
                    $.each(text, function (key, val) {
                        var $updateTarget = $("#template-" + key);
                        if ($updateTarget.length > 0) {
                            $updateTarget.html(val);
                        }
                    })
                    
                    $("#templatesModal").modal("hide");
                    triggerAlert("Successfully updated this contract text", "success");
                }
                else {
                    console.log("failure");
                    triggerAlert("Something went wrong when trying to update the contract text on the server", "warning");
                }
                

            }
        });
    });

    $("#save-main-template-changes").click(function () {

        $.ajax({
            "url": serverPrefix + "CustomerContract/SaveMainContractText/",
            "type": "POST",
            "data": {
                "customer": customerName,
                "contract-id": contractId,
                "epilog": tinymce.get('epilog-text').getContent(),
                "prolog": tinymce.get('prolog-text').getContent(),
                "tophead": $("#main-top-head").val(),
                "moduleText": tinymce.get('module-text').getContent()

            },
            success: function (data) {
                if (data > 0) {
                    console.log("Sucseess");
                    $(".crm-pdf-main-contract-epilog-section").html(tinymce.get('epilog-text').getContent());
                    $(".crm-pdf-main-contract-header-prolog").html(tinymce.get('prolog-text').getContent());
                    $(".crm-pdf-module-section-text").html(tinymce.get('module-text').getContent());
                    $("#main-top-title-text").html($("#main-top-head").val());
                    $(document).trigger("clear-alerts");
                    $(document).trigger("add-alerts", [
                      {
                          'message': "Successfully updated values",
                          'priority': 'success'
                      }
                    ]);
                    $("#mainTemplatesModal").modal("hide");
                }
                else {
                    $(document).trigger("clear-alerts");
                    $(document).trigger("add-alerts", [
                      {
                          'message': "Something went wrong when trying to update, some data might not been saved",
                          'priority': 'warning'
                      }
                    ]);
                }


            }

        });
    });
});


var loadTextData = function (templateID) {


    $.ajax({
        "url": serverPrefix + "CustomerContract/GetTemplateText/",
        "type": "POST",
        "data": {
            "customer": customerName,
            "contract-id": contractId,
            "selected": $("#template-number-select").val(),
        },
        "success": function (data) {
            if (data != "0") {

                var template = JSON.parse(data);
                if (typeof template.Document_type == "undefined") {
                    $("#document-type-text").val(template.Contract_type);
                }
                else {
                    $("#document-type-text").val(template.Document_type);
                }
                
                $("#title-text").val(template.Title);
                $("#page-head-text").val(template.Page_head);
                $("#document-foot-text").val(template.Document_foot);
                $("#bodytitle").val(template.Document_foot_title),
                $("#deluhtitle").val(template.Delivery_maint_title),
                $("#deluhtext").val(template.Delivery_maint_text)
            }

        }
    });
};<commit_msg>Fix bug where select box didnt change texts.<commit_after>﻿$(document).ready(function () {

    

    $("#textTemplate-modal-button").click(function () {
        
        if (isMainCont == "True") {
            $("#main-template-number-select").val("current");
            $("#mainTemplatesModal").appendTo("body").modal("show").find('.modal-content').draggable();
            loadTopHeadText();
        }
        else {
            loadSelectData();
            loadTextData();
            $("#templatesModal").appendTo("body").modal("show").find('.modal-content').draggable();
        }
       
    });

    $("#template-number-select").bind("change", function () {
        loadTextData();
    });
    $("#main-template-number-select").bind("change", function () {
        loadPrologText();
        loadEpilogText();
        loadTopHeadText();
        loadModuleText();
    });
    $("#save-template-changes").click(function () {
        var text = {};
        text["Contract_type"] = $("#document-type-text").val();
        text["Title"] = $("#title-text").val();
        //text["Page_head"] = $("#page-head-text").val();
        text["Page_head"] = tinymce.get('page-head-text').getContent();
        //text["Document_foot"] = $("#document-foot-text").val();
        text["Document_foot"] = tinymce.get('document-foot-text').getContent();
        text["Document_foot_title"] = $("#bodytitle").val(),
        text["Delivery_maint_title"] = $("#deluhtitle").val(),
        //text["Delivery_maint_text"] = $("#deluhtext").val()
        text["Delivery_maint_text"] = tinymce.get('deluhtext').getContent();
        text["Contract_id"] = contractId;
        text["Customer"] = customerName;
        text["Page_foot"] = "";
        text["Document_head"] = "";


        $.ajax({
            "url": serverPrefix + "CustomerContract/SaveContractText/",
            "type": "POST",
            "data": {
                "customer": customerName,
                "contract-id": contractId,
                "json": JSON.stringify(text)
            },
            "success": function (data) {
                

                if (data > 0) {

                    console.log("success");
                    $.each(text, function (key, val) {
                        var $updateTarget = $("#template-" + key);
                        if ($updateTarget.length > 0) {
                            $updateTarget.html(val);
                        }
                    })
                    
                    $("#templatesModal").modal("hide");
                    triggerAlert("Successfully updated this contract text", "success");
                }
                else {
                    console.log("failure");
                    triggerAlert("Something went wrong when trying to update the contract text on the server", "warning");
                }
                

            }
        });
    });

    $("#save-main-template-changes").click(function () {

        $.ajax({
            "url": serverPrefix + "CustomerContract/SaveMainContractText/",
            "type": "POST",
            "data": {
                "customer": customerName,
                "contract-id": contractId,
                "epilog": tinymce.get('epilog-text').getContent(),
                "prolog": tinymce.get('prolog-text').getContent(),
                "tophead": $("#main-top-head").val(),
                "moduleText": tinymce.get('module-text').getContent()

            },
            success: function (data) {
                if (data > 0) {
                    console.log("Sucseess");
                    $(".crm-pdf-main-contract-epilog-section").html(tinymce.get('epilog-text').getContent());
                    $(".crm-pdf-main-contract-header-prolog").html(tinymce.get('prolog-text').getContent());
                    $(".crm-pdf-module-section-text").html(tinymce.get('module-text').getContent());
                    $("#main-top-title-text").html($("#main-top-head").val());
                    $(document).trigger("clear-alerts");
                    $(document).trigger("add-alerts", [
                      {
                          'message': "Successfully updated values",
                          'priority': 'success'
                      }
                    ]);
                    $("#mainTemplatesModal").modal("hide");
                }
                else {
                    $(document).trigger("clear-alerts");
                    $(document).trigger("add-alerts", [
                      {
                          'message': "Something went wrong when trying to update, some data might not been saved",
                          'priority': 'warning'
                      }
                    ]);
                }


            }

        });
    });
});


var loadTextData = function (templateID) {


    $.ajax({
        "url": serverPrefix + "CustomerContract/GetTemplateText/",
        "type": "POST",
        "data": {
            "customer": customerName,
            "contract-id": contractId,
            "selected": $("#template-number-select").val(),
        },
        "success": function (data) {
            if (data != "0") {

                var template = JSON.parse(data);
                if (typeof template.Document_type == "undefined") {
                    $("#document-type-text").val(template.Contract_type);
                }
                else {
                    $("#document-type-text").val(template.Document_type);
                }
                
                $("#title-text").val(template.Title);
                $("#page-head-text").val(template.Page_head);
                $("#document-foot-text").val(template.Document_foot);
                $("#bodytitle").val(template.Document_foot_title);
                $("#deluhtitle").val(template.Delivery_maint_title);
                $("#deluhtext").val(template.Delivery_maint_text);

                for (var i = 0; i < tinyMCE.editors.length; i++) {
                    var currentED = tinyMCE.editors[i];
                    currentED.setContent($('#' + currentED.id).val());
                }


            }

        }
    });
};
{'fraction_non_alphanumeric': 0.1694718514219385, 'fraction_numerical': 0.0007462067821905314, 'mean_word_length': 1.5181628392484343, 'pattern_counts': {'":': 46, '<': 4, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2220488', 'n_tokens_mistral': 3175, 'n_tokens_neox': 3025, 'n_words': 425}