2021-04-21 18:04:52 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2021-06-18 17:49:51 +00:00
|
|
|
import { inject, observer } from 'mobx-react';
|
2021-04-21 18:04:52 +00:00
|
|
|
import { f7 } from 'framework7-react';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import ToolbarView from "../view/Toolbar";
|
|
|
|
|
2021-07-21 22:10:25 +00:00
|
|
|
const ToolbarController = inject('storeAppOptions', 'users', 'storeSpreadsheetInfo', 'storeFocusObjects', 'storeToolbarSettings')(observer(props => {
|
2021-04-21 18:04:52 +00:00
|
|
|
const {t} = useTranslation();
|
|
|
|
const _t = t("Toolbar", { returnObjects: true });
|
|
|
|
|
|
|
|
const appOptions = props.storeAppOptions;
|
|
|
|
const isDisconnected = props.users.isDisconnected;
|
2021-07-09 13:17:28 +00:00
|
|
|
const isObjectLocked = props.storeFocusObjects.isLocked;
|
2021-04-21 18:04:52 +00:00
|
|
|
const displayCollaboration = props.users.hasEditUsers || appOptions.canViewComments;
|
|
|
|
const docTitle = props.storeSpreadsheetInfo.dataDoc ? props.storeSpreadsheetInfo.dataDoc.title : '';
|
|
|
|
|
2021-06-09 12:18:04 +00:00
|
|
|
const showEditDocument = !appOptions.isEdit && appOptions.canEdit && appOptions.canRequestEditRights;
|
|
|
|
|
2021-07-21 22:10:25 +00:00
|
|
|
const storeToolbarSettings = props.storeToolbarSettings;
|
|
|
|
const isCanUndo = storeToolbarSettings.isCanUndo;
|
|
|
|
const isCanRedo = storeToolbarSettings.isCanRedo;
|
|
|
|
|
2021-04-21 18:04:52 +00:00
|
|
|
useEffect(() => {
|
2021-07-21 22:10:25 +00:00
|
|
|
Common.Gateway.on('init', loadConfig);
|
2021-04-21 18:04:52 +00:00
|
|
|
|
2021-07-21 22:10:25 +00:00
|
|
|
Common.Notifications.on('toolbar:activatecontrols', activateControls);
|
|
|
|
Common.Notifications.on('toolbar:deactivateeditcontrols', deactivateEditControls);
|
|
|
|
Common.Notifications.on('goback', goBack);
|
|
|
|
Common.Notifications.on('sheet:active', onApiActiveSheetChanged);
|
2021-04-21 18:04:52 +00:00
|
|
|
|
2021-06-18 17:49:51 +00:00
|
|
|
if (isDisconnected) {
|
|
|
|
f7.popover.close();
|
|
|
|
f7.sheet.close();
|
|
|
|
f7.popup.close();
|
|
|
|
}
|
|
|
|
|
2021-04-21 18:04:52 +00:00
|
|
|
return () => {
|
|
|
|
Common.Notifications.off('toolbar:activatecontrols', activateControls);
|
|
|
|
Common.Notifications.off('toolbar:deactivateeditcontrols', deactivateEditControls);
|
|
|
|
Common.Notifications.off('goback', goBack);
|
|
|
|
Common.Notifications.off('sheet:active', onApiActiveSheetChanged);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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() {
|
2021-06-08 15:22:28 +00:00
|
|
|
goBack(true);
|
2021-04-21 18:04:52 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: _t.stayButtonText,
|
|
|
|
bold: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}).open();
|
|
|
|
} else {
|
2021-06-08 15:22:28 +00:00
|
|
|
goBack(true);
|
2021-04-21 18:04:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 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);
|
|
|
|
};
|
|
|
|
|
2021-06-09 12:18:04 +00:00
|
|
|
const onEditDocument = () => {
|
|
|
|
Common.Gateway.requestEditRights();
|
|
|
|
};
|
|
|
|
|
2021-04-21 18:04:52 +00:00
|
|
|
return (
|
|
|
|
<ToolbarView openOptions={props.openOptions}
|
|
|
|
isEdit={appOptions.isEdit}
|
|
|
|
docTitle={docTitle}
|
|
|
|
isShowBack={isShowBack}
|
|
|
|
onBack={onBack}
|
|
|
|
isCanUndo={isCanUndo}
|
|
|
|
isCanRedo={isCanRedo}
|
|
|
|
onUndo={onUndo}
|
|
|
|
onRedo={onRedo}
|
|
|
|
disabledControls={disabledControls}
|
2021-07-09 13:17:28 +00:00
|
|
|
disabledEditControls={disabledEditControls || isObjectLocked}
|
2021-04-21 18:04:52 +00:00
|
|
|
disabledSettings={disabledSettings}
|
|
|
|
displayCollaboration={displayCollaboration}
|
2021-06-09 12:18:04 +00:00
|
|
|
showEditDocument={showEditDocument}
|
|
|
|
onEditDocument={onEditDocument}
|
2021-06-18 17:49:51 +00:00
|
|
|
isDisconnected={isDisconnected}
|
2021-04-21 18:04:52 +00:00
|
|
|
/>
|
|
|
|
)
|
2021-06-18 17:49:51 +00:00
|
|
|
}));
|
2021-04-21 18:04:52 +00:00
|
|
|
|
|
|
|
export {ToolbarController as Toolbar};
|