summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/todo/todo.html28
-rw-r--r--modules/todo/todo.js8
2 files changed, 29 insertions, 7 deletions
diff --git a/modules/todo/todo.html b/modules/todo/todo.html
index e2f13af..19b9370 100644
--- a/modules/todo/todo.html
+++ b/modules/todo/todo.html
@@ -5,6 +5,10 @@
<title>TODO</title>
<script>
"use strict";
+var preload_todolist=/*REPLACEME*/null/*TODOLIST*/;
+</script>
+<script>
+"use strict";
function fetch(method,url,data/*?*/,creds/*?*/,cb){
if(!creds){
@@ -155,18 +159,32 @@ function refreshlist(list){
}
}
+function handleReceivedList(list){
+ var i;
+ for(i=0;i<list.length;i++)list[i].date=new Date(list[i].date);
+ refreshlist(list);
+}
+
function getlist(){
- fetch("GET","/todo/list",function(status,json){
+ if(preload_todolist!=null){
+ handleReceivedList(preload_todolist);
+ preload_todolist=null;
+ return;
+ }
+
+ fetch("GET","/todo/list",function(status,body){
+ if(status!=200){
+ alert("Error: "+body);
+ return;
+ }
var list;
try {
- list=JSON.parse(json);
+ list=JSON.parse(body);
} catch(e){
alert("An error occurred!");
return;
}
- var i;
- for(i=0;i<list.length;i++)list[i].date=new Date(list[i].date);
- refreshlist(list);
+ handleReceivedList(list);
});
}
diff --git a/modules/todo/todo.js b/modules/todo/todo.js
index 0b3da3c..66433d9 100644
--- a/modules/todo/todo.js
+++ b/modules/todo/todo.js
@@ -3,7 +3,8 @@
var cmn=require("../$common.js"),
persist=require("node-persist"),
bcrypt=require("bcrypt"),
- basicAuth=require("basic-auth");
+ basicAuth=require("basic-auth"),
+ fs=require("fs");
var bcryptHashRounds=10;
@@ -134,7 +135,10 @@ module.exports=function(app,io,_moddir){
app.all(["/todo","/todo/*"],authMiddleware); //for all the other endpoints
app.get("/todo",function(req,res){
- res.sendFile(moddir+"/todo.html");
+ var contents=fs.readFileSync(moddir+"/todo.html","utf8");
+ var replaced=contents.replace("/*REPLACEME*/null/*TODOLIST*/",
+ JSON.stringify(tasks[req.authuser]));
+ res.send(replaced);
});
app.get("/todo/list",function(req,res){
res.json(tasks[req.authuser]);