/** * Generated by APIlite * https://gitea.tpsoft.org/TPsoft.org/APIlite * * */ export const backend = { endpont: window.location.origin + "apiName; ?>.php", /* ---------------------------------------------------- * General API call */ call(method, data, callback) { var xhttp = new XMLHttpRequest(); xhttp.withCredentials = true; xhttp.onreadystatechange = function() { if (this.readyState == 4) { if (this.status == 200) { if (callback != null) callback(JSON.parse(this.responseText)); } else { if (callback != null) callback({'status': 'ERROR', 'message': 'HTTP STATUS ' + this.status}); } } } var form_data = new FormData(); Object.keys(data).forEach(key => { let val = data[key]; if (typeof val == 'object') val = JSON.stringify(val); form_data.append(key, val); }); xhttp.open('POST', this.endpont + '?action=' + method); xhttp.send(form_data); }, callPromise(method, data) { return new Promise((resolve, reject) => { this.call(method, data, function(response) { if (response.status == 'OK') { resolve(response.data); } else { reject(response.msg); } }); }) }, /* ---------------------------------------------------- * API actions */ help() { return this.callPromise('__HELP__', {}); }, methods)) foreach ($this->methods as $method) { echo "\t".$method['name'].'('.implode(', ', array_map(function($param) { return $param['name']; }, $method['params'])).') {'; echo "\n\t\treturn this.callPromise('".$method['name']."', {".implode(', ', array_map(function($param) { return $param['name'].': '.$param['name']; }, $method['params']))."});"; echo "\n\t},\n\n"; } ?> };