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

    var $modals = $('.modal');
    var $editModal = $('.edit-modal');
    var customFieldCount = 0;

    function guidGenerator() {
        var S4 = function () {
            return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
        };
        return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
    }

    var deleteCustomField = function (customFieldId) {
        $('#' + customFieldId).remove();
    };

    var addNewCustomField = function (modal) {
        var $customFields = modal.find('.custom-fields');
        var $newCustomFieldKey = modal.find('.new-custom-field-key');
        var $newCustomFieldValue = modal.find('.new-custom-field-value');
        populateCustomField($customFields, {
            key: $newCustomFieldKey.val(),
            value: $newCustomFieldValue.val()
        });
        $newCustomFieldKey.val("");
        $newCustomFieldValue.val("");
    };

    var populateCustomField = function ($customFields, field) {
        var _id = guidGenerator();
        var $field = $("<div id='" + _id + "'>Key: " + field.key + ", Value:" + field.value + "</div>")
            .append($("<input name='customs[" + customFieldCount + "][key]' value='" + field.key + "' type='hidden'></input>"))
            .append($("<input name='customs[" + customFieldCount + "][value]' value='" + field.value + "' type='hidden'></input>"))
            .append($("<i class='fa fa-trash-o custom-field-delete' />")
                .click(deleteCustomField.bind(this, _id))
            );
        $customFields.append($field);
        customFieldCount++;
    };

    var populateCustomFields = function (modal, customFields) {
        var $customFields = modal.find('.custom-fields');
        customFields.forEach(function (field) {
            populateCustomField($customFields, field);
        });
        modal.find('.new-custom-field-add').click(addNewCustomField.bind(this, modal));
    };

    var populateCourseSelection = function (modal, courses) {
        var $selection = modal.find('.course-selection');
        courses.forEach(function (course) {
            var option = document.createElement("option");
            option.text = course.name;<commit_msg>fix a bug that does not remove old custom params from modal (#162)<commit_after>$(document).ready(function () {

    var $modals = $('.modal');
    var $editModal = $('.edit-modal');
    var customFieldCount = 0;

    function guidGenerator() {
        var S4 = function () {
            return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
        };
        return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
    }

    var deleteCustomField = function (customFieldId) {
        $('#' + customFieldId).remove();
    };

    var addNewCustomField = function (modal) {
        var $customFields = modal.find('.custom-fields');
        var $newCustomFieldKey = modal.find('.new-custom-field-key');
        var $newCustomFieldValue = modal.find('.new-custom-field-value');
        populateCustomField($customFields, {
            key: $newCustomFieldKey.val(),
            value: $newCustomFieldValue.val()
        });
        $newCustomFieldKey.val("");
        $newCustomFieldValue.val("");
    };

    var populateCustomField = function ($customFields, field) {
        if (!field.key || field.key == '') return;
        
        var _id = guidGenerator();
        var $field = $("<div id='" + _id + "'>Key: " + field.key + ", Value: " + field.value + "</div>")
            .append($("<input name='customs[" + customFieldCount + "][key]' value='" + field.key + "' type='hidden'></input>"))
            .append($("<input name='customs[" + customFieldCount + "][value]' value='" + field.value + "' type='hidden'></input>"))
            .append($("<i class='fa fa-trash-o custom-field-delete' />")
                .click(deleteCustomField.bind(this, _id))
            );
        $customFields.append($field);
        customFieldCount++;
    };

    var populateCustomFields = function (modal, customFields) {
        var $customFields = modal.find('.custom-fields');

        // cleanup
        $customFields.empty();

        customFields.forEach(function (field) {
            populateCustomField($customFields, field);
        });
        modal.find('.new-custom-field-add').click(addNewCustomField.bind(this, modal));
    };

    var populateCourseSelection = function (modal, courses) {
        var $selection = modal.find('.course-selection');
        courses.forEach(function (course) {
            var option = document.createElement("option");
            option.text = course.name;
{'fraction_non_alphanumeric': 0.18204911092294665, 'fraction_numerical': 0.009525825571549535, 'mean_word_length': 2.5526315789473686, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '83151', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1346, 'n_words': 263}