Skip to content

Commit afd6e2a

Browse files
committed
chore: confirmation modal
1 parent 31a5c61 commit afd6e2a

File tree

12 files changed

+140
-16
lines changed

12 files changed

+140
-16
lines changed

ckanext/theming/themes/bare/templates/admin/config.html

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,14 @@
3939
{%- endcall %}
4040

4141

42-
{% set close_button = ui.button(_("Close"), attrs={"onclick": "ckan.sandbox().ui.getModal('{modal_id}').close()".format(modal_id=modal_id)}) %}
4342
{% set form_id = ui.util.id() %}
44-
{% set confirm_button = ui.button(_("Confirm"), attrs={"onclick": "window['{form_id}'].submit()".format(form_id=form_id)}) %}
43+
{%- call ui.form_block("POST", action=h.url_for('admin.reset_config'), attrs={"id": form_id}) -%}
44+
{%- endcall %}
4545

46-
{%- call ui.util.call(ui.modal, title=_("Confirm"), id=modal_id, footer=close_button + confirm_button) -%}
46+
{%- call ui.util.call(ui.confirm_modal, id=modal_id, form_id=form_id) -%}
4747
{{ _('Are you sure you want to reset the config?') }}
48-
49-
{%- call ui.form_block("POST", action=h.url_for('admin.reset_config'), attrs={"id": form_id}) -%}
50-
51-
{%- endcall %}
5248
{%- endcall %}
49+
5350
{%- endblock %}
5451

5552
{%- block secondary_content -%}

ckanext/theming/themes/bare/templates/admin/trash.html

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@
88

99
{%- block primary_content_inner -%}
1010
{% set modal_id = ui.util.id() %}
11-
{{ ui.modal_handler(_('Purge all'), id=modal_id) }}
12-
13-
1411
{% set form_id = ui.util.id() %}
15-
{% set close_button = ui.button(_("Close"), attrs={"onclick": "ckan.sandbox().ui.getModal('{modal_id}').close()".format(modal_id=modal_id)}) %}
16-
{% set confirm_button = ui.button(_("Confirm"), attrs={"onclick": "window['{form_id}'].submit()".format(form_id=form_id)}) %}
12+
{%- call ui.form_block("POST", attrs={"id": form_id}) -%}
13+
<input type="hidden" name="action" value="all">
14+
{%- endcall %}
1715

18-
{%- call ui.util.call(ui.modal, title=_("Confirm"), id=modal_id, footer=close_button + confirm_button) -%}
16+
{{ ui.modal_handler(_('Purge all'), id=modal_id) }}
17+
18+
{%- call ui.util.call(ui.confirm_modal, id=modal_id, form_id=form_id) -%}
1919
{{ _('Are you sure you want to purge everything?') }}
20-
{%- call ui.form_block("POST", attrs={"id": form_id}) -%}
21-
<input type="hidden" name="action" value="all">
22-
{%- endcall %}
2320
{%- endcall %}
2421

2522
{% for ent_type, entities in data.items() %}

ckanext/theming/themes/bare/templates/macros/ui.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
{% set toast = feedback.toast %}
5757
{% set modal = feedback.modal %}
5858
{% set modal_handler = feedback.modal_handler %}
59+
{% set modal_close = feedback.modal_close %}
60+
{% set confirm_modal = feedback.confirm_modal %}
5961
{% set tooltip = feedback.tooltip %}
6062
{% set popover_content = feedback.popover_content %}
6163
{% set popover_handler = feedback.popover_handler %}

ckanext/theming/themes/bare/templates/macros/ui/feedback.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@
5050
{{ ui.button(content, attrs={"onclick": "ckan.sandbox().ui.getModal('{id}').show()".format(id=id)}) }}
5151
{%- endmacro %}
5252

