Преглед на файлове

fix: replaced clear button with discard button

(cherry picked from commit 9288d0cebf)
version-14
Shariq Ansari преди 2 години
committed by Mergify
родител
ревизия
bacb2cf2e5
променени са 3 файла, в които са добавени 20 реда и са изтрити 38 реда
  1. +15
    -18
      frappe/public/js/frappe/web_form/web_form.js
  2. +5
    -12
      frappe/website/doctype/web_form/templates/web_form.html
  3. +0
    -8
      frappe/website/doctype/web_form/web_form.py

+ 15
- 18
frappe/public/js/frappe/web_form/web_form.js Целия файл

@@ -28,7 +28,7 @@ export default class WebForm extends frappe.ui.FieldGroup {

if (this.is_new || this.in_edit_mode) {
this.setup_primary_action();
this.setup_clear_action();
this.setup_discard_action();
}

this.setup_previous_next_button();
@@ -56,8 +56,6 @@ export default class WebForm extends frappe.ui.FieldGroup {
setTimeout(() => {
e.stopPropagation();
frappe.form_dirty = true;
$(".web-form-footer .clear-btn").removeClass("hide");
$(".web-form-footer .right-area").prepend(this.$previous_button);
}, 200);
});
}
@@ -85,7 +83,7 @@ export default class WebForm extends frappe.ui.FieldGroup {
${__("Previous")}
</button>`);

$(".web-form-footer .right-area").prepend(this.$next_button);
$(".web-form-footer .right-area").append(this.$next_button);
$(".web-form-footer .left-area").prepend(this.$previous_button);

this.$previous_button.on("click", () => {
@@ -158,22 +156,21 @@ export default class WebForm extends frappe.ui.FieldGroup {
$(".web-form").on("submit", () => this.save());
}

setup_clear_action() {
$(".web-form-footer .clear-btn").on("click", () => this.clear_form());
setup_discard_action() {
$(".web-form-footer .discard-btn").on("click", () => this.discard_form());
}

clear_form() {
let title = __("Clear Form?");
let message = __("Are you sure you want to clear the form? It cannot be undone.");
let clear_button_text = __("Clear Form");

if (location.href.includes("/edit")) {
title = __("Reset Form?");
message = __("Are you sure you want to reset all field values?");
clear_button_text = __("Reset Form");
}

frappe.warn(title, message, () => location.reload(true), clear_button_text);
discard_form() {
frappe.warn(
__("Discard?"),
__("Are you sure you want to discard the changes?"),
() => {
let path = window.location.href;
// remove new or edit after last / from url
window.location.href = path.substring(0, path.lastIndexOf("/"));
},
__("Discard")
);
return false;
}



+ 5
- 12
frappe/website/doctype/web_form/templates/web_form.html Целия файл

@@ -25,21 +25,14 @@
{% endmacro %}

{% macro action_buttons() %}
<div class="left-area">
{% if not in_view_mode %}
<!-- clear button -->
<button class="clear-btn btn btn-link btn-sm hide">
{% if in_edit_mode %}
{{ _("Reset Form", null, "Button in web form") }}
{% else %}
{{ _("Clear Form", null, "Button in web form") }}
{% endif %}
</button>
{% endif %}
</div>
<div class="left-area"></div>
<div class="center-area paging"></div>
<div class="right-area">
{% if not in_view_mode %}
<!-- discard button -->
<button class="discard-btn btn btn-default btn-sm">
{{ _("Discard", null, "Button in web form") }}
</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>
{% endif %}


+ 0
- 8
frappe/website/doctype/web_form/web_form.py Целия файл

@@ -289,14 +289,6 @@ def get_context(context):
context.title = strip_html(
context.reference_doc.get(context.reference_doc.meta.get_title_field())
)
if context.in_edit_mode and context.parents:
context.parents.append(
{
"label": _(context.title),
"route": f"{self.route}/{context.doc_name}",
}
)
context.title = _("Editing {0}").format(context.title)
context.reference_doc.add_seen()
context.reference_doctype = context.reference_doc.doctype
context.reference_name = context.reference_doc.name


Зареждане…
Отказ
Запис