From 89d8b3703ef59d1406c1c3ef73e54cc38407fd0e Mon Sep 17 00:00:00 2001 From: JuliaSvinareva Date: Mon, 12 Apr 2021 19:03:42 +0300 Subject: [PATCH] [DE mobile] Make main controller, add run autostart macroses --- apps/documenteditor/mobile/locale/en.json | 6 +- .../mobile/src/controller/Error.jsx | 1 + .../mobile/src/controller/Main.jsx | 77 ++++++++++++++++--- 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/apps/documenteditor/mobile/locale/en.json b/apps/documenteditor/mobile/locale/en.json index e508cb033..9ca0208b9 100644 --- a/apps/documenteditor/mobile/locale/en.json +++ b/apps/documenteditor/mobile/locale/en.json @@ -52,7 +52,11 @@ "errorAccessDeny": "You are trying to perform an action you do not have rights for.
Please contact your Document Server administrator.", "errorUpdateVersion": "The file version has been changed. The page will be reloaded.", - "titleUpdateVersion": "Version changed" + "titleUpdateVersion": "Version changed", + "textHasMacros": "The file contains automatic macros.
Do you want to run macros?", + "textRemember": "Remember my choice", + "textYes": "Yes", + "textNo": "No" }, "Error": { "criticalErrorTitle": "Error", diff --git a/apps/documenteditor/mobile/src/controller/Error.jsx b/apps/documenteditor/mobile/src/controller/Error.jsx index f1fd7074b..6ae81ef0d 100644 --- a/apps/documenteditor/mobile/src/controller/Error.jsx +++ b/apps/documenteditor/mobile/src/controller/Error.jsx @@ -209,6 +209,7 @@ const ErrorController = inject('storeAppOptions')(({storeAppOptions, LoadingDocu } f7.dialog.create({ + cssClass: 'error-dialog', title : config.title, text : config.msg, buttons: [ diff --git a/apps/documenteditor/mobile/src/controller/Main.jsx b/apps/documenteditor/mobile/src/controller/Main.jsx index 4cb66c3ee..391f6dbdb 100644 --- a/apps/documenteditor/mobile/src/controller/Main.jsx +++ b/apps/documenteditor/mobile/src/controller/Main.jsx @@ -124,21 +124,21 @@ class MainController extends Component { docInfo.put_Permissions(_permissions); docInfo.put_EncryptedInfo(this.editorConfig.encryptionKeys); - // var enable = !this.editorConfig.customization || (this.editorConfig.customization.macros!==false); - // docInfo.asc_putIsEnabledMacroses(!!enable); - // enable = !this.editorConfig.customization || (this.editorConfig.customization.plugins!==false); - // docInfo.asc_putIsEnabledPlugins(!!enable); + let enable = !this.editorConfig.customization || (this.editorConfig.customization.macros !== false); + docInfo.asc_putIsEnabledMacroses(!!enable); + enable = !this.editorConfig.customization || (this.editorConfig.customization.plugins !== false); + docInfo.asc_putIsEnabledPlugins(!!enable); - // let type = /^(?:(pdf|djvu|xps))$/.exec(data.doc.fileType); - // if (type && typeof type[1] === 'string') { - // this.permissions.edit = this.permissions.review = false; - // } + const type = /^(?:(pdf|djvu|xps))$/.exec(data.doc.fileType); + if (type && typeof type[1] === 'string') { + this.permissions.edit = this.permissions.review = false; + } } this.api.asc_registerCallback('asc_onGetEditorPermissions', onEditorPermissions); this.api.asc_registerCallback('asc_onDocumentContentReady', onDocumentContentReady); this.api.asc_registerCallback('asc_onLicenseChanged', this.onLicenseChanged.bind(this)); - // this.api.asc_registerCallback('asc_onRunAutostartMacroses', _.bind(this.onRunAutostartMacroses, this)); + this.api.asc_registerCallback('asc_onRunAutostartMacroses', this.onRunAutostartMacroses.bind(this)); this.api.asc_setDocInfo(docInfo); this.api.asc_getEditorPermissions(this.editorConfig.licenseUrl, this.editorConfig.customerId); @@ -258,6 +258,19 @@ class MainController extends Component { Common.Gateway.on('showmessage', this.onExternalMessage.bind(this)); Common.Gateway.on('opendocument', loadDocument); Common.Gateway.appReady(); + + Common.Gateway.on('internalcommand', function(data) { + if (data.command === 'hardBack') { + if ($$('.modal-in').length > 0) { + if ( !($$('.error-dialog.modal-in').length > 0) ) { + f7.dialog.close(); + } + Common.Gateway.internalMessage('hardBack', false); + } else + Common.Gateway.internalMessage('hardBack', true); + } + }); + Common.Gateway.internalMessage('listenHardBack'); }, error => { console.log('promise failed ' + error); }); @@ -677,6 +690,52 @@ class MainController extends Component { } } + onRunAutostartMacroses () { + const config = this.props.storeAppOptions.config; + const enable = !config.customization || (config.customization.macros !== false); + if (enable) { + const value = this.props.storeApplicationSettings.macrosMode; + if (value === 1) { + this.api.asc_runAutostartMacroses(); + } else if (value === 0) { + const _t = this._t; + f7.dialog.create({ + title: _t.notcriticalErrorTitle, + text: _t.textHasMacros, + content: `
+ + ${_t.textRemember} +
`, + buttons: [{ + text: _t.textYes, + onClick: () => { + const dontshow = $$('input[name="checkbox-show-macros"]').prop('checked'); + if (dontshow) { + this.props.storeApplicationSettings.changeMacrosSettings(1); + LocalStorage.setItem("de-mobile-macros-mode", 1); + } + setTimeout(() => { + this.api.asc_runAutostartMacroses(); + }, 1); + }}, + { + text: _t.textNo, + onClick: () => { + const dontshow = $$('input[name="checkbox-show-macros"]').prop('checked'); + if (dontshow) { + this.props.storeApplicationSettings.changeMacrosSettings(2); + LocalStorage.setItem("de-mobile-macros-mode", 2); + } + } + }] + }).open(); + } + } + } + render() { return (