diff --git a/apps/documenteditor/mobile/locale/en.json b/apps/documenteditor/mobile/locale/en.json index 256d9cef3b..013b6cd6de 100644 --- a/apps/documenteditor/mobile/locale/en.json +++ b/apps/documenteditor/mobile/locale/en.json @@ -476,6 +476,8 @@ "errorUpdateVersion": "The file version has been changed. The page will be reloaded.", "leavePageText": "You have unsaved changes. Click 'Stay on this Page' to wait for autosave. Click 'Leave this Page' to discard all the unsaved changes.", "notcriticalErrorTitle": "Warning", + "textDocumentProtected": "The document is protected. Edit settings are not available", + "textOk": "Ok", "SDK": { " -Section ": " -Section ", "above": "above", diff --git a/apps/documenteditor/mobile/src/controller/Main.jsx b/apps/documenteditor/mobile/src/controller/Main.jsx index 984c289ed1..6deb76d39b 100644 --- a/apps/documenteditor/mobile/src/controller/Main.jsx +++ b/apps/documenteditor/mobile/src/controller/Main.jsx @@ -19,6 +19,7 @@ import PluginsController from '../../../../common/mobile/lib/controller/Plugins. import EncodingController from "./Encoding"; import DropdownListController from "./DropdownList"; import { Device } from '../../../../common/mobile/utils/device'; + @inject( "users", "storeAppOptions", @@ -46,7 +47,8 @@ class MainController extends Component { this._state = { licenseType: false, isFromGatewayDownloadAs: false, - isDocModified: false + isDocModified: false, + docProtection: false }; this.defaultTitleText = __APP_TITLE_TEXT__; @@ -762,6 +764,10 @@ class MainController extends Component { } }); + // Protection document + this.api.asc_registerCallback('asc_onChangeDocumentProtection', this.onChangeProtectDocument.bind(this)); + // this.api.asc_registerCallback('asc_onLockDocumentProtection', this.onLockDocumentProtection.bind(this)); + // Toolbar settings const storeToolbarSettings = this.props.storeToolbarSettings; @@ -783,6 +789,69 @@ class MainController extends Component { }); } + onChangeProtectDocument() { + const { t } = this.props; + const storeAppOptions = this.props.storeAppOptions; + const props = this.getDocProps(true); + const isProtected = props && (props.isReadOnly || props.isCommentsOnly || props.isFormsOnly || props.isReviewOnly); + + storeAppOptions.setProtection(isProtected); + props && this.applyRestrictions(props.type); + Common.Notifications.trigger('protect:doclock', props); + + if(isProtected) { + f7.dialog.create({ + title: t('Main.notcriticalErrorTitle'), + text: t('Main.textDocumentProtected'), + buttons: [ + { + text: t('Main.textOk') + } + ] + }).open(); + } + } + + applyRestrictions(type) { + const storeAppOptions = this.props.storeAppOptions; + + if (type === Asc.c_oAscEDocProtect.ReadOnly) { + this.api.asc_setRestriction(Asc.c_oAscRestrictionType.View); + } else if (type === Asc.c_oAscEDocProtect.Comments) { + this.api.asc_setRestriction(storeAppOptions.canComments ? Asc.c_oAscRestrictionType.OnlyComments : Asc.c_oAscRestrictionType.View); + } else if (type === Asc.c_oAscEDocProtect.Forms) { + this.api.asc_setRestriction(storeAppOptions.canFillForms ? Asc.c_oAscRestrictionType.OnlyForms : Asc.c_oAscRestrictionType.View); + } else { + if (storeAppOptions?.isRestrictedEdit) { + storeAppOptions.canComments && this.api.asc_setRestriction(Asc.c_oAscRestrictionType.OnlyComments); + storeAppOptions.canFillForms && this.api.asc_setRestriction(Asc.c_oAscRestrictionType.OnlyForms); + } else { + this.api.asc_setRestriction(Asc.c_oAscRestrictionType.None); + } + } + }; + + getDocProps(isUpdate) { + const storeAppOptions = this.props.storeAppOptions; + + if (!storeAppOptions || !storeAppOptions.isEdit && !storeAppOptions.isRestrictedEdit) return; + + if (isUpdate || !this.state.docProtection) { + const props = this.api.asc_getDocumentProtection(); + const type = props ? props.asc_getEditType() : Asc.c_oAscEDocProtect.None; + + this._state.docProtection = { + type: type, + isReadOnly: type === Asc.c_oAscEDocProtect.ReadOnly, + isCommentsOnly: type === Asc.c_oAscEDocProtect.Comments, + isReviewOnly: type === Asc.c_oAscEDocProtect.TrackedChanges, + isFormsOnly: type === Asc.c_oAscEDocProtect.Forms + }; + } + + return this._state.docProtection; + } + onApiTextReplaced(found, replaced) { const { t } = this.props; diff --git a/apps/documenteditor/mobile/src/page/main.jsx b/apps/documenteditor/mobile/src/page/main.jsx index 0930ea82d1..4a3767fb86 100644 --- a/apps/documenteditor/mobile/src/page/main.jsx +++ b/apps/documenteditor/mobile/src/page/main.jsx @@ -140,6 +140,7 @@ class MainPage extends Component { const disabledControls = storeToolbarSettings.disabledControls; const disabledSettings = storeToolbarSettings.disabledSettings; const config = appOptions.config; + const isProtected = appOptions.isProtected; let showLogo = !(config.customization && (config.customization.loaderName || config.customization.loaderLogo)); if (!Object.keys(config).length) { @@ -250,7 +251,7 @@ class MainPage extends Component { text={isMobileView ? t("Toolbar.textSwitchedMobileView") : t("Toolbar.textSwitchedStandardView")}/> } - {isViewer && !disabledSettings && !disabledControls && !isDisconnected && isAvailableExt && isEdit && + {isViewer && !disabledSettings && !disabledControls && !isDisconnected && isAvailableExt && isEdit && !isProtected && this.turnOffViewerMode()}> diff --git a/apps/documenteditor/mobile/src/store/appOptions.js b/apps/documenteditor/mobile/src/store/appOptions.js index 307a41afd8..8d4fae0651 100644 --- a/apps/documenteditor/mobile/src/store/appOptions.js +++ b/apps/documenteditor/mobile/src/store/appOptions.js @@ -29,12 +29,20 @@ export class storeAppOptions { changeViewerMode: action, isMobileView: observable, - changeMobileView: action + changeMobileView: action, + + isProtected: observable, + setProtection: action }); } isEdit = false; + isProtected = false; + setProtection(value) { + this.isProtected = value; + } + isMobileView = true; changeMobileView() { this.isMobileView = !this.isMobileView;