summaryrefslogtreecommitdiffhomepage
path: root/html/whiteboard.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/whiteboard.js')
-rw-r--r--html/whiteboard.js72
1 files changed, 68 insertions, 4 deletions
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");