2020-06-05 22:03:37 +00:00
|
|
|
"use strict";
|
2020-05-04 02:53:28 +00:00
|
|
|
|
2020-06-05 22:03:37 +00:00
|
|
|
const events = require("../events.js");
|
|
|
|
const views = require("../util/views.js");
|
|
|
|
const misc = require("../util/misc.js");
|
|
|
|
const PoolSummaryView = require("./pool_summary_view.js");
|
|
|
|
const PoolEditView = require("./pool_edit_view.js");
|
|
|
|
const PoolMergeView = require("./pool_merge_view.js");
|
|
|
|
const PoolDeleteView = require("./pool_delete_view.js");
|
|
|
|
const EmptyView = require("../views/empty_view.js");
|
2020-05-04 02:53:28 +00:00
|
|
|
|
2020-06-05 22:03:37 +00:00
|
|
|
const template = views.getTemplate("pool");
|
2020-05-04 02:53:28 +00:00
|
|
|
|
|
|
|
class PoolView extends events.EventTarget {
|
|
|
|
constructor(ctx) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this._ctx = ctx;
|
2020-06-05 22:03:37 +00:00
|
|
|
ctx.pool.addEventListener("change", (e) => this._evtChange(e));
|
|
|
|
ctx.section = ctx.section || "summary";
|
2020-06-23 16:36:26 +00:00
|
|
|
ctx.getPrettyName = misc.getPrettyName;
|
2020-05-04 02:53:28 +00:00
|
|
|
|
2020-06-05 22:03:37 +00:00
|
|
|
this._hostNode = document.getElementById("content-holder");
|
2020-05-04 02:53:28 +00:00
|
|
|
this._install();
|
|
|
|
}
|
|
|
|
|
|
|
|
_install() {
|
|
|
|
const ctx = this._ctx;
|
|
|
|
views.replaceContent(this._hostNode, template(ctx));
|
|
|
|
|
2020-06-05 22:03:37 +00:00
|
|
|
for (let item of this._hostNode.querySelectorAll("[data-name]")) {
|
2020-05-04 02:53:28 +00:00
|
|
|
item.classList.toggle(
|
2020-06-05 22:03:37 +00:00
|
|
|
"active",
|
|
|
|
item.getAttribute("data-name") === ctx.section
|
|
|
|
);
|
|
|
|
if (item.getAttribute("data-name") === ctx.section) {
|
2020-05-04 02:53:28 +00:00
|
|
|
item.parentNode.scrollLeft =
|
|
|
|
item.getBoundingClientRect().left -
|
2020-06-05 22:03:37 +00:00
|
|
|
item.parentNode.getBoundingClientRect().left;
|
2020-05-04 02:53:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-05 22:03:37 +00:00
|
|
|
ctx.hostNode = this._hostNode.querySelector(".pool-content-holder");
|
|
|
|
if (ctx.section === "edit") {
|
2020-05-04 02:53:28 +00:00
|
|
|
if (!this._ctx.canEditAnything) {
|
|
|
|
this._view = new EmptyView();
|
|
|
|
this._view.showError(
|
2020-06-05 22:03:37 +00:00
|
|
|
"You don't have privileges to edit pools."
|
|
|
|
);
|
2020-05-04 02:53:28 +00:00
|
|
|
} else {
|
|
|
|
this._view = new PoolEditView(ctx);
|
2020-06-05 22:03:37 +00:00
|
|
|
events.proxyEvent(this._view, this, "submit");
|
2020-05-04 02:53:28 +00:00
|
|
|
}
|
2020-06-05 22:03:37 +00:00
|
|
|
} else if (ctx.section === "merge") {
|
2020-05-04 02:53:28 +00:00
|
|
|
if (!this._ctx.canMerge) {
|
|
|
|
this._view = new EmptyView();
|
|
|
|
this._view.showError(
|
2020-06-05 22:03:37 +00:00
|
|
|
"You don't have privileges to merge pools."
|
|
|
|
);
|
2020-05-04 02:53:28 +00:00
|
|
|
} else {
|
|
|
|
this._view = new PoolMergeView(ctx);
|
2020-06-05 22:03:37 +00:00
|
|
|
events.proxyEvent(this._view, this, "submit", "merge");
|
2020-05-04 02:53:28 +00:00
|
|
|
}
|
2020-06-05 22:03:37 +00:00
|
|
|
} else if (ctx.section === "delete") {
|
2020-05-04 02:53:28 +00:00
|
|
|
if (!this._ctx.canDelete) {
|
|
|
|
this._view = new EmptyView();
|
|
|
|
this._view.showError(
|
2020-06-05 22:03:37 +00:00
|
|
|
"You don't have privileges to delete pools."
|
|
|
|
);
|
2020-05-04 02:53:28 +00:00
|
|
|
} else {
|
|
|
|
this._view = new PoolDeleteView(ctx);
|
2020-06-05 22:03:37 +00:00
|
|
|
events.proxyEvent(this._view, this, "submit", "delete");
|
2020-05-04 02:53:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this._view = new PoolSummaryView(ctx);
|
|
|
|
}
|
|
|
|
|
2020-06-05 22:03:37 +00:00
|
|
|
events.proxyEvent(this._view, this, "change");
|
2020-05-04 02:53:28 +00:00
|
|
|
views.syncScrollPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
clearMessages() {
|
|
|
|
this._view.clearMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
enableForm() {
|
|
|
|
this._view.enableForm();
|
|
|
|
}
|
|
|
|
|
|
|
|
disableForm() {
|
|
|
|
this._view.disableForm();
|
|
|
|
}
|
|
|
|
|
|
|
|
showSuccess(message) {
|
|
|
|
this._view.showSuccess(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
showError(message) {
|
|
|
|
this._view.showError(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
_evtChange(e) {
|
|
|
|
this._ctx.pool = e.detail.pool;
|
|
|
|
this._install(this._ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = PoolView;
|