Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify link modals #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 53 additions & 32 deletions frontend/static/yw/javascript/owot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down Expand Up @@ -5242,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);
Expand Down Expand Up @@ -6547,9 +6545,8 @@ Object.assign(w, {
menu: null,
ui: {
announcements: {},
coordLinkModal: null,
coordGotoModal: null,
urlModal: null,
linkModal: null,
colorModal: null,
selectionModal: null
},
Expand Down Expand Up @@ -6641,9 +6638,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;
Expand All @@ -6658,9 +6655,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 = "";
Expand Down Expand Up @@ -7139,19 +7133,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();
Expand All @@ -7164,18 +7145,33 @@ 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;
resetLinkModalVisibility();
}

function buildBackgroundColorModal(modal) {
Expand Down Expand Up @@ -7229,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);
Expand Down Expand Up @@ -7561,6 +7580,7 @@ function reapplyProperties(props) {

updateScaleConsts();
resetColorModalVisibility();
resetLinkModalVisibility();
updateMenuEntryVisiblity();
updateWorldName();

Expand Down Expand Up @@ -7857,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;
Expand Down Expand Up @@ -8054,9 +8076,8 @@ function begin() {
setWriteInterval();
setupPoolCleanupInterval();

makeCoordLinkModal();
makeCoordGotoModal();
makeURLModal();
makeLinkModal();
makeColorModal();
makeSelectionModal();
addColorShortcuts();
Expand Down