Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subsite change detection #516

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/dist/js/LeftAndMain_Subsites.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 34 additions & 1 deletion client/src/js/LeftAndMain_Subsites.js
@@ -1,9 +1,42 @@
/* jslint browser: true, nomen: true */
/* global $, window, jQuery */
/* global $, ss, window, jQuery */
(function ($) {
// eslint-disable-next-line no-shadow
$.entwine('ss', ($) => {
$('#SubsitesSelect').entwine({
/**
* Store current subsite id and ask to reload the page if it detects any change
*/
detectSubsiteChange(selectedId) {
const sessionKey = 'admin_subsite_id';
let reloadPending = false;
try {
localStorage.setItem(sessionKey, selectedId);

window.addEventListener('storage', () => {
if (reloadPending) {
return;
}
const tabId = localStorage.getItem(sessionKey);
// eslint-disable-next-line eqeqeq
if (tabId && selectedId != tabId) {
const msg = ss.i18n._t('Admin.SUBSITECHANGED', 'You\'ve changed subsite in another tab, do you want to reload the page?');
reloadPending = true; // Don't trigger multiple confirm dialog
// eslint-disable-next-line no-alert
if (confirm(msg)) {
window.location.reload();
}
// Don't ask again if cancelled
}
});
} catch (e) {
// Maybe storage is full or not available, disable this feature and ignore error
}
},

onmatch() {
this.detectSubsiteChange(this.find('option[selected]').attr('value'));
},
onadd() {
this.on('change', function () {
window.location.search = $.query.set('SubsiteID', $(this).val());
Expand Down