From 1f1f2f85a95c466a2ee98b6d28120f1dbe6003c1 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Tue, 20 Jul 2021 14:25:26 +0200 Subject: [PATCH 1/4] do not disable submit buttons client side validation is sufficient --- templates/devices/detail/device_detail.html | 16 ---------------- .../devices/detail/device_ipaddress_card.html | 2 +- templates/devices/detail/device_tags_card.html | 2 +- templates/users/profile.html | 10 +--------- 4 files changed, 3 insertions(+), 27 deletions(-) diff --git a/templates/devices/detail/device_detail.html b/templates/devices/detail/device_detail.html index 48bb62ed..741894a8 100644 --- a/templates/devices/detail/device_detail.html +++ b/templates/devices/detail/device_detail.html @@ -429,22 +429,6 @@

{% trans "Installed software from backend providers" %}

{% block scriptend %} {% include "devices/detail/device_detail.js" with device_id=device.id provided_data=provided_data %} $(function() { - $("#id_ipaddresses").on("change", function(e) { - if ($(this).val()) { - $("#submitipaddress").removeClass("disabled"); - } else { - $("#submitipaddress").addClass("disabled"); - } - }); - - $("#id_tags").on("change", function(e) { - if ($(this).val()) { - $("#submittags").removeClass("disabled"); - } else { - $("#submittags").addClass("disabled"); - } - }); - $("#id_mailtemplate").change(function() { if ($(this).val() !== "") { $.ajax({ diff --git a/templates/devices/detail/device_ipaddress_card.html b/templates/devices/detail/device_ipaddress_card.html index 9107a757..12c63111 100644 --- a/templates/devices/detail/device_ipaddress_card.html +++ b/templates/devices/detail/device_ipaddress_card.html @@ -26,7 +26,7 @@ {% csrf_token %}
{{ ipaddressform.ipaddresses }}
-
diff --git a/templates/devices/detail/device_tags_card.html b/templates/devices/detail/device_tags_card.html index 073c6e62..0c355f92 100644 --- a/templates/devices/detail/device_tags_card.html +++ b/templates/devices/detail/device_tags_card.html @@ -17,7 +17,7 @@ {% csrf_token %}
{{ tagform.tags }}
-
diff --git a/templates/users/profile.html b/templates/users/profile.html index 0dc9b2b2..2d241391 100644 --- a/templates/users/profile.html +++ b/templates/users/profile.html @@ -262,7 +262,7 @@
{% trans "User doesn't own any IP-Addresses." %}
{% csrf_token %}
{{ ipaddressform.ipaddresses }}
-
@@ -311,14 +311,6 @@
{% trans "User hasn't edited anything." %}
{% endblock %} {% block scriptend %} - $("#id_ipaddresses").on("change", function(e) { - if ($(this).val()) { - $("#submitipaddress").removeClass("disabled"); - } else { - $("#submitipaddress").addClass("disabled"); - } - }); - $(function() { var $affix = $(".affix-container"); var $parent = $affix.parent(); From 81a234f06a8f34d08b4963520cec28c141217418 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Tue, 20 Jul 2021 14:27:01 +0200 Subject: [PATCH 2/4] rm unused affix code fixup 65491fbb0bdd031665e487cf9638ab4e4a286d2c --- templates/users/profile.html | 8 -------- 1 file changed, 8 deletions(-) diff --git a/templates/users/profile.html b/templates/users/profile.html index 2d241391..b8e869d1 100644 --- a/templates/users/profile.html +++ b/templates/users/profile.html @@ -312,14 +312,6 @@
{% trans "User hasn't edited anything." %}
{% block scriptend %} $(function() { - var $affix = $(".affix-container"); - var $parent = $affix.parent(); - var resize = function() { - $affix.width($parent.width()); - }; - $(window).resize(resize); - resize(); - var url = document.location.toString(); if (url.match('#')) { $('.nav-tabs a[href=#'+url.split('#')[1]+']').tab('show') ; From 65a0827accefcc5614ce8112a41aa7bb3d06ae7a Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Tue, 20 Jul 2021 14:27:20 +0200 Subject: [PATCH 3/4] mv tab code to lagerregal.js --- static/js/lagerregal.js | 6 ++++++ templates/users/profile.html | 9 --------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/static/js/lagerregal.js b/static/js/lagerregal.js index 47ad2771..5d0af33a 100644 --- a/static/js/lagerregal.js +++ b/static/js/lagerregal.js @@ -71,4 +71,10 @@ } }); }); + + $(function() { + if (document.location.hash) { + $('[data-toggle="tab"][href="' + document.location.hash + '"]').tab('show') ; + } + }); })(); diff --git a/templates/users/profile.html b/templates/users/profile.html index b8e869d1..8f509833 100644 --- a/templates/users/profile.html +++ b/templates/users/profile.html @@ -309,12 +309,3 @@
{% trans "User hasn't edited anything." %}
{% include "snippets/modals/avatarView.html" with modalname="avatarModal" avatarpath=profileuser.avatar.url %} {% endif %} {% endblock %} - -{% block scriptend %} - $(function() { - var url = document.location.toString(); - if (url.match('#')) { - $('.nav-tabs a[href=#'+url.split('#')[1]+']').tab('show') ; - } - }); -{% endblock %} From 37f04e2fa3b2b916a0f9fa7ce784d09f57e1c114 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Tue, 20 Jul 2021 14:31:18 +0200 Subject: [PATCH 4/4] rm unnecessary form_scripts - DeviceMailForm does not have a field "owner" - LendForm.owner uses the select2 widget --- devices/views.py | 2 -- templates/devices/base_form.html | 1 - templates/devicetypes/type_form.html | 2 -- 3 files changed, 5 deletions(-) diff --git a/devices/views.py b/devices/views.py index ba31c4c2..b67ba534 100644 --- a/devices/views.py +++ b/devices/views.py @@ -684,7 +684,6 @@ class DeviceLend(PermissionRequiredMixin, FormView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['actionstring'] = "Mark device as lend" - context['form_scripts'] = "$('#id_owner').select2();" if "device" in self.request.POST: deviceid = self.request.POST["device"] if deviceid != "": @@ -860,7 +859,6 @@ def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) # Add in a QuerySet of all the books - context['form_scripts'] = "$('#id_owner').select2();" context["breadcrumbs"] = [ (reverse("device-list"), _("Devices")), (reverse("device-detail", kwargs={"pk": self.device.pk}), self.device.name), diff --git a/templates/devices/base_form.html b/templates/devices/base_form.html index ffe4b7c0..3ada74a8 100644 --- a/templates/devices/base_form.html +++ b/templates/devices/base_form.html @@ -78,5 +78,4 @@

{% trans "Help" %}

}).done(response); } }); - {% autoescape off %}{{ form_scripts }}{% endautoescape %} {% endblock %} diff --git a/templates/devicetypes/type_form.html b/templates/devicetypes/type_form.html index eb629e5a..15f3d37d 100644 --- a/templates/devicetypes/type_form.html +++ b/templates/devicetypes/type_form.html @@ -63,6 +63,4 @@ }); } }); - - {% autoescape off %}{{ form_scripts }}{% endautoescape %} {% endblock %} \ No newline at end of file