webui: splitting rs() into rs() and rs.request()

This commit is contained in:
zeners 2016-01-05 20:01:47 +01:00
parent 03e2a18be1
commit 62ee95e706
2 changed files with 37 additions and 14 deletions

View File

@ -9,10 +9,12 @@ var accountMap = new Map();
function login(){
//alert("login:" + curraccount.location + "; passwort: " + currentpasswd);
rs("control/login", {data: {id: curraccount.id}, callback:function(){
rs.request("control/login", {id: curraccount.id}, function(){
//alert("login send");
rs("control/password",{data: {password: currentpasswd}});
}});
rs.request("control/password", {password: currentpasswd}, function(){
m.redraw();
});
});
}
function cancel(){

View File

@ -130,17 +130,23 @@ function schedule_request_missing(){
});
}
function rs(path, optionen){
if(optionen === undefined) {
if(cache[path] === undefined){
cache[path] = {
data: undefined,
statetoken: undefined,
requested: false,
};
schedule_request_missing();
}
return cache[path].data;
function rs(path, args, callback){
if(cache[path] === undefined){
cache[path] = {
data: args,
statetoken: undefined,
requested: false,
then: function(){
if (callback != undefined) {
callback();
}
}
};
schedule_request_missing();
}
return cache[path].data;
}
/*
} else{
m.request({
method: "POST",
@ -157,5 +163,20 @@ function rs(path, optionen){
});
}
}
*/
module.exports = rs;
rs.request=function(path, args, callback){
m.request({
method: "POST",
url: api_url + path,
data: args,
background: true
}).then(function(response){
if (callback != undefined) {
callback(response.data, response.statetoken);
}
});
}