pridany modul Backend pre komuniaciu s API,
pridany template pre Bug Add, implementovana funkcionalita pre Bug Add, doplnene BUILD a DEV premenne
This commit is contained in:
76
webapp/src/backend.js
Normal file
76
webapp/src/backend.js
Normal file
@ -0,0 +1,76 @@
|
||||
export const backend = {
|
||||
endpont: __IS_BUILD__
|
||||
? window.location.origin + __SUBPATH__ + "api.php"
|
||||
: "http://localhost/bugreport/api.php",
|
||||
|
||||
/* ----------------------------------------------------
|
||||
* Vsebecne API volanie
|
||||
*/
|
||||
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 => {
|
||||
form_data.append(key, data[key]);
|
||||
});
|
||||
xhttp.open('POST', this.endpont + '?action=' + method);
|
||||
//xhttp.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
|
||||
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 akcie
|
||||
*/
|
||||
add(title, description, status, group, priority) {
|
||||
return this.callPromise('add', {
|
||||
title: title,
|
||||
description: description,
|
||||
status: status,
|
||||
group: group,
|
||||
priority: priority});
|
||||
},
|
||||
|
||||
update(id, title, description, status, group, priority) {
|
||||
return this.callPromise('update', {
|
||||
id: id,
|
||||
title: title,
|
||||
description: description,
|
||||
status: status,
|
||||
group: group,
|
||||
priority: priority});
|
||||
},
|
||||
|
||||
delete(id) {
|
||||
return this.callPromise('delete', {id: id});
|
||||
},
|
||||
|
||||
get(id) {
|
||||
return this.callPromise('get', {id: id});
|
||||
},
|
||||
|
||||
getAll() {
|
||||
return this.callPromise('getall', {});
|
||||
},
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user