From a4b27115ac3addb9354fd66aa471839fa7a5ec8c Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 25 Jun 2019 20:32:49 -0500 Subject: [PATCH] Refactor all Buefy form submit buttons, per Chrome behavior ugh, what a pain. and turns out i'd previously ran into this same issue for jQuery, per commit e945ebe3257bc43065a1d17f82c0683f8d8fd460 --- tailbone/forms/core.py | 5 +- .../static/js/tailbone.buefy.oncebutton.js | 28 +- tailbone/templates/appsettings.mako | 270 ++++++++++-------- tailbone/templates/batch/view.mako | 53 ++-- .../templates/datasync/changes/index.mako | 52 +++- tailbone/templates/form.mako | 32 +-- tailbone/templates/forms/deform_buefy.mako | 29 +- tailbone/templates/master/clone.mako | 30 +- tailbone/templates/master/delete.mako | 30 +- tailbone/templates/master/edit.mako | 2 + tailbone/templates/master/index.mako | 35 ++- tailbone/templates/master/merge.mako | 144 +++++----- tailbone/templates/page.mako | 4 + .../templates/principal/find_by_perm.mako | 24 +- tailbone/templates/settings/email/view.mako | 73 ++--- tailbone/templates/tempmon/probes/graph.mako | 1 + tailbone/templates/upgrades/view.mako | 24 +- 17 files changed, 517 insertions(+), 319 deletions(-) diff --git a/tailbone/forms/core.py b/tailbone/forms/core.py index 1aea1d7d..8c77dfa4 100644 --- a/tailbone/forms/core.py +++ b/tailbone/forms/core.py @@ -758,7 +758,10 @@ class Form(object): context.setdefault('form_kwargs', {}) # TODO: deprecate / remove the latter option here if self.auto_disable_save or self.auto_disable: - context['form_kwargs']['class_'] = 'autodisable' + if self.use_buefy: + context['form_kwargs']['@submit'] = 'submit{}'.format(self.component_studly) + else: + context['form_kwargs']['class_'] = 'autodisable' if self.focus_spec: context['form_kwargs']['data-focus'] = self.focus_spec context['request'] = self.request diff --git a/tailbone/static/js/tailbone.buefy.oncebutton.js b/tailbone/static/js/tailbone.buefy.oncebutton.js index c8e7e1e1..e00d677c 100644 --- a/tailbone/static/js/tailbone.buefy.oncebutton.js +++ b/tailbone/static/js/tailbone.buefy.oncebutton.js @@ -1,21 +1,19 @@ const OnceButton = { - template: [ - '', - '{{ buttonText }}', - '' - ].join(' '), + template: ` + + {{ buttonText }} + + `, props: { type: String, diff --git a/tailbone/templates/appsettings.mako b/tailbone/templates/appsettings.mako index 68a79bc7..983f679b 100644 --- a/tailbone/templates/appsettings.mako +++ b/tailbone/templates/appsettings.mako @@ -33,6 +33,153 @@ % endif + +% if use_buefy: + + +
+ +
+ + + +% else: +## legacy / not buefy
${h.form(form.action_url, id=dform.formid, method='post', class_='autodisable')} ${h.csrf_token(request)} @@ -50,13 +197,6 @@
% endif - % if use_buefy: -
- -
- - % else: - ## not buefy
@@ -105,122 +245,6 @@ ${h.link_to("Cancel", form.cancel_url, class_='cancel button{}'.format(' autodisable' if form.auto_disable_cancel else ''))}
- ## end of legacy (not buefy) - % endif - ${h.end_form()}
- -% if use_buefy: - - - % endif diff --git a/tailbone/templates/batch/view.mako b/tailbone/templates/batch/view.mako index 63ac6bd4..aa87f408 100644 --- a/tailbone/templates/batch/view.mako +++ b/tailbone/templates/batch/view.mako @@ -75,16 +75,27 @@ <%def name="execute_submit_button()"> - - + + % if master.has_execution_options(batch): + ${execute_title} + % else: + {{ executeFormButtonText }} + % endif + <%def name="object_helpers()"> @@ -131,8 +142,7 @@

Batch has not yet been executed.

% if use_buefy: % if master.has_execution_options(batch): - ## TODO: this doesn't work yet - ${self.execute_submit_button()} +

TODO: must implement execution with options

