diff --git a/web/index.html b/web/index.html index 5195bcc..fea75c6 100644 --- a/web/index.html +++ b/web/index.html @@ -15,6 +15,38 @@ diff --git a/web/js/index.js b/web/js/index.js index 9ee6afe..0bfac9e 100644 --- a/web/js/index.js +++ b/web/js/index.js @@ -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); +}