53+
{%- macro modal_close(content, id) -%}
54+
{{ ui.button(content, attrs={"onclick": "ckan.sandbox().ui.getModal('{id}').close()".format(id=id)}) }}
55+
{%- endmacro %}
56+
57+
{%- macro confirm_modal(content, title, id, form_id, cancel_label, confirm_label) -%}
58+
{%- if not form_id -%}
59+
{% set form_id = ui.util.id() %}
60+
{%- call ui.form_block("POST", attrs={"id": form_id}) -%}
61+
{%- endcall %}
62+
{%- endif %}
63+
64+
{%- set close_button = ui.modal_close(cancel_label or _("Close"), id=id) %}
65+
{%- set confirm_button = ui.button(confirm_label or _("Confirm"), attrs={"onclick": "window['{form_id}'].submit()".format(form_id=form_id)}) %}
66+
67+
{%- call ui.util.call(ui.modal, title=title or _("Confirm"), id=id, footer=close_button ~ confirm_button, **kwargs) -%}
68+
{{ content }}
69+
{%- endcall %}
70+
71+
{%- endmacro %}
72+
5373
{%- macro tooltip(content, tooltip) -%}
5474
<span {{ ui.util.attrs(kwargs) }} title="{{ tooltip }}">{{ content }}</span>
5575
{%- endmacro %}

ckanext/theming/themes/bs5/templates/macros/ui.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@
9999
{% set alert = feedback.alert %}
100100
{% set toast = feedback.toast %}
101101
{% set modal = feedback.modal %}
102+
{% set modal_handler = feedback.modal_handler %}
103+
{% set modal_close = feedback.modal_close %}
104+
{% set confirm_modal = feedback.confirm_modal %}
102105
{% set tooltip = feedback.tooltip %}
103106
{% set popover_content = feedback.popover_content %}
104107
{% set popover_handler = feedback.popover_handler %}

ckanext/theming/themes/bs5/templates/macros/ui/feedback.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@ <h5 class="modal-title" id="{{ id }}Label">{{ title }}</h5>
6060
</div>
6161
{%- endmacro %}
6262

63+
{%- macro modal_handler(content, id) -%}
64+
{{ ui.button(content, attrs={"onclick": "ckan.sandbox().ui.getModal('{id}').show()".format(id=id)}) }}
65+
{%- endmacro %}
66+
67+
{%- macro modal_close(content, id) -%}
68+
{{ ui.button(content, attrs={"onclick": "ckan.sandbox().ui.getModal('{id}').close()".format(id=id)}) }}
69+
{%- endmacro %}
70+
71+
{%- macro confirm_modal(content, title, id, form_id, cancel_label, confirm_label) -%}
72+
{%- if not form_id -%}
73+
{% set form_id = ui.util.id() %}
74+
{%- call ui.form_block("POST", attrs={"id": form_id}) -%}
75+
{%- endcall %}
76+
{%- endif %}
77+
78+
{%- set close_button = ui.modal_close(cancel_label or _("Close"), id=id) %}
79+
{%- set confirm_button = ui.button(confirm_label or _("Confirm"), attrs={"onclick": "window['{form_id}'].submit()".format(form_id=form_id)}) %}
80+
81+
{%- call ui.util.call(ui.modal, title=title or _("Confirm"), id=id, footer=close_button ~ confirm_button, **kwargs) -%}
82+
{{ content }}
83+
{%- endcall %}
84+
85+
{%- endmacro %}
86+
6387
{%- macro tooltip(content, tooltip) -%}
6488
<span class="d-inline-block" data-bs-toggle="tooltip" data-bs-title="{{ tooltip }}" {{ ui.util.attrs(kwargs) }}>
6589
{{ content }}

ckanext/theming/themes/bulma/templates/macros/ui.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@
9999
{% set alert = feedback.alert %}
100100
{% set toast = feedback.toast %}
101101
{% set modal = feedback.modal %}
102+
{% set modal_handler = feedback.modal_handler %}
103+
{% set modal_close = feedback.modal_close %}
104+
{% set confirm_modal = feedback.confirm_modal %}
102105
{% set tooltip = feedback.tooltip %}
103106
{% set popover_content = feedback.popover_content %}
104107
{% set popover_handler = feedback.popover_handler %}

