<commit_before>// __BEGIN_LICENSE__
//Copyright (c) 2015, United States Government, as represented by the 
//Administrator of the National Aeronautics and Space Administration. 
//All rights reserved.
//
//The xGDS platform is licensed under the Apache License, Version 2.0 
//(the "License"); you may not use this file except in compliance with the License. 
//You may obtain a copy of the License at 
//http://www.apache.org/licenses/LICENSE-2.0.
//
//Unless required by applicable law or agreed to in writing, software distributed 
//under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
//CONDITIONS OF ANY KIND, either express or implied. See the License for the 
//specific language governing permissions and limitations under the License.
// __END_LICENSE__

var options = {
        // target: '#output0', // target element(s) to be updated with
        // server response
        // beforeSubmit: showRequest, // pre-submit callback
        // success: showResponse, // post-submit callback

        // other available options:
        url: submitNoteUrl, // override for form's 'action' attribute
        type: 'post',       // 'get' or 'post', override for form's 'method' attribute
        dataType: 'json',   // 'xml', 'script', or 'json' (expected server response type)
        // clearForm: false // clear all form fields after successful submit
        // resetForm: true // reset the form after successful submit

        // $.ajax options can be used here too, for example:
        timeout: 3000
};

var check_image_url = 'url(' + STATIC_URL + 'xgds_video/images/check.png)';
var cross_image_url = 'url(' + STATIC_URL + 'xgds_video/images/cross.png)';

function showSuccess(errorMessage, index) {
    $('#error_content' + index).text(errorMessage);
    $('#error_image' + index).css('background', check_image_url);
    $('#error_div' + index).show();
}

function showError(errorMessage, index) {
    $('#error_content' + index).text(errorMessage);
    $('#error_image' + index).css('background', cross_image_url);
    $('#error_div' + index).show();
}

function hideError(index) {
    // $('#error_content').text('');
    $('#error_div' + index).hide();
}

/*
 * Form submission
 *
 */
$(function() {
    $('.noteSubmit').on('click', function(e) {
        var parent = $(this).closest('form');
        // get the index
        var index = parent.find('input#id_index').val();
        // validate and process form here
        var content_text = parent.find('input#id_content' + index);
        var content = content_text.val();

        hideError(index);
        var tagsId = 'input#id_tags' + index;
        var tagInput = parent.find(tagsId);
        var tags = tagInput.val();

        if (tags == '') {
            var addtag = parent.find('input#id_tags' + index + '_tag');
            // see if we have any contents in the tag that should be created as a tag
            if (addtag.val() != '' && addtag.val() != 'add a tag') {
                tagInput.addTag(addtag.val());
                tags = tagInput.val();
            }
        }
        if ((content == '') && (tags == '')) {
            content_text.focus();
            showError('Note must not be empty.', index);
            return false;
        }
        var extras = parent.find('input#id_extras').val();
        var dataString = 'content=' + content + '&tags=' + tags + '&extras=' + extras;
        // not live, pull the time out of the video
        var iso_string = '';
        if (isLive == false) {
            var event_time = getPlayerVideoTime(parent.find('input#source').val());
            iso_string = event_time.toISOString();
            iso_string = iso_string.replace('T', ' ');
            iso_string = iso_string.substring(0, 19);
            dataString = dataString + '&event_time=' + iso_string;
        } else {
            try {
                if (event_timestring !== undefined){
                    dataString = dataString + '&event_time=' + event_timestring;
                } else {
                    dataString = dataString + "&serverNow=true";
                }
            }
            catch(err) {
                dataString = dataString + "&serverNow=true";
            }
        } 
        $.ajax({
            type: 'POST',
            url: submitNoteUrl,
            data: dataString,
            success: function(response) {
                showSuccess('Saved ' + content + ' ' + iso_string, index);
                content_text.val('');
                tagInput.importTags('');
            },
            error: function(jqXHR, textStatus, errorThrown) {
                if (errorThrown == '' && textStatus == 'error') {
                    showError('Lost server connection', index);
                } else {
                    showError(textStatus + ' ' + errorThrown, index);
                }
                console.log(jqXHR.getAllResponseHeaders());
            }

        });
        e.preventDefault();
    });
});

