(cherry picked from commit 7cd528084e
)
version-14
@@ -3,12 +3,12 @@ | |||||
{% block breadcrumbs %}{% endblock %} | {% block breadcrumbs %}{% endblock %} | ||||
{% macro header_buttons() %} | {% macro header_buttons() %} | ||||
{% if allow_edit and doc_name and not in_edit_mode %} | |||||
{% if allow_edit and in_view_mode %} | |||||
<!-- edit button --> | <!-- edit button --> | ||||
<a href="/{{ route }}/{{ doc_name }}/edit" class="edit-button btn btn-default btn-sm">{{ _("Edit Response", null, "Button in web form") }}</a> | <a href="/{{ route }}/{{ doc_name }}/edit" class="edit-button btn btn-default btn-sm">{{ _("Edit Response", null, "Button in web form") }}</a> | ||||
{% endif %} | {% endif %} | ||||
{% if allow_print and not is_new %} | |||||
{% if allow_print and in_view_mode %} | |||||
{% set print_format_url = "/printview?doctype=" + doc_type + "&name=" + doc_name + "&format=" + print_format %} | {% set print_format_url = "/printview?doctype=" + doc_type + "&name=" + doc_name + "&format=" + print_format %} | ||||
<!-- print button --> | <!-- print button --> | ||||
<a href="{{ print_format_url }}" target="_blank" class="print-btn btn btn-default btn-sm ml-2"> | <a href="{{ print_format_url }}" target="_blank" class="print-btn btn btn-default btn-sm ml-2"> | ||||
@@ -18,8 +18,8 @@ | |||||
{% endmacro %} | {% endmacro %} | ||||
{% macro action_buttons() %} | {% macro action_buttons() %} | ||||
{% if is_new or in_edit_mode %} | |||||
<div class="left-area"> | |||||
<div class="left-area"> | |||||
{% if not in_view_mode %} | |||||
<!-- clear button --> | <!-- clear button --> | ||||
<a href="/{{ path }}" class="clear-btn btn btn-default btn-sm"> | <a href="/{{ path }}" class="clear-btn btn btn-default btn-sm"> | ||||
{% if in_edit_mode %} | {% if in_edit_mode %} | ||||
@@ -28,13 +28,15 @@ | |||||
{{ _("Clear Form", null, "Button in web form") }} | {{ _("Clear Form", null, "Button in web form") }} | ||||
{% endif %} | {% endif %} | ||||
</a> | </a> | ||||
</div> | |||||
<div class="center-area paging"></div> | |||||
<div class="right-area"> | |||||
{% endif %} | |||||
</div> | |||||
<div class="center-area paging"></div> | |||||
<div class="right-area"> | |||||
{% if not in_view_mode %} | |||||
<!-- submit button --> | <!-- submit button --> | ||||
<button type="submit" class="submit-btn btn btn-primary btn-sm ml-2">{{ button_label or _("Submit", null, "Button in web form") }}</button> | <button type="submit" class="submit-btn btn btn-primary btn-sm ml-2">{{ button_label or _("Submit", null, "Button in web form") }}</button> | ||||
</div> | |||||
{% endif %} | |||||
{% endif %} | |||||
</div> | |||||
{% endmacro %} | {% endmacro %} | ||||
{% block page_content %} | {% block page_content %} | ||||
@@ -125,6 +125,7 @@ def get_context(context): | |||||
def get_context(self, context): | def get_context(self, context): | ||||
"""Build context to render the `web_form.html` template""" | """Build context to render the `web_form.html` template""" | ||||
context.in_edit_mode = False | context.in_edit_mode = False | ||||
context.in_view_mode = False | |||||
self.set_web_form_module() | self.set_web_form_module() | ||||
if frappe.form_dict.is_list: | if frappe.form_dict.is_list: | ||||
@@ -156,11 +157,15 @@ def get_context(context): | |||||
frappe.redirect(f"/{self.route}/new") | frappe.redirect(f"/{self.route}/new") | ||||
if frappe.form_dict.is_edit and not self.allow_edit: | if frappe.form_dict.is_edit and not self.allow_edit: | ||||
context.in_view_mode = True | |||||
frappe.redirect(f"/{self.route}/{frappe.form_dict.name}") | frappe.redirect(f"/{self.route}/{frappe.form_dict.name}") | ||||
if frappe.form_dict.is_edit: | if frappe.form_dict.is_edit: | ||||
context.in_edit_mode = True | context.in_edit_mode = True | ||||
if frappe.form_dict.is_read: | |||||
context.in_view_mode = True | |||||
if ( | if ( | ||||
not frappe.form_dict.is_edit | not frappe.form_dict.is_edit | ||||
and not frappe.form_dict.is_read | and not frappe.form_dict.is_read | ||||
@@ -179,6 +184,7 @@ def get_context(context): | |||||
): | ): | ||||
name = frappe.db.get_value(self.doc_type, {"owner": frappe.session.user}, "name") | name = frappe.db.get_value(self.doc_type, {"owner": frappe.session.user}, "name") | ||||
if name: | if name: | ||||
context.in_view_mode = True | |||||
frappe.redirect(f"/{self.route}/{name}") | frappe.redirect(f"/{self.route}/{name}") | ||||
# Show new form when | # Show new form when | ||||
@@ -203,7 +209,9 @@ def get_context(context): | |||||
# load web form doc | # load web form doc | ||||
context.web_form_doc = self.as_dict(no_nulls=True) | context.web_form_doc = self.as_dict(no_nulls=True) | ||||
context.web_form_doc.update(dict_with_keys(context, ["is_list", "is_new", "in_edit_mode"])) | |||||
context.web_form_doc.update( | |||||
dict_with_keys(context, ["is_list", "is_new", "in_edit_mode", "in_view_mode"]) | |||||
) | |||||
if self.show_sidebar and self.website_sidebar: | if self.show_sidebar and self.website_sidebar: | ||||
context.sidebar_items = get_sidebar_items(self.website_sidebar) | context.sidebar_items = get_sidebar_items(self.website_sidebar) | ||||