diff options
author | Roland Reichwein <mail@reichwein.it> | 2022-11-22 19:07:31 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2022-11-22 19:07:31 +0100 |
commit | 9487db69020bfa7b91d70ee62b97441ef6c9ece4 (patch) | |
tree | e4092abdd0243c5935146b7815edd5e1ff309c2d /html | |
parent | 2a4d96188afa83110b30931559732d4fd9bacab2 (diff) |
Save data on file backend
Diffstat (limited to 'html')
-rw-r--r-- | html/index.html | 3 | ||||
-rw-r--r-- | html/whiteboard.js | 72 |
2 files changed, 71 insertions, 4 deletions
diff --git a/html/index.html b/html/index.html index 64eae90..fdd56dc 100644 --- a/html/index.html +++ b/html/index.html @@ -14,6 +14,9 @@ <textarea rows="30" cols="80" id="board" name="board"></textarea> <br/> <br/> + <button class="button" onclick="on_new_page();">New page</button> + <br/> + <br/> Reichwein.IT Whiteboard by <a href="https://www.reichwein.it">https://www.reichwein.it</a><br/> </div> diff --git a/html/whiteboard.js b/html/whiteboard.js index 2b35180..9018f92 100644 --- a/html/whiteboard.js +++ b/html/whiteboard.js @@ -6,6 +6,12 @@ function init() { function init_board() { var xhr = new XMLHttpRequest(); + const searchParams = (new URL(document.location)).searchParams; + if (!searchParams.has('id')) { + redirect_to_new_page(); + return; + } + // run on data received back xhr.onreadystatechange = function() { if (this.readyState == 3) { @@ -47,7 +53,7 @@ function init_board() { requestElement.appendChild(commandElement); var idElement = xmlDocument.createElement("id"); - idElement.appendChild(document.createTextNode("id1")); + idElement.appendChild(document.createTextNode(get_id())); requestElement.appendChild(idElement); xhr.open("POST", "whiteboard.fcgi", true); @@ -58,7 +64,65 @@ function init_board() { //set_status("Please wait while server prepares " + filename + " ..."); } -function on_modify() { +function get_id() +{ + const searchParams = (new URL(document.location)).searchParams; + return searchParams.get('id'); +} + +function on_new_page() +{ + redirect_to_new_page(); +} + +function redirect_to_new_page() +{ + var xhr = new XMLHttpRequest(); + + // run on data received back + xhr.onreadystatechange = function() { + if (this.readyState == 3) { + //set_status("Please wait while downloading " + filename + " ..."); + return; + } + if (this.readyState != 4) { + return; + } + if (this.status != 200) { + //set_status("Server Error while retrieving " + filename + ", status: " + this.status + " " + this.statusText); + return; + } + + var id = this.responseText; + //alert("location=" + document.location.href); + var new_location = document.location.href; + var pos = new_location.search("\\?"); + if (pos >= 0) + new_location = new_location.substring(0, pos); + new_location += '?id=' + id; + + window.location.href = new_location; + //set_status(""); // OK + } + + var parser = new DOMParser(); + var xmlDocument = parser.parseFromString("<request></request>", "text/xml"); + + var requestElement = xmlDocument.getElementsByTagName("request")[0]; + + var commandElement = xmlDocument.createElement("command"); + commandElement.appendChild(document.createTextNode("newid")); + requestElement.appendChild(commandElement); + + xhr.open("POST", "whiteboard.fcgi", true); + xhr.setRequestHeader("Content-type", "text/xml"); + xhr.send(xmlDocument); + + //set_status("Please wait while server prepares " + filename + " ..."); +} + +function on_modify() +{ var xhr = new XMLHttpRequest(); // run on data received back @@ -88,7 +152,7 @@ function on_modify() { requestElement.appendChild(commandElement); var idElement = xmlDocument.createElement("id"); - idElement.appendChild(document.createTextNode("id1")); + idElement.appendChild(document.createTextNode(get_id())); requestElement.appendChild(idElement); var dataElement = xmlDocument.createElement("data"); @@ -155,7 +219,7 @@ function checkupdate() { requestElement.appendChild(commandElement); var idElement = xmlDocument.createElement("id"); - idElement.appendChild(document.createTextNode("id1")); + idElement.appendChild(document.createTextNode(get_id())); requestElement.appendChild(idElement); var checksumElement = xmlDocument.createElement("checksum"); |