ckanext/theming/themes/bulma/templates/macros/ui/feedback.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@
5555
</div>
5656
{%- endmacro %}
5757

58+
{%- macro modal_handler(content, id) -%}
59+
{{ ui.button(content, attrs={"onclick": "ckan.sandbox().ui.getModal('{id}').show()".format(id=id)}) }}
60+
{%- endmacro %}
61+
62+
{%- macro modal_close(content, id) -%}
63+
{{ ui.button(content, attrs={"onclick": "ckan.sandbox().ui.getModal('{id}').close()".format(id=id)}) }}
64+
{%- endmacro %}
65+
66+
{%- macro confirm_modal(content, title, id, form_id, cancel_label, confirm_label) -%}
67+
{%- if not form_id -%}
68+
{% set form_id = ui.util.id() %}
69+
{%- call ui.form_block("POST", attrs={"id": form_id}) -%}
70+
{%- endcall %}
71+
{%- endif %}
72+
73+
{%- set close_button = ui.modal_close(cancel_label or _("Close"), id=id) %}
74+
{%- set confirm_button = ui.button(confirm_label or _("Confirm"), attrs={"onclick": "window['{form_id}'].submit()".format(form_id=form_id)}) %}
75+
76+
{%- call ui.util.call(ui.modal, title=title or _("Confirm"), id=id, footer=close_button ~ confirm_button, **kwargs) -%}
77+
{{ content }}
78+
{%- endcall %}
79+
80+
{%- endmacro %}
81+
5882
{%- macro tooltip(content, tooltip) -%}
5983
{%- do kwargs -%}
6084
<span class="has-tooltip" data-tooltip="{{ tooltip }}">{{ content }}</span>

ckanext/theming/themes/pico/templates/macros/ui.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@
9999
{% set alert = feedback.alert %}
100100
{% set toast = feedback.toast %}
101101
{% set modal = feedback.modal %}
102+
{% set modal_handler = feedback.modal_handler %}
103+
{% set modal_close = feedback.modal_close %}
104+
{% set confirm_modal = feedback.confirm_modal %}
102105
{% set tooltip = feedback.tooltip %}
103106
{% set popover_content = feedback.popover_content %}
104107
{% set popover_handler = feedback.popover_handler %}

ckanext/theming/themes/pico/templates/macros/ui/feedback.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,30 @@ <h3>{{ title }}</h3>
5252
</dialog>
5353
{%- endmacro %}
5454

55+
{%- macro modal_handler(content, id) -%}
56+
{{ ui.button(content, attrs={"onclick": "ckan.sandbox().ui.getModal('{id}').show()".format(id=id)}) }}
57+
{%- endmacro %}
58+
59+
{%- macro modal_close(content, id) -%}
60+
{{ ui.button(content, attrs={"onclick": "ckan.sandbox().ui.getModal('{id}').close()".format(id=id)}) }}
61+
{%- endmacro %}
62+
63+
{%- macro confirm_modal(content, title, id, form_id, cancel_label, confirm_label) -%}
64+
{%- if not form_id -%}
65+
{% set form_id = ui.util.id() %}
66+
{%- call ui.form_block("POST", attrs={"id": form_id}) -%}
67+
{%- endcall %}
68+
{%- endif %}
69+
70+
{%- set close_button = ui.modal_close(cancel_label or _("Close"), id=id) %}
71+
{%- set confirm_button = ui.button(confirm_label or _("Confirm"), attrs={"onclick": "window['{form_id}'].submit()".format(form_id=form_id)}) %}
72+
73+
{%- call ui.util.call(ui.modal, title=title or _("Confirm"), id=id, footer=close_button ~ confirm_button, **kwargs) -%}
74+
{{ content }}
75+
{%- endcall %}
76+
77+
{%- endmacro %}
78+
5579
{%- macro tooltip(content, tooltip) -%}
5680
{%- do kwargs -%}
5781
<span class="tooltip" data-tooltip="{{ tooltip }}">{{ content }}</span>

0 commit comments

Comments
 (0)