Started on web front end
This commit is contained in:
web
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user