2021-03-18 12:34:08 +01:00
|
|
|
$('.mailbox-select').multipleSelect();
|
|
|
|
|
2021-03-18 14:21:26 +01:00
|
|
|
function confirmDeleteAlias() {
|
2021-03-18 12:34:08 +01:00
|
|
|
let that = $(this);
|
2021-03-18 14:21:26 +01:00
|
|
|
let alias = that.data("alias-email");
|
2021-03-18 14:45:18 +01:00
|
|
|
let aliasDomainTrashUrl = that.data("custom-domain-trash-url");
|
|
|
|
|
|
|
|
let message = `Maybe you want to disable the alias instead? Please note once deleted, it <b>can't</b> be restored.`;
|
|
|
|
if (aliasDomainTrashUrl !== undefined) {
|
2022-07-04 16:01:04 +02:00
|
|
|
message = `Maybe you want to disable the alias instead? When it's deleted, it's moved to the domain
|
2021-03-18 14:45:18 +01:00
|
|
|
<a href="${aliasDomainTrashUrl}">trash</a>`;
|
|
|
|
}
|
2021-03-18 12:34:08 +01:00
|
|
|
|
2021-03-18 14:21:26 +01:00
|
|
|
bootbox.dialog({
|
|
|
|
title: `Delete ${alias}`,
|
2021-03-18 14:45:18 +01:00
|
|
|
message: message,
|
2021-03-18 14:21:26 +01:00
|
|
|
size: 'large',
|
|
|
|
onEscape: true,
|
|
|
|
backdrop: true,
|
2021-03-18 12:34:08 +01:00
|
|
|
buttons: {
|
2021-03-18 14:21:26 +01:00
|
|
|
disable: {
|
|
|
|
label: 'Disable it',
|
|
|
|
className: 'btn-primary',
|
|
|
|
callback: function () {
|
|
|
|
that.closest("form").find('input[name="form-name"]').val("disable-alias");
|
|
|
|
that.closest("form").submit();
|
|
|
|
}
|
2021-03-18 12:34:08 +01:00
|
|
|
},
|
2021-03-18 14:21:26 +01:00
|
|
|
|
|
|
|
delete: {
|
2021-03-22 15:40:17 +01:00
|
|
|
label: "Delete it, I don't need it anymore",
|
2021-03-18 14:21:26 +01:00
|
|
|
className: 'btn-outline-danger',
|
|
|
|
callback: function () {
|
|
|
|
that.closest("form").submit();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-03-18 12:34:08 +01:00
|
|
|
cancel: {
|
|
|
|
label: 'Cancel',
|
|
|
|
className: 'btn-outline-primary'
|
2021-03-18 14:21:26 +01:00
|
|
|
},
|
|
|
|
|
2021-03-18 12:34:08 +01:00
|
|
|
}
|
2021-11-03 10:53:39 +01:00
|
|
|
});
|
2021-03-18 14:21:26 +01:00
|
|
|
}
|
2021-03-18 12:34:08 +01:00
|
|
|
|
2021-03-18 13:54:14 +01:00
|
|
|
$(".enable-disable-alias").change(async function () {
|
2021-03-18 12:34:08 +01:00
|
|
|
let aliasId = $(this).data("alias");
|
|
|
|
let alias = $(this).data("alias-email");
|
|
|
|
|
2021-03-18 13:52:58 +01:00
|
|
|
await disableAlias(aliasId, alias);
|
2021-11-03 10:20:21 +01:00
|
|
|
});
|
2021-03-18 13:52:58 +01:00
|
|
|
|
|
|
|
async function disableAlias(aliasId, alias) {
|
|
|
|
let oldValue;
|
2021-03-18 12:34:08 +01:00
|
|
|
try {
|
|
|
|
let res = await fetch(`/api/aliases/${aliasId}/toggle`, {
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
let json = await res.json();
|
|
|
|
|
|
|
|
if (json.enabled) {
|
|
|
|
toastr.success(`${alias} is enabled`);
|
|
|
|
$(`#send-email-${aliasId}`).removeClass("disabled");
|
|
|
|
} else {
|
|
|
|
toastr.success(`${alias} is disabled`);
|
|
|
|
$(`#send-email-${aliasId}`).addClass("disabled");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
|
|
|
// reset to the original value
|
2021-03-18 13:46:50 +01:00
|
|
|
oldValue = !$(this).prop("checked");
|
2021-03-18 12:34:08 +01:00
|
|
|
$(this).prop("checked", oldValue);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
|
|
|
// reset to the original value
|
2021-03-18 13:46:50 +01:00
|
|
|
oldValue = !$(this).prop("checked");
|
2021-03-18 12:34:08 +01:00
|
|
|
$(this).prop("checked", oldValue);
|
|
|
|
}
|
2021-03-18 13:52:58 +01:00
|
|
|
}
|
2021-03-18 12:34:08 +01:00
|
|
|
|
|
|
|
$(".enable-disable-pgp").change(async function (e) {
|
|
|
|
let aliasId = $(this).data("alias");
|
|
|
|
let alias = $(this).data("alias-email");
|
2021-03-18 13:46:50 +01:00
|
|
|
const oldValue = !$(this).prop("checked");
|
2021-03-18 12:34:08 +01:00
|
|
|
let newValue = !oldValue;
|
|
|
|
|
|
|
|
try {
|
|
|
|
let res = await fetch(`/api/aliases/${aliasId}`, {
|
|
|
|
method: "PUT",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
disable_pgp: oldValue,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
if (newValue) {
|
|
|
|
toastr.success(`PGP is enabled for ${alias}`);
|
|
|
|
} else {
|
|
|
|
toastr.info(`PGP is disabled for ${alias}`);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
|
|
|
// reset to the original value
|
|
|
|
$(this).prop("checked", oldValue);
|
|
|
|
}
|
2021-11-03 10:53:39 +01:00
|
|
|
} catch (err) {
|
2021-03-18 12:34:08 +01:00
|
|
|
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
|
|
|
// reset to the original value
|
|
|
|
$(this).prop("checked", oldValue);
|
|
|
|
}
|
2021-11-03 10:20:21 +01:00
|
|
|
});
|
2021-03-18 12:34:08 +01:00
|
|
|
|
2021-03-18 13:54:14 +01:00
|
|
|
$(".pin-alias").change(async function () {
|
2021-03-18 12:34:08 +01:00
|
|
|
let aliasId = $(this).data("alias");
|
|
|
|
let alias = $(this).data("alias-email");
|
2021-03-18 13:46:50 +01:00
|
|
|
const oldValue = !$(this).prop("checked");
|
2021-03-18 12:34:08 +01:00
|
|
|
let newValue = !oldValue;
|
|
|
|
|
|
|
|
try {
|
|
|
|
let res = await fetch(`/api/aliases/${aliasId}`, {
|
|
|
|
method: "PUT",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
pinned: newValue,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
if (newValue) {
|
2021-09-19 19:50:50 +02:00
|
|
|
toastr.success(`${alias} is pinned`);
|
2021-03-18 12:34:08 +01:00
|
|
|
} else {
|
2021-09-19 19:50:50 +02:00
|
|
|
toastr.info(`${alias} is unpinned`);
|
2021-03-18 12:34:08 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
|
|
|
// reset to the original value
|
|
|
|
$(this).prop("checked", oldValue);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
|
|
|
// reset to the original value
|
|
|
|
$(this).prop("checked", oldValue);
|
|
|
|
}
|
2021-11-03 10:20:21 +01:00
|
|
|
});
|
2021-03-18 12:34:08 +01:00
|
|
|
|
|
|
|
$(".save-note").on("click", async function () {
|
2021-03-18 13:46:50 +01:00
|
|
|
let oldValue;
|
2021-03-18 12:34:08 +01:00
|
|
|
let aliasId = $(this).data("alias");
|
|
|
|
let note = $(`#note-${aliasId}`).val();
|
|
|
|
|
|
|
|
try {
|
|
|
|
let res = await fetch(`/api/aliases/${aliasId}`, {
|
|
|
|
method: "PUT",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
note: note,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (res.ok) {
|
2021-08-21 16:11:17 +02:00
|
|
|
toastr.success(`Saved`);
|
2021-03-18 12:34:08 +01:00
|
|
|
} else {
|
|
|
|
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
|
|
|
// reset to the original value
|
2021-03-18 13:46:50 +01:00
|
|
|
oldValue = !$(this).prop("checked");
|
2021-03-18 12:34:08 +01:00
|
|
|
$(this).prop("checked", oldValue);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
|
|
|
// reset to the original value
|
2021-03-18 13:46:50 +01:00
|
|
|
oldValue = !$(this).prop("checked");
|
2021-03-18 12:34:08 +01:00
|
|
|
$(this).prop("checked", oldValue);
|
|
|
|
}
|
|
|
|
|
2021-11-03 10:20:21 +01:00
|
|
|
});
|
2021-03-18 12:34:08 +01:00
|
|
|
|
|
|
|
$(".save-mailbox").on("click", async function () {
|
2021-03-18 13:46:50 +01:00
|
|
|
let oldValue;
|
2021-03-18 12:34:08 +01:00
|
|
|
let aliasId = $(this).data("alias");
|
|
|
|
let mailbox_ids = $(`#mailbox-${aliasId}`).val();
|
|
|
|
|
2021-03-18 13:46:50 +01:00
|
|
|
if (mailbox_ids.length === 0) {
|
2021-03-18 12:34:08 +01:00
|
|
|
toastr.error("You must select at least a mailbox", "Error");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
let res = await fetch(`/api/aliases/${aliasId}`, {
|
|
|
|
method: "PUT",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
mailbox_ids: mailbox_ids,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
toastr.success(`Mailbox Updated`);
|
|
|
|
} else {
|
|
|
|
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
|
|
|
// reset to the original value
|
2021-03-18 13:46:50 +01:00
|
|
|
oldValue = !$(this).prop("checked");
|
2021-03-18 12:34:08 +01:00
|
|
|
$(this).prop("checked", oldValue);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
|
|
|
// reset to the original value
|
2021-03-18 13:46:50 +01:00
|
|
|
oldValue = !$(this).prop("checked");
|
2021-03-18 12:34:08 +01:00
|
|
|
$(this).prop("checked", oldValue);
|
|
|
|
}
|
|
|
|
|
2021-11-03 10:20:21 +01:00
|
|
|
});
|
2021-03-18 12:34:08 +01:00
|
|
|
|
|
|
|
$(".save-alias-name").on("click", async function () {
|
|
|
|
let aliasId = $(this).data("alias");
|
|
|
|
let name = $(`#alias-name-${aliasId}`).val();
|
|
|
|
|
|
|
|
try {
|
|
|
|
let res = await fetch(`/api/aliases/${aliasId}`, {
|
|
|
|
method: "PUT",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
name: name,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
toastr.success(`Alias Name Saved`);
|
|
|
|
} else {
|
|
|
|
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
|
|
|
}
|
|
|
|
|
2021-11-03 10:20:21 +01:00
|
|
|
});
|
2021-03-18 12:34:08 +01:00
|
|
|
|
|
|
|
|
2021-03-18 13:46:50 +01:00
|
|
|
new Vue({
|
2021-03-18 12:34:08 +01:00
|
|
|
el: '#filter-app',
|
|
|
|
delimiters: ["[[", "]]"], // necessary to avoid conflict with jinja
|
|
|
|
data: {
|
|
|
|
showFilter: false
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async toggleFilter() {
|
|
|
|
let that = this;
|
|
|
|
that.showFilter = !that.showFilter;
|
|
|
|
store.set('showFilter', that.showFilter);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async mounted() {
|
|
|
|
if (store.get("showFilter"))
|
|
|
|
this.showFilter = true;
|
|
|
|
}
|
2021-03-18 13:46:50 +01:00
|
|
|
});
|