Skip to content

Commit

Permalink
* Fix: 'cancel' tries to close the portal window, but fails and redir…
Browse files Browse the repository at this point in the history
…ects to the main iTop page (which could be console) instead of staying in portal
  • Loading branch information
jbostoen committed Jan 15, 2023
1 parent 06a5d64 commit 8a36c42
Showing 1 changed file with 27 additions and 5 deletions.
Expand Up @@ -426,12 +426,34 @@ $(function()
}
else
{
// Try to close the window
window.close();

if(window.history.length == 1) {

// This window doesn't seem to be a modal, yet there is no history. Try to close the window.
window.close();

// 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.
var sHomepageUrl = (this.options.base_url !== null) ? this.options.base_url : $('#sidebar .menu .brick_menu_item:first a').attr('href')
window.location.href = sHomepageUrl;
// 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.
var sHomepageUrl = (this.options.base_url !== null) ? this.options.base_url : $('#sidebar .menu .brick_menu_item:first a').attr('href')

var regexPortal = new RegExp('(pages\\/exec\\.php)(.*?)(\\?exec_module=itop-portal-base&exec_page=index\\.php&portal_id=.*?)(&|$)');
var aRegexMatch = window.location.href.match(regexPortal);

if(aRegexMatch !== null) {

sHomepageUrl += aRegexMatch[1] + aRegexMatch[3];

}

window.location.href = sHomepageUrl;

}
else {

// Unless the previous page was for some reason an automatic redirection to the current one, this should work:
window.history.back(-1);

}

}
},
submit: function(oEvent)
Expand Down

0 comments on commit 8a36c42

Please sign in to comment.