{"size": 8070, "ext": "js", "max_stars_repo_path": "src/main/www/iot-emulator/data-api.js", "max_stars_repo_name": "signomix/signomix", "max_stars_repo_stars_event_min_datetime": "2018-10-18T13:11:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-18T07:59:13.000Z", "max_issues_repo_path": "src/main/www/iot-emulator/data-api.js", "max_issues_repo_name": "gskorupa/signomix", "max_issues_repo_issues_event_min_datetime": "2018-10-26T19:16:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-30T11:10:09.000Z", "max_forks_repo_path": "src/main/www/iot-emulator/data-api.js", "max_forks_repo_name": "signomix/signomix", "max_forks_repo_forks_event_min_datetime": "2020-12-12T06:09:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-12T06:09:47.000Z"}
{"max_stars_count": 6, "max_issues_count": 48, "max_forks_count": 1, "avg_line_length": 32.9387755102, "max_line_length": 135, "alphanum_fraction": 0.5288723668}
/*
* Copyright (C) Grzegorz Skorupa 2018.
* Distributed under the MIT License (license terms are at http://opensource.org/licenses/MIT).
 */
// get data from the service
function getData(url, query, token, callback, eventBus, successEventName, errorEventName, debug, appEventBus) {

    var oReq = new XMLHttpRequest();
    var defaultErrorEventName = "dataerror:";
    oReq.onerror = function (oEvent) {
        if (debug) {
            console.log("onerror " + this.status + " " + oEvent.toString())
        }
        ;
    };
    oReq.onload = function (oEvent) {/*getdataCallback(elementId, statusId);*/
        if (debug) {
            console.log("onload " + this.status + " " + oEvent.toString())
        }
        ;
        if (this.status != 200) {
            var fullErrName
            if (errorEventName == null) {
                fullErrName = defaultErrorEventName + this.status;
            } else {
                fullErrName = errorEventName;
            }
            if (appEventBus == null) {
                eventBus.trigger(fullErrName);
            } else {
                appEventBus.trigger(fullErrName);
            }
        }
        ;
    };
    oReq.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
            console.log(JSON.parse(this.responseText));
            if (callback != null) {
                callback(this.responseText);
            } else {
                eventBus.trigger(successEventName);
            }
        } else if (this.readyState == 4 && this.status == 0) {
            //eventBus.trigger(errorEventName);
            if (errorEventName == null) {
                eventBus.trigger(defaultErrorEventName + this.status);
            } else {
                eventBus.trigger(errorEventName);
            }
        }
    };

    oReq.open("get", url, true);
    if (token != null) {
        oReq.withCredentials = true;
        oReq.setRequestHeader("Authentication", token);
    }
    oReq.send(query);
    return false;
}

function sendFormData(oFormElement, method, url, token, callback, eventBus, successEventName, errorEventName, debug, appEventBus) {
    if (debug) {
        console.log("postFormData")
    }
    ;
    var oReq = new XMLHttpRequest();
    var defaultErrorEventName = "dataerror:";
    oReq.onerror = function (oEvent) {
        if (debug) {
            console.log("onerror " + this.status + " " + oEvent.toString())
        }
        ;
    };
    oReq.onload = function (oEvent) {/*getdataCallback(elementId, statusId);*/
        if (debug) {
            console.log("onload " + this.status + " " + oEvent.toString())
        }
        ;
        if (this.status != 200) {
            var fullErrName
            if (errorEventName == null) {
                fullErrName = defaultErrorEventName + this.status;
            } else {
                fullErrName = errorEventName;
            }
            if (appEventBus == null) {
                eventBus.trigger(fullErrName);
            } else {
                appEventBus.trigger(fullErrName);
            }
        }
        ;
    };

    oReq.onreadystatechange = function () {
        if (this.readyState == 4 && (this.status == 200 || this.status == 201)) {
            console.log(JSON.parse(this.responseText));
            if (callback != null) {
                callback(this.responseText);
            } else {
                eventBus.trigger(successEventName);
            }
        } else if (this.readyState == 4 && this.status == 0) {
            //eventBus.trigger(errorEventName);
            if (errorEventName == null) {
                eventBus.trigger(defaultErrorEventName + this.status);
            } else {
                eventBus.trigger(errorEventName);
            }
        }
    };
    // method declared in the form is ignored
    oReq.open(method, url);
    if (token != null) {
        oReq.withCredentials = true;
        oReq.setRequestHeader("Authentication", token);
    }
    oReq.send(new FormData(oFormElement));
    return false;
}

