From 823d072ad49e30832d167e4c04bdf1b64b5a5336 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 25 Feb 2017 09:55:13 +0100 Subject: todo: Shift ahead repeating items --- modules/todo/todo.html | 79 ++++++++++++++++++++++++++++++++++++++++---------- modules/todo/todo.js | 39 +++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 16 deletions(-) (limited to 'modules') diff --git a/modules/todo/todo.html b/modules/todo/todo.html index 19b9370..22cce9b 100644 --- a/modules/todo/todo.html +++ b/modules/todo/todo.html @@ -61,6 +61,17 @@ function beginOfDay(date){ return d; } +function shiftDate(date,repweeks){ + var Y=date.getFullYear(), + M=date.getMonth(), + D=date.getDate(), + h=date.getHours(), + m=date.getMinutes(), + s=date.getSeconds(), + ms=date.getMilliseconds(); + return new Date(Y,M,D+7*repweeks,h,m,s,ms); +} + function fancytime(timeS){ return pad(timeS.hour,2,"0")+":"+pad(timeS.min,2,"0")+(timeS.sec==0?"":":"+pad(timeS.sec,2,"0")); } @@ -95,7 +106,7 @@ function tablerowfor(task){ var div=document.createElement("div"); div.classList.add("task"); - var e=document.createElement("span"); + var e=document.createElement("span"),e2; e.classList.add("tasksubject"); e.appendChild(document.createTextNode(task.subject)); div.appendChild(e); @@ -108,22 +119,43 @@ function tablerowfor(task){ e.appendChild(document.createTextNode((task.repweeks!=0?"(rep) ":"")+fancydate(task.date))); e.setAttribute("title",task.date.toString()); e.appendChild(document.createElement("br")); - var e2=document.createElement("span"); - e2.classList.add("subdate"); - e2.appendChild(document.createTextNode(task.date.toString())); + e2=document.createElement("span"); + e2.classList.add("subdate"); + e2.appendChild(document.createTextNode(task.date.toString())); e.appendChild(e2); float.appendChild(e); - e=document.createElement("span"); - e.classList.add("taskdelete"); - e.appendChild(document.createTextNode("X")); - e.addEventListener("click",function(ev){ - if(!confirm("Really delete task \""+task.subject+"\"?"))return - fetch("DELETE","/todo/task",task.id,function(status,body){ - if(status==200)getlist(); - else alert("Delete failed: "+body); + e=document.createElement("div"); + e.classList.add("taskbuttons"); + e2=document.createElement("span"); + e2.classList.add("taskdelete"); + e2.appendChild(document.createTextNode("X")); + e2.addEventListener("click",function(ev){ + if(!confirm("Really delete task \""+task.subject+"\"?"))return; + fetch("DELETE","/todo/task",task.id,function(status,body){ + if(status==200)getlist(); + else alert("Delete failed: "+body); + }); }); - }); + e.appendChild(e2); + + if(task.repweeks!=0){ + e.appendChild(document.createElement("br")); + + e2=document.createElement("span"); + e2.classList.add("taskshiftahead"); + e2.appendChild(document.createTextNode("→")); + e2.addEventListener("click",function(ev){ + if(!confirm("Really shift task \""+task.subject+"\" ahead by "+ + task.repweeks+" week"+(task.repweeks!=1?"s":"")+"?"))return; + fetch("POST","/todo/task/shiftahead",task.id,function(status,body){ + if(status==200)getlist(); + else alert("Shiftahead failed: "+body); + }); + }); + e.appendChild(e2); + } + float.appendChild(e); div.appendChild(float); @@ -141,7 +173,7 @@ function refreshlist(list){ task=list[i]; if(task.repweeks!=0){ while(task.date