Skip to content

Commit 8a36c42

Browse files
committed
* Fix: 'cancel' tries to close the portal window, but fails and redirects to the main iTop page (which could be console) instead of staying in portal
1 parent 06a5d64 commit 8a36c42

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

datamodels/2.x/itop-portal-base/portal/public/js/portal_form_handler.js

+27-5
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,34 @@ $(function()
426426
}
427427
else
428428
{
429-
// Try to close the window
430-
window.close();
429+
430+
if(window.history.length == 1) {
431+
432+
// This window doesn't seem to be a modal, yet there is no history. Try to close the window.
433+
window.close();
431434

432-
// In some browser (eg. Firefox 70), window won't close if it has NOT been open by JS. In that case, we try to redirect to homepage as a fallback.
433-
var sHomepageUrl = (this.options.base_url !== null) ? this.options.base_url : $('#sidebar .menu .brick_menu_item:first a').attr('href')
434-
window.location.href = sHomepageUrl;
435+
// In some browser (eg. Firefox 70), window won't close if it has NOT been open by JS. In that case, we try to redirect to homepage as a fallback.
436+
var sHomepageUrl = (this.options.base_url !== null) ? this.options.base_url : $('#sidebar .menu .brick_menu_item:first a').attr('href')
437+
438+
var regexPortal = new RegExp('(pages\\/exec\\.php)(.*?)(\\?exec_module=itop-portal-base&exec_page=index\\.php&portal_id=.*?)(&|$)');
439+
var aRegexMatch = window.location.href.match(regexPortal);
440+
441+
if(aRegexMatch !== null) {
442+
443+
sHomepageUrl += aRegexMatch[1] + aRegexMatch[3];
444+
445+
}
446+
447+
window.location.href = sHomepageUrl;
448+
449+
}
450+
else {
451+
452+
// Unless the previous page was for some reason an automatic redirection to the current one, this should work:
453+
window.history.back(-1);
454+
455+
}
456+
435457
}
436458
},
437459
submit: function(oEvent)

0 commit comments

Comments
 (0)