VersaWhiteboard/s_whiteboard.js

43 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-02-08 17:45:07 +01:00
//This file is only for saving the whiteboard. (Not to a file, only to RAM atm. Whiteboard is gone after server restart)
var savedBoards = {};
module.exports = {
handleEventsAndData : function(content) {
var tool = content["t"]; //Tool witch is used
var wid = content["wid"]; //whiteboard ID
var username = content["username"];
if(tool==="clear") { //Clear the whiteboard
delete savedBoards[wid];
} else if(tool==="undo") { //Undo an action
if(savedBoards[wid]) {
for(var i=savedBoards[wid].length-1;i>=0;i--){
if(savedBoards[wid][i]["username"]==username) {
var drawId = savedBoards[wid][i]["drawId"];
for(var i=savedBoards[wid].length-1;i>=0;i--){
if(savedBoards[wid][i]["drawId"]==drawId && savedBoards[wid][i]["username"]==username) {
savedBoards[wid].splice(i, 1);
}
}
break;
}
}
}
2019-01-11 15:58:58 +01:00
} else if(["line", "pen", "rect", "circle", "eraser", "addImgBG", "recSelect", "eraseRec", "addTextBox", "setTextboxText"].includes(tool)) { //Save all this actions
2018-02-08 17:45:07 +01:00
if(!savedBoards[wid]) {
savedBoards[wid] = [];
}
delete content["wid"]; //Delete id from content so we don't store it twice
2019-01-11 15:58:58 +01:00
if(tool==="setTextboxText") {
for(var i=savedBoards[wid].length-1;i>=0;i--){ //Remove old textbox tex -> dont store it twice
if(savedBoards[wid][i]["t"]==="setTextboxText" && savedBoards[wid][i]["d"][0]===content["d"][0]) {
savedBoards[wid].splice(i,1);
}
}
}
2018-02-08 17:45:07 +01:00
savedBoards[wid].push(content);
}
},
loadStoredData : function(wid) { //Load saved whiteboard
2019-01-11 11:33:43 +01:00
return savedBoards[wid] ? savedBoards[wid] : [];
2018-02-08 17:45:07 +01:00
}
}