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:
@@ -22,8 +22,18 @@
|
||||
});
|
||||
editor = $(this);
|
||||
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);
|
||||
$(".legislation-draft-versions-edit .warning").show();
|
||||
|
||||
if (textarea.value === textarea.defaultValue) {
|
||||
warning.hide();
|
||||
} else {
|
||||
warning.show();
|
||||
}
|
||||
});
|
||||
editor.find("textarea").on("scroll", function() {
|
||||
editor.find(".markdown-preview").scrollTop($(this).scrollTop());
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
<%= 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 %>
|
||||
|
||||
<div class="row">
|
||||
<%= 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">
|
||||
<%= translations_form.text_field :title,
|
||||
placeholder: t("admin.legislation.draft_versions.form.title_placeholder") %>
|
||||
|
||||
@@ -11,12 +11,6 @@
|
||||
|
||||
<%= 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">
|
||||
<h3 class="inline-block"><%= @draft_version.title %></h3>
|
||||
|
||||
|
||||
@@ -102,6 +102,8 @@ describe "Admin legislation draft versions" do
|
||||
visit path
|
||||
fill_in_markdown_editor "Text", with: "Version 1b"
|
||||
|
||||
expect(page).to have_content "You've edited the text"
|
||||
|
||||
dismiss_confirm(prompt) do
|
||||
click_link "Proposals", match: :first
|
||||
end
|
||||
@@ -141,7 +143,11 @@ describe "Admin legislation draft versions" do
|
||||
expect(page).to have_css("h2", text: "Proposals")
|
||||
|
||||
go_back
|
||||
|
||||
fill_in_markdown_editor "Text", with: "Version 1"
|
||||
|
||||
expect(page).not_to have_content "You've edited the text"
|
||||
|
||||
click_link "Proposals", match: :first
|
||||
|
||||
expect(page).to have_css("h2", text: "Proposals")
|
||||
|
||||
Reference in New Issue
Block a user