<commit_before>/*
    js sents data to php
    js receives from php

*/
/*
Example data sent by post request
{ 
    tableName: "Example-Table", 
    rowData: [1, 123, 321], 
    deletion: false
}

Example data send by get request
{
    tableName: "Example-Table",
}
Example data received by get request
{
    "tableName": "Example-Table",
    "tableData": [{
        "id": 1,
        "a": 123,
        "b": 321
        },{
        "id": 2,
        "a": 123123,
        "b": 321312
        },{
        "id": 3,
        "a": 124233,
        "b": 333521
        }
    ]
}
*/
$changeHandler = function($rowElement) {
    console.log("Executing changeHandler");   
    // $rowElement: the tr element.
 

    var sendDataToServer = function ($element) {
        var rowData = [];
        for(let td of $element.children) {
            rowData.push(td.innerHTML);
        }
        rowData.pop(); // remove button
        rowData.shift(); // remove rowdata #
        //TODO: Example
        $.post( {
            url: "php/serverApplication.php",  //server script to process data
            data: { tableName: $element.name,
                    rowData: rowData,
                    deletion: false
                  },
            success: function($element) {
                console.log("sucessfull post of table data");
                $.get({ 
                    url: "serverApplication.php",  //server script to process data
                    data: { tableName: $element.name,
                            rowData: rowData},
                    success: function(stringData) {
                        let data = JSON.parse(stringData);
                        let tds = this.getElementsByTagName('td');
                        console.log(data) // for debug reasons
                        let k;
                        for(k = 0; k < length(data.tableData); ++k ) {
                            if(k == $element.firstChild.innerHTML) {
                                break;
                            }
                        }
                        let rowData = data.tableData[k];
                        let j = 0;
                        for(i in tds) {
                            tds[i].innerHTML = rowData[j];
                            j++;
                        }
                    }.bind(null, $element),
                    cache: false
                });            
            }.bind(null, $element),
            cache: false
        });
    }.bind(null, $rowElement);

  // dont fire the previous wait if you were waiting
    clearTimeout($.data(this, 'timer'));
    var wait = setTimeout(sendDataToServer, 500); // delay after user types
    $(this).data('timer', wait);    
}
/*
Example data sent by delete request<commit_msg>bind problem solved<commit_after>/*
    js sents data to php
    js receives from php

*/
/*
Example data sent by post request
{ 
    tableName: "Example-Table", 
    rowData: [1, 123, 321], 
    deletion: false
}

Example data send by get request
{
    tableName: "Example-Table",
}
Example data received by get request
{
    "tableName": "Example-Table",
    "tableData": [{
        "id": 1,
        "a": 123,
        "b": 321
        },{
        "id": 2,
        "a": 123123,
        "b": 321312
        },{
        "id": 3,
        "a": 124233,
        "b": 333521
        }
    ]
}
*/
$changeHandler = function($rowElement) {
    console.log("Executing changeHandler");   
    // $rowElement: the tr element.
 

    var sendDataToServer = function ($element) {
        var rowData = [];
        for(let td of $element.children) {
            rowData.push(td.innerHTML);
        }
        rowData.pop(); // remove button
        rowData.shift(); // remove rowdata #
        //TODO: Example
        $.post( {
            url: "php/serverApplication.php",  //server script to process data
            data: { tableName: $element.name,
                    rowData: rowData,
                    deletion: false
                  },
            success: function($element) {
                console.log("sucessfull post of table data");
                $.get({ 
                    url: "serverApplication.php",  //server script to process data
                    data: { tableName: $element.name,
                            rowData: rowData},
                    success: function(stringData) {
                        let $element = this;
                        let data = JSON.parse(stringData);
                        let tds = this.getElementsByTagName('td');
                        console.log(data) // for debug reasons
                        let k;
                        for(k = 0; k < length(data.tableData); ++k ) {
                            if(k == $element.firstChild.innerHTML) {
                                break;
                            }
                        }
                        let rowData = data.tableData[k];
                        let j = 0;
                        for(i in tds) {
                            tds[i].innerHTML = rowData[j];
                            j++;
                        }
                    }.bind(null, $element),
                    cache: false
                });            
            }.bind($element),
            cache: false
        });
    }.bind(null, $rowElement);

  // dont fire the previous wait if you were waiting
    clearTimeout($.data(this, 'timer'));
    var wait = setTimeout(sendDataToServer, 500); // delay after user types
    $(this).data('timer', wait);    
}
/*
Example data sent by delete request
{'fraction_non_alphanumeric': 0.11584817413203814, 'fraction_numerical': 0.016189962223421478, 'mean_word_length': 1.202852614896989, 'pattern_counts': {'":': 22, '<': 5, '<?xml version=': 0, '>': 3, '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': '567157', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1415, 'n_words': 387}