2021-03-23 13:43:10 +00:00
|
|
|
import React, { Fragment } from 'react';
|
2021-03-24 17:50:09 +00:00
|
|
|
import { View, Toolbar, Link, Icon, Popover, List, ListButton, Actions, ActionsGroup, ActionsButton } from 'framework7-react';
|
2020-12-28 20:52:32 +00:00
|
|
|
import { observer, inject } from "mobx-react";
|
2021-03-23 13:43:10 +00:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2021-03-24 17:50:09 +00:00
|
|
|
import { Device } from '../../../../common/mobile/utils/device';
|
2020-12-15 21:17:26 +00:00
|
|
|
|
|
|
|
const viewStyle = {
|
|
|
|
height: 30
|
|
|
|
};
|
2020-12-10 13:14:52 +00:00
|
|
|
|
2020-12-28 20:52:32 +00:00
|
|
|
const StatusbarView = inject('sheets')(observer(props => {
|
2021-03-23 13:43:10 +00:00
|
|
|
const { t } = useTranslation();
|
|
|
|
const _t = t('Statusbar', {returnObjects: true});
|
2021-03-24 17:50:09 +00:00
|
|
|
const isAndroid = Device.android;
|
|
|
|
const isPhone = Device.isPhone;
|
2020-12-28 20:52:32 +00:00
|
|
|
const { sheets } = props;
|
2021-03-23 22:46:37 +00:00
|
|
|
const hiddenSheets = sheets.hiddensheets;
|
2021-03-22 16:57:40 +00:00
|
|
|
const getTabClassList = model => `tab ${model.active ? 'active' : ''} ${model.locked ? 'locked' : ''}`;
|
2021-03-24 17:50:09 +00:00
|
|
|
const $boxTabs = $$('.sheet-tabs');
|
|
|
|
// $boxTabs.css('position', 'absolute');
|
|
|
|
|
|
|
|
$boxTabs.on('touchstart', onTouchStart);
|
|
|
|
$boxTabs.on('touchmove', onTouchMove);
|
|
|
|
$boxTabs.on('touchend', onTouchEnd);
|
|
|
|
|
|
|
|
let touch = {};
|
|
|
|
|
|
|
|
function hasInvisible() {
|
|
|
|
let _left_bound_ = $boxTabs.offset().left,
|
|
|
|
_right_bound_ = _left_bound_ + $boxTabs.width();
|
|
|
|
|
|
|
|
// console.log(_left_bound_);
|
|
|
|
// console.log(_right_bound_);
|
|
|
|
|
|
|
|
let tab = $$('.sheet-tabs li')[0];
|
|
|
|
let rect = tab.getBoundingClientRect();
|
|
|
|
|
|
|
|
if (!(rect.left < _left_bound_)) {
|
|
|
|
tab = $$('.sheet-tabs li')[$$('.sheet-tabs li').length - 1];
|
|
|
|
rect = tab.getBoundingClientRect();
|
|
|
|
|
|
|
|
if (!(rect.right > _right_bound_))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTouchStart(e) {
|
|
|
|
if (hasInvisible()) {
|
|
|
|
// console.log(e);
|
|
|
|
let touches = e.changedTouches;
|
|
|
|
touch.startx = touches[0].clientX;
|
|
|
|
touch.scrollx = $boxTabs.scrollLeft();
|
|
|
|
// console.log(touch.scrollx);
|
|
|
|
|
|
|
|
touch.timer = setTimeout(function () {
|
|
|
|
// touch.longtouch = true;
|
|
|
|
}, 500);
|
|
|
|
// e.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTouchMove(e) {
|
|
|
|
if (touch.startx !== undefined) {
|
|
|
|
// console.log(e);
|
|
|
|
let touches = e.changedTouches;
|
|
|
|
|
|
|
|
if (touch.longtouch) {}
|
|
|
|
else {
|
|
|
|
if (touch.timer) clearTimeout(touch.timer), delete touch.timer;
|
|
|
|
let valueLeft = touch.scrollx + (touch.startx - touches[0].clientX);
|
|
|
|
// console.log(valueLeft);
|
|
|
|
$boxTabs.scrollLeft(valueLeft);
|
|
|
|
}
|
|
|
|
|
|
|
|
// e.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTouchEnd(e) {
|
|
|
|
if (touch.startx !== undefined) {
|
|
|
|
// console.log(e);
|
|
|
|
touch.longtouch = false;
|
|
|
|
delete touch.startx;
|
|
|
|
// e.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
2020-12-28 20:52:32 +00:00
|
|
|
|
2021-03-23 13:43:10 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<View id="idx-statusbar" className="statusbar" style={viewStyle}>
|
2020-12-28 20:52:32 +00:00
|
|
|
<div id="idx-box-add-tab">
|
|
|
|
<Link href="false" id="idx-btn-addtab" className="tab" onClick={e => props.onAddTabClicked()}>
|
|
|
|
<Icon className="icon icon-plus" />
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
<div className="statusbar--box-tabs">
|
|
|
|
<ul className="sheet-tabs bottom">
|
|
|
|
{sheets.sheets.map((model,i) =>
|
|
|
|
model.hidden ? null :
|
2021-03-22 16:57:40 +00:00
|
|
|
<li className={getTabClassList(model)} key={i} onClick={(e) => props.onTabClick(i, e.target)}>
|
2021-03-23 22:46:37 +00:00
|
|
|
<a /* onClick={e => props.onTabClicked(i)} */>{model.name}</a>
|
2020-12-28 20:52:32 +00:00
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</ul>
|
|
|
|
</div>
|
2021-03-23 13:43:10 +00:00
|
|
|
</View>
|
|
|
|
<Popover id="idx-tab-context-menu-popover"
|
2021-03-19 22:38:40 +00:00
|
|
|
className="document-menu"
|
|
|
|
backdrop={false}
|
|
|
|
closeByBackdropClick={false}
|
|
|
|
closeByOutsideClick={false}
|
|
|
|
>
|
|
|
|
<List className="list-block">
|
2021-03-23 13:43:10 +00:00
|
|
|
<ListButton title={_t.textDuplicate} onClick={() => props.onTabMenu('copy')} />
|
|
|
|
<ListButton title={_t.textDelete} onClick={() => props.onTabMenu('del')} />
|
2021-03-24 17:50:09 +00:00
|
|
|
{isPhone || isAndroid ? (
|
|
|
|
<ListButton title={_t.textMore} onClick={() => props.onTabMenu('showMore')} />
|
|
|
|
) : (
|
|
|
|
<Fragment>
|
|
|
|
<ListButton title={_t.textRename} onClick={() => props.onTabMenu('ren')} />
|
|
|
|
<ListButton title={_t.textHide} onClick={() => props.onTabMenu('hide')} />
|
|
|
|
{hiddenSheets.length ? (
|
|
|
|
<ListButton title={_t.textUnhide} onClick={() => props.onTabMenu('unhide')} />
|
|
|
|
): null}
|
|
|
|
</Fragment>
|
|
|
|
)}
|
2021-03-19 22:38:40 +00:00
|
|
|
</List>
|
2021-03-23 13:43:10 +00:00
|
|
|
</Popover>
|
2021-03-24 17:50:09 +00:00
|
|
|
{isPhone || isAndroid ? (
|
|
|
|
<Actions id="idx-tab-menu-actions" backdrop={true} closeByBackdropClick={true}>
|
|
|
|
<ActionsGroup>
|
|
|
|
<ActionsButton onClick={() => props.onTabMenu('ren')}>{_t.textRename}</ActionsButton>
|
|
|
|
<ActionsButton onClick={() => props.onTabMenu('hide')}>{_t.textHide}</ActionsButton>
|
|
|
|
<ActionsButton onClick={() => props.onTabMenu('unhide')}>{_t.textUnhide}</ActionsButton>
|
|
|
|
</ActionsGroup>
|
|
|
|
<ActionsGroup>
|
|
|
|
<ActionsButton>{_t.textCancel}</ActionsButton>
|
|
|
|
</ActionsGroup>
|
|
|
|
</Actions>
|
|
|
|
) : null}
|
2021-03-23 13:43:10 +00:00
|
|
|
{hiddenSheets.length ? (
|
|
|
|
<Popover id="idx-hidden-sheets-popover"
|
|
|
|
className="document-menu"
|
|
|
|
backdrop={false}
|
|
|
|
closeByBackdropClick={false}
|
|
|
|
closeByOutsideClick={false}
|
|
|
|
>
|
|
|
|
<List className="list-block">
|
|
|
|
{hiddenSheets.map(sheet => {
|
|
|
|
return (
|
2021-03-23 22:46:37 +00:00
|
|
|
<ListButton key={sheet.index} data-event={`reveal:${sheet.index}`} title={sheet.name}
|
|
|
|
onClick={() => props.onTabMenu(`reveal:${sheet.index}`)} />
|
2021-03-23 13:43:10 +00:00
|
|
|
)
|
|
|
|
})}
|
|
|
|
</List>
|
|
|
|
</Popover>
|
|
|
|
) : null}
|
|
|
|
</Fragment>
|
2021-03-19 22:38:40 +00:00
|
|
|
)
|
2021-03-23 13:43:10 +00:00
|
|
|
}));
|
2021-03-19 22:38:40 +00:00
|
|
|
|
2021-03-23 13:43:10 +00:00
|
|
|
export {StatusbarView};
|