summaryrefslogtreecommitdiff
path: root/modules/todo/todo.html
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-02-17 20:29:09 +0100
committertomsmeding <tom.smeding@gmail.com>2017-02-17 20:29:09 +0100
commit54e0f34a0430fb3dd5dfe46f1a01e61a22e822e3 (patch)
tree62f6acfec7164db214b38c0b3a14931fc6b9cc6a /modules/todo/todo.html
parentad7b72a8cf8b335193ed00d1d1e053f155b9d301 (diff)
todo: Preload todolist on page load
Diffstat (limited to 'modules/todo/todo.html')
-rw-r--r--modules/todo/todo.html28
1 files changed, 23 insertions, 5 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);
});
}