first pond stuff

This commit is contained in:
Jeena 2014-02-04 08:47:46 +01:00
parent d8723a3d9e
commit 08639f9999
5 changed files with 340 additions and 0 deletions

43
js/Pond.js Normal file
View file

@ -0,0 +1,43 @@
function Pond(app, server_url, session_token) {
this.app = app;
this.server_url = server_url;
this.session_token = session_token;
window.addEventListener("offline", this.onoffline.bind(this));
window.addEventListener("online", this.ononline.bind(this));
}
Pond.prototype.onoffline = function() {
// Do nothing
};
Pond.prototype.ononline = function() {
// Send read
};
Pond.prototype.toString = function() {
return "Pond"
};
Pond.login = function(server_url, user, password, callback) {
var url = server_url + "/api/auth/sessions";
var password_hash = md5(user + ':' + password)
var options = "username=" + user.toLowerCase() + "&" + "password=" + password_hash;
var xhr = new XMLHttpRequest({mozSystem: true});
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(xhr.status == 201) {
callback(JSON.parse(xhr.responseText))
} else {
alert("error: " + typeof(xhr.status) + " " + xhr.statusText + "\n\n" + xhr.responseText)
}
}
}
xhr.open("POST", url, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader("Content-Length", options.length);
xhr.setRequestHeader("Connection", "close");
xhr.send(options);
}