From f742cc01a21653662eed4371a6b2eb67aa96ccb5 Mon Sep 17 00:00:00 2001 From: SergeyEzhin Date: Fri, 12 Jul 2024 19:29:14 +0300 Subject: [PATCH 1/2] [DE PE SSE mobile] Adding region parameter for measurement units --- .../mobile/src/controller/Main.jsx | 33 ++++++++++ .../mobile/src/store/appOptions.js | 1 + .../mobile/src/controller/Main.jsx | 32 ++++++++++ .../mobile/src/store/appOptions.js | 1 + .../mobile/src/controller/Main.jsx | 61 +++++++++++++------ 5 files changed, 111 insertions(+), 17 deletions(-) diff --git a/apps/documenteditor/mobile/src/controller/Main.jsx b/apps/documenteditor/mobile/src/controller/Main.jsx index 908f9ad767..29c547ba0c 100644 --- a/apps/documenteditor/mobile/src/controller/Main.jsx +++ b/apps/documenteditor/mobile/src/controller/Main.jsx @@ -186,6 +186,9 @@ class MainController extends Component { this.props.storeAppOptions.wopi = this.editorConfig.wopi; Common.Notifications.trigger('configOptionsFill'); + + this.loadDefaultMetricSettings(); + }; const loadDocument = data => { @@ -496,6 +499,36 @@ class MainController extends Component { } } + loadDefaultMetricSettings() { + const appOptions = this.props.storeAppOptions; + let region = ''; + + if (appOptions.location) { + console.log("Obsolete: The 'location' parameter of the 'editorConfig' section is deprecated. Please use 'region' parameter in the 'editorConfig' section instead."); + region = appOptions.location; + } else if (appOptions.region) { + let val = appOptions.region; + val = Common.util.LanguageInfo.getLanguages().hasOwnProperty(val) ? Common.util.LanguageInfo.getLocalLanguageName(val)[0] : val; + + if (val && typeof val === 'string') { + let arr = val.split(/[\-_]/); + if (arr.length > 1) region = arr[arr.length - 1] + } + } else { + let arr = (appOptions.lang || 'en').split(/[\-_]/); + + if (arr.length > 1) region = arr[arr.length - 1] + if (!region) { + arr = (navigator.language || '').split(/[\-_]/); + if (arr.length > 1) region = arr[arr.length - 1] + } + } + + if (/^(ca|us)$/i.test(region)) { + Common.Utils.Metric.setDefaultMetric(Common.Utils.Metric.c_MetricUnits.inch); + } + } + changeEditorBrandColorForPdf() { const bodyElement = document.body; bodyElement.classList.add('pdf-view'); diff --git a/apps/documenteditor/mobile/src/store/appOptions.js b/apps/documenteditor/mobile/src/store/appOptions.js index 032bc7519d..10513b6f84 100644 --- a/apps/documenteditor/mobile/src/store/appOptions.js +++ b/apps/documenteditor/mobile/src/store/appOptions.js @@ -125,6 +125,7 @@ export class storeAppOptions { this.createUrl = config.createUrl; this.lang = config.lang ?? 'en'; this.location = (typeof (config.location) == 'string') ? config.location.toLowerCase() : ''; + this.region = (typeof (config.region) == 'string') ? config.region.toLowerCase() : config.region; this.sharingSettingsUrl = config.sharingSettingsUrl; this.canRequestSharingSettings = config.canRequestSharingSettings; this.fileChoiceUrl = config.fileChoiceUrl; diff --git a/apps/presentationeditor/mobile/src/controller/Main.jsx b/apps/presentationeditor/mobile/src/controller/Main.jsx index 236d2e1a14..cf0abeacdb 100644 --- a/apps/presentationeditor/mobile/src/controller/Main.jsx +++ b/apps/presentationeditor/mobile/src/controller/Main.jsx @@ -128,6 +128,8 @@ class MainController extends Component { value = LocalStorage.getItem("pe-mobile-allow-macros-request"); this.props.storeApplicationSettings.changeMacrosRequest((value !== null) ? parseInt(value) : 0); + + this.loadDefaultMetricSettings(); }; const loadDocument = data => { @@ -317,6 +319,36 @@ class MainController extends Component { window.onunload = this.onUnload.bind(this); } + loadDefaultMetricSettings() { + const appOptions = this.props.storeAppOptions; + let region = ''; + + if (appOptions.location) { + console.log("Obsolete: The 'location' parameter of the 'editorConfig' section is deprecated. Please use 'region' parameter in the 'editorConfig' section instead."); + region = appOptions.location; + } else if (appOptions.region) { + let val = appOptions.region; + val = Common.util.LanguageInfo.getLanguages().hasOwnProperty(val) ? Common.util.LanguageInfo.getLocalLanguageName(val)[0] : val; + + if (val && typeof val === 'string') { + let arr = val.split(/[\-_]/); + if (arr.length > 1) region = arr[arr.length - 1] + } + } else { + let arr = (appOptions.lang || 'en').split(/[\-_]/); + + if (arr.length > 1) region = arr[arr.length - 1] + if (!region) { + arr = (navigator.language || '').split(/[\-_]/); + if (arr.length > 1) region = arr[arr.length - 1] + } + } + + if (/^(ca|us)$/i.test(region)) { + Common.Utils.Metric.setDefaultMetric(Common.Utils.Metric.c_MetricUnits.inch); + } + } + onDocumentModifiedChanged () { const isModified = this.api.asc_isDocumentCanSave(); if (this._state.isDocModified !== isModified) { diff --git a/apps/presentationeditor/mobile/src/store/appOptions.js b/apps/presentationeditor/mobile/src/store/appOptions.js index ad9351c67f..606fb9486e 100644 --- a/apps/presentationeditor/mobile/src/store/appOptions.js +++ b/apps/presentationeditor/mobile/src/store/appOptions.js @@ -60,6 +60,7 @@ export class storeAppOptions { this.createUrl = config.createUrl; this.lang = config.lang; this.location = (typeof (config.location) == 'string') ? config.location.toLowerCase() : ''; + this.region = (typeof (config.region) == 'string') ? config.region.toLowerCase() : config.region; this.sharingSettingsUrl = config.sharingSettingsUrl; this.fileChoiceUrl = config.fileChoiceUrl; this.mergeFolderUrl = config.mergeFolderUrl; diff --git a/apps/spreadsheeteditor/mobile/src/controller/Main.jsx b/apps/spreadsheeteditor/mobile/src/controller/Main.jsx index 2381a6a606..f41091e0cb 100644 --- a/apps/spreadsheeteditor/mobile/src/controller/Main.jsx +++ b/apps/spreadsheeteditor/mobile/src/controller/Main.jsx @@ -188,7 +188,7 @@ class MainController extends Component { EditorUIController.isSupportEditFeature(); this.editorConfig = Object.assign({}, this.editorConfig, data.config); - this.appOptions.lang = this.editorConfig.lang; + this.appOptions.lang = this.editorConfig.lang; const appOptions = this.props.storeAppOptions; appOptions.setConfigOptions(this.editorConfig, _t); @@ -204,30 +204,27 @@ class MainController extends Component { if (value !== null) { this.api.asc_setLocale(parseInt(value)); } else { - value = appOptions.region; - value = Common.util.LanguageInfo.getLanguages().hasOwnProperty(value) ? value : Common.util.LanguageInfo.getLocalLanguageCode(value); - if (value !== null) { - value = parseInt(value); - } else { - value = (appOptions.lang) ? parseInt(Common.util.LanguageInfo.getLocalLanguageCode(appOptions.lang)) : 0x0409; - } - this.api.asc_setLocale(value); + value = appOptions.region; + value = Common.util.LanguageInfo.getLanguages().hasOwnProperty(value) ? value : Common.util.LanguageInfo.getLocalLanguageCode(value); + if (value !== null) { + value = parseInt(value); + } else { + value = (appOptions.lang) ? parseInt(Common.util.LanguageInfo.getLocalLanguageCode(appOptions.lang)) : 0x0409; + } + this.api.asc_setLocale(value); } - if (appOptions.location == 'us' || appOptions.location == 'ca') { - Common.Utils.Metric.setDefaultMetric(Common.Utils.Metric.c_MetricUnits.inch); - } - - //if (!appOptions.customization || !(appOptions.customization.loaderName || appOptions.customization.loaderLogo)) - //$('#editor_sdk').append('
' + '
'.repeat(2) + '
'); + this.loadDefaultMetricSettings(); value = LocalStorage.getItem("sse-mobile-macros-mode"); + if (value === null) { - value = appOptions.customization ? appOptions.customization.macrosMode : 'warn'; - value = (value === 'enable') ? 1 : (value === 'disable' ? 2 : 0); + value = appOptions.customization ? appOptions.customization.macrosMode : 'warn'; + value = (value === 'enable') ? 1 : (value === 'disable' ? 2 : 0); } else { value = parseInt(value); } + this.props.storeApplicationSettings.changeMacrosSettings(value); value = LocalStorage.getItem("sse-mobile-allow-macros-request"); @@ -395,6 +392,36 @@ class MainController extends Component { } } + loadDefaultMetricSettings() { + const appOptions = this.props.storeAppOptions; + let region = ''; + + if (appOptions.location) { + console.log("Obsolete: The 'location' parameter of the 'editorConfig' section is deprecated. Please use 'region' parameter in the 'editorConfig' section instead."); + region = appOptions.location; + } else if (appOptions.region) { + let val = appOptions.region; + val = Common.util.LanguageInfo.getLanguages().hasOwnProperty(val) ? Common.util.LanguageInfo.getLocalLanguageName(val)[0] : val; + + if (val && typeof val === 'string') { + let arr = val.split(/[\-_]/); + if (arr.length > 1) region = arr[arr.length - 1] + } + } else { + let arr = (appOptions.lang || 'en').split(/[\-_]/); + + if (arr.length > 1) region = arr[arr.length - 1] + if (!region) { + arr = (navigator.language || '').split(/[\-_]/); + if (arr.length > 1) region = arr[arr.length - 1] + } + } + + if (/^(ca|us)$/i.test(region)) { + Common.Utils.Metric.setDefaultMetric(Common.Utils.Metric.c_MetricUnits.inch); + } + } + bindEvents() { $$(window).on('resize', () => { this.api.asc_Resize(); From aa5502d260624d4da00a73e3973b2c73e30a05be Mon Sep 17 00:00:00 2001 From: SergeyEzhin Date: Thu, 18 Jul 2024 16:58:15 +0300 Subject: [PATCH 2/2] [DE PE SSE mobile] Restoring LanguageInfo import --- apps/documenteditor/mobile/src/controller/Main.jsx | 2 +- apps/presentationeditor/mobile/src/controller/Main.jsx | 1 + apps/spreadsheeteditor/mobile/src/controller/Main.jsx | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/documenteditor/mobile/src/controller/Main.jsx b/apps/documenteditor/mobile/src/controller/Main.jsx index 29c547ba0c..de1befa752 100644 --- a/apps/documenteditor/mobile/src/controller/Main.jsx +++ b/apps/documenteditor/mobile/src/controller/Main.jsx @@ -20,7 +20,7 @@ import EncodingController from "./Encoding"; import DropdownListController from "./DropdownList"; import { Device } from '../../../../common/mobile/utils/device'; import { processArrayScripts } from '../../../../common/mobile/utils/processArrayScripts.js'; - +import '../../../../common/main/lib/util/LanguageInfo.js' @inject( "users", "storeAppOptions", diff --git a/apps/presentationeditor/mobile/src/controller/Main.jsx b/apps/presentationeditor/mobile/src/controller/Main.jsx index cf0abeacdb..3c190aa293 100644 --- a/apps/presentationeditor/mobile/src/controller/Main.jsx +++ b/apps/presentationeditor/mobile/src/controller/Main.jsx @@ -17,6 +17,7 @@ import PluginsController from '../../../../common/mobile/lib/controller/Plugins. import { Device } from '../../../../common/mobile/utils/device'; import { Themes } from '../../../../common/mobile/lib/controller/Themes.jsx'; import { processArrayScripts } from '../../../../common/mobile/utils/processArrayScripts.js'; +import '../../../../common/main/lib/util/LanguageInfo.js' @inject( "users", diff --git a/apps/spreadsheeteditor/mobile/src/controller/Main.jsx b/apps/spreadsheeteditor/mobile/src/controller/Main.jsx index f41091e0cb..47b46ed26e 100644 --- a/apps/spreadsheeteditor/mobile/src/controller/Main.jsx +++ b/apps/spreadsheeteditor/mobile/src/controller/Main.jsx @@ -24,6 +24,7 @@ import { StatusbarController } from "./Statusbar"; import { Device } from '../../../../common/mobile/utils/device'; import { Themes } from '../../../../common/mobile/lib/controller/Themes.jsx'; import { processArrayScripts } from '../../../../common/mobile/utils/processArrayScripts.js'; +import '../../../../common/main/lib/util/LanguageInfo.js' @inject( "users",