From 1c013d8a4f24b451c6e0aeda525a0b96cd672e8c Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 5 Feb 2020 16:18:09 +0100 Subject: [PATCH] Fix stacking disconnection alerts --- www/common/common-interface.js | 5 +++++ www/common/common-ui-elements.js | 15 +++++++++++++++ www/common/onlyoffice/inner.js | 11 ++--------- www/common/sframe-app-framework.js | 4 ++-- www/drive/inner.js | 6 ++++-- www/poll/inner.js | 6 ++++-- www/teams/inner.js | 4 ++-- 7 files changed, 34 insertions(+), 17 deletions(-) diff --git a/www/common/common-interface.js b/www/common/common-interface.js index 04f806d4f..f08a9aa72 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -491,6 +491,11 @@ define([ $ok.focus(); Notifier.notify(); }); + + return { + element: frame, + delete: close + }; }; UI.prompt = function (msg, def, cb, opt, force) { diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index c60ef652d..d106702b5 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -56,6 +56,21 @@ define([ }); }; + var dcAlert; + UIElements.disconnectAlert = function () { + if (dcAlert && $(dcAlert.element).length) { return; } + dcAlert = UI.alert(Messages.common_connectionLost, undefined, true); + }; + UIElements.reconnectAlert = function () { + if (!dcAlert) { return; } + if (!dcAlert.delete) { + dcAlert = undefined; + return; + } + dcAlert.delete(); + dcAlert = undefined; + }; + var importContent = function (type, f, cfg) { return function () { var $files = $('', {type:"file"}); diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 8b2d8328b..4270b0f4c 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -1606,17 +1606,10 @@ define([ pinImages(); }; - config.onAbort = function () { - // inform of network disconnect - setEditable(false); - toolbar.failed(); - UI.alert(Messages.common_connectionLost, undefined, true); - }; - config.onConnectionChange = function (info) { if (info.state) { // If we tried to send changes while we were offline, force a page reload - UI.findOKButton().click(); + UIElements.reconnectAlert(); if (Object.keys(pendingChanges).length) { return void UI.confirm(Messages.oo_reconnect, function (yes) { if (!yes) { return; } @@ -1629,7 +1622,7 @@ define([ setEditable(false); offline = true; UI.findOKButton().click(); - UI.alert(Messages.common_connectionLost, undefined, true); + UIElements.disconnectAlert(); } }; diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index ed8652809..ea22aaf5f 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -396,9 +396,9 @@ define([ if (state === STATE.DELETED) { return; } stateChange(info.state ? STATE.INITIALIZING : STATE.DISCONNECTED, info.permanent); /*if (info.state) { - UI.findOKButton().click(); + UIElements.reconnectAlert(); } else { - UI.alert(Messages.common_connectionLost, undefined, true); + UIElements.disconnectAlert(); }*/ }; diff --git a/www/drive/inner.js b/www/drive/inner.js index 03bf73697..a5325a651 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -5,6 +5,7 @@ define([ '/common/common-util.js', '/common/common-hash.js', '/common/common-interface.js', + '/common/common-ui-elements.js', '/common/common-feedback.js', '/bower_components/nthen/index.js', '/common/sframe-common.js', @@ -22,6 +23,7 @@ define([ Util, Hash, UI, + UIElements, Feedback, nThen, SFCommon, @@ -272,13 +274,13 @@ define([ setEditable(false); if (drive.refresh) { drive.refresh(); } APP.toolbar.failed(); - if (!noAlert) { UI.alert(Messages.common_connectionLost, undefined, true); } + if (!noAlert) { UIElements.disconnectAlert(); } }; var onReconnect = function () { setEditable(true); if (drive.refresh) { drive.refresh(); } APP.toolbar.reconnecting(); - UI.findOKButton().click(); + UIElements.reconnectAlert(); }; sframeChan.on('EV_DRIVE_LOG', function (msg) { diff --git a/www/poll/inner.js b/www/poll/inner.js index 7420f5c09..d1d583757 100644 --- a/www/poll/inner.js +++ b/www/poll/inner.js @@ -13,6 +13,7 @@ define([ '/common/sframe-common-codemirror.js', '/common/common-thumbnail.js', '/common/common-interface.js', + '/common/common-ui-elements.js', '/common/hyperscript.js', '/customize/messages.js', 'cm/lib/codemirror', @@ -42,6 +43,7 @@ define([ SframeCM, Thumb, UI, + UIElements, h, Messages, CMeditor, @@ -1098,13 +1100,13 @@ define([ }); } setEditable(false); - //UI.alert(Messages.common_connectionLost, undefined, true); + //UIElements.disconnectAlert(); }; var onReconnect = function () { if (APP.unrecoverable) { return; } setEditable(true); - //UI.findOKButton().click(); + //UIElements.reconnectAlert(); }; var getHeadingText = function () { diff --git a/www/teams/inner.js b/www/teams/inner.js index 3f26874b2..4dea3e80d 100644 --- a/www/teams/inner.js +++ b/www/teams/inner.js @@ -1379,13 +1379,13 @@ define([ setEditable(false); if (APP.team && driveAPP.refresh) { driveAPP.refresh(); } toolbar.failed(); - if (!noAlert) { UI.alert(Messages.common_connectionLost, undefined, true); } + if (!noAlert) { UIElements.disconnectAlert(); } }; var onReconnect = function () { setEditable(true); if (APP.team && driveAPP.refresh) { driveAPP.refresh(); } toolbar.reconnecting(); - UI.findOKButton().click(); + UIElements.reconnectAlert(); }; sframeChan.on('EV_DRIVE_LOG', function (msg) {