Skip to content

Commit

Permalink
Merge pull request tolk#41 from fcsonline/feature/avoid-lose-data
Browse files Browse the repository at this point in the history
Avoid lose data
  • Loading branch information
fcsonline committed Mar 14, 2013
2 parents cc90222 + 620739c commit 96a69ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion app/assets/javascripts/tolk/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,29 @@ $(function () {
var row = $(this).parents("tr")
, original = row.find(".phrase .original").text();

row.find(".translation textarea").val(original.trim());
row.find(".translation textarea").addClass("dirty").val(original.trim());

// Bind the dirty callback after copy
window.onbeforeunload = confirm;
});

// avoid lose data
$(".translations textarea").bind("blur", function () {
if ($(this).is(".dirty")) {
window.onbeforeunload = confirm;
}
});

$(".translations textarea").bind("keydown", function () {
$(this).addClass("dirty");
});

$("input.save, input.apply").click(function () {
window.onbeforeunload = null;
});

function confirm() {
return "You are leaving this page with non-saved data. Are you sure you want to continue?";
}

});
2 changes: 1 addition & 1 deletion app/views/layouts/tolk/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<body>
<div id="container">
<div id="head">
<h1><span class="home"><%= link_to "Tolk", root_path %></span><% if @locale.present? %><span class="locale"><%= link_to @locale.language_name, locale_path(@locale) %></span><% end %><span class="locale"><%= button_to "Apply Changes", dump_all_locales_path, :method => :post %></span></h1>
<h1><span class="home"><%= link_to "Tolk", root_path %></span><% if @locale.present? %><span class="locale"><%= link_to @locale.language_name, locale_path(@locale) %></span><% end %><span class="locale"><%= button_to "Apply Changes", dump_all_locales_path, :method => :post, :class => "apply" %></span></h1>
</div>
<%= yield %>
</div>
Expand Down

0 comments on commit 96a69ca

Please sign in to comment.