From 1fc2dbe5a3e867eb5e6c2f759409f1c94146a794 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Sat, 22 Oct 2022 11:19:14 +0200 Subject: [proxy] make popup script injection configurable throught the web UI --- .../templates/import/checkbox_tricks.html.jinja | 9 +- .../include/checkbox_tricks_style.css.jinja | 10 ++ .../proxy/web_ui/templates/index.html.jinja | 119 ++++++++++++++++++++- .../web_ui/templates/repos/show_single.html.jinja | 4 +- .../web_ui/templates/rules/show_single.html.jinja | 2 +- 5 files changed, 139 insertions(+), 5 deletions(-) (limited to 'src/hydrilla/proxy/web_ui/templates') diff --git a/src/hydrilla/proxy/web_ui/templates/import/checkbox_tricks.html.jinja b/src/hydrilla/proxy/web_ui/templates/import/checkbox_tricks.html.jinja index 999208b..4ad9ca1 100644 --- a/src/hydrilla/proxy/web_ui/templates/import/checkbox_tricks.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/import/checkbox_tricks.html.jinja @@ -23,7 +23,7 @@ code in a proprietary work, I am not going to enforce this in court. {{ name }}_chbx {%- endmacro %} -{% macro sibling_hider(button_text, name, initial_show=false) %} +{% macro sibling_hider_but(button_text, name, initial_show=false) %} {% set attrs = {'type': 'checkbox', 'class': 'chbx-tricks-show-hide'} %} {% do attrs.update({'id': hider_id(name)}) %} {% do attrs.update({'checked': none if initial_show else ''}) %} @@ -33,3 +33,10 @@ code in a proprietary work, I am not going to enforce this in court. {{ button_text }} {% endmacro %} + +{% macro sibling_hider_radio(name, radio_id, initial_show=false) %} + {% set attrs = {'type': 'radio', 'class': 'chbx-tricks-show'} %} + {% do attrs.update({'name': name, 'id': radio_id}) %} + {% do attrs.update({'checked': '' if initial_show else none}) %} + +{% endmacro %} diff --git a/src/hydrilla/proxy/web_ui/templates/include/checkbox_tricks_style.css.jinja b/src/hydrilla/proxy/web_ui/templates/include/checkbox_tricks_style.css.jinja index 6932228..a47a438 100644 --- a/src/hydrilla/proxy/web_ui/templates/include/checkbox_tricks_style.css.jinja +++ b/src/hydrilla/proxy/web_ui/templates/include/checkbox_tricks_style.css.jinja @@ -33,3 +33,13 @@ input.chbx-tricks-hide-show:checked+*, input.chbx-tricks-show-hide:not(:checked)+* { display: none !important; } + + +input.chbx-tricks-show, input.chbx-tricks-hide { + display: none !important; +} + +input.chbx-tricks-hide:checked+*, +input.chbx-tricks-show:not(:checked)+* { + display: none !important; +} diff --git a/src/hydrilla/proxy/web_ui/templates/index.html.jinja b/src/hydrilla/proxy/web_ui/templates/index.html.jinja index 010c2ed..2b49361 100644 --- a/src/hydrilla/proxy/web_ui/templates/index.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/index.html.jinja @@ -22,6 +22,14 @@ code in a proprietary work, I am not going to enforce this in court. {% block title %} {{ _('web_ui.home.title') }} {% endblock %} +{% block style %} + {{ super() }} + + {% include 'include/checkbox_tricks_style.css.jinja' %} +{% endblock %} + +{% import 'import/checkbox_tricks.html.jinja' as tricks %} + {% block main %}

{{ _('web_ui.home.heading.welcome_to_haketilo') }} @@ -182,4 +190,113 @@ code in a proprietary work, I am not going to enforce this in court. ]) }} {% endif %} -{% endblock %} + +
+ + {{ label(_('web_ui.home.popup_settings_label')) }} + + {% + macro render_popup_settings( + page_type, + initial_show = false, + popup_change_but_base_classes = ['red-button', 'blue-button'] + ) + %} + {% set radio_id = 'popup_settings_radio_' ~ page_type %} + {{ tricks.sibling_hider_radio('popup_settings', radio_id, initial_show) }} + +
+

+ {{ _('web_ui.home.configure_popup_settings_on_pages_with') }} +

