From 1c5b2e905720eb15a7b72aaab30ea6ab8bc26d29 Mon Sep 17 00:00:00 2001 From: SergeyEzhin Date: Thu, 17 Aug 2023 17:34:12 +0300 Subject: [PATCH] [DE mobile] Fix Bug 63649 --- apps/documenteditor/mobile/locale/en.json | 3 +- .../mobile/src/controller/Main.jsx | 3 +- .../mobile/src/controller/Toolbar.jsx | 70 ++++++++++++++++--- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/apps/documenteditor/mobile/locale/en.json b/apps/documenteditor/mobile/locale/en.json index 01b50d599f..c718dae558 100644 --- a/apps/documenteditor/mobile/locale/en.json +++ b/apps/documenteditor/mobile/locale/en.json @@ -391,7 +391,8 @@ "textType": "Type", "textWe": "We", "textWrap": "Wrap", - "textWrappingStyle": "Wrapping Style" + "textWrappingStyle": "Wrapping Style", + "textInvalidName": "The file name cannot contain any of the following characters: " }, "Error": { "convertationTimeoutText": "Conversion timeout exceeded.", diff --git a/apps/documenteditor/mobile/src/controller/Main.jsx b/apps/documenteditor/mobile/src/controller/Main.jsx index 63e05a2d87..8e5538cd26 100644 --- a/apps/documenteditor/mobile/src/controller/Main.jsx +++ b/apps/documenteditor/mobile/src/controller/Main.jsx @@ -105,13 +105,14 @@ class MainController extends Component { value = localStorage.getItem("de-mobile-allow-macros-request"); this.props.storeApplicationSettings.changeMacrosRequest((value !== null) ? parseInt(value) : 0); + this.props.storeAppOptions.wopi = this.editorConfig.wopi; + Common.Notifications.trigger('configOptionsFill'); }; const loadDocument = data => { this.permissions = {}; this.document = data.doc; - let docInfo = {}; if (data.doc) { diff --git a/apps/documenteditor/mobile/src/controller/Toolbar.jsx b/apps/documenteditor/mobile/src/controller/Toolbar.jsx index a9182eced5..1fdef499ac 100644 --- a/apps/documenteditor/mobile/src/controller/Toolbar.jsx +++ b/apps/documenteditor/mobile/src/controller/Toolbar.jsx @@ -27,9 +27,9 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeReview', 'sto const disabledEditControls = storeToolbarSettings.disabledEditControls; const disabledSettings = storeToolbarSettings.disabledSettings; const showEditDocument = !appOptions.isEdit && appOptions.canEdit && appOptions.canRequestEditRights; - const docInfo = props.storeDocumentInfo; - const docExt = docInfo.dataDoc ? docInfo.dataDoc.fileType : ''; - const docTitle = docInfo.dataDoc ? docInfo.dataDoc.title : ''; + const storeDocumentInfo = props.storeDocumentInfo; + const docExt = storeDocumentInfo.dataDoc ? storeDocumentInfo.dataDoc.fileType : ''; + const docTitle = storeDocumentInfo.dataDoc ? storeDocumentInfo.dataDoc.title : ''; useEffect(() => { Common.Gateway.on('init', loadConfig); @@ -212,7 +212,24 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeReview', 'sto title: t('Toolbar.textRenameFile'), text : t('Toolbar.textEnterNewFileName'), content: Device.ios ? - '
' : '', + `
+ +
` : + ``, cssClass: 'dlg-adv-options', buttons: [ { @@ -225,6 +242,7 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeReview', 'sto close: false, onClick: () => { const titleFieldValue = document.querySelector('#modal-title').value; + if(titleFieldValue.trim().length) { changeTitle(titleFieldValue); f7.dialog.close(); @@ -254,16 +272,48 @@ const ToolbarController = inject('storeAppOptions', 'users', 'storeReview', 'sto }).open(); } + const cutDocName = name => { + if(name.length <= docExt.length) return name; + const idx = name.length - docExt.length; + + return name.substring(idx) == docExt ? name.substring(0, idx) : name; + }; + const changeTitle = (name) => { const api = Common.EditorApi.get(); - const storeDocumentInfo = props.storeDocumentInfo; const docInfo = storeDocumentInfo.docInfo; - const title = `${name}.${docExt}`; + const currentTitle = `${name}.${docExt}`; + let formatName = name.trim(); - storeDocumentInfo.changeTitle(title); - docInfo.put_Title(title); - storeDocumentInfo.setDocInfo(docInfo); - api.asc_setDocInfo(docInfo); + if(formatName.length > 0 && cutDocName(currentTitle) !== formatName) { + if(/[\t*\+:\"<>?|\\\\/]/gim.test(formatName)) { + f7.dialog.create({ + title: t('Edit.notcriticalErrorTitle'), + text: t('Edit.textInvalidName') + '*+:\"<>?|\/', + buttons: [ + { + text: t('Edit.textOk'), + close: true + } + ] + }).open(); + } else { + const wopi = appOptions.wopi; + formatName = cutDocName(formatName); + + if(wopi) { + api.asc_wopi_renameFile(formatName); + } else { + Common.Gateway.requestRename(formatName); + } + + const newTitle = `${formatName}.${docExt}`; + + storeDocumentInfo.changeTitle(newTitle); + docInfo.put_Title(newTitle); + storeDocumentInfo.setDocInfo(docInfo); + } + } } const closeHistory = () => {