Started on web front end

This commit is contained in:
Tim Shannon
2016-04-13 21:59:28 +00:00
parent 05eb182419
commit a1ced419c0
2 changed files with 90 additions and 6 deletions

@@ -6,14 +6,66 @@
(function() {
"use strict";
var r = new Ractive({
var r = new Ractive({
el: "body",
template: "#tMain",
data: function() {
return {
data: function() {
return {
view: "projects",
projects: [],
};
},
});
};
},
});
getProjects();
function getProjects() {
get("/log/",
function(result) {
r.set("projects", result.data);
},
function(result) {
console.log("error", result);
});
}
})();
function ajax(type, url, data, success, error) {
"use strict";
var req = new XMLHttpRequest();
req.open(type, url);
if (success || error) {
req.onload = function() {
if (req.status >= 200 && req.status < 400) {
if (success && typeof success === 'function') {
success(JSON.parse(req.responseText));
}
return;
}
//failed
if (error && typeof error === 'function') {
error(req);
}
};
req.onerror = function() {
if (error && typeof error === 'function') {
error(req);
}
};
}
if (type != "get") {
req.setRequestHeader("Content-Type", "application/json");
}
req.send(data);
}
function get(url, success, error) {
"use strict";
ajax("GET", url, null, success, error);
}