From eba2255fe94c41514ab1e3d04ec448c86c0f7145 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Jun 2021 12:30:22 +0200 Subject: [PATCH] Handle disconnection in forms and disable offline mode --- www/form/app-form.less | 25 +++++++++++++++++++++++++ www/form/inner.js | 19 ++++++++++++++++++- www/form/main.js | 4 ++-- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/www/form/app-form.less b/www/form/app-form.less index 114abf395..e1fdceff8 100644 --- a/www/form/app-form.less +++ b/www/form/app-form.less @@ -37,6 +37,31 @@ } } + &.cp-readonly { + .cp-form-creator-inline-add { + display: none; + } + .cp-form-creator-add-full { + display: none !important; + } + .cp-form-edit-buttons-container button { + display: none; + } + .cp-form-edit-save { + display: none; + } + .cp-form-block { + cursor: default !important; + .cp-form-block-drag-handle { + display: none !important; + } + } + } + + #cp-toolbar .cp-toolbar-title-readonly { + display: none; + } + #cp-app-form-container { display: flex; flex: 1; diff --git a/www/form/inner.js b/www/form/inner.js index b398261ec..e2524da39 100644 --- a/www/form/inner.js +++ b/www/form/inner.js @@ -2358,7 +2358,7 @@ define([ updateAddInline(); if (editable) { - Sortable.create($container[0], { + APP.mainSortable = Sortable.create($container[0], { direction: "vertical", filter: "input, button, .CodeMirror, .cp-form-type-sort", preventOnFilter: false, @@ -2413,6 +2413,23 @@ define([ var helpMenu = framework._.sfCommon.createHelpMenu(['text', 'pad']); $toolbarContainer.after(helpMenu.menu); + var offlineEl = h('div.alert.alert-danger.cp-burn-after-reading', Messages.disconnected); + var oldFilter; + framework.onEditableChange(function (editable) { + if (editable) { + if (APP.mainSortable) { APP.mainSortable.options.filter = oldFilter; } + if (!APP.isEditor) { $(offlineEl).remove(); } + $body.removeClass('cp-readonly'); + } else { + if (APP.mainSortable) { + oldFilter = APP.mainSortable.options.filter; + APP.mainSortable.options.filter = function () { return true; }; + } + if (!APP.isEditor) { $('.cp-help-container').before(offlineEl); } + $body.addClass('cp-readonly'); + } + }); + if (!APP.isEditor) { framework._.toolbar.alone(); } diff --git a/www/form/main.js b/www/form/main.js index 0d288dbe3..4e6345efc 100644 --- a/www/form/main.js +++ b/www/form/main.js @@ -182,7 +182,7 @@ define([ validateKey: keys.secondaryValidateKey, owners: [myKeys.edPublic], crypto: crypto, - // XXX Cache + Cache: Utils.Cache }; var results = {}; config.onError = function (info) { @@ -346,7 +346,7 @@ define([ SFCommonO.start({ addData: addData, addRpc: addRpc, - cache: true, + //cache: true, noDrive: true, hash: hash, href: href,