From 3224d7fc7bcc8e80bee8849d0fb946974bdcbf78 Mon Sep 17 00:00:00 2001 From: topninja Date: Fri, 27 Nov 2020 11:22:09 -0500 Subject: [PATCH] Erase all button on menu --- client-data/board.html | 1 + client-data/tools/new/new.js | 60 +++++++++++++++++++++++++++++++++++ client-data/tools/new/new.svg | 9 ++++++ server/boardData.js | 8 +++++ server/sockets.js | 3 ++ 5 files changed, 81 insertions(+) create mode 100644 client-data/tools/new/new.js create mode 100644 client-data/tools/new/new.svg diff --git a/client-data/board.html b/client-data/board.html index 00e01632..f6eb7186 100644 --- a/client-data/board.html +++ b/client-data/board.html @@ -90,6 +90,7 @@ + diff --git a/client-data/tools/new/new.js b/client-data/tools/new/new.js new file mode 100644 index 00000000..28c919ce --- /dev/null +++ b/client-data/tools/new/new.js @@ -0,0 +1,60 @@ +/** + * WHITEBOPHIR + ********************************************************* + * @licstart The following is the entire license notice for the + * JavaScript code in this page. + * + * Copyright (C) 2013 Ophir LOJKINE + * + * + * The JavaScript code in this page is free software: you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License (GNU GPL) as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. The code is distributed WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. + * + * As additional permission under GNU GPL version 3 section 7, you + * may distribute non-source (e.g., minimized or compacted) forms of + * that code without the copy of the GNU GPL normally required by + * section 4, provided you include this license notice and a URL + * through which recipients can access the Corresponding Source. + * + * @licend + */ + +(function grid() { + // when new button clicks then calls this function + function btnClickHandler() { + Tools.socket.emit('broadcast', { + board: Tools.boardName, + data : { + tool : "New", + type : "deleteall" + } + }); + Tools.drawingArea.innerHTML = ''; + } + + // this is callback handler from socket + function eraseAll(data) { + switch (data.type) { + case "deleteall": + Tools.drawingArea.innerHTML = ''; + break; + } + } + + Tools.add({ + "name": "New", + "shortcut": "n", + "listeners": {}, + "icon": "tools/new/new.svg", + "oneTouch": true, + "onstart": btnClickHandler, + "draw": eraseAll, + "mouseCursor": "crosshair", + }); + +})(); \ No newline at end of file diff --git a/client-data/tools/new/new.svg b/client-data/tools/new/new.svg new file mode 100644 index 00000000..6a9d7548 --- /dev/null +++ b/client-data/tools/new/new.svg @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/server/boardData.js b/server/boardData.js index 1539a44f..3a53c841 100644 --- a/server/boardData.js +++ b/server/boardData.js @@ -97,6 +97,14 @@ BoardData.prototype.delete = function (id) { this.delaySave(); }; +/** Removes all data from the board + */ +BoardData.prototype.deleteall = function () { + //KISS + this.board = []; + this.delaySave(); +}; + /** Reads data from the board * @param {string} id - Identifier of the element to get. * @returns {object} The element with the given id, or undefined if no element has this id diff --git a/server/sockets.js b/server/sockets.js index d24c2cef..ae459b4e 100644 --- a/server/sockets.js +++ b/server/sockets.js @@ -143,6 +143,9 @@ async function saveHistory(boardName, message) { case "delete": if (id) board.delete(id); break; + case "deleteall": + board.deleteall(); + break; case "update": if (id) board.update(id, message); break;