From 8f321139fd1f0bb9b64b51aa0c71809e2b786308 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Tue, 28 Nov 2023 14:01:15 +0100 Subject: [PATCH] UI - 'Request body' section disappears after switching from 'Playwright' to 'System settings default' and back on 'Request' tab - Fixed #1449 --- .../static/js/global-settings.js | 15 ------- changedetectionio/static/js/vis.js | 15 +++++++ changedetectionio/static/js/watch-settings.js | 40 +++++-------------- changedetectionio/templates/edit.html | 20 +++++----- changedetectionio/templates/settings.html | 4 +- 5 files changed, 37 insertions(+), 57 deletions(-) create mode 100644 changedetectionio/static/js/vis.js diff --git a/changedetectionio/static/js/global-settings.js b/changedetectionio/static/js/global-settings.js index 16ba33e1..f6930547 100644 --- a/changedetectionio/static/js/global-settings.js +++ b/changedetectionio/static/js/global-settings.js @@ -1,19 +1,4 @@ $(document).ready(function () { - function toggle() { - if ($('input[name="application-fetch_backend"]:checked').val() != 'html_requests') { - $('#requests-override-options').hide(); - $('#webdriver-override-options').show(); - } else { - $('#requests-override-options').show(); - $('#webdriver-override-options').hide(); - } - } - - $('input[name="application-fetch_backend"]').click(function (e) { - toggle(); - }); - toggle(); - $("#api-key").hover( function () { $("#api-key-copy").html('copy').fadeIn(); diff --git a/changedetectionio/static/js/vis.js b/changedetectionio/static/js/vis.js new file mode 100644 index 00000000..b3c036ff --- /dev/null +++ b/changedetectionio/static/js/vis.js @@ -0,0 +1,15 @@ +$(document).ready(function () { + + // Lazy Hide/Show elements mechanism + $('[data-visible-for]').hide(); + $(':radio').on('keyup keypress blur change click', function (e) { + $('[data-visible-for]').hide(); + var n = $(this).attr('name') + "=" + $(this).val(); + if (n === 'fetch_backend=system') { + n = "fetch_backend=" + default_system_fetch_backend; + } + $(`[data-visible-for~="${n}"]`).show(); + + }); + $(':radio:checked').change(); +}); \ No newline at end of file diff --git a/changedetectionio/static/js/watch-settings.js b/changedetectionio/static/js/watch-settings.js index 0b419959..25b3f2d2 100644 --- a/changedetectionio/static/js/watch-settings.js +++ b/changedetectionio/static/js/watch-settings.js @@ -1,39 +1,17 @@ $(document).ready(function () { - function toggle() { - if ($('input[name="fetch_backend"]:checked').val() == 'html_webdriver') { - if (playwright_enabled) { - // playwright supports headers, so hide everything else - // See #664 - $('#requests-override-options #request-method').hide(); - $('#requests-override-options #request-body').hide(); - // @todo connect this one up - $('#ignore-status-codes-option').hide(); - } else { - // selenium/webdriver doesnt support anything afaik, hide it all - $('#requests-override-options').hide(); - } - - $('#webdriver-override-options').show(); - - } else if ($('input[name="fetch_backend"]:checked').val() == 'system') { - $('#requests-override-options #request-method').hide(); - $('#requests-override-options #request-body').hide(); - $('#ignore-status-codes-option').hide(); - $('#requests-override-options').hide(); - $('#webdriver-override-options').hide(); - } else { - - $('#requests-override-options').show(); - $('#requests-override-options *:hidden').show(); - $('#webdriver-override-options').hide(); + // Lazy Hide/Show elements mechanism + $('[data-visible-for]').hide(); + $(':radio').on('keyup keypress blur change click', function (e){ + $('[data-visible-for]').hide(); + var n = $(this).attr('name') + "=" + $(this).val(); + if (n === 'fetch_backend=system') { + n = "fetch_backend=" + default_system_fetch_backend; } - } + $(`[data-visible-for~="${n}"]`).show(); - $('input[name="fetch_backend"]').click(function (e) { - toggle(); }); - toggle(); + $(':radio:checked').change(); $('#notification-setting-reset-to-default').click(function (e) { $('#notification_title').val(''); diff --git a/changedetectionio/templates/edit.html b/changedetectionio/templates/edit.html index e6882280..8a0d3172 100644 --- a/changedetectionio/templates/edit.html +++ b/changedetectionio/templates/edit.html @@ -3,6 +3,7 @@ {% from '_helpers.jinja' import render_field, render_checkbox_field, render_button %} {% from '_common_fields.jinja' import render_common_settings_form %} + @@ -124,10 +125,8 @@ {% endif %} -
- {{ render_checkbox_field(form.ignore_status_codes) }} -
-
+ +
{{ render_field(form.webdriver_delay) }}
@@ -148,14 +147,14 @@
{% if not playwright_enabled %} -
+
Request override is currently only used by the Basic fast Plaintext/HTTP Client method.
{% endif %} -
+
{{ render_field(form.method) }}
-
+
{{ render_field(form.headers, rows=5, placeholder="Example Cookie: foobar User-Agent: wonderbra 1.0") }} @@ -171,7 +170,7 @@ User-Agent: wonderbra 1.0") }}
-
+
{{ render_field(form.body, rows=5, placeholder="Example { \"name\":\"John\", @@ -180,6 +179,9 @@ User-Agent: wonderbra 1.0") }} }") }}
+
+ {{ render_checkbox_field(form.ignore_status_codes) }} +
{% if playwright_enabled %}
diff --git a/changedetectionio/templates/settings.html b/changedetectionio/templates/settings.html index 461208f0..44dec3c7 100644 --- a/changedetectionio/templates/settings.html +++ b/changedetectionio/templates/settings.html @@ -11,7 +11,7 @@ - +
-
+
If you're having trouble waiting for the page to be fully rendered (text missing etc), try increasing the 'wait' time here.