Ver código fonte

fix: added in_view_mode flag

(cherry picked from commit 7cd528084e)
version-14
Shariq Ansari 2 anos atrás
committed by Mergify
pai
commit
b7bd48938a
2 arquivos alterados com 20 adições e 10 exclusões
  1. +11
    -9
      frappe/website/doctype/web_form/templates/web_form.html
  2. +9
    -1
      frappe/website/doctype/web_form/web_form.py

+ 11
- 9
frappe/website/doctype/web_form/templates/web_form.html Ver arquivo

@@ -3,12 +3,12 @@
{% block breadcrumbs %}{% endblock %}

{% macro header_buttons() %}
{% if allow_edit and doc_name and not in_edit_mode %}
{% if allow_edit and in_view_mode %}
<!-- edit button -->
<a href="/{{ route }}/{{ doc_name }}/edit" class="edit-button btn btn-default btn-sm">{{ _("Edit Response", null, "Button in web form") }}</a>
{% 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 %}
<!-- print button -->
<a href="{{ print_format_url }}" target="_blank" class="print-btn btn btn-default btn-sm ml-2">
@@ -18,8 +18,8 @@
{% endmacro %}

{% 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 -->
<a href="/{{ path }}" class="clear-btn btn btn-default btn-sm">
{% if in_edit_mode %}
@@ -28,13 +28,15 @@
{{ _("Clear Form", null, "Button in web form") }}
{% endif %}
</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 -->
<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 %}

{% block page_content %}


+ 9
- 1
frappe/website/doctype/web_form/web_form.py Ver arquivo

@@ -125,6 +125,7 @@ def get_context(context):
def get_context(self, context):
"""Build context to render the `web_form.html` template"""
context.in_edit_mode = False
context.in_view_mode = False
self.set_web_form_module()

if frappe.form_dict.is_list:
@@ -156,11 +157,15 @@ def get_context(context):
frappe.redirect(f"/{self.route}/new")

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}")

if frappe.form_dict.is_edit:
context.in_edit_mode = True

if frappe.form_dict.is_read:
context.in_view_mode = True

if (
not frappe.form_dict.is_edit
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")
if name:
context.in_view_mode = True
frappe.redirect(f"/{self.route}/{name}")

# Show new form when
@@ -203,7 +209,9 @@ def get_context(context):

# load web form doc
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:
context.sidebar_items = get_sidebar_items(self.website_sidebar)


Carregando…
Cancelar
Salvar