Who is using which tablet, for which client, and when they are available
Loading…
Local mode: bookings are saved in this browser only and are not visible to colleagues. To share the data, fill in API_URL in the code (see the setup guide).
2 weeks4 weeks3 months
Confirmed (colour = client)TentativeTodayClick a booking for details
New booking
ConfirmedTentative
Bookings
Tablet
Client
Colleague
From
To
Status
Note
(function(){
/* ===== CONFIGURATION ===== */
var API_URL = ""; // Paste the Google Apps Script web app URL here (ending in /exec)
var NB_TABLETTES = 12; // Number of tablets in the fleet
/* ========================= */
var LS_KEY="tbx-reservations-v2", ME_KEY="tbx-me";
var A=document.getElementById("tbx");
function $(s){return A.querySelector(s)} function $$(s){return A.querySelectorAll(s)}
function p2(n){return(n<10?"0":"")+n}
function iso(d){return d.getFullYear()+"-"+p2(d.getMonth()+1)+"-"+p2(d.getDate())}
function today(){return iso(new Date())}
function parse(s){return new Date(s+"T12:00:00")}
function addD(s,n){var d=parse(s);d.setDate(d.getDate()+n);return iso(d)}
function diff(a,b){return Math.round((parse(b)-parse(a))/864e5)}
function monday(s){return addD(s,-((parse(s).getDay()+6)%7))}
function fr(s){return s?s.slice(8,10)+"/"+s.slice(5,7)+"/"+s.slice(0,4):""}
function frc(s){return s?s.slice(8,10)+"/"+s.slice(5,7):""}
function esc(s){return String(s==null?"":s).replace(/[&"']/g,function(c){return{"&":"&","":">",'"':""","'":"'"}[c]})}
function uid(){return Date.now().toString(36)+Math.random().toString(36).slice(2,7)}
var JOURS=["Su","Mo","Tu","We","Th","Fr","Sa"];
var MOIS=["January","February","March","April","May","June","July","August","September","October","November","December"];
var PAL=["#9c2786","#2e86ab","#d9731a","#3a9d5d","#c0392b","#6c5ce7","#1f7a8c","#b8860b","#d35490","#4a6fa5","#7b8d42","#8e44ad"];
function col(c){var h=0,s=String(c).toLowerCase();for(var i=0;i>>0;return PAL[h%PAL.length]}
var TABS=[];for(var i=1;i<=NB_TABLETTES;i++)TABS.push(i);
var data=[], loaded=false, sel={}, detId=null;
var view={start:addD(monday(today()),-7),days:28,q:""};
/* ----- Data ----- */
function readLocal(){try{return JSON.parse(localStorage.getItem(LS_KEY))||[]}catch(e){return[]}}
function writeLocal(){try{localStorage.setItem(LS_KEY,JSON.stringify(data))}catch(e){}}
function conflicts(t,du,au,list){return(list||data).filter(function(r){return +r.tablet===+t&&r.from<=au&&du<=r.to})}
function load(){
if(!API_URL){data=readLocal();return Promise.resolve()}
return fetch(API_URL+"?action=list&_="+Date.now()).then(function(r){return r.json()}).then(function(j){if(!j.ok)throw new Error(j.error||"Server error");data=j.data||[]})
}
function send(p){
if(!API_URL){
if(p.action==="add"){
var c=[];p.items.forEach(function(it){conflicts(it.tablet,it.from,it.to).forEach(function(r){c.push("Tablet "+r.tablet+" already booked from "+fr(r.from)+" to "+fr(r.to)+" ("+r.client+", "+r.colleague+")")})});
if(c.length)return Promise.reject(new Error(c.join("\n")));
data=data.concat(p.items);
}else if(p.action==="delete"){data=data.filter(function(r){return r.id!==p.id})}
else if(p.action==="confirm"){data.forEach(function(r){if(r.id===p.id)r.status="confirmed"})}
writeLocal();return Promise.resolve();
}
return fetch(API_URL,{method:"POST",body:JSON.stringify(p)}).then(function(r){return r.json()}).then(function(j){if(!j.ok)throw new Error(j.error||"Server error");data=j.data||[]})
}
function setSync(t){$("#tbx-sync").textContent=t}
function refresh(){
setSync("Syncing…");
return load().then(function(){loaded=true;var d=new Date();setSync((API_URL?"Up to date":"Local mode")+" · "+p2(d.getHours())+":"+p2(d.getMinutes()));render()})
.catch(function(e){setSync("Connection failed");console.error(e);render()})
}
/* ----- Navigation ----- */
function go(n){$$(".tabs button").forEach(function(b){b.classList.toggle("on",b.getAttribute("data-tab")===n)});$$("[data-pane]").forEach(function(p){p.hidden=p.getAttribute("data-pane")!==n})}
$$(".tabs button").forEach(function(b){b.onclick=function(){go(b.getAttribute("data-tab"))}});
/* ----- Rendering ----- */
function current(t){var d=today();return data.filter(function(r){return +r.tablet===t&&r.from<=d&&dd}).sort(function(a,b){return a.from<b.from?-1:1})[0]}
function uniq(k){var o={};data.forEach(function(r){if(r[k])o[r[k]]=1});return Object.keys(o).sort(function(a,b){return a.localeCompare(b,"fr")})}
function render(){renderOverview();renderGantt();renderChips();renderList();
$("#tbx-dl-col").innerHTML=uniq("colleague").map(function(v){return''}).join("");
$("#tbx-dl-cli").innerHTML=uniq("client").map(function(v){return''}).join("");
}
function renderOverview(){
var use=0,d=today(),in7=addD(d,7),soon=0;
var html=TABS.map(function(t){
var c=current(t),n=nextOf(t);if(c)use++;if(n&&n.from<=in7)soon++;
var pill=c?(c.status==="tentative"?'In use (tentative)':'In use'):'Available';
var body;
if(c){body='
Client
'+esc(c.client)+'
Colleague
'+esc(c.colleague)+'
Return date
'+fr(c.to)+'
'+(n?'Next: '+esc(n.client)+' from '+frc(n.from)+'':'')}
else{body=''+(n?'Available until '+fr(addD(n.from,-1))+' Next: '+esc(n.client)+' ('+esc(n.colleague)+')':'No upcoming bookings')+''}
return'
';
}
function pct(n){return(n/view.days*100)+"%"}
function renderGantt(){
var s=view.start,days=view.days,e=addD(s,days-1),td=today(),q=view.q.toLowerCase().trim();
$("#tbx-range").textContent=fr(s)+" → "+fr(e);
var months="",ticks="",shades="",i=0;
while(i<days){var m=addD(s,i).slice(0,7),j=i;while(j<days&&addD(s,j).slice(0,7)===m)j++;months+='
';
}
var t0=diff(s,td),now=(t0>=0&&t0<days)?'':"";
var rows=TABS.map(function(t){
var bars=data.filter(function(r){return +r.tablet===t&&r.from=s}).map(function(r){
var a=Math.max(0,diff(s,r.from)),b=Math.min(days-1,diff(s,r.to));
var dim=q&&(r.client+" "+r.colleague).toLowerCase().indexOf(q)<0;
var tip=r.client+" | "+r.colleague+" | "+fr(r.from)+" → "+fr(r.to)+(r.status==="tentative"?" (tentative)":"")+(r.note?" | "+r.note:"");
return'
'+esc(r.client)+" · "+esc(r.colleague)+'
';
}).join("");
return'
Tablet '+t+'
'+bars+'
';
}).join("");
$("#tbx-gantt").innerHTML='
'+months+'
'+ticks+'
'+shades+now+'
'+rows+'
';
renderDetail();
}
function renderDetail(){
var r=detId&&data.filter(function(x){return x.id===detId})[0];
if(!r){$("#tbx-det").innerHTML="";return}
$("#tbx-det").innerHTML='
Tablet '+r.tablet+' · '+esc(r.client)+' Responsible colleague: '+esc(r.colleague)+' From '+fr(r.from)+' to '+fr(r.to)+' ('+(diff(r.from,r.to)+1)+(diff(r.from,r.to)?' days':' day')+') · '+(r.status==="tentative"?"Tentative":"Confirmed")+(r.note?' Note: '+esc(r.note):'')+'
'+(r.status==="tentative"?'':'')+'
';
}
function dates(){return{from:$("#tbx-du").value,to:$("#tbx-au").value}}
function renderChips(){
var d=dates(),ok=d.from&&d.to&&d.from<=d.to;
$("#tbx-chips").innerHTML=TABS.map(function(t){
if(!ok)return'Tablet '+t+'';
var c=conflicts(t,d.from,d.to);
if(c.length){delete sel[t];return'Tablet '+t+''}
return'Tablet '+t+'';
}).join("");
}
function renderList(){
var q=$("#tbx-lq").value.toLowerCase().trim(),h=$("#tbx-hist").checked,d=today();
var l=data.filter(function(r){return(h||r.to>=d)&&(!q||("tablet "+r.tablet+" "+r.client+" "+r.colleague+" "+(r.note||"")).toLowerCase().indexOf(q)>=0)})
.sort(function(a,b){return a.from===b.from?a.tablet-b.tablet:(a.from<b.from?-1:1)});
$("#tbx-list").innerHTML=l.map(function(r){
var st=r.from<=d&&d<=r.to?'In use':r.to<d?'Finished':r.status==="tentative"?'Tentative':'Confirmed';
return'
'+r.tablet+'
'+esc(r.client)+'
'+esc(r.colleague)+'
'+fr(r.from)+'
'+fr(r.to)+'
'+st+'
'+esc(r.note||"")+'
'+(r.status==="tentative"&&r.to>=d?'':'')+'
';
}).join("")||'
No bookings.
';
}
/* ----- Actions ----- */
function msg(t,ok){var m=$("#tbx-msg");m.className="msg "+(ok?"ok":"ko");m.style.whiteSpace="pre-line";m.textContent=t}
function busy(b,on){if(b)b.disabled=on}
A.addEventListener("click",function(ev){
var b=ev.target.closest("[data-chip],[data-book],[data-rid],[data-del],[data-conf],[data-close]");if(!b)return;var v;
if(v=b.getAttribute("data-chip")){if(sel[v])delete sel[v];else sel[v]=1;renderChips();return}
if(v=b.getAttribute("data-book")){sel={};sel[v]=1;if(!$("#tbx-du").value){$("#tbx-du").value=today();$("#tbx-au").value=today()}renderChips();go("bk");$("#tbx-col").focus();return}
if(v=b.getAttribute("data-rid")){detId=v;renderDetail();return}
if(b.getAttribute("data-close")){detId=null;renderDetail();return}
if(v=b.getAttribute("data-conf")){busy(b,true);send({action:"confirm",id:v}).then(render).catch(function(e){alert(e.message)}).then(function(){busy(b,false)});return}
if(v=b.getAttribute("data-del")){
var r=data.filter(function(x){return x.id===v})[0];if(!r)return;
if(!confirm("Cancel the booking of tablet "+r.tablet+" for "+r.client+" ("+fr(r.from)+" → "+fr(r.to)+") ?"))return;
busy(b,true);send({action:"delete",id:v}).then(function(){if(detId===v)detId=null;render()}).catch(function(e){alert(e.message)}).then(function(){busy(b,false)});
}
});
["#tbx-du","#tbx-au"].forEach(function(s){$(s).addEventListener("change",function(){if(s==="#tbx-du"&&(!$("#tbx-au").value||$("#tbx-au").value<$("#tbx-du").value))$("#tbx-au").value=$("#tbx-du").value;renderChips()})});
$("#tbx-save").onclick=function(){
var b=this,c=$("#tbx-col").value.trim(),cl=$("#tbx-cli").value.trim(),d=dates(),ts=Object.keys(sel).map(Number).sort(function(a,b){return a-b});
if(!c||!cl)return msg("Enter the responsible colleague and the client.");
if(!d.from||!d.to)return msg("Enter the start and end dates.");
if(d.to1?"s ":" ")+ts.join(", ")+" for "+cl+", from "+fr(d.from)+" to "+fr(d.to)+".",true);
sel={};$("#tbx-cli").value="";$("#tbx-note").value="";render();
}).catch(function(e){msg(e.message);refresh()}).then(function(){busy(b,false)});
};
$("#tbx-prev").onclick=function(){view.start=addD(view.start,-Math.round(view.days/2));renderGantt()};
$("#tbx-next").onclick=function(){view.start=addD(view.start,Math.round(view.days/2));renderGantt()};
$("#tbx-today").onclick=function(){view.start=addD(monday(today()),-7);renderGantt()};
$("#tbx-span").onchange=function(){view.days=+this.value;renderGantt()};
$("#tbx-q").oninput=function(){view.q=this.value;renderGantt()};
$("#tbx-lq").oninput=renderList;$("#tbx-hist").onchange=renderList;
/* ----- Start ----- */
try{var me=localStorage.getItem(ME_KEY);if(me)$("#tbx-col").value=me}catch(e){}
if(!API_URL)$("#tbx-warn").hidden=false;
refresh();
if(API_URL){setInterval(function(){if(!document.hidden)refresh()},60000);document.addEventListener("visibilitychange",function(){if(!document.hidden)refresh()})}
})();
Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Altijd actief
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.