Create/update and previous panel
This commit is contained in:
parent
b2bd693e81
commit
0dc21cd96e
3 changed files with 53 additions and 16 deletions
6
index.js
6
index.js
|
@ -404,6 +404,12 @@ let ContainerService = {
|
||||||
|
|
||||||
// FIXME: icon and color conversion based on FF version.
|
// FIXME: icon and color conversion based on FF version.
|
||||||
const identity = ContextualIdentityService.create(args.name, args.icon, args.color);
|
const identity = ContextualIdentityService.create(args.name, args.icon, args.color);
|
||||||
|
|
||||||
|
this._identitiesState[identity.userContextId] = {
|
||||||
|
hiddenTabUrls: [],
|
||||||
|
openTabs: 0
|
||||||
|
};
|
||||||
|
|
||||||
return Promise.resolve(this._convert(identity));
|
return Promise.resolve(this._convert(identity));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,8 @@ function log(...args) {
|
||||||
let Logic = {
|
let Logic = {
|
||||||
_identities: [],
|
_identities: [],
|
||||||
_currentIdentity: null,
|
_currentIdentity: null,
|
||||||
|
_currentPanel: null,
|
||||||
|
_previousPanel: null,
|
||||||
_panels: {},
|
_panels: {},
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
@ -62,6 +64,9 @@ let Logic = {
|
||||||
throw("Something really bad happened. Unknown panel: " + panel + "\n");
|
throw("Something really bad happened. Unknown panel: " + panel + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._previousPanel = this._currentPanel;
|
||||||
|
this._currentPanel = panel;
|
||||||
|
|
||||||
this._currentIdentity = currentIdentity;
|
this._currentIdentity = currentIdentity;
|
||||||
|
|
||||||
// Initialize the panel before showing it.
|
// Initialize the panel before showing it.
|
||||||
|
@ -73,6 +78,14 @@ let Logic = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
showPreviousPanel() {
|
||||||
|
if (!this._previousPanel) {
|
||||||
|
throw "Current panel not set!";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.showPanel(this._previousPanel, this._currentIdentity);
|
||||||
|
},
|
||||||
|
|
||||||
registerPanel(panelName, panelObject) {
|
registerPanel(panelName, panelObject) {
|
||||||
this._panels[panelName] = panelObject;
|
this._panels[panelName] = panelObject;
|
||||||
panelObject.initialize();
|
panelObject.initialize();
|
||||||
|
@ -140,7 +153,7 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
|
||||||
|
|
||||||
// This method is called when the object is registered.
|
// This method is called when the object is registered.
|
||||||
initialize() {
|
initialize() {
|
||||||
document.querySelector(".add-container-link").addEventListener("click", () => {
|
document.querySelector("#container-add-link").addEventListener("click", () => {
|
||||||
Logic.showPanel(P_CONTAINER_EDIT, {});
|
Logic.showPanel(P_CONTAINER_EDIT, {});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -167,7 +180,6 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
|
||||||
fragment.appendChild(tr);
|
fragment.appendChild(tr);
|
||||||
tr.classList.add("container-panel-row");
|
tr.classList.add("container-panel-row");
|
||||||
tr.classList.add("clickable");
|
tr.classList.add("clickable");
|
||||||
tr.setAttribute("data-identity-cookie-store-id", identity.userContextId);
|
|
||||||
tr.innerHTML = `
|
tr.innerHTML = `
|
||||||
<td>
|
<td>
|
||||||
<div class="userContext-icon open-newtab"
|
<div class="userContext-icon open-newtab"
|
||||||
|
@ -213,7 +225,7 @@ Logic.registerPanel(P_CONTAINER_INFO, {
|
||||||
// This method is called when the object is registered.
|
// This method is called when the object is registered.
|
||||||
initialize() {
|
initialize() {
|
||||||
document.querySelector("#close-container-info-panel").addEventListener("click", () => {
|
document.querySelector("#close-container-info-panel").addEventListener("click", () => {
|
||||||
Logic.showPanel(P_CONTAINERS_LIST);
|
Logic.showPreviousPanel();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelector("#container-info-hideorshow").addEventListener("click", e => {
|
document.querySelector("#container-info-hideorshow").addEventListener("click", e => {
|
||||||
|
@ -303,6 +315,10 @@ Logic.registerPanel(P_CONTAINERS_EDIT, {
|
||||||
|
|
||||||
// This method is called when the object is registered.
|
// This method is called when the object is registered.
|
||||||
initialize() {
|
initialize() {
|
||||||
|
document.querySelector("#edit-containers-add-link").addEventListener("click", () => {
|
||||||
|
Logic.showPanel(P_CONTAINER_EDIT, {});
|
||||||
|
});
|
||||||
|
|
||||||
document.querySelector("#exit-edit-mode-link").addEventListener("click", () => {
|
document.querySelector("#exit-edit-mode-link").addEventListener("click", () => {
|
||||||
Logic.showPanel(P_CONTAINERS_LIST);
|
Logic.showPanel(P_CONTAINERS_LIST);
|
||||||
});
|
});
|
||||||
|
@ -314,7 +330,6 @@ Logic.registerPanel(P_CONTAINERS_EDIT, {
|
||||||
Logic.identities().forEach(identity => {
|
Logic.identities().forEach(identity => {
|
||||||
let tr = document.createElement("tr");
|
let tr = document.createElement("tr");
|
||||||
fragment.appendChild(tr);
|
fragment.appendChild(tr);
|
||||||
tr.setAttribute("data-identity-cookie-store-id", identity.userContextId);
|
|
||||||
tr.classList.add("clickable");
|
tr.classList.add("clickable");
|
||||||
tr.innerHTML = `
|
tr.innerHTML = `
|
||||||
<td>
|
<td>
|
||||||
|
@ -327,16 +342,12 @@ Logic.registerPanel(P_CONTAINERS_EDIT, {
|
||||||
<td class="edit-container">
|
<td class="edit-container">
|
||||||
<img
|
<img
|
||||||
title="Edit ${identity.name} container"
|
title="Edit ${identity.name} container"
|
||||||
data-identity-cookie-store-id="${identity.userContextId}"
|
|
||||||
id="edit-${identity.userContextId}-container-icon"
|
|
||||||
src="/img/container-edit.svg"
|
src="/img/container-edit.svg"
|
||||||
class="icon edit-container-icon" />
|
class="icon edit-container-icon" />
|
||||||
</td>
|
</td>
|
||||||
<td class="remove-container" >
|
<td class="remove-container" >
|
||||||
<img
|
<img
|
||||||
title="Remove ${identity.name} container"
|
title="Remove ${identity.name} container"
|
||||||
data-identity-cookie-store-id="${identity.userContextId}"
|
|
||||||
id="delete-${identity.userContextId}-container-icon"
|
|
||||||
class="icon delete-container-icon"
|
class="icon delete-container-icon"
|
||||||
src="/img/container-delete.svg"
|
src="/img/container-delete.svg"
|
||||||
/>
|
/>
|
||||||
|
@ -367,18 +378,38 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
|
||||||
// This method is called when the object is registered.
|
// This method is called when the object is registered.
|
||||||
initialize() {
|
initialize() {
|
||||||
document.querySelector("#edit-container-panel-back-arrow").addEventListener("click", () => {
|
document.querySelector("#edit-container-panel-back-arrow").addEventListener("click", () => {
|
||||||
Logic.showPanel(P_CONTAINERS_EDIT);
|
Logic.showPreviousPanel();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelector("#edit-container-cancel-link").addEventListener("click", () => {
|
document.querySelector("#edit-container-cancel-link").addEventListener("click", () => {
|
||||||
Logic.showPanel(P_CONTAINERS_EDIT);
|
Logic.showPreviousPanel();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelector("#edit-container-ok-link").addEventListener("click", () => {
|
||||||
|
// FIXME: if the name is empty?
|
||||||
|
|
||||||
|
let identity = Logic.currentIdentity();
|
||||||
|
browser.runtime.sendMessage({
|
||||||
|
method: identity.userContextId ? "updateIdentity" : "createIdentity",
|
||||||
|
userContextId: identity.userContextId || 0,
|
||||||
|
name: document.getElementById("edit-container-panel-name-input").value,
|
||||||
|
icon: identity.image || "fingerprint",
|
||||||
|
color: identity.color || "green",
|
||||||
|
}).then(() => {
|
||||||
|
return Logic.refreshIdentities();
|
||||||
|
}).then(() => {
|
||||||
|
Logic.showPreviousPanel();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// This method is called when the panel is shown.
|
// This method is called when the panel is shown.
|
||||||
prepare() {
|
prepare() {
|
||||||
let identity = Logic.currentIdentity();
|
let identity = Logic.currentIdentity();
|
||||||
document.querySelector("#edit-container-panel-name-input").value = identity.name;
|
document.querySelector("#edit-container-panel-name-input").value = identity.name || "";
|
||||||
|
|
||||||
|
// FIXME: color and icon must be set. But we need the UI first.
|
||||||
|
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -392,7 +423,7 @@ Logic.registerPanel(P_CONTAINER_DELETE, {
|
||||||
// This method is called when the object is registered.
|
// This method is called when the object is registered.
|
||||||
initialize() {
|
initialize() {
|
||||||
document.querySelector("#delete-container-cancel-link").addEventListener("click", () => {
|
document.querySelector("#delete-container-cancel-link").addEventListener("click", () => {
|
||||||
Logic.showPanel(P_CONTAINERS_EDIT);
|
Logic.showPreviousPanel();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelector("#delete-container-ok-link").addEventListener("click", () => {
|
document.querySelector("#delete-container-ok-link").addEventListener("click", () => {
|
||||||
|
@ -402,7 +433,7 @@ Logic.registerPanel(P_CONTAINER_DELETE, {
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
return Logic.refreshIdentities();
|
return Logic.refreshIdentities();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
Logic.showPanel(P_CONTAINERS_EDIT);
|
Logic.showPreviousPanel();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
<a id="edit-containers-link">Edit Containers</a>
|
<a id="edit-containers-link">Edit Containers</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="small-2 columns add-container">
|
<div class="small-2 columns add-container">
|
||||||
<a class="add-container-link">
|
<a class="add-container-link" id="container-add-link">
|
||||||
<img alt="Create new container icon" title="Create new container" src="/img/container-add.svg" class="icon" />
|
<img alt="Create new container icon" title="Create new container" src="/img/container-add.svg" class="icon" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -84,7 +84,7 @@
|
||||||
<a id="exit-edit-mode-link">< Exit Edit Mode</a>
|
<a id="exit-edit-mode-link">< Exit Edit Mode</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="small-2 columns add-container">
|
<div class="small-2 columns add-container">
|
||||||
<a class="add-container-link">
|
<a class="add-container-link" id="edit-containers-add-link">
|
||||||
<img alt="Create new container icon" title="Create new container" src="/img/container-add.svg" class="icon" />
|
<img alt="Create new container icon" title="Create new container" src="/img/container-add.svg" class="icon" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -126,7 +126,7 @@
|
||||||
<a class="button secondary expanded footer-button cancel-button" id="edit-container-cancel-link">Cancel</a>
|
<a class="button secondary expanded footer-button cancel-button" id="edit-container-cancel-link">Cancel</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="small-6 columns footer-columns">
|
<div class="small-6 columns footer-columns">
|
||||||
<a class="button expanded footer-button">OK</a>
|
<a class="button expanded footer-button" id="edit-container-ok-link">OK</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue