Skip to content

Commit

Permalink
[fix] ux for web forms that dont require login, fixes #2266 (#2322)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehta committed Nov 16, 2016
1 parent e4f279b commit cf81fe2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 21 deletions.
37 changes: 22 additions & 15 deletions frappe/templates/generators/web_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ <h1>{{ title }}</h1>
{% endblock %}

{% block breadcrumbs %}
{% if has_header %}
{% if has_header and login_required %}
{% include "templates/includes/breadcrumbs.html" %}
{% endif %}
{% endblock %}

{% block header_actions %}
{% if not read_only and has_header %}
<div style="padding-bottom: 15px;">
<a href="{{ cancel_url or pathname }}" class="btn btn-default btn-sm">
{{ _("Cancel") }}</a>
{% if login_required -%}
<a href="{{ cancel_url or pathname }}" class="btn btn-default btn-sm">
{{ _("Cancel") }}</a>
{%- endif %}
<button type="submit" class="btn btn-primary btn-sm btn-form-submit">
{{ _("Save") }}</button>
</div>
Expand All @@ -43,7 +45,7 @@ <h1>{{ title }}</h1>
<p class="text-muted">{{ introduction_text }}</p>
{% endif %}
</div>
<div class="form-message alert alert-warning hide"></div>
<div class="form-message hide"></div>
{% if _login_required %}
<div class="login-required">
<div class="text-muted">
Expand Down Expand Up @@ -340,15 +342,15 @@ <h3>{{ _("Comments") }}</h3>
frappe.ready(function() {
frappe.file_reading = false;
frappe.allow_incomplete = {{ allow_incomplete or 0 }};
frappe.success_message = "{{ success_message or "" }}";
frappe.success_link = '{{ success_message }}<p><a href="{{ success_url }}">{{ _("Continue") }}</a></p>'
frappe.success_link = '<p>{{ success_message or _("Your information has been submitted") }}</p><p><a href="{{ success_url or "/" }}" class="btn btn-sm btn-default">{{ _("Continue") }}</a></p>'
frappe.datepicker_format = "{{ frappe.date_format.replace('yyyy', 'yy') }}";
frappe.web_form_doctype = "{{ doc_type }}";
frappe.web_form_name = "{{ name }}";
frappe.is_new = {{ 1 if frappe.form_dict.new else 0 }};
frappe.is_read_only = {{ 1 if read_only else 0 }};
frappe.doc_name = "{{ frappe.form_dict.name or "" }}";
frappe.form_dirty = false;
frappe.login_required = {{ 1 if login_required else 0 }};
frappe.max_attachment_size = {{ max_attachment_size }};
moment.defaultFormat = "{{ frappe.date_format.upper() }}";
{% if row_template %}frappe.web_form_row_template = "{{ row_template }}";{% endif %}
Expand Down Expand Up @@ -627,22 +629,25 @@ <h3>{{ _("Comments") }}</h3>
callback: function(data) {
if(!data.exc) {
frappe.doc_name = data.message;
if(frappe.success_message) {
if(!frappe.login_required) {
$form.addClass("hide");
$(".comments, .introduction").addClass("hide");
$(".comments, .introduction, .page-head").addClass("hide");
scroll(0, 0);
set_message(frappe.success_message);
set_message(frappe.success_link, true);
} else {
set_message(__('Saved'));
}
if(frappe.is_new) {

if(frappe.is_new && frappe.login_required) {
// reload page (with ID)
window.location.href = window.location.pathname + "?name=" + frappe.doc_name;
}
if(for_payment && data.message) {
// redirect to payment
window.location.href = data.message;
}
} else {
set_message(__('Not Saved'));
frappe.msgprint(__('There were errors. Please report this.'));
}
},
always: function() {
Expand All @@ -666,14 +671,16 @@ <h3>{{ _("Comments") }}</h3>
+ text.join('<br>'));
}

function set_message(msg) {
function set_message(msg, permanent) {
$(".form-message")
.html(msg)
.removeClass("hide");

setTimeout(function() {
$(".form-message").addClass('hide');
}, 5000);
if(!permanent) {
setTimeout(function() {
$(".form-message").addClass('hide');
}, 5000);
}
}

// submit
Expand Down
40 changes: 34 additions & 6 deletions frappe/website/doctype/web_form_field/web_form_field.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "fieldtype",
"fieldname": "fieldname",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"label": "Fieldtype",
"label": "Fieldname",
"length": 0,
"no_copy": 0,
"options": "Attach\nCheck\nData\nDate\nDatetime\nFloat\nHTML\nInt\nLink\nSelect\nText\nTable\nSection Break\nColumn Break\nPage Break",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
Expand All @@ -41,20 +42,23 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "fieldname",
"fieldname": "fieldtype",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"label": "Fieldname",
"label": "Fieldtype",
"length": 0,
"no_copy": 0,
"options": "Attach\nCheck\nData\nDate\nDatetime\nFloat\nHTML\nInt\nLink\nSelect\nText\nTable\nSection Break\nColumn Break\nPage Break",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
Expand All @@ -72,6 +76,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"label": "Label",
"length": 0,
Expand All @@ -80,6 +85,7 @@
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
Expand All @@ -97,6 +103,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"label": "Mandatory",
"length": 0,
Expand All @@ -105,6 +112,7 @@
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
Expand All @@ -122,6 +130,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"label": "Read Only",
"length": 0,
Expand All @@ -130,6 +139,7 @@
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
Expand All @@ -147,6 +157,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"label": "Hidden",
"length": 0,
Expand All @@ -155,6 +166,7 @@
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
Expand All @@ -172,13 +184,15 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
Expand All @@ -196,6 +210,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"label": "Options",
"length": 0,
Expand All @@ -204,6 +219,7 @@
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
Expand All @@ -221,6 +237,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"label": "Max Length",
"length": 0,
Expand All @@ -230,6 +247,7 @@
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
Expand All @@ -248,6 +266,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"label": "Max Value",
"length": 0,
Expand All @@ -257,6 +276,7 @@
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
Expand All @@ -274,13 +294,15 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
Expand All @@ -298,6 +320,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"label": "Description",
"length": 0,
Expand All @@ -306,6 +329,7 @@
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
Expand All @@ -323,13 +347,15 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
Expand All @@ -347,6 +373,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"label": "Default",
"length": 0,
Expand All @@ -355,6 +382,7 @@
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
Expand All @@ -372,7 +400,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2016-09-26 07:22:54.305948",
"modified": "2016-11-15 12:36:51.897756",
"modified_by": "Administrator",
"module": "Website",
"name": "Web Form Field",
Expand Down

0 comments on commit cf81fe2

Please sign in to comment.