X-Git-Url: https://git-public.kairo.at/?p=lantea.git;a=blobdiff_plain;f=js%2Flibrary.js;h=9cb6d24a2ba9c4914ec3d9fc7f9b480f71f2b349;hp=2130f022d5c56ecd83c286c4217ef126defe277d;hb=5fa27c77949b9a4145d50243e5f18586865c87cb;hpb=846a4dacf7230152237b1d42944196694695b5da diff --git a/js/library.js b/js/library.js index 2130f02..9cb6d24 100644 --- a/js/library.js +++ b/js/library.js @@ -21,10 +21,15 @@ function showLibrary() { litem.textContent = "Error: " + aResult; tlist.appendChild(litem); } + else if (!aResult.length) { + var litem = document.createElement("li"); + litem.textContent = "No tracks uploaded yet."; + tlist.appendChild(litem); + } else { for (var i = 0; i < aResult.length; i++) { var litem = document.createElement("li"); - litem.textContent = aResult[i]["time_created"] + " - "; + litem.textContent = dtformat(aResult[i]["time_created"]) + " - "; var llink = document.createElement("a"); llink.setAttribute("href", gBackendURL + "/track_gpx?id=" + aResult[i]["id"]); llink.textContent = aResult[i]["comment"]; @@ -43,3 +48,15 @@ function hideLibrary() { document.getElementById("libraryArea").classList.add("hidden"); } +function dtformat(aUnixTimestamp) { + // Library display time format: YYYY-MM-DD HH:mm + // Note that JS has millisecond timestamps while standard/unix has seconds. + var tsDate = new Date(aUnixTimestamp * 1000); + // Note that .getUTCMonth() returns a number between 0 and 11 (0 for January)! + return tsDate.getUTCFullYear() + "-" + + (tsDate.getUTCMonth() < 9 ? "0" : "") + (tsDate.getUTCMonth() + 1 ) + "-" + + (tsDate.getUTCDate() < 10 ? "0" : "") + tsDate.getUTCDate() + " " + + (tsDate.getUTCHours() < 10 ? "0" : "") + tsDate.getUTCHours() + ":" + + (tsDate.getUTCMinutes() < 10 ? "0" : "") + tsDate.getUTCMinutes(); +} +