Skip to content

Commit

Permalink
Fix mozilla#1670 - Add option to manually assign an URL to a container
Browse files Browse the repository at this point in the history
  • Loading branch information
dannycolin committed Dec 19, 2024
1 parent 037a804 commit 459c4f1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const Logic = {
notificationCards.forEach(notificationCard => {
notificationCard.textContent = text;
notificationCard.classList.add("is-shown");

setTimeout(() => {
notificationCard.classList.remove("is-shown");
}, 2000);
Expand Down Expand Up @@ -1450,10 +1450,44 @@ Logic.registerPanel(P_CONTAINER_ASSIGNMENTS, {
const userContextId = Logic.currentUserContextId();
const assignments = await Logic.getAssignmentObjectByContainer(userContextId);
this.showAssignedContainers(assignments);
this.addAssignment();

return Promise.resolve(null);
},

addAssignment() {
const addAssignmentBtn =
document.getElementById("edit-sites-add-assignment");
const userContextId = Logic.currentUserContextId();

addAssignmentBtn.addEventListener("click", async () => {
const addAssignmentInput =
document.getElementById("edit-sites-add-assignment-info").value;

try {
const url = new URL(addAssignmentInput);

Utils.setOrRemoveAssignment(
false, addAssignmentInput, userContextId, false
);

} catch (e) {
const addAssignmentError =
document.getElementById("edit-sites-add-assignment-error");
addAssignmentError.textContent = "Bad input.";
return;
}

const assignments =
await Logic.getAssignmentObjectByContainer(userContextId);
this.showAssignedContainers(assignments);

const addAssignmentError =
document.getElementById("edit-sites-add-assignment-error");
addAssignmentError.textContent = "Good input.";
});
},

showAssignedContainers(assignments) {
const closeContEl = document.querySelector("#close-container-assignment-panel");
Utils.addEnterHandler(closeContEl, () => {
Expand Down Expand Up @@ -2319,7 +2353,7 @@ Logic.registerPanel(P_CLEAR_CONTAINER_STORAGE, {
// This method is called when the panel is shown.
prepare() {
const identity = Logic.currentIdentity();

// Populating the panel: name, icon, and warning message
document.getElementById("container-clear-storage-title").textContent = identity.name;
return Promise.resolve(null);
Expand Down
8 changes: 8 additions & 0 deletions src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ <h3 class="title" id="edit-assignments-title" data-i18n-message-id="default"></h
</tr>
</table>
</div>
<div id="edit-sites-new-assignment">
<input
id="edit-sites-add-assignment-info"
type="text"
style="display: block;">
<p id="edit-sites-add-assignment-error"></p>
<button id="edit-sites-add-assignment">Add site</button>
</div>
</div>

<div class="hide panel delete-container-panel" id="delete-container-panel">
Expand Down

0 comments on commit 459c4f1

Please sign in to comment.