[mobile] Open add comment from context menu

This commit is contained in:
JuliaSvinareva 2021-03-05 18:23:35 +03:00
parent 7cf42452ae
commit 79e1acb89d
6 changed files with 48 additions and 27 deletions

View file

@ -218,8 +218,20 @@ class CommentsController extends Component {
class AddCommentController extends Component { class AddCommentController extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.closeAddComment = this.closeAddComment.bind(this);
this.getUserInfo = this.getUserInfo.bind(this); this.getUserInfo = this.getUserInfo.bind(this);
this.onAddNewComment = this.onAddNewComment.bind(this); this.onAddNewComment = this.onAddNewComment.bind(this);
this.state = {
isOpen: false
};
Common.Notifications.on('addcomment', () => {
this.setState({isOpen: true});
});
}
closeAddComment () {
this.setState({isOpen: false});
} }
getUserInfo () { getUserInfo () {
this.currentUser = this.props.users.currentUser; this.currentUser = this.props.users.currentUser;
@ -255,13 +267,8 @@ class AddCommentController extends Component {
return false; return false;
} }
render() { render() {
const isOpen = this.props.storeComments.isOpenAddComment;
let userInfo;
if (isOpen) {
userInfo = this.getUserInfo();
}
return( return(
isOpen ? <AddComment userInfo={userInfo} onAddNewComment={this.onAddNewComment} /> : null this.state.isOpen ? <AddComment userInfo={this.getUserInfo()} onAddNewComment={this.onAddNewComment} closeAddComment={this.closeAddComment}/> : null
) )
} }
} }

View file

@ -102,15 +102,6 @@ export class storeComments {
return false; return false;
} }
// Add comment modal window
@observable isOpenAddComment = false;
@action openAddComment (open) {
if (open !== this.isOpenAddComment) {
this.isOpenAddComment = open;
}
}
// Edit comment // Edit comment
currentComment = null; currentComment = null;
@observable isOpenEditComment = false; @observable isOpenEditComment = false;

View file

