implement user expiry functionality
All works now, but i'll add a field on the accounts tab for users with an expiry, as well as a 'disabled' badge.
This commit is contained in:
+35
-36
@@ -59,20 +59,20 @@ export class DOMInvite implements Invite {
|
||||
get expiresIn(): string { return this._expiresIn }
|
||||
set expiresIn(expiry: string) {
|
||||
this._expiresIn = expiry;
|
||||
this._infoArea.querySelector("span.inv-expiry").textContent = expiry;
|
||||
this._infoArea.querySelector("span.inv-duration").textContent = expiry;
|
||||
}
|
||||
|
||||
private _userDuration: string;
|
||||
get userDurationTime(): string { return this._userDuration; }
|
||||
set userDurationTime(d: string) {
|
||||
const duration = this._middle.querySelector("span.user-duration") as HTMLSpanElement;
|
||||
private _userExpiry: string;
|
||||
get userExpiryTime(): string { return this._userExpiry; }
|
||||
set userExpiryTime(d: string) {
|
||||
const expiry = this._middle.querySelector("span.user-expiry") as HTMLSpanElement;
|
||||
if (!d) {
|
||||
duration.textContent = "";
|
||||
expiry.textContent = "";
|
||||
} else {
|
||||
duration.textContent = window.lang.strings("userDuration");
|
||||
expiry.textContent = window.lang.strings("userExpiry");
|
||||
}
|
||||
this._userDuration = d;
|
||||
this._middle.querySelector("strong.user-duration-time").textContent = d;
|
||||
this._userExpiry = d;
|
||||
this._middle.querySelector("strong.user-expiry-time").textContent = d;
|
||||
}
|
||||
|
||||
private _remainingUses: string = "1";
|
||||
@@ -278,7 +278,7 @@ export class DOMInvite implements Invite {
|
||||
<span class="inv-email-chip"><i></i></span>
|
||||
<span class="content sm"></span>
|
||||
</div>
|
||||
<span class="inv-expiry mr-1"></span>
|
||||
<span class="inv-duration mr-1"></span>
|
||||
<span class="button ~critical !normal inv-delete">${window.lang.strings("delete")}</span>
|
||||
<label>
|
||||
<i class="icon clickable ri-arrow-down-s-line not-rotated"></i>
|
||||
@@ -344,7 +344,7 @@ export class DOMInvite implements Invite {
|
||||
this._middle.innerHTML = `
|
||||
<p class="supra mb-1 top">${window.lang.strings("inviteDateCreated")} <strong class="inv-created"></strong></p>
|
||||
<p class="supra mb-1">${window.lang.strings("inviteRemainingUses")} <strong class="inv-remaining"></strong></p>
|
||||
<p class="supra mb-1"><span class="user-duration"></span> <strong class="user-duration-time"></strong></p>
|
||||
<p class="supra mb-1"><span class="user-expiry"></span> <strong class="user-expiry-time"></strong></p>
|
||||
`;
|
||||
|
||||
this._right = document.createElement('div') as HTMLDivElement;
|
||||
@@ -376,7 +376,7 @@ export class DOMInvite implements Invite {
|
||||
if (invite.label) {
|
||||
this.label = invite.label;
|
||||
}
|
||||
this.userDurationTime = invite.userDurationTime || "";
|
||||
this.userExpiryTime = invite.userExpiryTime || "";
|
||||
}
|
||||
|
||||
asElement = (): HTMLDivElement => { return this._container; }
|
||||
@@ -477,16 +477,16 @@ function parseInvite(invite: { [f: string]: string | number | string[][] | boole
|
||||
parsed.email = invite["email"] as string || "";
|
||||
parsed.label = invite["label"] as string || "";
|
||||
let time = "";
|
||||
let userDurationTime = "";
|
||||
let userExpiryTime = "";
|
||||
const fields = ["days", "hours", "minutes"];
|
||||
let prefixes = [""];
|
||||
if (invite["user-duration"] as boolean) { prefixes.push("user-"); }
|
||||
if (invite["user-expiry"] as boolean) { prefixes.push("user-"); }
|
||||
for (let i = 0; i < fields.length; i++) {
|
||||
for (let j = 0; j < prefixes.length; j++) {
|
||||
if (invite[prefixes[j]+fields[i]]) {
|
||||
let text = `${invite[prefixes[j]+fields[i]]}${fields[i][0]} `;
|
||||
if (prefixes[j] == "user-") {
|
||||
userDurationTime += text;
|
||||
userExpiryTime += text;
|
||||
} else {
|
||||
time += text;
|
||||
}
|
||||
@@ -494,8 +494,8 @@ function parseInvite(invite: { [f: string]: string | number | string[][] | boole
|
||||
}
|
||||
}
|
||||
parsed.expiresIn = window.lang.var("strings", "inviteExpiresInTime", time.slice(0, -1));
|
||||
parsed.userDuration = invite["user-duration"] as boolean;
|
||||
parsed.userDurationTime = userDurationTime.slice(0, -1);
|
||||
parsed.userExpiry = invite["user-expiry"] as boolean;
|
||||
parsed.userExpiryTime = userExpiryTime.slice(0, -1);
|
||||
parsed.remainingUses = invite["no-limit"] ? "∞" : String(invite["remaining-uses"])
|
||||
parsed.usedBy = invite["used-by"] as string[][] || [];
|
||||
parsed.created = invite["created"] as string || window.lang.strings("unknown");
|
||||
@@ -508,7 +508,7 @@ function parseInvite(invite: { [f: string]: string | number | string[][] | boole
|
||||
export class createInvite {
|
||||
private _sendToEnabled = document.getElementById("create-send-to-enabled") as HTMLInputElement;
|
||||
private _sendTo = document.getElementById("create-send-to") as HTMLInputElement;
|
||||
private _userDurationToggle = document.getElementById("create-user-duration-enabled") as HTMLInputElement;
|
||||
private _userExpiryToggle = document.getElementById("create-user-expiry-enabled") as HTMLInputElement;
|
||||
private _uses = document.getElementById('create-uses') as HTMLInputElement;
|
||||
private _infUses = document.getElementById("create-inf-uses") as HTMLInputElement;
|
||||
private _infUsesWarning = document.getElementById('create-inf-uses-warning') as HTMLParagraphElement;
|
||||
@@ -524,9 +524,9 @@ export class createInvite {
|
||||
private _userMinutes = document.getElementById("user-minutes") as HTMLSelectElement;
|
||||
|
||||
private _invDurationButton = document.getElementById('radio-inv-duration') as HTMLInputElement;
|
||||
private _userDurationButton = document.getElementById('radio-user-duration') as HTMLInputElement;
|
||||
private _userExpiryButton = document.getElementById('radio-user-expiry') as HTMLInputElement;
|
||||
private _invDuration = document.getElementById('inv-duration');
|
||||
private _userDuration = document.getElementById('user-duration');
|
||||
private _userExpiry = document.getElementById('user-expiry');
|
||||
|
||||
// Broadcast when new invite created
|
||||
private _newInviteEvent = new CustomEvent("newInviteEvent");
|
||||
@@ -619,11 +619,11 @@ export class createInvite {
|
||||
this._minutes.value = ""+n;
|
||||
this._checkDurationValidity();
|
||||
}
|
||||
get userDuration(): boolean {
|
||||
return this._userDurationToggle.checked;
|
||||
get userExpiry(): boolean {
|
||||
return this._userExpiryToggle.checked;
|
||||
}
|
||||
set userDuration(enabled: boolean) {
|
||||
this._userDurationToggle.checked = enabled;
|
||||
set userExpiry(enabled: boolean) {
|
||||
this._userExpiryToggle.checked = enabled;
|
||||
this._userDays.disabled = !enabled;
|
||||
this._userHours.disabled = !enabled;
|
||||
this._userMinutes.disabled = !enabled;
|
||||
@@ -679,15 +679,15 @@ export class createInvite {
|
||||
|
||||
create = () => {
|
||||
toggleLoader(this._createButton);
|
||||
let userDuration = this.userDuration;
|
||||
let userExpiry = this.userExpiry;
|
||||
if (this.userDays == 0 && this.userHours == 0 && this.userMinutes == 0) {
|
||||
userDuration = false;
|
||||
userExpiry = false;
|
||||
}
|
||||
let send = {
|
||||
"days": this.days,
|
||||
"hours": this.hours,
|
||||
"minutes": this.minutes,
|
||||
"user-duration": userDuration,
|
||||
"user-expiry": userExpiry,
|
||||
"user-days": this.userDays,
|
||||
"user-hours": this.userHours,
|
||||
"user-minutes": this.userMinutes,
|
||||
@@ -716,8 +716,8 @@ export class createInvite {
|
||||
this._infUses.onchange = () => { this.infiniteUses = this.infiniteUses; };
|
||||
this.infiniteUses = false;
|
||||
this._sendToEnabled.onchange = () => { this.sendToEnabled = this.sendToEnabled; };
|
||||
this.userDuration = false;
|
||||
this._userDurationToggle.onchange = () => { this.userDuration = this._userDurationToggle.checked; }
|
||||
this.userExpiry = false;
|
||||
this._userExpiryToggle.onchange = () => { this.userExpiry = this._userExpiryToggle.checked; }
|
||||
this._userDays.disabled = true;
|
||||
this._userHours.disabled = true;
|
||||
this._userMinutes.disabled = true;
|
||||
@@ -728,18 +728,17 @@ export class createInvite {
|
||||
this.label = "";
|
||||
|
||||
const checkDuration = () => {
|
||||
console.log("bbbb")
|
||||
const invSpan = this._invDurationButton.nextElementSibling as HTMLSpanElement;
|
||||
const userSpan = this._userDurationButton.nextElementSibling as HTMLSpanElement;
|
||||
const userSpan = this._userExpiryButton.nextElementSibling as HTMLSpanElement;
|
||||
if (this._invDurationButton.checked) {
|
||||
this._invDuration.classList.remove("unfocused");
|
||||
this._userDuration.classList.add("unfocused");
|
||||
this._userExpiry.classList.add("unfocused");
|
||||
invSpan.classList.add("!high");
|
||||
invSpan.classList.remove("!normal");
|
||||
userSpan.classList.add("!normal");
|
||||
userSpan.classList.remove("!high");
|
||||
} else if (this._userDurationButton.checked) {
|
||||
this._userDuration.classList.remove("unfocused");
|
||||
} else if (this._userExpiryButton.checked) {
|
||||
this._userExpiry.classList.remove("unfocused");
|
||||
this._invDuration.classList.add("unfocused");
|
||||
invSpan.classList.add("!normal");
|
||||
invSpan.classList.remove("!high");
|
||||
@@ -748,9 +747,9 @@ export class createInvite {
|
||||
}
|
||||
};
|
||||
|
||||
this._userDurationButton.checked = false;
|
||||
this._userExpiryButton.checked = false;
|
||||
this._invDurationButton.checked = true;
|
||||
this._userDurationButton.onchange = checkDuration;
|
||||
this._userExpiryButton.onchange = checkDuration;
|
||||
this._invDurationButton.onchange = checkDuration;
|
||||
|
||||
this._days.onchange = this._checkDurationValidity;
|
||||
|
||||
+13
-5
@@ -694,6 +694,7 @@ class EmailEditor {
|
||||
private _form = document.getElementById("form-editor") as HTMLFormElement;
|
||||
private _header = document.getElementById("header-editor") as HTMLSpanElement;
|
||||
private _variables = document.getElementById("editor-variables") as HTMLDivElement;
|
||||
private _variablesLabel = document.getElementById("label-editor-variables") as HTMLElement;
|
||||
private _textArea = document.getElementById("textarea-editor") as HTMLTextAreaElement;
|
||||
private _preview = document.getElementById("editor-preview") as HTMLDivElement;
|
||||
private _previewContent: HTMLElement;
|
||||
@@ -745,6 +746,11 @@ class EmailEditor {
|
||||
let ci = i % colors.length;
|
||||
innerHTML += '<span class="button ~' + colors[ci] +' !normal mb-1" style="margin-left: 0.25rem; margin-right: 0.25rem;"></span>'
|
||||
}
|
||||
if (this._templ.variables.length == 0) {
|
||||
this._variablesLabel.classList.add("unfocused");
|
||||
} else {
|
||||
this._variablesLabel.classList.remove("unfocused");
|
||||
}
|
||||
this._variables.innerHTML = innerHTML
|
||||
const buttons = this._variables.querySelectorAll("span.button") as NodeListOf<HTMLSpanElement>;
|
||||
for (let i = 0; i < this._templ.variables.length; i++) {
|
||||
@@ -761,10 +767,12 @@ class EmailEditor {
|
||||
}
|
||||
loadPreview = () => {
|
||||
let content = this._textArea.value;
|
||||
for (let variable of this._templ.variables) {
|
||||
let value = this._templ.values[variable.slice(1, -1)];
|
||||
if (value === undefined) { value = variable; }
|
||||
content = content.replace(new RegExp(variable, "g"), value);
|
||||
if (this._templ.variables) {
|
||||
for (let variable of this._templ.variables) {
|
||||
let value = this._templ.values[variable.slice(1, -1)];
|
||||
if (value === undefined) { value = variable; }
|
||||
content = content.replace(new RegExp(variable, "g"), value);
|
||||
}
|
||||
}
|
||||
if (this._templ.html == "") {
|
||||
content = stripMarkdown(content);
|
||||
@@ -785,7 +793,7 @@ class EmailEditor {
|
||||
}
|
||||
|
||||
showList = () => {
|
||||
_get("/config/emails", null, (req: XMLHttpRequest) => {
|
||||
_get("/config/emails?lang=" + window.language, null, (req: XMLHttpRequest) => {
|
||||
if (req.readyState == 4) {
|
||||
if (req.status != 200) {
|
||||
window.notifications.customError("loadTemplateError", window.lang.notif("errorFailureCheckLogs"));
|
||||
|
||||
Reference in New Issue
Block a user