From 77d8966f803527ba7d5112b571459734df7b5311 Mon Sep 17 00:00:00 2001 From: KKosty4ka <49340075+KKosty4ka@users.noreply.github.com> Date: Sat, 13 Jul 2024 20:29:20 +0700 Subject: [PATCH 1/2] Unify links modals --- frontend/static/yw/javascript/owot.js | 55 ++++++++++++--------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/frontend/static/yw/javascript/owot.js b/frontend/static/yw/javascript/owot.js index 0925d101..2ed6bd92 100644 --- a/frontend/static/yw/javascript/owot.js +++ b/frontend/static/yw/javascript/owot.js @@ -5153,8 +5153,7 @@ function buildMenu() { }); menuOptions.changeColor = menu.addOption("Change color", w.color); menuOptions.goToCoords = menu.addOption("Go to coordinates", w.goToCoord); - menuOptions.coordLink = menu.addOption("Create link to coordinates", w.coordLink); - menuOptions.urlLink = menu.addOption("Create link to URL", w.urlLink); + menuOptions.link = menu.addOption("Create link", w.link); menuOptions.ownerArea = menu.addOption("Make an area owner-only", function() { return w.doProtect("owner-only"); }); @@ -6547,9 +6546,8 @@ Object.assign(w, { menu: null, ui: { announcements: {}, - coordLinkModal: null, coordGotoModal: null, - urlModal: null, + linkModal: null, colorModal: null, selectionModal: null }, @@ -6641,9 +6639,9 @@ Object.assign(w, { w.isLinking = true; w.link_input_type = 0; }, - urlLink: function() { + link: function() { stopLinkUI(); - w.ui.urlModal.open(); + w.ui.linkModal.open(); }, doCoordLink: function(y, x) { linkAuto.active = true; @@ -6658,9 +6656,6 @@ Object.assign(w, { w.isLinking = true; w.link_input_type = 1; }, - coordLink: function() { - w.ui.coordLinkModal.open(); - }, doProtect: function(protectType, unprotect) { // show the protection precision menu elm.protect_precision.style.display = ""; @@ -7139,19 +7134,6 @@ function enableBgColorPicker() { colorInputBg.jscolor.fromString("#DCE943"); } -function makeCoordLinkModal() { - var modal = new Modal(); - modal.createForm(); - modal.setFormTitle("Enter the coordinates to create a link to. You can then click on a letter to create the link.\n"); - var coordX = modal.addEntry("X", "text", "number").input; - var coordY = modal.addEntry("Y", "text", "number").input; - modal.setMaximumSize(360, 300); - modal.onSubmit(function() { - w.doCoordLink(parseFloat(coordY.value), parseFloat(coordX.value)); - }); - w.ui.coordLinkModal = modal; -} - function makeCoordGotoModal() { var modal = new Modal(); modal.createForm(); @@ -7164,18 +7146,32 @@ function makeCoordGotoModal() { w.ui.coordGotoModal = modal; } -function makeURLModal() { +function makeLinkModal() { var modal = new Modal(); - modal.setMinimumSize(250, 120); + modal.addTab("url", "URL"); + modal.addTab("coord", "Coordinates"); + + modal.focusTab("url"); modal.createForm(); - modal.setFormTitle("\n"); + modal.setFormTitle("Enter the URL to create a link to.\n"); var urlInput = modal.addEntry("URL", "text").input; urlInput.style.width = "175px"; + + modal.focusTab("coord"); + modal.createForm(); + modal.setFormTitle("Enter the coordinates to create a link to.\n"); + var coordX = modal.addEntry("X", "text", "number").input; + var coordY = modal.addEntry("Y", "text", "number").input; + modal.onSubmit(function() { - w.doUrlLink(urlInput.value); + if(modal.getCurrentTabId() == "url") { + w.doUrlLink(urlInput.value); + } else { + w.doCoordLink(parseFloat(coordY.value), parseFloat(coordX.value)); + } }); - modal.unalignForm(); - w.ui.urlModal = modal; + + w.ui.linkModal = modal; } function buildBackgroundColorModal(modal) { @@ -8054,9 +8050,8 @@ function begin() { setWriteInterval(); setupPoolCleanupInterval(); - makeCoordLinkModal(); makeCoordGotoModal(); - makeURLModal(); + makeLinkModal(); makeColorModal(); makeSelectionModal(); addColorShortcuts(); From c66048cba81362d45d787619aa604323217b57d2 Mon Sep 17 00:00:00 2001 From: KKosty4ka <49340075+KKosty4ka@users.noreply.github.com> Date: Sun, 14 Jul 2024 19:01:01 +0700 Subject: [PATCH 2/2] Show the link modal tabs only when needed --- frontend/static/yw/javascript/owot.js | 30 +++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/frontend/static/yw/javascript/owot.js b/frontend/static/yw/javascript/owot.js index 2ed6bd92..07317e53 100644 --- a/frontend/static/yw/javascript/owot.js +++ b/frontend/static/yw/javascript/owot.js @@ -5241,8 +5241,7 @@ function updateMenuEntryVisiblity() { var permEraseArea = Permissions.can_erase(state.userModel, state.worldModel); w.menu.setEntryVisibility(menuOptions.changeColor, permColorText || permColorCell); w.menu.setEntryVisibility(menuOptions.goToCoords, permGoToCoord); - w.menu.setEntryVisibility(menuOptions.coordLink, permCoordLink); - w.menu.setEntryVisibility(menuOptions.urlLink, permUrlLink); + w.menu.setEntryVisibility(menuOptions.link, permUrlLink || permCoordLink); w.menu.setEntryVisibility(menuOptions.ownerArea, permOwnerArea); w.menu.setEntryVisibility(menuOptions.memberArea, permMemberArea); w.menu.setEntryVisibility(menuOptions.publicArea, permMemberArea); @@ -7172,6 +7171,7 @@ function makeLinkModal() { }); w.ui.linkModal = modal; + resetLinkModalVisibility(); } function buildBackgroundColorModal(modal) { @@ -7225,6 +7225,29 @@ function resetColorModalVisibility() { } } +function resetLinkModalVisibility() { + var permCoordLink = Permissions.can_coordlink(state.userModel, state.worldModel); + var permUrlLink = Permissions.can_urllink(state.userModel, state.worldModel); + + if(permUrlLink) { + w.ui.linkModal.showTab("url"); + } else { + w.ui.linkModal.hideTab("url"); + w.ui.linkModal.focusTab("coord"); + } + + if(permCoordLink) { + w.ui.linkModal.showTab("coord"); + } else { + w.ui.linkModal.hideTab("coord"); + w.ui.linkModal.focusTab("url"); + } + + if(!permUrlLink && !permCoordLink) { + w.ui.linkModal.close(); + } +} + function makeColorModal() { var modal = new Modal(); modal.setMinimumSize(290, 128); @@ -7557,6 +7580,7 @@ function reapplyProperties(props) { updateScaleConsts(); resetColorModalVisibility(); + resetLinkModalVisibility(); updateMenuEntryVisiblity(); updateWorldName(); @@ -7853,9 +7877,11 @@ var ws_functions = { break; case "coordLink": state.worldModel.feature_coord_link = value; + resetLinkModalVisibility(); break; case "urlLink": state.worldModel.feature_url_link = value; + resetLinkModalVisibility(); break; case "paste": state.worldModel.feature_paste = value;