VersaWhiteboard/src/js/services/ReadOnlyService.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

/**
* Class the handle the read-only logic
*/
class ReadOnlyService {
/**
* @type {boolean}
*/
#readOnlyActive = true;
get readOnlyActive() {
return this.#readOnlyActive;
}
/**
* @type {object}
*/
#previousToolHtmlElem = null;
get previousToolHtmlElem() {
return this.#previousToolHtmlElem;
}
/**
* Activate read-only mode
*/
activateReadOnlyMode() {
this.#readOnlyActive = true;
this.#previousToolHtmlElem = $(".whiteboard-tool.active");
// switch to mouse tool to prevent the use of the
// other tools
$(".whiteboard-tool[tool=mouse]").click();
$(".whiteboard-tool").prop("disabled", true);
$(".whiteboard-edit-group > button").prop("disabled", true);
$(".whiteboard-edit-group").addClass("group-disabled");
$("#whiteboardUnlockBtn").hide();
$("#whiteboardLockBtn").show();
}
/**
* Deactivate read-only mode
*/
deactivateReadOnlyMode() {
this.#readOnlyActive = false;
$(".whiteboard-tool").prop("disabled", false);
$(".whiteboard-edit-group > button").prop("disabled", false);
$(".whiteboard-edit-group").removeClass("group-disabled");
$("#whiteboardUnlockBtn").show();
$("#whiteboardLockBtn").hide();
// restore previously selected tool
const { previousToolHtmlElem } = this;
if (previousToolHtmlElem) previousToolHtmlElem.click();
}
}
2020-05-09 15:40:26 +02:00
export default new ReadOnlyService();