From 70e014cdfcf502393abcf0b4630686336ad122fe Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 15 Feb 2018 11:34:44 +0100 Subject: [PATCH] Hide infinite spinner and disconnect modals when pad is deleted --- .../src/less2/include/creation.less | 6 +++++ www/common/common-ui-elements.js | 19 ++++++++++++++ www/common/sframe-app-framework.js | 17 +++---------- www/common/sframe-common.js | 1 + www/poll/inner.js | 25 +++++++------------ www/whiteboard/inner.js | 22 ++++++---------- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/customize.dist/src/less2/include/creation.less b/customize.dist/src/less2/include/creation.less index cf2bc6b88..58d5a53ba 100644 --- a/customize.dist/src/less2/include/creation.less +++ b/customize.dist/src/less2/include/creation.less @@ -160,5 +160,11 @@ } } } + .cp-creation-deleted { + background: #111; + padding: 10px; + text-align: justify; + font-weight: bold; + } } } diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index e0e5f1ff7..8e4fce0e4 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -1829,5 +1829,24 @@ define([ }, Messages.creation_settings))).appendTo($creation); }; + UIElements.onServerError = function (common, err, toolbar, cb) { + if (["EDELETED", "EEXPIRED"].indexOf(err.type) === -1) { return; } + var msg = err.type; + if (err.type === 'EEXPIRED') { + msg = Messages.expiredError; + if (err.loaded) { + msg += Messages.expiredErrorCopy; + } + } else if (err.type === 'EDELETED') { + msg = Messages.deletedError; + if (err.loaded) { + msg += Messages.expiredErrorCopy; + } + } + if (toolbar && typeof toolbar.deleted === "function") { toolbar.deleted(); } + UI.errorLoadingScreen(msg, true, true); + (cb || function () {})(); + }; + return UIElements; }); diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index ef516e86d..7540f4a0b 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -333,20 +333,9 @@ define([ }; var onError = function (err) { - stateChange(STATE.DELETED); - var msg = err.type; - if (err.type === 'EEXPIRED') { - msg = Messages.expiredError; - if (err.loaded) { - msg += Messages.expiredErrorCopy; - } - } else if (err.type === 'EDELETED') { - msg = Messages.deletedError; - if (err.loaded) { - msg += Messages.expiredErrorCopy; - } - } - UI.errorLoadingScreen(msg, true, true); + common.onServerError(err, toolbar, function () { + stateChange(STATE.DELETED); + }); }; var setFileExporter = function (extension, fe, async) { diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index 029118b88..3f4070eaf 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -92,6 +92,7 @@ define([ funcs.createMarkdownToolbar = callWithCommon(UIElements.createMarkdownToolbar); funcs.getPadCreationScreen = callWithCommon(UIElements.getPadCreationScreen); funcs.createNewPadModal = callWithCommon(UIElements.createNewPadModal); + funcs.onServerError = callWithCommon(UIElements.onServerError); // Thumb funcs.displayThumbnail = callWithCommon(Thumb.displayThumbnail); diff --git a/www/poll/inner.js b/www/poll/inner.js index f88ac5763..8f31116a1 100644 --- a/www/poll/inner.js +++ b/www/poll/inner.js @@ -1130,27 +1130,20 @@ define([ // Manage disconnections because of network or error var onDisconnect = function (info) { - setEditable(false); - if (info && ['EEXPIRED', 'EDELETED'].indexOf(info.type) !== -1) { - APP.toolbar.deleted(); - var msg = info.type; - if (info.type === 'EEXPIRED') { - msg = Messages.expiredError; - if (info.loaded) { - msg += Messages.expiredErrorCopy; - } - } else if (info.type === 'EDELETED') { - msg = Messages.deletedError; - if (info.loaded) { - msg += Messages.expiredErrorCopy; - } - } - return void UI.errorLoadingScreen(msg, true, true); + if (APP.unrecoverable) { return; } + if (info && info.type) { + // Server error + return void common.onServerError(info, APP.toolbar, function () { + APP.unrecoverable = true; + setEditable(false); + }); } + setEditable(false); UI.alert(Messages.common_connectionLost, undefined, true); }; var onReconnect = function () { + if (APP.unrecoverable) { return; } setEditable(true); UI.findOKButton().click(); }; diff --git a/www/whiteboard/inner.js b/www/whiteboard/inner.js index febf63c5b..8d2621aaf 100644 --- a/www/whiteboard/inner.js +++ b/www/whiteboard/inner.js @@ -598,6 +598,7 @@ define([ }; config.onAbort = function () { + if (APP.unrecoverable) { return; } // inform of network disconnect setEditable(false); toolbar.failed(); @@ -605,6 +606,7 @@ define([ }; config.onConnectionChange = function (info) { + if (APP.unrecoverable) { return; } setEditable(info.state); if (info.state) { initializing = true; @@ -615,27 +617,17 @@ define([ }; config.onError = function (err) { - setEditable(false); - toolbar.deleted(); - var msg = err.type; - if (err.type === 'EEXPIRED') { - msg = Messages.expiredError; - if (err.loaded) { - msg += Messages.expiredErrorCopy; - } - } else if (err.type === 'EDELETED') { - msg = Messages.deletedError; - if (err.loaded) { - msg += Messages.expiredErrorCopy; - } - } - UI.errorLoadingScreen(msg, true, true); + common.onServerError(err, toolbar, function () { + APP.unrecoverable = true; + setEditable(false); + }); }; cpNfInner = common.startRealtime(config); metadataMgr = cpNfInner.metadataMgr; cpNfInner.onInfiniteSpinner(function () { + if (APP.unrecoverable) { return; } setEditable(false); UI.confirm(Messages.realtime_unrecoverableError, function (yes) { if (!yes) { return; }