function sendJsonData(data, method, url, authHeader, token, callback, eventBus, successEventName, errorEventName, debug, appEventBus) {
    if (debug) {
        console.log("sendJsonData")
        console.log(method)
        console.log(url)
        console.log(token)
    }
    ;
    var oReq = new XMLHttpRequest();
    var defaultErrorEventName = "dataerror:";
    oReq.onerror = function (oEvent) {
        if (debug) {
            console.log("onerror " + this.status + " " + oEvent.toString())
        }
        ;
    };
    oReq.onload = function (oEvent) {/*getdataCallback(elementId, statusId);*/
        if (debug) {
            console.log("onload " + this.status + " " + oEvent.toString())
        }
        ;
        if (!(this.status == 200 || this.status == 201)) {
            var fullErrName
            if (errorEventName == null) {
                fullErrName = defaultErrorEventName + this.status;
            } else {
                fullErrName = errorEventName;
            }
            if (appEventBus == null) {
                eventBus.trigger(fullErrName);
            } else {
                appEventBus.trigger(fullErrName);
            }
        }
        ;
    };

    oReq.onreadystatechange = function () {
        if (this.readyState == 4 && (this.status == 200 || this.status == 201)) {
            console.log(JSON.parse(this.responseText));
            if (callback != null) {
                callback(this.responseText);
            } else {
                eventBus.trigger(successEventName);
            }
        } else if (this.readyState == 4 && this.status == 0) {
            //eventBus.trigger(errorEventName);
            if (errorEventName == null) {
                eventBus.trigger(defaultErrorEventName + this.status);
            } else {
                eventBus.trigger(errorEventName);
            }
        }
    };

    oReq.open(method, url, true);
    if (token != null) {
        oReq.withCredentials = true;
        oReq.setRequestHeader(authHeader, token);
    }
    oReq.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
    oReq.send(JSON.stringify(data));
    return false;
}

function deleteData(url, token, callback, eventBus, successEventName, errorEventName, debug, appEventBus) {

    var oReq = new XMLHttpRequest();
    var defaultErrorEventName = "dataerror:";
    oReq.onerror = function (oEvent) {
        if (debug) {
            console.log("onerror " + this.status + " " + oEvent.toString())
        }
        ;
    };
    oReq.onload = function (oEvent) {/*getdataCallback(elementId, statusId);*/
        if (debug) {
            console.log("onload " + this.status + " " + oEvent.toString())
        }
        ;
        if (this.status != 200) {
            var fullErrName
            if (errorEventName == null) {
                fullErrName = defaultErrorEventName + this.status;
            } else {
                fullErrName = errorEventName;
            }
            if (appEventBus == null) {
                eventBus.trigger(fullErrName);
            } else {
                appEventBus.trigger(fullErrName);
            }
        }
        ;
    };
    oReq.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
            console.log(JSON.parse(this.responseText));
            if (callback != null) {
                callback(this.responseText);
            } else {
                eventBus.trigger(successEventName);
            }
        } else if (this.readyState == 4 && this.status == 0) {
            //eventBus.trigger(errorEventName);
            if (errorEventName == null) {
                eventBus.trigger(defaultErrorEventName + this.status);
            } else {
                eventBus.trigger(errorEventName);
            }
        }
    };

    oReq.open("DELETE", url, true);
    if (token != null) {
        oReq.withCredentials = true;
        oReq.setRequestHeader("Authentication", token);
    }
    oReq.send(null);
    return false;
}
