From 4b7dde997e7cfaf7fa35647e4a726c5cb672727c Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 29 Sep 2016 23:06:15 +0200 Subject: Add history deletion to client (and fix bugs in it) --- modules/changes/changes.html | 65 ++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 17 deletions(-) (limited to 'modules/changes/changes.html') diff --git a/modules/changes/changes.html b/modules/changes/changes.html index 07cc7f9..2cccec4 100644 --- a/modules/changes/changes.html +++ b/modules/changes/changes.html @@ -47,7 +47,7 @@ function focusData(data){ var l=tbody.children,i; for(i=l.length-1;i>=0;i--)tbody.removeChild(l[i]); - var tr,td,s; + var tr,td,e,s,date; for(i=data.timeline.length-1;i>=0;i--){ tr=document.createElement("tr"); if(i>0&&data.timeline[i][1]==data.timeline[i-1][1]){ @@ -55,7 +55,8 @@ function focusData(data){ } td=document.createElement("td"); - td.appendChild(document.createTextNode(dateformat(new Date(data.timeline[i][0])))); + date=new Date(data.timeline[i][0]); + td.appendChild(document.createTextNode(dateformat(date))); tr.appendChild(td); td=document.createElement("td"); @@ -64,10 +65,51 @@ function focusData(data){ td.appendChild(document.createTextNode(s)); tr.appendChild(td); + td=document.createElement("td"); + e=document.createElement("a"); + e.href="javascript:void(0)"; + e.appendChild(document.createTextNode("Delete till here")); + e.addEventListener("click",(function(url,date){return function(ev){ + if(!confirm( + "This will delete history up to and including the selected date "+ + "("+dateformat(date)+"), for the following url:\n"+data.url+ + "\nIs this OK?")){ + return; + } + + fetch("DELETE","/changes/url/history",JSON.stringify({url:data.url,todate:date}),function(status,body){ + if(status!=200){ + alert("Error deleting history: ("+status+") "+body); + return; + } + focusURL(data.url); + }); + };})(data.url,date)); + td.appendChild(e); + tr.appendChild(td); + tbody.appendChild(tr); } } +function focusURL(url){ + fetch("GET","/changes/url?url="+encodeURIComponent(url),function(status,body){ + if(status!=200){ + alert("Error getting data: ("+status+") "+body); + return; + } + var data; + try { + data=JSON.parse(body); + } catch(e){ + alert("Server sent invalid data!"); + console.log("Invalid data:",data); + return; + } + focusData(data); + }); +} + function makeURLtr(url){ var tr=document.createElement("tr"); var td=document.createElement("td"); @@ -98,21 +140,7 @@ function makeURLtr(url){ td.appendChild(e); tr.addEventListener("click",function(ev){ - fetch("GET","/changes/url?url="+encodeURIComponent(url),function(status,body){ - if(status!=200){ - alert("Error getting data: ("+status+") "+body); - return; - } - var data; - try { - data=JSON.parse(body); - } catch(e){ - alert("Server sent invalid data!"); - console.log("Invalid data:",data); - return; - } - focusData(data); - }); + focusURL(url); }); tr.appendChild(td); @@ -220,6 +248,9 @@ h1{ #timelinetbl td, #timelinetbl th{ border:1px #888 solid; } +#timelinetbl td:nth-child(3){ + font-size:10px; +} tr.repeated{ color:#aaa; -- cgit v1.2.3-70-g09d2