/*
 * // pre-submit callback function showRequest(formData, jqForm, options) { //
 * formData is an array; here we use $.param to convert it to a string to
 * display it // but the form plugin does this for you automatically when it
 * submits the data var queryString = $.param(formData); // jqForm is a jQuery
 * object encapsulating the form element. To access the // DOM element for the<commit_msg>correctly take notes in delay and show time<commit_after>// __BEGIN_LICENSE__
//Copyright (c) 2015, United States Government, as represented by the 
//Administrator of the National Aeronautics and Space Administration. 
//All rights reserved.
//
//The xGDS platform is licensed under the Apache License, Version 2.0 
//(the "License"); you may not use this file except in compliance with the License. 
//You may obtain a copy of the License at 
//http://www.apache.org/licenses/LICENSE-2.0.
//
//Unless required by applicable law or agreed to in writing, software distributed 
//under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
//CONDITIONS OF ANY KIND, either express or implied. See the License for the 
//specific language governing permissions and limitations under the License.
// __END_LICENSE__

var options = {
        // target: '#output0', // target element(s) to be updated with
        // server response
        // beforeSubmit: showRequest, // pre-submit callback
        // success: showResponse, // post-submit callback

        // other available options:
        url: submitNoteUrl, // override for form's 'action' attribute
        type: 'post',       // 'get' or 'post', override for form's 'method' attribute
        dataType: 'json',   // 'xml', 'script', or 'json' (expected server response type)
        // clearForm: false // clear all form fields after successful submit
        // resetForm: true // reset the form after successful submit

        // $.ajax options can be used here too, for example:
        timeout: 3000
};

var check_image_url = 'url(' + STATIC_URL + 'xgds_video/images/check.png)';
var cross_image_url = 'url(' + STATIC_URL + 'xgds_video/images/cross.png)';

function showSuccess(errorMessage, index) {
    $('#error_content' + index).text(errorMessage);
    $('#error_image' + index).css('background', check_image_url);
    $('#error_div' + index).show();
}

function showError(errorMessage, index) {
    $('#error_content' + index).text(errorMessage);
    $('#error_image' + index).css('background', cross_image_url);
    $('#error_div' + index).show();
}

function hideError(index) {
    // $('#error_content').text('');
    $('#error_div' + index).hide();
}

/*
 * Form submission
 *
 */
$(function() {
    $('.noteSubmit').on('click', function(e) {
        var parent = $(this).closest('form');
        // get the index
        var index = parent.find('input#id_index').val();
        // validate and process form here
        var content_text = parent.find('input#id_content' + index);
        var content = content_text.val();

        hideError(index);
        var tagsId = 'input#id_tags' + index;
        var tagInput = parent.find(tagsId);
        var tags = tagInput.val();

        if (tags == '') {
            var addtag = parent.find('input#id_tags' + index + '_tag');
            // see if we have any contents in the tag that should be created as a tag
            if (addtag.val() != '' && addtag.val() != 'add a tag') {
                tagInput.addTag(addtag.val());
                tags = tagInput.val();
            }
        }
        if ((content == '') && (tags == '')) {
            content_text.focus();
            showError('Note must not be empty.', index);
            return false;
        }
        var extras = parent.find('input#id_extras').val();
        var dataString = 'content=' + content + '&tags=' + tags + '&extras=' + extras;
        // not live, pull the time out of the video
        var iso_string = '';
        if (isLive == false) {
            var event_time = getPlayerVideoTime(parent.find('input#source').val());
            iso_string = event_time.toISOString();
            iso_string = iso_string.replace('T', ' ');
            iso_string = iso_string.substring(0, 19);
            dataString = dataString + '&event_time=' + iso_string;
        } else {
            try {
                if (event_timestring !== undefined){
                    dataString = dataString + '&event_time=' + event_timestring;
                } else {
                    dataString = dataString + "&serverNow=true";
                }
            }
            catch(err) {
                dataString = dataString + "&serverNow=true";
            }
        } 
        $.ajax({
            type: 'POST',
            url: submitNoteUrl,
            data: dataString,
            success: function(response) {
                var printtime = iso_string;
                try {
                    printtime = response['event_time'];
                    m = moment(new Date(response['event_time']));
                    printtime = m.format("MM/DD/YYYY HH:mm:ss");
                } catch(err) {
                    // pass
                }
                showSuccess('Saved ' + content + ' ' + printtime, index);
                content_text.val('');
                tagInput.importTags('');
            },
            error: function(jqXHR, textStatus, errorThrown) {
                if (errorThrown == '' && textStatus == 'error') {
                    showError('Lost server connection', index);
                } else {
                    showError(textStatus + ' ' + errorThrown, index);
                }
                console.log(jqXHR.getAllResponseHeaders());
            }

        });
        e.preventDefault();
    });
});

/*
 * // pre-submit callback function showRequest(formData, jqForm, options) { //
 * formData is an array; here we use $.param to convert it to a string to
 * display it // but the form plugin does this for you automatically when it
 * submits the data var queryString = $.param(formData); // jqForm is a jQuery
 * object encapsulating the form element. To access the // DOM element for the
{'fraction_non_alphanumeric': 0.13103696375573343, 'fraction_numerical': 0.0028779566507779477, 'mean_word_length': 2.1376975169300225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '5006900', 'n_tokens_mistral': 3080, 'n_tokens_neox': 2980, 'n_words': 910}