From 66e41ab53de9e2e65c1d6064fe92b2117cd447cd Mon Sep 17 00:00:00 2001 From: Corban-Lee Jones Date: Fri, 27 Sep 2024 12:22:10 +0100 Subject: [PATCH] modals rewrite --- apps/home/models.py | 6 +- apps/home/static/home/js/servers.js | 8 + apps/home/static/home/js/tabs/subs.js | 44 +++- .../templates/home/includes/settingstab.html | 30 --- .../templates/home/includes/submodal.html | 192 ------------------ apps/home/templates/home/index.html | 20 +- .../deletemodal.html => modals/confirm.html} | 0 .../editFilter.html} | 0 .../editServer.html} | 0 apps/home/templates/home/modals/editSub.html | 92 +++++++++ 10 files changed, 160 insertions(+), 232 deletions(-) delete mode 100644 apps/home/templates/home/includes/settingstab.html delete mode 100644 apps/home/templates/home/includes/submodal.html rename apps/home/templates/home/{includes/deletemodal.html => modals/confirm.html} (100%) rename apps/home/templates/home/{includes/filtermodal.html => modals/editFilter.html} (100%) rename apps/home/templates/home/{includes/settingsmodal.html => modals/editServer.html} (100%) create mode 100644 apps/home/templates/home/modals/editSub.html diff --git a/apps/home/models.py b/apps/home/models.py index 542ec88..e7ec23a 100644 --- a/apps/home/models.py +++ b/apps/home/models.py @@ -110,9 +110,11 @@ class MessageStyle(models.Model): """ id = models.AutoField(primary_key=True) - server = models.ForeignKey(to=Server, on_delete=models.CASCADE) + server = models.ForeignKey(to=Server, on_delete=models.CASCADE, null=True, blank=False) + + is_embed = models.BooleanField() + colour = models.CharField(max_length=6) - is_embed = models.BooleanField(default=True) is_hyperlinked = models.BooleanField() # title only show_author = models.BooleanField() show_timestamp = models.BooleanField() diff --git a/apps/home/static/home/js/servers.js b/apps/home/static/home/js/servers.js index 349fe36..45ae5b1 100644 --- a/apps/home/static/home/js/servers.js +++ b/apps/home/static/home/js/servers.js @@ -154,13 +154,21 @@ $(document).on("selectedServerChange", function() { // #region Load Servers async function loadServers() { + $(".server-loading-item").show(); try { let response = await generateServers(); $(".server-loading-item").hide(); + + if (response.hasOwnProperty("retry_after")) { + $(".server-rate-limit").show(); + return; + } + response.forEach(server => { addToLoadedServers(server, false); }); + } catch (error) { logError(error); diff --git a/apps/home/static/home/js/tabs/subs.js b/apps/home/static/home/js/tabs/subs.js index 325f903..5640632 100644 --- a/apps/home/static/home/js/tabs/subs.js +++ b/apps/home/static/home/js/tabs/subs.js @@ -13,7 +13,7 @@ function initSubscriptionsModule() { className: "text-truncate", render: function(data, type, row) { const name = sanitise(data); - return ``; + return ``; } }, { @@ -118,3 +118,45 @@ $(subTableId).on("change", ".sub-toggle-active", async function() { let formData = objectToFormData(sub); await ajaxRequest(`/api/subscriptions/${id}/`, "PUT", formData); }); + + +// region New/Edit Modal + +$(subTableId).closest('.js-tableBody').siblings('.js-tableFilters').on("click", ".table-new-btn", async function() { + await openSubModal(-1); +}); + +$(subTableId).on("click", ".edit-modal", async function() { + let id = $(subTableId).DataTable().row($(this).closest("tr")).data().id; + await openSubModal(id) +}) + +async function openSubModal(id) { + $modal = $("#subFormModal"); + + if (parseInt(id) === -1) { + $modal.find(".form-create").show(); + $modal.find(".form-edit").hide(); + } + else { + $modal.find(".form-create").hide(); + $modal.find(".form-edit").show(); + + let data = await ajaxRequest(`/api/subscriptions/${id}/`, "GET"); + + $modal.find("[data-field]").each(function() { + let key = $(this).attr("data-field"); + let value = data[key]; + + if (typeof value === "boolean") { + $(this).prop("checked", value); + } + else { + $(this).val(value); + } + + }); + } + + $modal.modal("show"); +} diff --git a/apps/home/templates/home/includes/settingstab.html b/apps/home/templates/home/includes/settingstab.html deleted file mode 100644 index 4b004fa..0000000 --- a/apps/home/templates/home/includes/settingstab.html +++ /dev/null @@ -1,30 +0,0 @@ -
-
-
- - -
-
-
-
-
-
-
-
-
-
-
-
- -
- -
-
Is this server active?
-
-
-
-
\ No newline at end of file diff --git a/apps/home/templates/home/includes/submodal.html b/apps/home/templates/home/includes/submodal.html deleted file mode 100644 index 92e85b4..0000000 --- a/apps/home/templates/home/includes/submodal.html +++ /dev/null @@ -1,192 +0,0 @@ - - - diff --git a/apps/home/templates/home/index.html b/apps/home/templates/home/index.html index df02726..c603763 100644 --- a/apps/home/templates/home/index.html +++ b/apps/home/templates/home/index.html @@ -22,8 +22,8 @@
{% if forloop.counter0|divisibleby:2 %} -
+
{% else %}
@@ -33,6 +33,12 @@
{% endfor %} + @@ -154,10 +160,10 @@ -{% include "home/includes/submodal.html" %} -{% include "home/includes/filtermodal.html" %} -{% include "home/includes/deletemodal.html" %} -{% include "home/includes/settingsmodal.html" %} +{% include "home/modals/editSub.html" %} +{% include "home/modals/editFilter.html" %} +{% include "home/modals/editServer.html" %} +{% include "home/modals/confirm.html" %} {% endblock content %} {% block javascript %} diff --git a/apps/home/templates/home/includes/deletemodal.html b/apps/home/templates/home/modals/confirm.html similarity index 100% rename from apps/home/templates/home/includes/deletemodal.html rename to apps/home/templates/home/modals/confirm.html diff --git a/apps/home/templates/home/includes/filtermodal.html b/apps/home/templates/home/modals/editFilter.html similarity index 100% rename from apps/home/templates/home/includes/filtermodal.html rename to apps/home/templates/home/modals/editFilter.html diff --git a/apps/home/templates/home/includes/settingsmodal.html b/apps/home/templates/home/modals/editServer.html similarity index 100% rename from apps/home/templates/home/includes/settingsmodal.html rename to apps/home/templates/home/modals/editServer.html diff --git a/apps/home/templates/home/modals/editSub.html b/apps/home/templates/home/modals/editSub.html new file mode 100644 index 0000000..07f0bdc --- /dev/null +++ b/apps/home/templates/home/modals/editSub.html @@ -0,0 +1,92 @@ +