Hide unsaved changes warning after undoing them

This way showing the warning is consistent with warning users when
they're leaving the page.
This commit is contained in:
Javi Martín
2020-06-18 20:08:49 +02:00
parent cfc60b5de4
commit 0270c4c962
4 changed files with 25 additions and 8 deletions

View File

@@ -22,8 +22,18 @@
}); });
editor = $(this); editor = $(this);
editor.on("input", function() { editor.on("input", function() {
var textarea, warning;
textarea = editor.find("textarea")[0];
warning = $(this).closest(".translatable-fields").find(".warning");
App.MarkdownEditor.refresh_preview($(this), md); App.MarkdownEditor.refresh_preview($(this), md);
$(".legislation-draft-versions-edit .warning").show();
if (textarea.value === textarea.defaultValue) {
warning.hide();
} else {
warning.show();
}
}); });
editor.find("textarea").on("scroll", function() { editor.find("textarea").on("scroll", function() {
editor.find(".markdown-preview").scrollTop($(this).scrollTop()); editor.find(".markdown-preview").scrollTop($(this).scrollTop());

View File

@@ -1,11 +1,18 @@
<%= render "shared/globalize_locales", resource: @draft_version %> <%= render "shared/globalize_locales", resource: @draft_version %>
<%= translatable_form_for [:admin, @process, @draft_version], url: url do |f| %> <%= translatable_form_for [:admin, @process, @draft_version], url: url,
html: { data: { markdown_changes_message: I18n.t("admin.legislation.draft_versions.edit.markdown_changes_message") }} do |f| %>
<%= render "shared/errors", resource: @draft_version %> <%= render "shared/errors", resource: @draft_version %>
<div class="row"> <div class="row">
<%= f.translatable_fields do |translations_form| %> <%= f.translatable_fields do |translations_form| %>
<div class="small-12 column">
<div class="callout warning" style="display: none;">
<%= t("admin.legislation.draft_versions.edit.warning") %>
</div>
</div>
<div class="small-12 medium-9 column"> <div class="small-12 medium-9 column">
<%= translations_form.text_field :title, <%= translations_form.text_field :title,
placeholder: t("admin.legislation.draft_versions.form.title_placeholder") %> placeholder: t("admin.legislation.draft_versions.form.title_placeholder") %>

View File

@@ -11,12 +11,6 @@
<%= render "admin/legislation/processes/subnav", process: @process, active: "draft_versions" %> <%= render "admin/legislation/processes/subnav", process: @process, active: "draft_versions" %>
<div class="small-12 column">
<div class="callout warning" data-markdown-changes-message="<%= I18n.t("admin.legislation.draft_versions.edit.markdown_changes_message") %>" style="display: none;">
<%= t("admin.legislation.draft_versions.edit.warning") %>
</div>
</div>
<div class="small-12 column"> <div class="small-12 column">
<h3 class="inline-block"><%= @draft_version.title %></h3> <h3 class="inline-block"><%= @draft_version.title %></h3>

View File

@@ -102,6 +102,8 @@ describe "Admin legislation draft versions" do
visit path visit path
fill_in_markdown_editor "Text", with: "Version 1b" fill_in_markdown_editor "Text", with: "Version 1b"
expect(page).to have_content "You've edited the text"
dismiss_confirm(prompt) do dismiss_confirm(prompt) do
click_link "Proposals", match: :first click_link "Proposals", match: :first
end end
@@ -141,7 +143,11 @@ describe "Admin legislation draft versions" do
expect(page).to have_css("h2", text: "Proposals") expect(page).to have_css("h2", text: "Proposals")
go_back go_back
fill_in_markdown_editor "Text", with: "Version 1" fill_in_markdown_editor "Text", with: "Version 1"
expect(page).not_to have_content "You've edited the text"
click_link "Proposals", match: :first click_link "Proposals", match: :first
expect(page).to have_css("h2", text: "Proposals") expect(page).to have_css("h2", text: "Proposals")