Forms: Add support for form hotkeys
Adds JavaScript support to monitor keypresses or mouse events of forms with the classes .form-hotkey-enter or form-hotkey-double-click, and trigger the click event of the button with the CSS class .btn-hotkey-default. Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -217,6 +217,7 @@ class MayanApp {
|
||||
this.setupAJAXPeriodicWorkers();
|
||||
this.setupAJAXSpinner();
|
||||
this.setupAutoSubmit();
|
||||
this.setupFormHotkeys();
|
||||
this.setupFullHeightResizing();
|
||||
this.setupItemsSelector();
|
||||
this.setupNavbarCollapse();
|
||||
@@ -271,6 +272,21 @@ class MayanApp {
|
||||
});
|
||||
}
|
||||
|
||||
setupFormHotkeys () {
|
||||
$('body').on('keypress', '.form-hotkey-enter', function (e) {
|
||||
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
|
||||
$(this).find('.btn-hotkey-default').click();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
$('body').on('dblclick', '.form-hotkey-double-click', function (e) {
|
||||
$(this).find('.btn-hotkey-default').click();
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
setupFullHeightResizing () {
|
||||
var self = this;
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
|
||||
<div class="well">
|
||||
{% if form.is_multipart %}
|
||||
<form action="{{ form_action }}" class="{{ form_class|default:'' }}" enctype="multipart/form-data" method="{{ submit_method|default:'post' }}" name="{{ form.prefix }}" target="{{ submit_target|default:'_self' }}">
|
||||
<form action="{{ form_action }}" class="{{ form_css_classes|default:'' }}" enctype="multipart/form-data" method="{{ submit_method|default:'post' }}" name="{{ form.prefix }}" target="{{ submit_target|default:'_self' }}">
|
||||
{% else %}
|
||||
<form action="{{ form_action }}" class="{{ form_class|default:'' }}" method="{{ submit_method|default:'post' }}" name="{{ form.prefix }}" target="{{ submit_target|default:'_self' }}">
|
||||
<form action="{{ form_action }}" class="{{ form_css_classes|default:'' }}" method="{{ submit_method|default:'post' }}" name="{{ form.prefix }}" target="{{ submit_target|default:'_self' }}">
|
||||
{% endif %}
|
||||
|
||||
{{ wizard.management_form }}
|
||||
@@ -75,7 +75,7 @@
|
||||
{% if not form.management_form or wizard.management_form or form.forms %}
|
||||
{# Is a normal form, a wizard form, or a formset with at least one form #}
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary" name="{% if form.prefix %}{{ form.prefix }}-submit{% else %}submit{% endif %}" type="submit">
|
||||
<button class="btn btn-primary btn-hotkey-default" name="{% if form.prefix %}{{ form.prefix }}-submit{% else %}submit{% endif %}" type="submit">
|
||||
{% if submit_icon_class %}
|
||||
{{ submit_icon_class.render }}
|
||||
{% elif submit_icon %}
|
||||
@@ -86,7 +86,7 @@
|
||||
{% if submit_label %}{{ submit_label }}{% else %}{% if object %}{% trans 'Save' %}{% else %}{% trans 'Submit' %}{% endif %}{% endif %}
|
||||
</button>
|
||||
{% if previous %}
|
||||
<a class="btn btn-default" onclick='history.back();'>
|
||||
<a class="btn btn-default btn-hotkey-cancel" onclick='history.back();'>
|
||||
<i class="fa fa-times"></i> {% if cancel_label %}{{ cancel_label }}{% else %}{% trans 'Cancel' %}{% endif %}
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
{% load static %}
|
||||
<div class="well">
|
||||
{% if is_multipart %}
|
||||
<form action="{{ form_action }}" class="{{ form_class|default:'' }}" enctype="multipart/form-data" id="{{ form_id|default:'' }}" method="{{ submit_method|default:'post' }}">
|
||||
<form action="{{ form_action }}" class="{{ form_css_classes|default:'' }}" enctype="multipart/form-data" id="{{ form_id|default:'' }}" method="{{ submit_method|default:'post' }}">
|
||||
{% else %}
|
||||
<form action="{{ form_action }}" class="{{ form_class|default:'' }}" id="{{ form_id|default:'' }}" method="{{ submit_method|default:'post' }}">
|
||||
<form action="{{ form_action }}" class="{{ form_css_classes|default:'' }}" id="{{ form_id|default:'' }}" method="{{ submit_method|default:'post' }}">
|
||||
{% endif %}
|
||||
|
||||
{% for form_name, form in forms.items %}
|
||||
@@ -56,10 +56,10 @@
|
||||
|
||||
<div class="form-group">
|
||||
{% if not form_disable_submit %}
|
||||
<button class="btn btn-primary" name="{% if form.prefix %}{{ form.prefix }}-submit{% else %}submit{% endif %}" type="submit"><i class="{{ submit_icon|default:'fa fa-check' }}"></i> {% if submit_label %}{{ submit_label }}{% else %}{% if object %}{% trans 'Save' %}{% else %}{% trans 'Submit' %}{% endif %}{% endif %}</button>
|
||||
<button class="btn btn-primary btn-hotkey-default" name="{% if form.prefix %}{{ form.prefix }}-submit{% else %}submit{% endif %}" type="submit"><i class="{{ submit_icon|default:'fa fa-check' }}"></i> {% if submit_label %}{{ submit_label }}{% else %}{% if object %}{% trans 'Save' %}{% else %}{% trans 'Submit' %}{% endif %}{% endif %}</button>
|
||||
{% endif %}
|
||||
{% if previous %}
|
||||
<a class="btn btn-default" onclick='history.back();'>
|
||||
<a class="btn btn-default btn-hotkey-cancel" onclick='history.back();'>
|
||||
<i class="fa fa-cross"></i> {% if cancel_label %}{{ cancel_label }}{% else %}{% trans 'Cancel' %}{% endif %}
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
@@ -356,7 +356,7 @@ class UploadInteractiveView(UploadBaseView):
|
||||
kwargs=self.request.resolver_match.kwargs
|
||||
), self.request.META['QUERY_STRING']
|
||||
),
|
||||
'form_class': 'dropzone',
|
||||
'form_css_classes': 'dropzone',
|
||||
'form_disable_submit': True,
|
||||
'form_id': 'html5upload',
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user