Merge pull request #204 from okriuchykhin/ok_SCI-463

Fix issue with pop-up windows and turbolinks [SCI-463]
This commit is contained in:
okriuchykhin 2016-10-18 09:12:47 +02:00 committed by GitHub
commit 076353b207
2 changed files with 15 additions and 30 deletions

View file

@ -443,37 +443,22 @@ function initializeUnsavedWorkDialog() {
return;
}
$(document).on('page:before-change', beforechange);
$(window).on('beforeunload', beforeunload);
$(window).on("beforeunload", function() {
$(window).off('beforeunload');
$(document).off('page:before-change');
return alertText;
});
function beforeunload() {
//Check if we are actually in report editor
if ( $(REPORT_CONTENT).length ) {
return alertText;
} else {
// We are at another page so remove unload handlers if they exists
$(window).off('beforeunload', beforeunload);
$(document).off('page:before-change', beforechange);
$(document).on("page:before-change", function() {
var exit;
exit = confirm(alertText);
if ( exit ) {
// We leave the page so remove all listeners
$(window).off('beforeunload');
$(document).off('page:before-change');
}
}
function beforechange() {
//Check if we are actually in report editor
if ( $(REPORT_CONTENT).length ) {
var exit;
exit = confirm(alertText);
if ( exit ) {
// We leave the page so remove all listeners
$(window).off();
$(document).off();
}
return exit;
} else {
// We are at another page so remove unload handlers if they exists
$(window).off('beforeunload', beforeunload);
$(document).off('page:before-change', beforechange);
}
}
return exit;
});
}
/**

View file

@ -6,7 +6,7 @@
data-reports-click-new-report-step-text="<%=t 'tutorial.reports_index_click_new_report_html' %>">
<div>
<% if can_create_new_report(@project) %>
<%= link_to new_project_reports_path(@project), class: "btn btn-primary", id: "new-report-btn" do %>
<%= link_to new_project_reports_path(@project), class: 'btn btn-primary', id: 'new-report-btn', 'data-no-turbolink' => true do %>
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
<span class="hidden-xs"><%=t "projects.reports.index.new" %></span>
<% end %>