% else: % endif @@ -180,19 +190,26 @@ <%def name="render_this_page_buefy()"> % if use_buefy and master.handler.executable(batch) and request.has_perm('{}.execute'.format(permission_prefix)): ## TODO: stop using |n filter - ${execute_form.render_deform(buttons=capture(execute_submit_button))|n} + ${execute_form.render_deform(buttons=capture(execute_submit_button), form_kwargs={'@submit': 'submitExecuteForm'})|n} % endif ${parent.render_this_page_buefy()} -<%def name="declare_page_vars()"> - ${parent.declare_page_vars()} +<%def name="modify_this_page()"> + ${parent.modify_this_page()} % if not batch.executed and request.has_perm('{}.execute'.format(permission_prefix)): diff --git a/tailbone/templates/datasync/changes/index.mako b/tailbone/templates/datasync/changes/index.mako index 673bd25c..4a3b95a8 100644 --- a/tailbone/templates/datasync/changes/index.mako +++ b/tailbone/templates/datasync/changes/index.mako @@ -5,12 +5,17 @@ ${parent.grid_tools()} % if request.has_perm('datasync.restart'): - ${h.form(url('datasync.restart'), name='restart-datasync', class_='autodisable control')} + % if use_buefy: + ${h.form(url('datasync.restart'), name='restart-datasync', class_='control', **{'@submit': 'submitRestartDatasyncForm'})} + % else: + ${h.form(url('datasync.restart'), name='restart-datasync', class_='autodisable')} + % endif ${h.csrf_token(request)} % if use_buefy: - - + + {{ restartDatasyncFormButtonText }} + % else: ${h.submit('submit', "Restart DataSync", data_working_label="Restarting DataSync", class_='button')} % endif @@ -18,12 +23,49 @@ % endif % if allow_filemon_restart and request.has_perm('filemon.restart'): - ${h.form(url('filemon.restart'), name='restart-filemon', class_='autodisable control')} + % if use_buefy: + ${h.form(url('filemon.restart'), name='restart-filemon', class_='control', **{'@submit': 'submitRestartFilemonForm'})} + % else: + ${h.form(url('filemon.restart'), name='restart-filemon', class_='autodisable')} + % endif ${h.csrf_token(request)} + % if use_buefy: + + {{ restartFilemonFormButtonText }} + + % else: ${h.submit('submit', "Restart FileMon", data_working_label="Restarting FileMon", class_='button')} + % endif ${h.end_form()} % endif +<%def name="modify_tailbone_grid()"> + ${parent.modify_tailbone_grid()} + + + + ${parent.body()} diff --git a/tailbone/templates/form.mako b/tailbone/templates/form.mako index 0c541375..0a2dbd0f 100644 --- a/tailbone/templates/form.mako +++ b/tailbone/templates/form.mako @@ -15,15 +15,21 @@ +<%def name="page_content()"> +
+ % if use_buefy: + ${self.render_buefy_form()} + % else: + ${self.render_form()} + % endif +
+ + <%def name="render_this_page()">
-
- % if use_buefy: - ${self.render_buefy_form()} - % else: - ${self.render_form()} - % endif +
+ ${self.page_content()}
@@ -46,20 +52,6 @@ ${parent.render_this_page_buefy()} -<%def name="declare_page_vars()"> - ${parent.declare_page_vars()} - % if form is not Undefined: - - % endif - - <%def name="finalize_page_components()"> ${parent.finalize_page_components()} % if form is not Undefined: diff --git a/tailbone/templates/forms/deform_buefy.mako b/tailbone/templates/forms/deform_buefy.mako index b5f17b84..e134f272 100644 --- a/tailbone/templates/forms/deform_buefy.mako +++ b/tailbone/templates/forms/deform_buefy.mako @@ -44,10 +44,11 @@
## TODO: deprecate / remove the latter option here % if form.auto_disable_save or form.auto_disable: - - + + {{ ${form.component_studly}ButtonText }} + % else: @@ -83,6 +84,20 @@ diff --git a/tailbone/templates/master/clone.mako b/tailbone/templates/master/clone.mako index 48b5d229..0154e0a7 100644 --- a/tailbone/templates/master/clone.mako +++ b/tailbone/templates/master/clone.mako @@ -27,7 +27,11 @@ % endif
- ${h.form(request.current_route_url(), class_=None if use_buefy else 'autodisable')} + % if use_buefy: + ${h.form(request.current_route_url(), **{'@submit': 'submitForm'})} + % else: + ${h.form(request.current_route_url(), class_='autodisable')} + % endif ${h.csrf_token(request)} ${h.hidden('clone', value='clone')}
@@ -35,10 +39,11 @@ - - + + {{ submitButtonText }} + % else: ${h.link_to("Whoops, nevermind...", form.cancel_url, class_='button autodisable')} ${h.submit('submit', "Yes, please clone away")} @@ -47,5 +52,20 @@ ${h.end_form()} +<%def name="modify_this_page()"> + ${parent.modify_this_page()} + + + ${parent.body()} diff --git a/tailbone/templates/master/delete.mako b/tailbone/templates/master/delete.mako index 66ada13f..bba50f57 100644 --- a/tailbone/templates/master/delete.mako +++ b/tailbone/templates/master/delete.mako @@ -44,17 +44,22 @@ % endif
- ${h.form(request.current_route_url(), class_=None if use_buefy else 'autodisable')} + % if use_buefy: + ${h.form(request.current_route_url(), **{'@submit': 'submitForm'})} + % else: + ${h.form(request.current_route_url(), class_='autodisable')} + % endif ${h.csrf_token(request)}
% if use_buefy: - - + + {{ formButtonText }} + % else: Whoops, nevermind... ${h.submit('submit', "Yes, please DELETE this data forever!", class_='button is-primary')} @@ -63,5 +68,20 @@ ${h.end_form()} +<%def name="modify_this_page()"> + ${parent.modify_this_page()} + + + ${parent.body()} diff --git a/tailbone/templates/master/edit.mako b/tailbone/templates/master/edit.mako index 385e1fb3..febd0bcd 100644 --- a/tailbone/templates/master/edit.mako +++ b/tailbone/templates/master/edit.mako @@ -5,6 +5,7 @@ <%def name="extra_javascript()"> ${parent.extra_javascript()} + % if not use_buefy: + % endif <%def name="context_menu_items()"> diff --git a/tailbone/templates/master/index.mako b/tailbone/templates/master/index.mako index 94d93152..a857249d 100644 --- a/tailbone/templates/master/index.mako +++ b/tailbone/templates/master/index.mako @@ -14,9 +14,7 @@ <%def name="extra_javascript()"> ${parent.extra_javascript()} - % if use_buefy: - ${h.javascript_link(request.static_url('tailbone:static/js/tailbone.buefy.grid.js') + '?ver={}'.format(tailbone.__version__))} - % else: + % if not use_buefy: <%def name="make_tailbone_grid_app()"> diff --git a/tailbone/templates/master/merge.mako b/tailbone/templates/master/merge.mako index 470e28e2..086b4d1a 100644 --- a/tailbone/templates/master/merge.mako +++ b/tailbone/templates/master/merge.mako @@ -1,5 +1,5 @@ ## -*- coding: utf-8 -*- -<%inherit file="/base.mako" /> +<%inherit file="/page.mako" /> <%def name="title()">Merge 2 ${model_title_plural} @@ -91,62 +91,7 @@
  • ${h.link_to("Back to {}".format(model_title_plural), url(route_prefix))}
  • - -% if use_buefy: - - - - - -## end of buefy -% endif - - -
      - ${self.context_menu_items()} -
    +<%def name="page_content()">

    You are about to merge two ${model_title} records, @@ -193,16 +138,7 @@ % if use_buefy: - -

    - -
    - - + % else: ## no buefy; do legacy stuff @@ -216,3 +152,77 @@ ${h.csrf_token(request)}
    ${h.end_form()} % endif + + + +% if use_buefy: + + + +% endif + +${parent.body()} diff --git a/tailbone/templates/page.mako b/tailbone/templates/page.mako index 3d1407ca..0510b699 100644 --- a/tailbone/templates/page.mako +++ b/tailbone/templates/page.mako @@ -43,6 +43,8 @@ methods: {} } + let ThisPageData = {} + @@ -56,6 +58,8 @@ ${self.finalize_page_components()} -
    - -
    - - - -% else: - ## not buefy; do traditional thing - - ${h.form(url('email.preview'), name='send-email-preview', class_='autodisable')} - ${h.csrf_token(request)} - ${h.hidden('email_key', value=instance['key'])} - ${h.link_to("Preview HTML", '{}?key={}&type=html'.format(url('email.preview'), instance['key']), id='preview-html', class_='button', target='_blank')} - ${h.link_to("Preview TXT", '{}?key={}&type=txt'.format(url('email.preview'), instance['key']), id='preview-txt', class_='button', target='_blank')} - or - ${h.text('recipient', value=request.user.email_address or '')} - ${h.submit('send_{}'.format(instance['key']), value="Send Preview Email")} - ${h.end_form()} - % endif + +${parent.body()} diff --git a/tailbone/templates/tempmon/probes/graph.mako b/tailbone/templates/tempmon/probes/graph.mako index 68b5946f..21e44777 100644 --- a/tailbone/templates/tempmon/probes/graph.mako +++ b/tailbone/templates/tempmon/probes/graph.mako @@ -147,6 +147,7 @@ <%def name="modify_this_page()"> + ${parent.modify_this_page()}