summaryrefslogtreecommitdiff
path: root/modules/save/read.html
diff options
context:
space:
mode:
Diffstat (limited to 'modules/save/read.html')
-rw-r--r--modules/save/read.html131
1 files changed, 131 insertions, 0 deletions
diff --git a/modules/save/read.html b/modules/save/read.html
new file mode 100644
index 0000000..c359dd5
--- /dev/null
+++ b/modules/save/read.html
@@ -0,0 +1,131 @@
+<!doctype html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Save: Read</title>
+<script>
+var currentFname=null;
+
+function populateList(arr){
+ var ul=document.getElementById("ul");
+ ul.innerHTML="";
+
+ if(arr.length==0){
+ document.getElementById("nosaves").classList.remove("invisible");
+ return;
+ }
+ document.getElementById("nosaves").classList.add("invisible");
+
+ for(var i=0;i<arr.length;i++){
+ var li=document.createElement("li");
+ var a=document.createElement("a");
+ a.appendChild(document.createTextNode(arr[i]));
+ a.href="javascript:void 0";
+ a.addEventListener("click",(function(i,li){return function(){
+ var xhr=new XMLHttpRequest();
+ xhr.onreadystatechange=function(){
+ if(xhr.readyState==4){
+ if(xhr.status!=200){
+ alert("Error reading save '"+arr[i]+"'\n"+xhr.responseText);
+ } else {
+ var l=ul.getElementsByClassName("selected");
+ for(var i=0;i<l.length;i++)l[i].classList.remove("selected");
+ li.classList.add("selected");
+ displaySave(arr[i],xhr.responseText);
+ }
+ }
+ };
+ xhr.open("GET","/save/read/file/"+encodeURIComponent(arr[i]));
+ xhr.send();
+ };})(i,li));
+ li.appendChild(a);
+ ul.appendChild(li);
+ }
+}
+
+function displaySave(fname,text){
+ var e;
+ e=document.getElementById("filename");
+ e.innerHTML=""; e.appendChild(document.createTextNode(fname));
+
+ e=document.getElementById("contents");
+ e.innerHTML=""; e.appendChild(document.createTextNode(text));
+
+ document.getElementById("container").classList.remove("invisible");
+
+ currentFname=fname;
+}
+
+function deleteCurrent(){
+ if(!currentFname){
+ alert("No save selected");
+ return;
+ }
+
+ if(!confirm("Really delete this save?"))return;
+
+ var xhr=new XMLHttpRequest();
+ xhr.onreadystatechange=function(){
+ if(xhr.readyState==4){
+ if(xhr.status!=200){
+ alert("Error deleting saves\n"+xhr.responseText);
+ } else {
+ currentFname=null;
+ document.getElementById("container").classList.add("invisible");
+ loadSaves();
+ }
+ }
+ };
+ xhr.open("DELETE","/save/read/file/"+encodeURIComponent(currentFname));
+ xhr.send();
+}
+
+function loadSaves(){
+ var xhr=new XMLHttpRequest();
+ xhr.onreadystatechange=function(){
+ if(xhr.readyState==4){
+ if(xhr.status!=200){
+ alert("Error listing saves\n"+xhr.responseText);
+ } else {
+ populateList(JSON.parse(xhr.responseText));
+ }
+ }
+ };
+ xhr.open("GET","/save/read/files");
+ xhr.send();
+}
+
+window.addEventListener("load",function(){
+ loadSaves();
+});
+</script>
+<style>
+body {
+ font-family: sans-serif;
+ font-size: 16px;
+}
+#contents {
+ border: 1px gray solid;
+ padding: 5px;
+ display: inline-block;
+}
+li.selected {
+ font-weight: bold;
+}
+.invisible {
+ display: none;
+}
+</style>
+</head>
+<body>
+<h2>Save: Read</h2>
+<div id="nosaves"><i>No saves found!</i></div>
+<ul id="ul"></ul>
+<br>
+<div id="container" class="invisible">
+ <b id="filename"></b><br>
+ <a href="javascript:void 0" onclick="deleteCurrent()">Delete</a><br>
+ <pre id="contents"></pre>
+</div>
+</body>
+</html>