@ -19,7 +19,7 @@ const AddCommentPopup = inject("storeComments")(observer(props => {
<Navbar> <Navbar>
<NavLeft> <NavLeft>
<Link onClick={() => { <Link onClick={() => {
props.storeComments.openAddComment(false); props.closeAddComment();
f7.popup.close('.add-comment-popup'); f7.popup.close('.add-comment-popup');
}}>{_t.textCancel}</Link> }}>{_t.textCancel}</Link>
</NavLeft> </NavLeft>
@ -28,7 +28,7 @@ const AddCommentPopup = inject("storeComments")(observer(props => {
<Link className={stateText.length === 0 && 'disabled'} <Link className={stateText.length === 0 && 'disabled'}
onClick={() => { onClick={() => {
if (props.onAddNewComment(stateText, false)) { if (props.onAddNewComment(stateText, false)) {
props.storeComments.openAddComment(false); props.closeAddComment();
f7.popup.close('.add-comment-popup'); f7.popup.close('.add-comment-popup');
} }
}}> }}>
@ -87,14 +87,14 @@ const AddCommentDialog = inject("storeComments")(observer(props => {
const cancel = document.getElementById('comment-cancel'); const cancel = document.getElementById('comment-cancel');
cancel.addEventListener('click', () => { cancel.addEventListener('click', () => {
f7.dialog.close(); f7.dialog.close();
props.storeComments.openAddComment(false); props.closeAddComment();
}); });
const done = document.getElementById('comment-done'); const done = document.getElementById('comment-done');
done.addEventListener('click', () => { done.addEventListener('click', () => {
const value = document.getElementById('comment-text').value; const value = document.getElementById('comment-text').value;
if (value.length > 0 && props.onAddNewComment(value, false)) { if (value.length > 0 && props.onAddNewComment(value, false)) {
f7.dialog.close(); f7.dialog.close();
props.storeComments.openAddComment(false); props.closeAddComment();
} }
}); });
const area = document.getElementById('comment-text'); const area = document.getElementById('comment-text');
@ -118,8 +118,8 @@ const AddCommentDialog = inject("storeComments")(observer(props => {
const AddComment = props => { const AddComment = props => {
return ( return (
Device.phone ? Device.phone ?
<AddCommentPopup userInfo={props.userInfo} onAddNewComment={props.onAddNewComment} /> : <AddCommentPopup {...props} /> :
<AddCommentDialog userInfo={props.userInfo} onAddNewComment={props.onAddNewComment} /> <AddCommentDialog {...props} />
) )
}; };

View file

@ -47,6 +47,12 @@ class ContextMenu extends ContextMenuController {
onMenuItemClick(action) { onMenuItemClick(action) {
super.onMenuItemClick(action); super.onMenuItemClick(action);
switch (action) {
case 'addcomment':
Common.Notifications.trigger('addcomment');
break;
}
console.log("click context menu item: " + action); console.log("click context menu item: " + action);
} }
@ -78,7 +84,7 @@ class ContextMenu extends ContextMenuController {
}); });
} }
if ( canViewComments && this.isComments && isEdit ) { if ( canViewComments && this.isComments && !isEdit ) {
itemsText.push({ itemsText.push({
caption: /*me.menuViewComment*/'View Comment', caption: /*me.menuViewComment*/'View Comment',
event: 'viewcomment' event: 'viewcomment'
@ -152,6 +158,24 @@ class ContextMenu extends ContextMenuController {
}); });
} }
// For test
if ( this.isComments && canViewComments ) {
itemsText.push({
caption: /*me.menuViewComment*/'View Comment',
event: 'viewcomment'
});
}
const isObject = isShape || isChart || isImage || isTable;
const hideAddComment = !canViewComments || api.can_AddQuotedComment() === false || lockedText || lockedTable || lockedImage || lockedHeader || (!isText && isObject);
if ( !hideAddComment ) {
itemsText.push({
caption: /*me.menuAddComment*/'Add Comment',
event: 'addcomment'
});
}
// end test
if ( isTable && api.CheckBeforeMergeCells() && !lockedTable && !lockedHeader) { if ( isTable && api.CheckBeforeMergeCells() && !lockedTable && !lockedHeader) {
itemsText.push({ itemsText.push({
caption: /*me.menuMerge*/'Merge', caption: /*me.menuMerge*/'Merge',
@ -215,14 +239,14 @@ class ContextMenu extends ContextMenuController {
}); });
} }
const isObject = isShape || isChart || isImage || isTable; /*const isObject = isShape || isChart || isImage || isTable;
const hideAddComment = !canViewComments || api.can_AddQuotedComment() === false || lockedText || lockedTable || lockedImage || lockedHeader || (!isText && isObject); const hideAddComment = !canViewComments || api.can_AddQuotedComment() === false || lockedText || lockedTable || lockedImage || lockedHeader || (!isText && isObject);
if ( !hideAddComment ) { if ( !hideAddComment ) {
itemsText.push({ itemsText.push({
caption: /*me.menuAddComment*/'Add Comment', caption: 'Add Comment',
event: 'addcomment' event: 'addcomment'
}); });
} }*/
} }
} }

View file

@ -8,7 +8,6 @@ import EditOptions from '../view/edit/Edit';
import AddOptions from '../view/add/Add'; import AddOptions from '../view/add/Add';
import Settings from '../view/settings/Settings'; import Settings from '../view/settings/Settings';
import Collaboration from '../../../../common/mobile/lib/view/collaboration/Collaboration.jsx' import Collaboration from '../../../../common/mobile/lib/view/collaboration/Collaboration.jsx'
import { AddCommentController } from '../../../../common/mobile/lib/controller/collaboration/Comments.jsx';
import { Device } from '../../../../common/mobile/utils/device' import { Device } from '../../../../common/mobile/utils/device'
import { Search, SearchSettings } from '../controller/Search'; import { Search, SearchSettings } from '../controller/Search';
import ContextMenu from '../controller/ContextMenu'; import ContextMenu from '../controller/ContextMenu';

View file

@ -202,7 +202,7 @@ const AddOther = props => {
<List> <List>
<ListItem title={_t.textComment} onClick={() => { <ListItem title={_t.textComment} onClick={() => {
props.closeModal(); props.closeModal();
props.storeComments.openAddComment(true); Common.Notifications.trigger('addcomment');
}}> }}>
<Icon slot="media" icon="icon-insert-comment"></Icon> <Icon slot="media" icon="icon-insert-comment"></Icon>
</ListItem> </ListItem>