feat(front): handle read-only link sharing

This commit is contained in:
Florent Chehab 2020-06-01 21:36:04 +02:00
parent fd05f220f3
commit e7725e30d5
No known key found for this signature in database
GPG Key ID: 9A0CE018889EA246
3 changed files with 105 additions and 18 deletions

View File

@ -8,6 +8,8 @@ body {
height: calc(var(--vh, 1vh) * 100); height: calc(var(--vh, 1vh) * 100);
width: 100%; width: 100%;
overflow: hidden; overflow: hidden;
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica,
Arial, sans-serif;
} }
#whiteboardContainer { #whiteboardContainer {
@ -132,3 +134,33 @@ button {
.displayNone { .displayNone {
display: none; display: none;
} }
#shareWhiteboardDialog {
width: 100vw;
height: 100vh;
background-color: rgba(1, 1, 1, 0.35);
z-index: 10000000000000;
position: absolute;
top: 0;
left: 0;
}
#shareWhiteboardDialogMessage {
background-color: lightgreen;
padding: 20px;
font-weight: bold;
}
.shareWhiteboardDialogContent {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
width: 100%;
height: 100%;
}
.shareWhiteboardDialogItem {
padding: 5px;
margin: 5px;
}

View File

@ -258,5 +258,29 @@
<p># msg. sent to server: <i id="messageSentCount">0</i></p> <p># msg. sent to server: <i id="messageSentCount">0</i></p>
<p># msg. received from server: <i id="messageReceivedCount">0</i></p> <p># msg. received from server: <i id="messageReceivedCount">0</i></p>
</div> </div>
<div id="shareWhiteboardDialog" class="displayNone">
<div class="shareWhiteboardDialogContent">
<button
class="shareWhiteboardDialogItem"
id="shareWhiteboardDialogCopyReadOnlyLink"
>
<i class="fa fa-lock"></i>&nbsp;Share read-only link
</button>
<button
class="shareWhiteboardDialogItem displayNone"
id="shareWhiteboardDialogCopyReadWriteLink"
>
<i class="fa fa-lock-open"></i>&nbsp;Share read/write link
</button>
<button class="shareWhiteboardDialogItem" id="shareWhiteboardDialogGoBack">
<b>Go back to the whiteboard</b>
</button>
<p
class="shareWhiteboardDialogItem displayNone"
id="shareWhiteboardDialogMessage"
></p>
</div>
</div>
</body> </body>
</html> </html>

View File

@ -433,25 +433,56 @@ function initWhiteboard() {
$("#myFile").click(); $("#myFile").click();
}); });
$("#shareWhiteboardBtn").click(function () { $("#shareWhiteboardBtn").click(() => {
var url = window.location.href; function urlToClipboard(whiteboardId = null) {
var s = url.indexOf("&username=") !== -1 ? "&username=" : "username="; //Remove username from url const { protocol, host, pathname, search } = window.location;
var urlSlpit = url.split(s); const basePath = `${protocol}//${host}${pathname}`;
var urlStart = urlSlpit[0]; const getParams = new URLSearchParams(search);
if (urlSlpit.length > 1) {
var endSplit = urlSlpit[1].split("&"); // Clear ursername from get parameters
endSplit = endSplit.splice(1, 1); getParams.delete("username");
urlStart += "&" + endSplit.join("&");
if (whiteboardId) {
// override whiteboardId value in URL
getParams.set("whiteboardid", whiteboardId);
}
const url = `${basePath}?${getParams.toString()}`;
$("<textarea/>")
.appendTo("body")
.val(url)
.select()
.each(() => {
document.execCommand("copy");
})
.remove();
} }
$("<textarea/>")
.appendTo("body") // UI related
.val(urlStart) // clear message
.select() $("#shareWhiteboardDialogMessage").toggleClass("displayNone", true);
.each(function () {
document.execCommand("copy"); $("#shareWhiteboardDialog").toggleClass("displayNone", false);
}) $("#shareWhiteboardDialogGoBack").click(() => {
.remove(); $("#shareWhiteboardDialog").toggleClass("displayNone", true);
showBasicAlert("Copied Whiteboard-URL to clipboard.", { hideAfter: 2 }); });
$("#shareWhiteboardDialogCopyReadOnlyLink").click(() => {
urlToClipboard(ConfigService.correspondingReadOnlyWid);
$("#shareWhiteboardDialogMessage")
.toggleClass("displayNone", false)
.text("Read-only link copied to clipboard ✓");
});
$("#shareWhiteboardDialogCopyReadWriteLink")
.toggleClass("displayNone", ConfigService.isReadOnly)
.click(() => {
$("#shareWhiteboardDialogMessage")
.toggleClass("displayNone", false)
.text("Read/write link copied to clipboard ✓");
urlToClipboard();
});
}); });
$("#displayWhiteboardInfoBtn").click(() => { $("#displayWhiteboardInfoBtn").click(() => {