diff --git a/apps/spreadsheeteditor/mobile/locale/en.json b/apps/spreadsheeteditor/mobile/locale/en.json index e1b4b968c..773ef247b 100644 --- a/apps/spreadsheeteditor/mobile/locale/en.json +++ b/apps/spreadsheeteditor/mobile/locale/en.json @@ -29,6 +29,12 @@ "menuEdit": "Edit", "menuDelete": "Delete" }, + "Toolbar": { + "dlgLeaveTitleText": "You leave the application", + "dlgLeaveMsgText": "You have unsaved changes in this document. Click \\'Stay on this Page\\' to await the autosave of the document. Click \\'Leave this Page\\' to discard all the unsaved changes.", + "leaveButtonText": "Leave this Page", + "stayButtonText": "Stay on this Page" + }, "View" : { "Add" : { "textChart": "Chart", diff --git a/apps/spreadsheeteditor/mobile/src/controller/Main.jsx b/apps/spreadsheeteditor/mobile/src/controller/Main.jsx index afd6c2524..2b34515cb 100644 --- a/apps/spreadsheeteditor/mobile/src/controller/Main.jsx +++ b/apps/spreadsheeteditor/mobile/src/controller/Main.jsx @@ -278,6 +278,8 @@ class MainController extends Component { me.api.asc_getWorksheetsCount(); me.api.asc_showWorksheet(me.api.asc_getActiveWorksheetIndex()); + this.applyLicense(); + Common.Gateway.documentReady(); f7.emit('resize'); } @@ -291,6 +293,10 @@ class MainController extends Component { // } } + applyLicense () { + Common.Notifications.trigger('toolbar:activatecontrols'); + } + render() { return ( diff --git a/apps/spreadsheeteditor/mobile/src/controller/Toolbar.jsx b/apps/spreadsheeteditor/mobile/src/controller/Toolbar.jsx new file mode 100644 index 000000000..16dd1b657 --- /dev/null +++ b/apps/spreadsheeteditor/mobile/src/controller/Toolbar.jsx @@ -0,0 +1,207 @@ +import React, { useEffect, useState } from 'react'; +import { inject } from 'mobx-react'; +import { f7 } from 'framework7-react'; +import { useTranslation } from 'react-i18next'; +import ToolbarView from "../view/Toolbar"; + +const ToolbarController = inject('storeAppOptions', 'users', 'storeSpreadsheetInfo')(props => { + const {t} = useTranslation(); + const _t = t("Toolbar", { returnObjects: true }); + + const appOptions = props.storeAppOptions; + const isDisconnected = props.users.isDisconnected; + const displayCollaboration = props.users.hasEditUsers || appOptions.canViewComments; + const docTitle = props.storeSpreadsheetInfo.dataDoc ? props.storeSpreadsheetInfo.dataDoc.title : ''; + + useEffect(() => { + const onDocumentReady = () => { + const api = Common.EditorApi.get(); + api.asc_registerCallback('asc_onCanUndoChanged', onApiCanUndo); + api.asc_registerCallback('asc_onCanRedoChanged', onApiCanRedo); + api.asc_registerCallback('asc_onSelectionChanged', onApiSelectionChanged); + api.asc_registerCallback('asc_onWorkbookLocked', onApiSelectionChanged); + api.asc_registerCallback('asc_onWorksheetLocked', onApiSelectionChanged); + api.asc_registerCallback('asc_onActiveSheetChanged', onApiActiveSheetChanged); + api.asc_registerCallback('asc_onCoAuthoringDisconnect', onCoAuthoringDisconnect); + + Common.Notifications.on('api:disconnect', onCoAuthoringDisconnect); + Common.Notifications.on('toolbar:activatecontrols', activateControls); + Common.Notifications.on('toolbar:deactivateeditcontrols', deactivateEditControls); + Common.Notifications.on('goback', goBack); + Common.Notifications.on('sheet:active', onApiActiveSheetChanged); + }; + if ( !Common.EditorApi ) { + Common.Notifications.on('document:ready', onDocumentReady); + Common.Gateway.on('init', loadConfig); + } else { + onDocumentReady(); + } + + return () => { + Common.Notifications.off('document:ready', onDocumentReady); + Common.Notifications.off('api:disconnect', onCoAuthoringDisconnect); + Common.Notifications.off('toolbar:activatecontrols', activateControls); + Common.Notifications.off('toolbar:deactivateeditcontrols', deactivateEditControls); + Common.Notifications.off('goback', goBack); + Common.Notifications.off('sheet:active', onApiActiveSheetChanged); + + const api = Common.EditorApi.get(); + api.asc_unregisterCallback('asc_onCanUndoChanged', onApiCanUndo); + api.asc_unregisterCallback('asc_onCanRedoChanged', onApiCanRedo); + //api.asc_unregisterCallback('asc_onSelectionChanged', onApiSelectionChanged); TO DO + api.asc_unregisterCallback('asc_onWorkbookLocked', onApiSelectionChanged); + api.asc_unregisterCallback('asc_onWorksheetLocked', onApiSelectionChanged); + api.asc_unregisterCallback('asc_onActiveSheetChanged', onApiActiveSheetChanged); + api.asc_unregisterCallback('asc_onCoAuthoringDisconnect', onCoAuthoringDisconnect); + } + }); + + // Back button + const [isShowBack, setShowBack] = useState(false); + const loadConfig = (data) => { + if (data && data.config && data.config.canBackToFolder !== false && + data.config.customization && data.config.customization.goback && + (data.config.customization.goback.url || data.config.customization.goback.requestClose && data.config.canRequestClose)) { + setShowBack(true); + } + }; + const onBack = () => { + const api = Common.EditorApi.get(); + if (api.asc_isDocumentModified()) { + f7.dialog.create({ + title : _t.dlgLeaveTitleText, + text : _t.dlgLeaveMsgText, + verticalButtons: true, + buttons : [ + { + text: _t.leaveButtonText, + onClick: function() { + goBack(); + } + }, + { + text: _t.stayButtonText, + bold: true + } + ] + }).open(); + } else { + goBack(); + } + }; + const goBack = (current) => { + //if ( !Common.Controllers.Desktop.process('goback') ) { + if (appOptions.customization.goback.requestClose && appOptions.canRequestClose) { + Common.Gateway.requestClose(); + } else { + const href = appOptions.customization.goback.url; + if (!current && appOptions.customization.goback.blank !== false) { + window.open(href, "_blank"); + } else { + parent.location.href = href; + } + } + //} + } + + // Undo and Redo + const [isCanUndo, setCanUndo] = useState(false); + const [isCanRedo, setCanRedo] = useState(false); + const onApiCanUndo = (can) => { + if (isDisconnected) return; + setCanUndo(can); + }; + const onApiCanRedo = (can) => { + if (isDisconnected) return; + setCanRedo(can); + }; + const onUndo = () => { + const api = Common.EditorApi.get(); + if (api) { + api.asc_Undo(); + } + }; + const onRedo = () => { + const api = Common.EditorApi.get(); + if (api) { + api.asc_Redo(); + } + } + + const [disabledEditControls, setDisabledEditControls] = useState(false); + const onApiSelectionChanged = (cellInfo) => { + if (isDisconnected) return; + + const api = Common.EditorApi.get(); + const info = !!cellInfo ? cellInfo : api.asc_getCellInfo(); + let islocked = false; + + switch (info.asc_getSelectionType()) { + case Asc.c_oAscSelectionType.RangeChart: + case Asc.c_oAscSelectionType.RangeImage: + case Asc.c_oAscSelectionType.RangeShape: + case Asc.c_oAscSelectionType.RangeChartText: + case Asc.c_oAscSelectionType.RangeShapeText: + const objects = api.asc_getGraphicObjectProps(); + for ( let i in objects ) { + if ( objects[i].asc_getObjectType() == Asc.c_oAscTypeSelectElement.Image ) { + if ((islocked = objects[i].asc_getObjectValue().asc_getLocked())) + break; + } + } + break; + default: + islocked = info.asc_getLocked(); + } + + setDisabledEditControls(islocked); + }; + + const onApiActiveSheetChanged = (index) => { + Common.Notifications.trigger('comments:filterchange', ['doc', 'sheet' + Common.EditorApi.get().asc_getWorksheetId(index)], false ); + }; + + const [disabledSettings, setDisabledSettings] = useState(false); + const deactivateEditControls = (enableDownload) => { + setDisabledEditControls(true); + if (enableDownload) { + //DE.getController('Settings').setMode({isDisconnected: true, enableDownload: enableDownload}); + } else { + setDisabledSettings(true); + } + }; + + + const [disabledControls, setDisabledControls] = useState(true); + const activateControls = () => { + setDisabledControls(false); + }; + + const onCoAuthoringDisconnect = (enableDownload) => { + deactivateEditControls(enableDownload); + setCanUndo(false); + setCanRedo(false); + f7.popover.close(); + f7.sheet.close(); + f7.popup.close(); + }; + + return ( + + ) +}); + +export {ToolbarController as Toolbar}; \ No newline at end of file diff --git a/apps/spreadsheeteditor/mobile/src/page/main.jsx b/apps/spreadsheeteditor/mobile/src/page/main.jsx index 2f7b3713d..e02028e24 100644 --- a/apps/spreadsheeteditor/mobile/src/page/main.jsx +++ b/apps/spreadsheeteditor/mobile/src/page/main.jsx @@ -1,21 +1,21 @@ import React, { Component } from 'react'; -import { Page, View, Navbar, NavLeft, NavRight, Link, Icon } from 'framework7-react'; +import { Page, View, Navbar, Subnavbar, Icon } from 'framework7-react'; +import { observer, inject } from "mobx-react"; -// import EditOptions from '../view/edit/Edit'; import Settings from '../view/settings/Settings'; import CollaborationView from '../../../../common/mobile/lib/view/collaboration/Collaboration.jsx' import CellEditor from '../controller/CellEditor'; import Statusbar from '../controller/StatusBar' import AddOptions from "../view/add/Add"; import EditOptions from "../view/edit/Edit"; -import { Device } from '../../../../common/mobile/utils/device'; import { Search, SearchSettings } from '../controller/Search'; import { f7 } from 'framework7-react'; import {FunctionGroups} from "../controller/add/AddFunction"; import ContextMenu from '../controller/ContextMenu'; +import { Toolbar } from "../controller/Toolbar"; -export default class MainPage extends Component { +class MainPage extends Component { constructor(props) { super(props); this.state = { @@ -61,23 +61,18 @@ export default class MainPage extends Component { }; render() { + const appOptions = this.props.storeAppOptions; + const config = appOptions.config; + const showLogo = !(appOptions.canBrandingExt && (config.customization && (config.customization.loaderName || config.customization.loaderLogo))); return ( - + {/* Top Navbar */} - - {/*
*/} - - - - - - this.handleClickToOpenOptions('edit')}> - this.handleClickToOpenOptions('add')}> - { Device.phone ? null : } - this.handleClickToOpenOptions('coauth')}> - this.handleClickToOpenOptions('settings')}> - - + + {showLogo &&
} + + + +
this.handleClickToOpenOptions('add', {panels: panels, button: button})}/> {/* Page content */} @@ -106,4 +101,6 @@ export default class MainPage extends Component {
) } -}; \ No newline at end of file +} + +export default inject("storeAppOptions")(observer(MainPage)); \ No newline at end of file diff --git a/apps/spreadsheeteditor/mobile/src/store/appOptions.js b/apps/spreadsheeteditor/mobile/src/store/appOptions.js index bb3f69a2d..75900a131 100644 --- a/apps/spreadsheeteditor/mobile/src/store/appOptions.js +++ b/apps/spreadsheeteditor/mobile/src/store/appOptions.js @@ -12,8 +12,6 @@ export class storeAppOptions { isEdit = false; config = {}; - - isEdit = false; canViewComments = false; setConfigOptions (config) { diff --git a/apps/spreadsheeteditor/mobile/src/view/Toolbar.jsx b/apps/spreadsheeteditor/mobile/src/view/Toolbar.jsx new file mode 100644 index 000000000..26887d95b --- /dev/null +++ b/apps/spreadsheeteditor/mobile/src/view/Toolbar.jsx @@ -0,0 +1,33 @@ +import React, {Fragment} from 'react'; +import {NavLeft, NavRight, NavTitle, Link, Icon} from 'framework7-react'; +import { Device } from '../../../../common/mobile/utils/device'; +import EditorUIController from '../lib/patch' + +const ToolbarView = props => { + return ( + + + {props.isShowBack && } + {props.isEdit && EditorUIController.toolbarOptions && EditorUIController.toolbarOptions.getUndoRedo({ + disabledUndo: !props.isCanUndo, + disabledRedo: !props.isCanRedo, + onUndoClick: props.onUndo, + onRedoClick: props.onRedo + })} + + {!Device.phone && {props.docTitle}} + + {props.isEdit && EditorUIController.toolbarOptions && EditorUIController.toolbarOptions.getEditOptions({ + disabled: props.disabledEditControls || props.disabledControls, + onEditClick: () => props.openOptions('edit'), + onAddClick: () => props.openOptions('add') + })} + { Device.phone ? null : } + {props.displayCollaboration && props.openOptions('coauth')}>} + props.openOptions('settings')}> + + + ) +}; + +export default ToolbarView; \ No newline at end of file