styles functionality & rely more on abstract methods
This commit is contained in:
parent
23d2d44c04
commit
876e7ba204
@ -106,60 +106,61 @@ async function loadMessageStyleData() {
|
|||||||
// region New/Edit Modal
|
// region New/Edit Modal
|
||||||
|
|
||||||
$(styleTableId).closest(".js-tableBody").siblings(".js-tableFilters").on("click", ".table-new-btn", async function() {
|
$(styleTableId).closest(".js-tableBody").siblings(".js-tableFilters").on("click", ".table-new-btn", async function() {
|
||||||
await openStyleModal(-1);
|
await openDataModal(styleModalId, -1);
|
||||||
});
|
});
|
||||||
|
|
||||||
$(styleTableId).on("click", ".edit-modal", async function() {
|
$(styleTableId).on("click", ".edit-modal", async function() {
|
||||||
let id = $(styleTableId).DataTable().row($(this).closest("tr")).data().id;
|
let id = $(styleTableId).DataTable().row($(this).closest("tr")).data().id;
|
||||||
await openStyleModal(id);
|
await openDataModal(styleModalId, id, `/api/message-styles/${id}/`);
|
||||||
});
|
});
|
||||||
|
|
||||||
async function openStyleModal(id) {
|
$(styleModalId).on("submit", async function(event) {
|
||||||
$modal = $(styleModalId);
|
event.preventDefault();
|
||||||
|
|
||||||
if (parseInt(id) === -1) {
|
if (!selectedServer) {
|
||||||
$modal.find(".form-create").show();
|
throw new Error("Cannot submit form while no server is selected");
|
||||||
$modal.find(".form-edit").hide();
|
}
|
||||||
|
|
||||||
$modal.find("[data-field]").each(function() {
|
let data = { server: selectedServer.id };
|
||||||
const type = $(this).attr("type");
|
|
||||||
const defaultVal = $(this).attr("data-default") || "";
|
|
||||||
|
|
||||||
if (type === "checkbox") {
|
$(this).find("[data-field]").each(function() {
|
||||||
$(this).prop("checked", defaultVal === "true");
|
const type = $(this).attr("type");
|
||||||
}
|
const key = $(this).attr("data-field");
|
||||||
else if (type === "datetime-local") {
|
if (!key) {
|
||||||
$(this).val(getCurrentDateTime());
|
return;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
$(this).val(defaultVal).change();
|
let value;
|
||||||
}
|
if (type === "checkbox") {
|
||||||
});
|
value = $(this).prop("checked");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
value = $(this).val();
|
||||||
|
}
|
||||||
|
|
||||||
|
data[key] = value;
|
||||||
|
});
|
||||||
|
|
||||||
|
const formData = objectToFormData(data);
|
||||||
|
const id = $(this).data("primary-key");
|
||||||
|
|
||||||
|
if (parseInt(id) !== -1) {
|
||||||
|
ajaxRequest(`/api/message-styles/${id}/`, "PATCH", formData)
|
||||||
|
.then(response => {
|
||||||
|
$(this).modal("hide");
|
||||||
|
$(styleTableId).trigger("doDataLoad");
|
||||||
|
})
|
||||||
|
.catch(error => logError(error))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$modal.find(".form-create").hide();
|
ajaxRequest("/api/message-styles/", "POST", formData)
|
||||||
$modal.find(".form-edit").show();
|
.then(response => {
|
||||||
|
$(this).modal("hide");
|
||||||
const data = await ajaxRequest(`/api/message-styles/${id}/`, "GET");
|
$(styleTableId).trigger("doDataLoad");
|
||||||
|
})
|
||||||
$modal.find("[data-field]").each(function() {
|
.catch(error => logError(error));
|
||||||
const key = $(this).attr("data-field");
|
|
||||||
const value = data[key];
|
|
||||||
|
|
||||||
if (typeof value === "boolean") {
|
|
||||||
$(this).prop("checked", value);
|
|
||||||
}
|
|
||||||
else if (isISODateTimeString(value)) {
|
|
||||||
$(this).val(value.split('+')[0].substring(0, 16));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$(this).val(value).change();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
$modal.modal("show");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// region Load Mutator Options
|
// region Load Mutator Options
|
||||||
|
@ -116,55 +116,6 @@ $(subTableId).on("click", ".edit-modal", async function() {
|
|||||||
await openDataModal(subModalId, id, `/api/subscriptions/${id}/`);
|
await openDataModal(subModalId, id, `/api/subscriptions/${id}/`);
|
||||||
})
|
})
|
||||||
|
|
||||||
async function openSubModal(id) {
|
|
||||||
$modal = $(subModalId);
|
|
||||||
$modal.find('input[data-role="is-id"]').val(id);
|
|
||||||
|
|
||||||
if (parseInt(id) === -1) {
|
|
||||||
$modal.find(".form-create").show();
|
|
||||||
$modal.find(".form-edit").hide();
|
|
||||||
|
|
||||||
$modal.find("[data-field]").each(function() {
|
|
||||||
const type = $(this).attr("type");
|
|
||||||
const defaultVal = $(this).attr("data-default") || "";
|
|
||||||
|
|
||||||
if (type === "checkbox") {
|
|
||||||
$(this).prop("checked", defaultVal === "true");
|
|
||||||
}
|
|
||||||
else if (type === "datetime-local") {
|
|
||||||
$(this).val(getCurrentDateTime());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$(this).val(defaultVal).change();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$modal.find(".form-create").hide();
|
|
||||||
$modal.find(".form-edit").show();
|
|
||||||
|
|
||||||
const data = await ajaxRequest(`/api/subscriptions/${id}/`, "GET");
|
|
||||||
|
|
||||||
$modal.find("[data-field]").each(function() {
|
|
||||||
const key = $(this).attr("data-field");
|
|
||||||
const value = data[key];
|
|
||||||
|
|
||||||
if (typeof value === "boolean") {
|
|
||||||
$(this).prop("checked", value);
|
|
||||||
}
|
|
||||||
else if (isISODateTimeString(value)) {
|
|
||||||
console.log(value.split('+')[0].substring(0, 16));
|
|
||||||
$(this).val(value.split('+')[0].substring(0, 16));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$(this).val(value).change();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
$modal.modal("show");
|
|
||||||
}
|
|
||||||
|
|
||||||
$(subModalId).on("submit", async function(event) {
|
$(subModalId).on("submit", async function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
@ -193,7 +144,7 @@ $(subModalId).on("submit", async function(event) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const formData = objectToFormData(data);
|
const formData = objectToFormData(data);
|
||||||
const id = $(this).find('input[data-role="is-id"]').val();
|
const id = $(this).data("primary-key");
|
||||||
|
|
||||||
if (parseInt(id) !== -1) {
|
if (parseInt(id) !== -1) {
|
||||||
ajaxRequest(`/api/subscriptions/${id}/`, "PATCH", formData)
|
ajaxRequest(`/api/subscriptions/${id}/`, "PATCH", formData)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user