+ +
+ {% + for but_page_type, but_text in [ + ('jsallowed', _('web_ui.home.popup_settings_jsallowed_button')), + ('jsblocked', _('web_ui.home.popup_settings_jsblocked_button')), + ('payloadon', _('web_ui.home.popup_settings_payloadon_button')) + ] + %} + {% set attrs, classes = {}, ['green-button'] %} + + {% if but_page_type == page_type %} + {% do classes.append('disabled-button') %} + {% else %} + {% set but_radio_id = 'popup_settings_radio_' ~ but_page_type %} + {% do attrs.update({'for': but_radio_id}) %} + {% endif %} + + {% if not loop.first %} + {% do classes.append('button-bordering-left') %} + {% endif %} + {% if not loop.last %} + {% do classes.append('button-bordering-right') %} + {% endif %} + + {% do attrs.update({'class': classes|join(' ')}) %} + + + + {% if not loop.last %} +
+ {% endif %} + {% endfor %} +
+ + {% set popup_no_but_classes = [popup_change_but_base_classes[0]] %} + {% set popup_yes_but_classes = [popup_change_but_base_classes[1]] %} + + {% set settings_prop = 'default_popup_' ~ page_type %} + {% set is_on = (settings|attr(settings_prop)).keyboard_trigger %} + + {% if is_on %} + {% do popup_yes_but_classes.append('disabled-button') %} + {% else %} + {% do popup_no_but_classes.append('disabled-button') %} + {% endif %} + +

+ {{ caller(is_on) }} +

+ + {{ + button_row([ + (popup_no_but_classes, + _('web_ui.home.popup_no_button'), + {'action': 'popup_no_when_' ~ page_type}), + (popup_yes_but_classes, + _('web_ui.home.popup_yes_button'), + {'action': 'popup_yes_when_' ~ page_type}) + ]) + }} +
+ {% endmacro %} + + {% set but_classes = ['green-button', 'green-button'] %} + {% call(popup_is_on) render_popup_settings('jsallowed', true, but_classes) %} + {% if popup_is_on %} + {{ _('web_ui.home.jsallowed_popup_yes') }} + {% else %} + {{ _('web_ui.home.jsallowed_popup_no') }} + {% endif %} + {% endcall %} + + {% call(popup_is_on) render_popup_settings('jsblocked') %} + {% if popup_is_on %} + {{ _('web_ui.home.jsblocked_popup_yes') }} + {% else %} + {{ _('web_ui.home.jsblocked_popup_no') }} + {% endif %} + {% endcall %} + + {% call(popup_is_on) render_popup_settings('payloadon') %} + {% if popup_is_on %} + {{ _('web_ui.home.payloadon_popup_yes') }} + {% else %} + {{ _('web_ui.home.payloadon_popup_no') }} + {% endif %} + {% endcall %} +{% endblock main %} diff --git a/src/hydrilla/proxy/web_ui/templates/repos/show_single.html.jinja b/src/hydrilla/proxy/web_ui/templates/repos/show_single.html.jinja index c4b7a9a..8b070d9 100644 --- a/src/hydrilla/proxy/web_ui/templates/repos/show_single.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/repos/show_single.html.jinja @@ -59,7 +59,7 @@ code in a proprietary work, I am not going to enforce this in court. {% set button_text = _('web_ui.repos.single.update_name_button') %} {% set initial_show = repo_name_invalid is defined %} {% set initial_show = initial_show or repo_name_taken is defined %} - {{ tricks.sibling_hider(button_text, 'edit_name', initial_show) }} + {{ tricks.sibling_hider_but(button_text, 'edit_name', initial_show) }}
@@ -107,7 +107,7 @@ code in a proprietary work, I am not going to enforce this in court. {% set button_text = _('web_ui.repos.single.update_url_button') %} {% set initial_show = repo_url_invalid is defined %} - {{ tricks.sibling_hider(button_text, 'edit_url', initial_show) }} + {{ tricks.sibling_hider_but(button_text, 'edit_url', initial_show) }} diff --git a/src/hydrilla/proxy/web_ui/templates/rules/show_single.html.jinja b/src/hydrilla/proxy/web_ui/templates/rules/show_single.html.jinja index 95e8009..7d29a0d 100644 --- a/src/hydrilla/proxy/web_ui/templates/rules/show_single.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/rules/show_single.html.jinja @@ -47,7 +47,7 @@ code in a proprietary work, I am not going to enforce this in court. {% set button_text = _('web_ui.rules.single.update_pattern_button') %} {% set initial_show = rule_pattern_invalid is defined %} - {{ tricks.sibling_hider(button_text, 'edit_pattern', initial_show) }} + {{ tricks.sibling_hider_but(button_text, 'edit_pattern', initial_show) }} -- cgit v1.2.3