From 79e1acb89d1589db8eb10ca8f31cd1bfe7de3eaa Mon Sep 17 00:00:00 2001 From: JuliaSvinareva Date: Fri, 5 Mar 2021 18:23:35 +0300 Subject: [PATCH] [mobile] Open add comment from context menu --- .../lib/controller/collaboration/Comments.jsx | 19 +++++++---- apps/common/mobile/lib/store/comments.js | 9 ------ .../lib/view/collaboration/Comments.jsx | 12 +++---- .../mobile/src/controller/ContextMenu.jsx | 32 ++++++++++++++++--- apps/documenteditor/mobile/src/page/main.jsx | 1 - .../mobile/src/view/add/AddOther.jsx | 2 +- 6 files changed, 48 insertions(+), 27 deletions(-) diff --git a/apps/common/mobile/lib/controller/collaboration/Comments.jsx b/apps/common/mobile/lib/controller/collaboration/Comments.jsx index b363eb458..331adc103 100644 --- a/apps/common/mobile/lib/controller/collaboration/Comments.jsx +++ b/apps/common/mobile/lib/controller/collaboration/Comments.jsx @@ -218,8 +218,20 @@ class CommentsController extends Component { class AddCommentController extends Component { constructor(props) { super(props); + this.closeAddComment = this.closeAddComment.bind(this); this.getUserInfo = this.getUserInfo.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 () { this.currentUser = this.props.users.currentUser; @@ -255,13 +267,8 @@ class AddCommentController extends Component { return false; } render() { - const isOpen = this.props.storeComments.isOpenAddComment; - let userInfo; - if (isOpen) { - userInfo = this.getUserInfo(); - } return( - isOpen ? : null + this.state.isOpen ? : null ) } } diff --git a/apps/common/mobile/lib/store/comments.js b/apps/common/mobile/lib/store/comments.js index 145434609..ee08defaf 100644 --- a/apps/common/mobile/lib/store/comments.js +++ b/apps/common/mobile/lib/store/comments.js @@ -102,15 +102,6 @@ export class storeComments { return false; } - // Add comment modal window - @observable isOpenAddComment = false; - - @action openAddComment (open) { - if (open !== this.isOpenAddComment) { - this.isOpenAddComment = open; - } - } - // Edit comment currentComment = null; @observable isOpenEditComment = false; diff --git a/apps/common/mobile/lib/view/collaboration/Comments.jsx b/apps/common/mobile/lib/view/collaboration/Comments.jsx index d90cc3886..16f1ba3ce 100644 --- a/apps/common/mobile/lib/view/collaboration/Comments.jsx +++ b/apps/common/mobile/lib/view/collaboration/Comments.jsx @@ -19,7 +19,7 @@ const AddCommentPopup = inject("storeComments")(observer(props => { { - props.storeComments.openAddComment(false); + props.closeAddComment(); f7.popup.close('.add-comment-popup'); }}>{_t.textCancel} @@ -28,7 +28,7 @@ const AddCommentPopup = inject("storeComments")(observer(props => { { if (props.onAddNewComment(stateText, false)) { - props.storeComments.openAddComment(false); + props.closeAddComment(); f7.popup.close('.add-comment-popup'); } }}> @@ -87,14 +87,14 @@ const AddCommentDialog = inject("storeComments")(observer(props => { const cancel = document.getElementById('comment-cancel'); cancel.addEventListener('click', () => { f7.dialog.close(); - props.storeComments.openAddComment(false); + props.closeAddComment(); }); const done = document.getElementById('comment-done'); done.addEventListener('click', () => { const value = document.getElementById('comment-text').value; if (value.length > 0 && props.onAddNewComment(value, false)) { f7.dialog.close(); - props.storeComments.openAddComment(false); + props.closeAddComment(); } }); const area = document.getElementById('comment-text'); @@ -118,8 +118,8 @@ const AddCommentDialog = inject("storeComments")(observer(props => { const AddComment = props => { return ( Device.phone ? - : - + : + ) }; diff --git a/apps/documenteditor/mobile/src/controller/ContextMenu.jsx b/apps/documenteditor/mobile/src/controller/ContextMenu.jsx index 5a09e6f84..3e11cd706 100644 --- a/apps/documenteditor/mobile/src/controller/ContextMenu.jsx +++ b/apps/documenteditor/mobile/src/controller/ContextMenu.jsx @@ -47,6 +47,12 @@ class ContextMenu extends ContextMenuController { onMenuItemClick(action) { super.onMenuItemClick(action); + switch (action) { + case 'addcomment': + Common.Notifications.trigger('addcomment'); + break; + } + 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({ caption: /*me.menuViewComment*/'View Comment', 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) { itemsText.push({ 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); if ( !hideAddComment ) { itemsText.push({ - caption: /*me.menuAddComment*/'Add Comment', + caption: 'Add Comment', event: 'addcomment' }); - } + }*/ } } diff --git a/apps/documenteditor/mobile/src/page/main.jsx b/apps/documenteditor/mobile/src/page/main.jsx index be5a0685e..fbed1a5e1 100644 --- a/apps/documenteditor/mobile/src/page/main.jsx +++ b/apps/documenteditor/mobile/src/page/main.jsx @@ -8,7 +8,6 @@ import EditOptions from '../view/edit/Edit'; import AddOptions from '../view/add/Add'; import Settings from '../view/settings/Settings'; 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 { Search, SearchSettings } from '../controller/Search'; import ContextMenu from '../controller/ContextMenu'; diff --git a/apps/documenteditor/mobile/src/view/add/AddOther.jsx b/apps/documenteditor/mobile/src/view/add/AddOther.jsx index 15dc2e139..25040fc49 100644 --- a/apps/documenteditor/mobile/src/view/add/AddOther.jsx +++ b/apps/documenteditor/mobile/src/view/add/AddOther.jsx @@ -202,7 +202,7 @@ const AddOther = props => { { props.closeModal(); - props.storeComments.openAddComment(true); + Common.Notifications.trigger('addcomment'); }}>