Skip to content
Snippets Groups Projects
Commit b2cf15ea authored by Ere Maijala's avatar Ere Maijala Committed by Chris Hallberg
Browse files

Fixed favorite deletion to not handle the form submission as a login event. (#751)

After exploring new options to make login detection more robust, this is still the best system. Will continue to investigate.
parent ad627bc8
Branches
Tags
No related merge requests found
...@@ -41,6 +41,22 @@ var VuFind = (function VuFind() { ...@@ -41,6 +41,22 @@ var VuFind = (function VuFind() {
return _translations[op] || op; return _translations[op] || op;
}; };
/**
* Reload the page without causing trouble with POST parameters while keeping hash
*/
var refreshPage = function refreshPage() {
var parts = window.location.href.split('#');
if (typeof parts[1] === 'undefined') {
window.location.href = window.location.href;
} else {
var href = parts[0];
// Force reload with a timestamp
href += href.indexOf('?') === -1 ? '?_=' : '&_=';
href += new Date().getTime() + '#' + parts[1];
window.location.href = href;
}
}
//Reveal //Reveal
return { return {
defaultSearchBackend: defaultSearchBackend, defaultSearchBackend: defaultSearchBackend,
...@@ -48,6 +64,7 @@ var VuFind = (function VuFind() { ...@@ -48,6 +64,7 @@ var VuFind = (function VuFind() {
addTranslations: addTranslations, addTranslations: addTranslations,
init: init, init: init,
refreshPage: refreshPage,
register: register, register: register,
translate: translate translate: translate
}; };
......
...@@ -41,21 +41,6 @@ VuFind.register('lightbox', function Lightbox() { ...@@ -41,21 +41,6 @@ VuFind.register('lightbox', function Lightbox() {
return document.dispatchEvent(event); return document.dispatchEvent(event);
} }
/**
* Reload the page without causing trouble with POST parameters while keeping hash
*/
function _refreshPage() {
var parts = window.location.href.split('#');
if (typeof parts[1] === 'undefined') {
window.location.href = window.location.href;
} else {
var href = parts[0];
// Force reload with a timestamp
href += href.indexOf('?') === -1 ? '?_=' : '&_=';
href += new Date().getTime() + '#' + parts[1];
window.location.href = href;
}
}
// Public: Present an alert // Public: Present an alert
function showAlert(message, _type) { function showAlert(message, _type) {
var type = _type || 'info'; var type = _type || 'info';
...@@ -140,7 +125,7 @@ VuFind.register('lightbox', function Lightbox() { ...@@ -140,7 +125,7 @@ VuFind.register('lightbox', function Lightbox() {
_xhr.always(function lbAjaxAlways() { _xhr = false; }) _xhr.always(function lbAjaxAlways() { _xhr = false; })
.done(function lbAjaxDone(content, status, jq_xhr) { .done(function lbAjaxDone(content, status, jq_xhr) {
if (jq_xhr.status === 205) { if (jq_xhr.status === 205) {
_refreshPage(); VuFind.refreshPage();
return; return;
} }
// Place Hold error isolation // Place Hold error isolation
...@@ -154,7 +139,7 @@ VuFind.register('lightbox', function Lightbox() { ...@@ -154,7 +139,7 @@ VuFind.register('lightbox', function Lightbox() {
} }
if ( // Close the lightbox after deliberate login if ( // Close the lightbox after deliberate login
obj.method // is a form obj.method // is a form
&& ((obj.url.match(/MyResearch/) && !obj.url.match(/Bulk/)) // that matches login/create account && ((obj.url.match(/MyResearch/) && !obj.url.match(/Bulk/) && !obj.url.match(/Delete/)) // that matches login/create account
|| obj.url.match(/catalogLogin/)) // or catalog login for holds || obj.url.match(/catalogLogin/)) // or catalog login for holds
&& $('<div/>').html(content).find('.flash-message.alert-danger').length === 0 // skip failed logins && $('<div/>').html(content).find('.flash-message.alert-danger').length === 0 // skip failed logins
) { ) {
...@@ -164,7 +149,7 @@ VuFind.register('lightbox', function Lightbox() { ...@@ -164,7 +149,7 @@ VuFind.register('lightbox', function Lightbox() {
}); });
if (_originalUrl.match(/UserLogin/) || obj.url.match(/catalogLogin/)) { if (_originalUrl.match(/UserLogin/) || obj.url.match(/catalogLogin/)) {
if (eventResult) { if (eventResult) {
_refreshPage(); VuFind.refreshPage();
} }
return false; return false;
} else { } else {
...@@ -313,7 +298,7 @@ VuFind.register('lightbox', function Lightbox() { ...@@ -313,7 +298,7 @@ VuFind.register('lightbox', function Lightbox() {
_modalBody = _modal.find('.modal-body'); _modalBody = _modal.find('.modal-body');
_modal.on('hide.bs.modal', function lightboxHide() { _modal.on('hide.bs.modal', function lightboxHide() {
if (VuFind.lightbox.refreshOnClose) { if (VuFind.lightbox.refreshOnClose) {
_refreshPage(); VuFind.refreshPage();
} }
_emit('VuFind.lightbox.closing'); _emit('VuFind.lightbox.closing');
}); });
......
<form action="<?=$this->url('myresearch-delete')?>" method="post" name="bulkDelete"> <h2><?=$this->transEsc('delete_selected_favorites')?></h2>
<form action="<?=$this->url('myresearch-delete')?>" method="post" name="bulkDelete" data-lightbox-onclose="VuFind.refreshPage();">
<div id="popupMessages"><?=$this->flashmessages()?></div> <div id="popupMessages"><?=$this->flashmessages()?></div>
<div id="popupDetails"> <div id="popupDetails">
<h2><?=$this->transEsc('delete_selected_favorites')?></h2>
<? if (!$this->list): ?> <? if (!$this->list): ?>
<div class="alert alert-info"><?=$this->transEsc("fav_delete_warn") ?></div> <div class="alert alert-info"><?=$this->transEsc("fav_delete_warn") ?></div>
<? else: ?> <? else: ?>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment