2016-04-01 13:17:09 +00:00
/ *
*
2019-01-17 13:05:03 +00:00
* ( c ) Copyright Ascensio System SIA 2010 - 2019
2016-04-01 13:17:09 +00:00
*
* This program is a free software product . You can redistribute it and / or
* modify it under the terms of the GNU Affero General Public License ( AGPL )
* version 3 as published by the Free Software Foundation . In accordance with
* Section 7 ( a ) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non - infringement
* of any third - party rights .
*
* This program is distributed WITHOUT ANY WARRANTY ; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . For
* details , see the GNU AGPL at : http : //www.gnu.org/licenses/agpl-3.0.html
*
2019-01-17 13:00:34 +00:00
* You can contact Ascensio System SIA at 20 A - 12 Ernesta Birznieka - Upisha
* street , Riga , Latvia , EU , LV - 1050.
2016-04-01 13:17:09 +00:00
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices , as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7 ( b ) of the License you must retain the original Product
* logo when distributing the program . Pursuant to Section 7 ( e ) we decline to
* grant you any rights under trademark law for use of our trademarks .
*
* All the Product ' s GUI elements , including illustrations and icon sets , as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution - ShareAlike 4.0 International . See the License
* terms at http : //creativecommons.org/licenses/by-sa/4.0/legalcode
*
* /
2016-03-11 00:48:53 +00:00
/ * *
* Comments . js
*
* Created by Alexey Musinov on 16.01 . 14
2018-03-01 12:16:38 +00:00
* Copyright ( c ) 2018 Ascensio System SIA . All rights reserved .
2016-03-11 00:48:53 +00:00
*
* /
if ( Common === undefined )
var Common = { } ;
Common . Controllers = Common . Controllers || { } ;
define ( [
'core' ,
'common/main/lib/model/Comment' ,
'common/main/lib/collection/Comments' ,
2018-06-07 14:09:54 +00:00
'common/main/lib/view/Comments' ,
'common/main/lib/view/ReviewPopover'
2016-03-11 00:48:53 +00:00
] , function ( ) {
'use strict' ;
// NOTE: временное решение
function buildCommentData ( ) {
2016-04-05 12:57:51 +00:00
if ( typeof Asc . asc _CCommentDataWord !== 'undefined' ) {
return new Asc . asc _CCommentDataWord ( null ) ;
2016-03-11 00:48:53 +00:00
}
2016-05-11 13:26:45 +00:00
return new Asc . asc _CCommentData ( null ) ;
2016-03-11 00:48:53 +00:00
}
Common . Controllers . Comments = Backbone . Controller . extend ( _ . extend ( {
models : [ ] ,
collections : [
'Common.Collections.Comments'
] ,
views : [
'Common.Views.Comments' ,
2018-06-07 14:09:54 +00:00
'Common.Views.ReviewPopover'
2016-03-11 00:48:53 +00:00
] ,
sdkViewName : '#id_main' ,
subEditStrings : { } ,
filter : undefined ,
hintmode : false ,
2019-01-14 13:51:23 +00:00
viewmode : false ,
2016-03-11 00:48:53 +00:00
isSelectedComment : false ,
uids : [ ] ,
oldUids : [ ] ,
isDummyComment : false ,
initialize : function ( ) {
this . addListeners ( {
'Common.Views.Comments' : {
// comments handlers
'comment:add' : _ . bind ( this . onCreateComment , this ) ,
'comment:change' : _ . bind ( this . onChangeComment , this ) ,
'comment:remove' : _ . bind ( this . onRemoveComment , this ) ,
'comment:resolve' : _ . bind ( this . onResolveComment , this ) ,
'comment:show' : _ . bind ( this . onShowComment , this ) ,
// reply handlers
'comment:addReply' : _ . bind ( this . onAddReplyComment , this ) ,
'comment:changeReply' : _ . bind ( this . onChangeReplyComment , this ) ,
'comment:removeReply' : _ . bind ( this . onRemoveReplyComment , this ) ,
'comment:editReply' : _ . bind ( this . onShowEditReplyComment , this ) ,
// work handlers
2021-07-06 19:58:36 +00:00
'comment:closeEditing' : _ . bind ( this . closeEditing , this ) ,
'comment:sort' : _ . bind ( this . setComparator , this )
2018-06-07 14:09:54 +00:00
} ,
'Common.Views.ReviewPopover' : {
// comments handlers
'comment:change' : _ . bind ( this . onChangeComment , this ) ,
'comment:remove' : _ . bind ( this . onRemoveComment , this ) ,
'comment:resolve' : _ . bind ( this . onResolveComment , this ) ,
'comment:show' : _ . bind ( this . onShowComment , this ) ,
// reply handlers
'comment:addReply' : _ . bind ( this . onAddReplyComment , this ) ,
'comment:changeReply' : _ . bind ( this . onChangeReplyComment , this ) ,
'comment:removeReply' : _ . bind ( this . onRemoveReplyComment , this ) ,
'comment:editReply' : _ . bind ( this . onShowEditReplyComment , this ) ,
// work handlers
2016-03-11 00:48:53 +00:00
'comment:closeEditing' : _ . bind ( this . closeEditing , this ) ,
'comment:disableHint' : _ . bind ( this . disableHint , this ) ,
'comment:addDummyComment' : _ . bind ( this . onAddDummyComment , this )
2019-10-18 10:28:30 +00:00
} ,
'Common.Views.ReviewChanges' : {
2021-04-06 07:53:53 +00:00
'comment:removeComments' : _ . bind ( this . onRemoveComments , this ) ,
'comment:resolveComments' : _ . bind ( this . onResolveComments , this )
2016-03-11 00:48:53 +00:00
}
} ) ;
Common . NotificationCenter . on ( 'comments:updatefilter' , _ . bind ( this . onUpdateFilter , this ) ) ;
2017-03-29 16:29:04 +00:00
Common . NotificationCenter . on ( 'app:comment:add' , _ . bind ( this . onAppAddComment , this ) ) ;
2017-08-09 17:02:41 +00:00
Common . NotificationCenter . on ( 'layout:changed' , function ( area ) {
Common . Utils . asyncCall ( function ( e ) {
2018-07-31 09:51:31 +00:00
if ( ( e == 'toolbar' || e == 'status' ) && this . view . $el . is ( ':visible' ) ) {
2017-08-09 17:02:41 +00:00
this . onAfterShow ( ) ;
}
} , this , area ) ;
} . bind ( this ) ) ;
2016-03-11 00:48:53 +00:00
} ,
onLaunch : function ( ) {
2021-07-06 19:58:36 +00:00
var filter = Common . localStorage . getKeysFilter ( ) ;
this . appPrefix = ( filter && filter . length ) ? filter . split ( ',' ) [ 0 ] : '' ;
2016-03-11 00:48:53 +00:00
this . collection = this . getApplication ( ) . getCollection ( 'Common.Collections.Comments' ) ;
2021-07-06 19:58:36 +00:00
this . setComparator ( ) ;
2016-03-11 00:48:53 +00:00
this . popoverComments = new Common . Collections . Comments ( ) ;
if ( this . popoverComments ) {
2018-07-20 14:01:07 +00:00
this . popoverComments . comparator = function ( collection ) { return collection . get ( 'time' ) ; } ;
2016-03-11 00:48:53 +00:00
}
2018-11-16 13:44:11 +00:00
this . groupCollection = [ ] ;
2018-06-07 14:09:54 +00:00
this . view = this . createView ( 'Common.Views.Comments' , { store : this . collection } ) ;
2016-03-11 00:48:53 +00:00
this . view . render ( ) ;
2018-06-04 11:45:22 +00:00
this . userCollection = this . getApplication ( ) . getCollection ( 'Common.Collections.Users' ) ;
this . userCollection . on ( 'reset' , _ . bind ( this . onUpdateUsers , this ) ) ;
this . userCollection . on ( 'add' , _ . bind ( this . onUpdateUsers , this ) ) ;
2016-03-11 00:48:53 +00:00
this . bindViewEvents ( this . view , this . events ) ;
} ,
setConfig : function ( data , api ) {
this . setApi ( api ) ;
if ( data ) {
this . currentUserId = data . config . user . id ;
this . sdkViewName = data [ 'sdkviewname' ] || this . sdkViewName ;
this . hintmode = data [ 'hintmode' ] || false ;
2019-01-14 13:51:23 +00:00
this . viewmode = data [ 'viewmode' ] || false ;
2016-03-11 00:48:53 +00:00
}
} ,
setApi : function ( api ) {
if ( api ) {
this . api = api ;
this . api . asc _registerCallback ( 'asc_onAddComment' , _ . bind ( this . onApiAddComment , this ) ) ;
this . api . asc _registerCallback ( 'asc_onAddComments' , _ . bind ( this . onApiAddComments , this ) ) ;
this . api . asc _registerCallback ( 'asc_onRemoveComment' , _ . bind ( this . onApiRemoveComment , this ) ) ;
this . api . asc _registerCallback ( 'asc_onChangeComments' , _ . bind ( this . onChangeComments , this ) ) ;
2019-10-18 10:28:30 +00:00
this . api . asc _registerCallback ( 'asc_onRemoveComments' , _ . bind ( this . onApiRemoveComments , this ) ) ;
2016-03-11 00:48:53 +00:00
this . api . asc _registerCallback ( 'asc_onChangeCommentData' , _ . bind ( this . onApiChangeCommentData , this ) ) ;
this . api . asc _registerCallback ( 'asc_onLockComment' , _ . bind ( this . onApiLockComment , this ) ) ;
this . api . asc _registerCallback ( 'asc_onUnLockComment' , _ . bind ( this . onApiUnLockComment , this ) ) ;
this . api . asc _registerCallback ( 'asc_onShowComment' , _ . bind ( this . onApiShowComment , this ) ) ;
this . api . asc _registerCallback ( 'asc_onHideComment' , _ . bind ( this . onApiHideComment , this ) ) ;
this . api . asc _registerCallback ( 'asc_onUpdateCommentPosition' , _ . bind ( this . onApiUpdateCommentPosition , this ) ) ;
this . api . asc _registerCallback ( 'asc_onDocumentPlaceChanged' , _ . bind ( this . onDocumentPlaceChanged , this ) ) ;
2021-03-23 15:41:11 +00:00
this . api . asc _registerCallback ( 'asc_onDeleteComment' , _ . bind ( this . onDeleteComment , this ) ) ; // only for PE, when del or ctrl+x pressed
2016-03-11 00:48:53 +00:00
}
} ,
setMode : function ( mode ) {
this . mode = mode ;
this . isModeChanged = true ; // change show-comment mode from/to hint mode using canComments flag
2019-01-14 13:51:23 +00:00
this . view . viewmode = ! this . mode . canComments ;
this . view . changeLayout ( mode ) ;
2016-03-11 00:48:53 +00:00
return this ;
} ,
//
2021-07-06 19:58:36 +00:00
setComparator : function ( type ) {
if ( this . collection ) {
var sort = ( type !== undefined ) ;
if ( type === undefined ) {
2021-07-11 21:30:52 +00:00
type = Common . localStorage . getItem ( this . appPrefix + "comments-sort" ) || 'date-desc' ;
2021-07-06 19:58:36 +00:00
}
Common . localStorage . setItem ( this . appPrefix + "comments-sort" , type ) ;
Common . Utils . InternalSettings . set ( this . appPrefix + "comments-sort" , type ) ;
if ( type == 'position' ) {
2021-07-11 21:30:52 +00:00
} else if ( type == 'author-asc' || type == 'author-desc' ) {
var direction = ( type == 'author-asc' ) ? 1 : - 1 ;
this . collection . comparator = function ( item1 , item2 ) {
var n1 = item1 . get ( 'parsedName' ) . toLowerCase ( ) ,
n2 = item2 . get ( 'parsedName' ) . toLowerCase ( ) ;
if ( n1 == n2 ) return 0 ;
return ( n1 < n2 ) ? - direction : direction ;
2021-07-06 19:58:36 +00:00
} ;
} else { // date
2021-07-11 21:30:52 +00:00
var direction = ( type == 'date-asc' ) ? 1 : - 1 ;
2021-07-06 19:58:36 +00:00
this . collection . comparator = function ( collection ) {
2021-07-11 21:30:52 +00:00
return direction * collection . get ( 'time' ) ;
2021-07-06 19:58:36 +00:00
} ;
}
sort && this . updateComments ( true ) ;
}
} ,
getComparator : function ( ) {
return Common . Utils . InternalSettings . get ( this . appPrefix + "comments-sort" ) || 'date' ;
} ,
2016-03-11 00:48:53 +00:00
onCreateComment : function ( panel , commentVal , editMode , hidereply , documentFlag ) {
if ( this . api && commentVal && commentVal . length > 0 ) {
var comment = buildCommentData ( ) ; // new asc_CCommentData(null);
if ( comment ) {
this . showPopover = true ;
this . editPopover = editMode ? true : false ;
this . hidereply = hidereply ;
this . isSelectedComment = false ;
this . uids = [ ] ;
comment . asc _putText ( commentVal ) ;
comment . asc _putTime ( this . utcDateToString ( new Date ( ) ) ) ;
2017-08-04 08:18:37 +00:00
comment . asc _putOnlyOfficeTime ( this . ooDateToString ( new Date ( ) ) ) ;
2016-03-11 00:48:53 +00:00
comment . asc _putUserId ( this . currentUserId ) ;
2021-03-26 11:29:16 +00:00
comment . asc _putUserName ( AscCommon . UserInfoParser . getCurrentName ( ) ) ;
2016-03-11 00:48:53 +00:00
comment . asc _putSolved ( false ) ;
if ( ! _ . isUndefined ( comment . asc _putDocumentFlag ) ) {
comment . asc _putDocumentFlag ( documentFlag ) ;
}
this . api . asc _addComment ( comment ) ;
this . view . showEditContainer ( false ) ;
}
}
this . view . txtComment . focus ( ) ;
} ,
onRemoveComment : function ( id ) {
if ( this . api && id ) {
this . api . asc _removeComment ( id ) ;
}
} ,
2019-10-18 10:28:30 +00:00
onRemoveComments : function ( type ) {
if ( this . api ) {
2021-02-04 09:39:56 +00:00
this . api . asc _RemoveAllComments ( type == 'my' || ! this . mode . canDeleteComments , type == 'current' ) ; // 1 param = true if remove only my comments, 2 param - remove current comments
2019-10-18 10:28:30 +00:00
}
} ,
2021-04-06 07:53:53 +00:00
onResolveComments : function ( type ) {
if ( this . api ) {
this . api . asc _ResolveAllComments ( type == 'my' || ! this . mode . canEditComments , type == 'current' ) ; // 1 param = true if resolve only my comments, 2 param - resolve current comments
}
} ,
2018-11-16 13:44:11 +00:00
onResolveComment : function ( uid ) {
2016-03-11 00:48:53 +00:00
var t = this ,
reply = null ,
addReply = null ,
ascComment = buildCommentData ( ) , // new asc_CCommentData(null),
2018-11-16 13:44:11 +00:00
comment = t . findComment ( uid ) ;
2016-03-11 00:48:53 +00:00
if ( _ . isUndefined ( uid ) ) {
uid = comment . get ( 'uid' ) ;
}
if ( ascComment && comment ) {
ascComment . asc _putText ( comment . get ( 'comment' ) ) ;
ascComment . asc _putQuoteText ( comment . get ( 'quote' ) ) ;
ascComment . asc _putTime ( t . utcDateToString ( new Date ( comment . get ( 'time' ) ) ) ) ;
2017-08-04 08:18:37 +00:00
ascComment . asc _putOnlyOfficeTime ( t . ooDateToString ( new Date ( comment . get ( 'time' ) ) ) ) ;
2017-06-01 14:34:17 +00:00
ascComment . asc _putUserId ( comment . get ( 'userid' ) ) ;
ascComment . asc _putUserName ( comment . get ( 'username' ) ) ;
2016-03-11 00:48:53 +00:00
ascComment . asc _putSolved ( ! comment . get ( 'resolved' ) ) ;
2019-07-18 11:05:31 +00:00
ascComment . asc _putGuid ( comment . get ( 'guid' ) ) ;
2020-08-31 11:27:54 +00:00
ascComment . asc _putUserData ( comment . get ( 'userdata' ) ) ;
2016-03-11 00:48:53 +00:00
if ( ! _ . isUndefined ( ascComment . asc _putDocumentFlag ) ) {
ascComment . asc _putDocumentFlag ( comment . get ( 'unattached' ) ) ;
}
reply = comment . get ( 'replys' ) ;
if ( reply && reply . length ) {
reply . forEach ( function ( reply ) {
addReply = buildCommentData ( ) ; // new asc_CCommentData(null);
if ( addReply ) {
addReply . asc _putText ( reply . get ( 'reply' ) ) ;
addReply . asc _putTime ( t . utcDateToString ( new Date ( reply . get ( 'time' ) ) ) ) ;
2017-08-04 08:18:37 +00:00
addReply . asc _putOnlyOfficeTime ( t . ooDateToString ( new Date ( reply . get ( 'time' ) ) ) ) ;
2016-03-11 00:48:53 +00:00
addReply . asc _putUserId ( reply . get ( 'userid' ) ) ;
addReply . asc _putUserName ( reply . get ( 'username' ) ) ;
2020-08-31 11:27:54 +00:00
addReply . asc _putUserData ( reply . get ( 'userdata' ) ) ;
2016-03-11 00:48:53 +00:00
ascComment . asc _addReply ( addReply ) ;
}
} ) ;
}
t . api . asc _changeComment ( uid , ascComment ) ;
return true ;
}
return false ;
} ,
2020-11-18 12:28:47 +00:00
onShowComment : function ( id , selected , fromLeftPanelSelection ) {
2019-07-17 12:07:53 +00:00
var comment = this . findComment ( id ) ;
2016-03-11 00:48:53 +00:00
if ( comment ) {
if ( null !== comment . get ( 'quote' ) ) {
if ( this . api ) {
if ( this . hintmode ) {
this . animate = true ;
if ( comment . get ( 'unattached' ) ) {
if ( this . getPopover ( ) ) {
2018-06-07 14:09:54 +00:00
this . getPopover ( ) . hideComments ( ) ;
2016-03-11 00:48:53 +00:00
return ;
}
}
} else {
var model = this . popoverComments . findWhere ( { uid : id } ) ;
2019-01-16 09:55:46 +00:00
if ( model && ! this . getPopover ( ) . isVisible ( ) ) {
this . getPopover ( ) . showComments ( true ) ;
2019-04-22 08:04:54 +00:00
this . api . asc _selectComment ( id ) ;
2016-03-11 00:48:53 +00:00
return ;
}
}
if ( ! _ . isUndefined ( selected ) && this . hintmode ) {
this . isSelectedComment = selected ;
}
2020-11-18 12:28:47 +00:00
if ( ! fromLeftPanelSelection || ! ( ( 0 === _ . difference ( this . uids , [ id ] ) . length ) && ( 0 === _ . difference ( [ id ] , this . uids ) . length ) ) ) {
this . api . asc _selectComment ( id ) ;
this . _dontScrollToComment = true ;
this . api . asc _showComment ( id , false ) ;
}
2016-03-11 00:48:53 +00:00
}
} else {
if ( this . hintmode ) {
this . api . asc _selectComment ( id ) ;
}
if ( this . getPopover ( ) ) {
2018-06-07 14:09:54 +00:00
this . getPopover ( ) . hideComments ( ) ;
2016-03-11 00:48:53 +00:00
}
this . isSelectedComment = false ;
this . uids = [ ] ;
}
}
} ,
onChangeComment : function ( id , commentVal ) {
if ( commentVal && commentVal . length > 0 ) {
var t = this ,
comment2 = null ,
reply = null ,
addReply = null ,
ascComment = buildCommentData ( ) , // new asc_CCommentData(null),
comment = t . findComment ( id ) ;
if ( comment && ascComment ) {
ascComment . asc _putText ( commentVal ) ;
ascComment . asc _putQuoteText ( comment . get ( 'quote' ) ) ;
ascComment . asc _putTime ( t . utcDateToString ( new Date ( comment . get ( 'time' ) ) ) ) ;
2017-08-04 08:18:37 +00:00
ascComment . asc _putOnlyOfficeTime ( t . ooDateToString ( new Date ( comment . get ( 'time' ) ) ) ) ;
2016-03-11 00:48:53 +00:00
ascComment . asc _putUserId ( t . currentUserId ) ;
2021-03-26 11:29:16 +00:00
ascComment . asc _putUserName ( AscCommon . UserInfoParser . getCurrentName ( ) ) ;
2016-03-11 00:48:53 +00:00
ascComment . asc _putSolved ( comment . get ( 'resolved' ) ) ;
2019-07-18 11:05:31 +00:00
ascComment . asc _putGuid ( comment . get ( 'guid' ) ) ;
2020-08-31 11:27:54 +00:00
ascComment . asc _putUserData ( comment . get ( 'userdata' ) ) ;
2016-03-11 00:48:53 +00:00
if ( ! _ . isUndefined ( ascComment . asc _putDocumentFlag ) ) {
ascComment . asc _putDocumentFlag ( comment . get ( 'unattached' ) ) ;
}
comment . set ( 'editTextInPopover' , false ) ;
comment2 = t . findPopupComment ( id ) ;
if ( comment2 ) {
comment2 . set ( 'editTextInPopover' , false ) ;
}
if ( t . subEditStrings [ id ] ) { delete t . subEditStrings [ id ] ; }
if ( t . subEditStrings [ id + '-R' ] ) { delete t . subEditStrings [ id + '-R' ] ; }
reply = comment . get ( 'replys' ) ;
if ( reply && reply . length ) {
reply . forEach ( function ( reply ) {
addReply = buildCommentData ( ) ; // new asc_CCommentData(null);
if ( addReply ) {
addReply . asc _putText ( reply . get ( 'reply' ) ) ;
addReply . asc _putTime ( t . utcDateToString ( new Date ( reply . get ( 'time' ) ) ) ) ;
2017-08-04 08:18:37 +00:00
addReply . asc _putOnlyOfficeTime ( t . ooDateToString ( new Date ( reply . get ( 'time' ) ) ) ) ;
2016-03-11 00:48:53 +00:00
addReply . asc _putUserId ( reply . get ( 'userid' ) ) ;
addReply . asc _putUserName ( reply . get ( 'username' ) ) ;
2020-08-31 11:27:54 +00:00
addReply . asc _putUserData ( reply . get ( 'userdata' ) ) ;
2016-03-11 00:48:53 +00:00
ascComment . asc _addReply ( addReply ) ;
}
} ) ;
}
t . api . asc _changeComment ( id , ascComment ) ;
return true ;
}
}
return false ;
} ,
onChangeReplyComment : function ( id , replyId , replyVal ) {
if ( replyVal && replyVal . length > 0 ) {
var me = this ,
reply = null ,
addReply = null ,
ascComment = buildCommentData ( ) , // new asc_CCommentData(null),
comment = me . findComment ( id ) ;
if ( ascComment && comment ) {
ascComment . asc _putText ( comment . get ( 'comment' ) ) ;
ascComment . asc _putQuoteText ( comment . get ( 'quote' ) ) ;
ascComment . asc _putTime ( me . utcDateToString ( new Date ( comment . get ( 'time' ) ) ) ) ;
2017-08-04 08:18:37 +00:00
ascComment . asc _putOnlyOfficeTime ( me . ooDateToString ( new Date ( comment . get ( 'time' ) ) ) ) ;
2016-03-11 00:48:53 +00:00
ascComment . asc _putUserId ( comment . get ( 'userid' ) ) ;
ascComment . asc _putUserName ( comment . get ( 'username' ) ) ;
ascComment . asc _putSolved ( comment . get ( 'resolved' ) ) ;
2019-07-18 11:05:31 +00:00
ascComment . asc _putGuid ( comment . get ( 'guid' ) ) ;
2020-08-31 11:27:54 +00:00
ascComment . asc _putUserData ( comment . get ( 'userdata' ) ) ;
2016-03-11 00:48:53 +00:00
if ( ! _ . isUndefined ( ascComment . asc _putDocumentFlag ) ) {
ascComment . asc _putDocumentFlag ( comment . get ( 'unattached' ) ) ;
}
reply = comment . get ( 'replys' ) ;
if ( reply && reply . length ) {
reply . forEach ( function ( reply ) {
addReply = buildCommentData ( ) ; // new asc_CCommentData();
if ( addReply ) {
if ( reply . get ( 'id' ) === replyId && ! _ . isUndefined ( replyVal ) ) {
addReply . asc _putText ( replyVal ) ;
addReply . asc _putUserId ( me . currentUserId ) ;
2021-03-26 11:29:16 +00:00
addReply . asc _putUserName ( AscCommon . UserInfoParser . getCurrentName ( ) ) ;
2016-03-11 00:48:53 +00:00
} else {
addReply . asc _putText ( reply . get ( 'reply' ) ) ;
addReply . asc _putUserId ( reply . get ( 'userid' ) ) ;
addReply . asc _putUserName ( reply . get ( 'username' ) ) ;
}
addReply . asc _putTime ( me . utcDateToString ( new Date ( reply . get ( 'time' ) ) ) ) ;
2017-08-04 08:18:37 +00:00
addReply . asc _putOnlyOfficeTime ( me . ooDateToString ( new Date ( reply . get ( 'time' ) ) ) ) ;
2020-08-31 11:27:54 +00:00
addReply . asc _putUserData ( reply . get ( 'userdata' ) ) ;
2016-03-11 00:48:53 +00:00
ascComment . asc _addReply ( addReply ) ;
}
} ) ;
}
me . api . asc _changeComment ( id , ascComment ) ;
return true ;
}
}
return false ;
} ,
onAddReplyComment : function ( id , replyVal ) {
if ( replyVal . length > 0 ) {
var me = this ,
uid = null ,
reply = null ,
addReply = null ,
ascComment = buildCommentData ( ) , // new asc_CCommentData(null),
comment = me . findComment ( id ) ;
if ( ascComment && comment ) {
uid = comment . get ( 'uid' ) ;
if ( uid ) {
if ( me . subEditStrings [ uid ] ) { delete me . subEditStrings [ uid ] ; }
if ( me . subEditStrings [ uid + '-R' ] ) { delete me . subEditStrings [ uid + '-R' ] ; }
comment . set ( 'showReplyInPopover' , false ) ;
}
ascComment . asc _putText ( comment . get ( 'comment' ) ) ;
ascComment . asc _putQuoteText ( comment . get ( 'quote' ) ) ;
ascComment . asc _putTime ( me . utcDateToString ( new Date ( comment . get ( 'time' ) ) ) ) ;
2017-08-04 08:18:37 +00:00
ascComment . asc _putOnlyOfficeTime ( me . ooDateToString ( new Date ( comment . get ( 'time' ) ) ) ) ;
2016-03-11 00:48:53 +00:00
ascComment . asc _putUserId ( comment . get ( 'userid' ) ) ;
ascComment . asc _putUserName ( comment . get ( 'username' ) ) ;
ascComment . asc _putSolved ( comment . get ( 'resolved' ) ) ;
2019-07-18 11:05:31 +00:00
ascComment . asc _putGuid ( comment . get ( 'guid' ) ) ;
2020-08-31 11:27:54 +00:00
ascComment . asc _putUserData ( comment . get ( 'userdata' ) ) ;
2016-03-11 00:48:53 +00:00
if ( ! _ . isUndefined ( ascComment . asc _putDocumentFlag ) ) {
ascComment . asc _putDocumentFlag ( comment . get ( 'unattached' ) ) ;
}
reply = comment . get ( 'replys' ) ;
if ( reply && reply . length ) {
reply . forEach ( function ( reply ) {
addReply = buildCommentData ( ) ; // new asc_CCommentData(null);
if ( addReply ) {
addReply . asc _putText ( reply . get ( 'reply' ) ) ;
addReply . asc _putTime ( me . utcDateToString ( new Date ( reply . get ( 'time' ) ) ) ) ;
2017-08-04 08:18:37 +00:00
addReply . asc _putOnlyOfficeTime ( me . ooDateToString ( new Date ( reply . get ( 'time' ) ) ) ) ;
2016-03-11 00:48:53 +00:00
addReply . asc _putUserId ( reply . get ( 'userid' ) ) ;
addReply . asc _putUserName ( reply . get ( 'username' ) ) ;
2020-08-31 11:27:54 +00:00
addReply . asc _putUserData ( reply . get ( 'userdata' ) ) ;
2016-03-11 00:48:53 +00:00
ascComment . asc _addReply ( addReply ) ;
}
} ) ;
}
addReply = buildCommentData ( ) ; // new asc_CCommentData(null);
if ( addReply ) {
addReply . asc _putText ( replyVal ) ;
addReply . asc _putTime ( me . utcDateToString ( new Date ( ) ) ) ;
2017-08-04 08:18:37 +00:00
addReply . asc _putOnlyOfficeTime ( me . ooDateToString ( new Date ( ) ) ) ;
2016-03-11 00:48:53 +00:00
addReply . asc _putUserId ( me . currentUserId ) ;
2021-03-26 11:29:16 +00:00
addReply . asc _putUserName ( AscCommon . UserInfoParser . getCurrentName ( ) ) ;
2016-03-11 00:48:53 +00:00
ascComment . asc _addReply ( addReply ) ;
me . api . asc _changeComment ( id , ascComment ) ;
2019-12-20 14:40:15 +00:00
me . mode && me . mode . canRequestSendNotify && me . view . pickEMail ( ascComment . asc _getGuid ( ) , replyVal ) ;
2016-03-11 00:48:53 +00:00
return true ;
}
}
}
return false ;
} ,
onRemoveReplyComment : function ( id , replyId ) {
if ( ! _ . isUndefined ( id ) && ! _ . isUndefined ( replyId ) ) {
var me = this ,
replies = null ,
addReply = null ,
ascComment = buildCommentData ( ) , // new asc_CCommentData(null),
comment = me . findComment ( id ) ;
if ( ascComment && comment ) {
ascComment . asc _putText ( comment . get ( 'comment' ) ) ;
ascComment . asc _putQuoteText ( comment . get ( 'quote' ) ) ;
ascComment . asc _putTime ( me . utcDateToString ( new Date ( comment . get ( 'time' ) ) ) ) ;
2017-08-04 08:18:37 +00:00
ascComment . asc _putOnlyOfficeTime ( me . ooDateToString ( new Date ( comment . get ( 'time' ) ) ) ) ;
2016-03-11 00:48:53 +00:00
ascComment . asc _putUserId ( comment . get ( 'userid' ) ) ;
ascComment . asc _putUserName ( comment . get ( 'username' ) ) ;
ascComment . asc _putSolved ( comment . get ( 'resolved' ) ) ;
2019-07-18 11:05:31 +00:00
ascComment . asc _putGuid ( comment . get ( 'guid' ) ) ;
2020-08-31 11:27:54 +00:00
ascComment . asc _putUserData ( comment . get ( 'userdata' ) ) ;
2016-03-11 00:48:53 +00:00
if ( ! _ . isUndefined ( ascComment . asc _putDocumentFlag ) ) {
ascComment . asc _putDocumentFlag ( comment . get ( 'unattached' ) ) ;
}
replies = comment . get ( 'replys' ) ;
if ( replies && replies . length ) {
replies . forEach ( function ( reply ) {
if ( reply . get ( 'id' ) !== replyId ) {
addReply = buildCommentData ( ) ; // new asc_CCommentData(null);
if ( addReply ) {
addReply . asc _putText ( reply . get ( 'reply' ) ) ;
addReply . asc _putTime ( me . utcDateToString ( new Date ( reply . get ( 'time' ) ) ) ) ;
2017-08-04 08:18:37 +00:00
addReply . asc _putOnlyOfficeTime ( me . ooDateToString ( new Date ( reply . get ( 'time' ) ) ) ) ;
2016-03-11 00:48:53 +00:00
addReply . asc _putUserId ( reply . get ( 'userid' ) ) ;
addReply . asc _putUserName ( reply . get ( 'username' ) ) ;
2020-08-31 11:27:54 +00:00
addReply . asc _putUserData ( reply . get ( 'userdata' ) ) ;
2016-03-11 00:48:53 +00:00
ascComment . asc _addReply ( addReply ) ;
}
}
} ) ;
}
me . api . asc _changeComment ( id , ascComment ) ;
return true ;
}
}
return false ;
} ,
onShowEditReplyComment : function ( id , replyId , inpopover ) {
var i , model , repliesSrc , repliesCopy ;
if ( ! _ . isUndefined ( id ) && ! _ . isUndefined ( replyId ) ) {
if ( inpopover ) {
model = this . popoverComments . findWhere ( { uid : id } ) ;
if ( model ) {
repliesSrc = model . get ( 'replys' ) ;
repliesCopy = _ . clone ( model . get ( 'replys' ) ) ;
if ( repliesCopy ) {
for ( i = 0 ; i < repliesCopy . length ; ++ i ) {
if ( replyId === repliesCopy [ i ] . get ( 'id' ) ) {
repliesCopy [ i ] . set ( 'editTextInPopover' , true ) ;
repliesSrc . length = 0 ;
model . set ( 'replys' , repliesCopy ) ;
return true ;
}
}
}
}
} else {
model = this . collection . findWhere ( { uid : id } ) ;
if ( model ) {
repliesSrc = model . get ( 'replys' ) ;
repliesCopy = _ . clone ( model . get ( 'replys' ) ) ;
if ( repliesCopy ) {
for ( i = 0 ; i < repliesCopy . length ; ++ i ) {
if ( replyId === repliesCopy [ i ] . get ( 'id' ) ) {
repliesCopy [ i ] . set ( 'editText' , true ) ;
repliesSrc . length = 0 ;
model . set ( 'replys' , repliesCopy ) ;
return true ;
}
}
}
}
}
}
return false ;
} ,
onUpdateFilter : function ( filter , applyOnly ) {
if ( filter ) {
2018-02-15 08:57:48 +00:00
if ( ! this . view . isVisible ( ) ) {
this . view . needUpdateFilter = filter ;
2018-11-16 13:44:11 +00:00
applyOnly = true ;
2018-02-15 08:57:48 +00:00
}
2018-11-16 13:44:11 +00:00
this . filter = filter ;
2016-03-11 00:48:53 +00:00
2018-11-16 13:44:11 +00:00
var me = this ,
comments = [ ] ;
this . filter . forEach ( function ( item ) {
if ( ! me . groupCollection [ item ] )
me . groupCollection [ item ] = new Backbone . Collection ( [ ] , { model : Common . Models . Comment } ) ;
comments = comments . concat ( me . groupCollection [ item ] . models ) ;
} ) ;
this . collection . reset ( comments ) ;
this . collection . groups = this . filter ;
2016-03-11 00:48:53 +00:00
if ( ! applyOnly ) {
if ( this . getPopover ( ) ) {
this . getPopover ( ) . hide ( ) ;
}
2018-11-16 13:44:11 +00:00
this . view . needUpdateFilter = false ;
2016-03-11 00:48:53 +00:00
2018-11-16 13:44:11 +00:00
var end = true ;
for ( var i = this . collection . length - 1 ; i >= 0 ; -- i ) {
if ( end ) {
this . collection . at ( i ) . set ( 'last' , true , { silent : true } ) ;
} else {
if ( this . collection . at ( i ) . get ( 'last' ) ) {
this . collection . at ( i ) . set ( 'last' , false , { silent : true } ) ;
}
}
end = false ;
2016-03-11 00:48:53 +00:00
}
2018-11-16 13:44:11 +00:00
this . view . render ( ) ;
2018-02-14 09:14:22 +00:00
this . view . update ( ) ;
2018-11-16 13:44:11 +00:00
}
2016-03-11 00:48:53 +00:00
}
} ,
2017-06-30 11:33:31 +00:00
onAppAddComment : function ( sender , to _doc ) {
if ( ! ! this . api . can _AddQuotedComment && this . api . can _AddQuotedComment ( ) === false || to _doc ) return ;
2017-06-28 11:20:49 +00:00
this . addDummyComment ( ) ;
2017-03-29 16:29:04 +00:00
} ,
2016-03-11 00:48:53 +00:00
2018-11-16 13:44:11 +00:00
addCommentToGroupCollection : function ( comment ) {
var groupname = comment . get ( 'groupName' ) ;
if ( ! this . groupCollection [ groupname ] )
this . groupCollection [ groupname ] = new Backbone . Collection ( [ ] , { model : Common . Models . Comment } ) ;
this . groupCollection [ groupname ] . push ( comment ) ;
} ,
2016-03-11 00:48:53 +00:00
// SDK
onApiAddComment : function ( id , data ) {
var comment = this . readSDKComment ( id , data ) ;
if ( comment ) {
2018-11-16 13:44:11 +00:00
if ( comment . get ( 'groupName' ) ) {
this . addCommentToGroupCollection ( comment ) ;
( _ . indexOf ( this . collection . groups , comment . get ( 'groupName' ) ) > - 1 ) && this . collection . push ( comment ) ;
} else
this . collection . push ( comment ) ;
2016-03-11 00:48:53 +00:00
this . updateComments ( true ) ;
if ( this . showPopover ) {
if ( null !== data . asc _getQuoteText ( ) ) {
this . api . asc _selectComment ( id ) ;
this . _dontScrollToComment = true ;
this . api . asc _showComment ( id , true ) ;
}
this . showPopover = undefined ;
this . editPopover = false ;
}
}
} ,
onApiAddComments : function ( data ) {
for ( var i = 0 ; i < data . length ; ++ i ) {
2016-05-31 15:42:12 +00:00
var comment = this . readSDKComment ( data [ i ] . asc _getId ( ) , data [ i ] ) ;
2018-11-16 13:44:11 +00:00
comment . get ( 'groupName' ) ? this . addCommentToGroupCollection ( comment ) : this . collection . push ( comment ) ;
2016-03-11 00:48:53 +00:00
}
this . updateComments ( true ) ;
} ,
onApiRemoveComment : function ( id , silentUpdate ) {
2018-11-16 13:44:11 +00:00
for ( var name in this . groupCollection ) {
var store = this . groupCollection [ name ] ,
model = store . findWhere ( { uid : id } ) ;
if ( model ) {
store . remove ( model ) ;
break ;
}
}
2016-03-11 00:48:53 +00:00
if ( this . collection . length ) {
var model = this . collection . findWhere ( { uid : id } ) ;
if ( model ) {
this . collection . remove ( model ) ;
if ( ! silentUpdate ) {
this . updateComments ( true ) ;
}
}
if ( this . popoverComments . length ) {
model = this . popoverComments . findWhere ( { uid : id } ) ;
if ( model ) {
this . popoverComments . remove ( model ) ;
if ( 0 === this . popoverComments . length ) {
if ( this . getPopover ( ) ) {
2018-06-07 14:09:54 +00:00
this . getPopover ( ) . hideComments ( ) ;
2016-03-11 00:48:53 +00:00
}
}
}
}
}
} ,
onChangeComments : function ( data ) {
for ( var i = 0 ; i < data . length ; ++ i ) {
this . onApiChangeCommentData ( data [ i ] . Comment . Id , data [ i ] . Comment , true ) ;
}
this . updateComments ( true ) ;
} ,
2019-10-18 10:28:30 +00:00
onApiRemoveComments : function ( data ) {
2016-03-11 00:48:53 +00:00
for ( var i = 0 ; i < data . length ; ++ i ) {
this . onApiRemoveComment ( data [ i ] , true ) ;
}
this . updateComments ( true ) ;
} ,
onApiChangeCommentData : function ( id , data , silentUpdate ) {
var t = this ,
i = 0 ,
date = null ,
replies = null ,
repliesCount = 0 ,
dateReply = null ,
2018-11-16 13:44:11 +00:00
comment = this . findComment ( id ) || this . findCommentInGroup ( id ) ;
2016-03-11 00:48:53 +00:00
if ( comment ) {
t = this ;
2017-08-04 08:18:37 +00:00
date = ( data . asc _getOnlyOfficeTime ( ) ) ? new Date ( this . stringOOToLocalDate ( data . asc _getOnlyOfficeTime ( ) ) ) :
( ( data . asc _getTime ( ) == '' ) ? new Date ( ) : new Date ( this . stringUtcToLocalDate ( data . asc _getTime ( ) ) ) ) ;
2016-03-11 00:48:53 +00:00
2018-06-04 11:45:22 +00:00
var user = this . userCollection . findOriginalUser ( data . asc _getUserId ( ) ) ;
2021-07-11 21:30:52 +00:00
var needSort = ( this . getComparator ( ) == 'author-asc' || this . getComparator ( ) == 'author-desc' ) && ( data . asc _getUserName ( ) !== comment . get ( 'username' ) ) ;
2016-03-11 00:48:53 +00:00
comment . set ( 'comment' , data . asc _getText ( ) ) ;
comment . set ( 'userid' , data . asc _getUserId ( ) ) ;
comment . set ( 'username' , data . asc _getUserName ( ) ) ;
2021-07-06 19:58:36 +00:00
comment . set ( 'parsedName' , AscCommon . UserInfoParser . getParsedName ( data . asc _getUserName ( ) ) ) ;
2018-06-04 11:45:22 +00:00
comment . set ( 'usercolor' , ( user ) ? user . get ( 'color' ) : null ) ;
2016-03-11 00:48:53 +00:00
comment . set ( 'resolved' , data . asc _getSolved ( ) ) ;
comment . set ( 'quote' , data . asc _getQuoteText ( ) ) ;
2020-08-31 11:27:54 +00:00
comment . set ( 'userdata' , data . asc _getUserData ( ) ) ;
2016-03-11 00:48:53 +00:00
comment . set ( 'time' , date . getTime ( ) ) ;
comment . set ( 'date' , t . dateToLocaleTimeString ( date ) ) ;
2021-03-26 11:29:16 +00:00
comment . set ( 'editable' , ( t . mode . canEditComments || ( data . asc _getUserId ( ) == t . currentUserId ) ) && AscCommon . UserInfoParser . canEditComment ( data . asc _getUserName ( ) ) ) ;
comment . set ( 'removable' , ( t . mode . canDeleteComments || ( data . asc _getUserId ( ) == t . currentUserId ) ) && AscCommon . UserInfoParser . canDeleteComment ( data . asc _getUserName ( ) ) ) ;
comment . set ( 'hide' , ! AscCommon . UserInfoParser . canViewComment ( data . asc _getUserName ( ) ) ) ;
2016-03-11 00:48:53 +00:00
replies = _ . clone ( comment . get ( 'replys' ) ) ;
replies . length = 0 ;
repliesCount = data . asc _getRepliesCount ( ) ;
for ( i = 0 ; i < repliesCount ; ++ i ) {
2017-08-04 08:18:37 +00:00
dateReply = ( data . asc _getReply ( i ) . asc _getOnlyOfficeTime ( ) ) ? new Date ( this . stringOOToLocalDate ( data . asc _getReply ( i ) . asc _getOnlyOfficeTime ( ) ) ) :
( ( data . asc _getReply ( i ) . asc _getTime ( ) == '' ) ? new Date ( ) : new Date ( this . stringUtcToLocalDate ( data . asc _getReply ( i ) . asc _getTime ( ) ) ) ) ;
2016-03-11 00:48:53 +00:00
2018-06-04 11:45:22 +00:00
user = this . userCollection . findOriginalUser ( data . asc _getReply ( i ) . asc _getUserId ( ) ) ;
2016-03-11 00:48:53 +00:00
replies . push ( new Common . Models . Reply ( {
id : Common . UI . getId ( ) ,
userid : data . asc _getReply ( i ) . asc _getUserId ( ) ,
username : data . asc _getReply ( i ) . asc _getUserName ( ) ,
2021-07-06 19:58:36 +00:00
parsedName : AscCommon . UserInfoParser . getParsedName ( data . asc _getReply ( i ) . asc _getUserName ( ) ) ,
2018-06-04 11:45:22 +00:00
usercolor : ( user ) ? user . get ( 'color' ) : null ,
2016-03-11 00:48:53 +00:00
date : t . dateToLocaleTimeString ( dateReply ) ,
reply : data . asc _getReply ( i ) . asc _getText ( ) ,
2020-08-31 11:27:54 +00:00
userdata : data . asc _getReply ( i ) . asc _getUserData ( ) ,
2016-03-11 00:48:53 +00:00
time : dateReply . getTime ( ) ,
editText : false ,
editTextInPopover : false ,
showReplyInPopover : false ,
2017-04-11 13:43:31 +00:00
scope : t . view ,
2021-03-26 11:29:16 +00:00
editable : ( t . mode . canEditComments || ( data . asc _getReply ( i ) . asc _getUserId ( ) == t . currentUserId ) ) && AscCommon . UserInfoParser . canEditComment ( data . asc _getReply ( i ) . asc _getUserName ( ) ) ,
2021-05-18 12:18:58 +00:00
removable : ( t . mode . canDeleteComments || ( data . asc _getReply ( i ) . asc _getUserId ( ) == t . currentUserId ) ) && AscCommon . UserInfoParser . canDeleteComment ( data . asc _getReply ( i ) . asc _getUserName ( ) )
2016-03-11 00:48:53 +00:00
} ) ) ;
}
comment . set ( 'replys' , replies ) ;
2021-03-17 17:08:47 +00:00
if ( ! this . popoverComments . findWhere ( { hide : false } ) ) {
this . getPopover ( ) && this . getPopover ( ) . hideComments ( ) ;
}
2016-03-11 00:48:53 +00:00
if ( ! silentUpdate ) {
2021-07-06 19:58:36 +00:00
this . updateComments ( needSort , ! needSort ) ;
2016-03-11 00:48:53 +00:00
2018-04-06 09:04:20 +00:00
// if (this.getPopover() && this.getPopover().isVisible()) {
// this._dontScrollToComment = true;
// this.api.asc_showComment(id, true);
// }
2016-03-11 00:48:53 +00:00
}
}
} ,
onApiLockComment : function ( id , userId ) {
2018-11-16 13:44:11 +00:00
var cur = this . findComment ( id ) || this . findCommentInGroup ( id ) ,
2016-03-11 00:48:53 +00:00
user = null ;
if ( cur ) {
2018-06-04 11:45:22 +00:00
if ( this . userCollection ) {
user = this . userCollection . findUser ( userId ) ;
2016-03-11 00:48:53 +00:00
if ( user ) {
this . getPopover ( ) && this . getPopover ( ) . saveText ( ) ;
2018-05-17 14:34:04 +00:00
this . view . saveText ( ) ;
2016-03-11 00:48:53 +00:00
cur . set ( 'lock' , true ) ;
cur . set ( 'lockuserid' , this . view . getUserName ( user . get ( 'username' ) ) ) ;
}
}
}
} ,
onApiUnLockComment : function ( id ) {
2018-11-16 13:44:11 +00:00
var cur = this . findComment ( id ) || this . findCommentInGroup ( id ) ;
2016-03-11 00:48:53 +00:00
if ( cur ) {
cur . set ( 'lock' , false ) ;
this . getPopover ( ) && this . getPopover ( ) . loadText ( ) ;
2018-05-17 14:34:04 +00:00
this . view . loadText ( ) ;
2016-03-11 00:48:53 +00:00
}
} ,
onApiShowComment : function ( uids , posX , posY , leftX , opts , hint ) {
2019-11-13 11:47:32 +00:00
var apihint = hint ;
2018-04-06 09:04:20 +00:00
var same _uids = ( 0 === _ . difference ( this . uids , uids ) . length ) && ( 0 === _ . difference ( uids , this . uids ) . length ) ;
2016-03-11 00:48:53 +00:00
2019-01-14 13:51:23 +00:00
if ( hint && this . isSelectedComment && same _uids && ! this . isModeChanged ) {
2016-03-11 00:48:53 +00:00
// хотим показать тот же коментарий что был и выбран
return ;
}
if ( this . mode && ! this . mode . canComments )
hint = true ;
2017-06-14 11:53:29 +00:00
var popover = this . getPopover ( ) ;
if ( popover ) {
2016-03-11 00:48:53 +00:00
this . clearDummyComment ( ) ;
2019-01-14 13:51:23 +00:00
if ( this . isSelectedComment && same _uids && ! this . isModeChanged ) {
2016-03-11 00:48:53 +00:00
//NOTE: click to sdk view ?
if ( this . api ) {
//this.view.txtComment.blur();
2017-06-14 11:53:29 +00:00
popover . commentsView && popover . commentsView . setFocusToTextBox ( true ) ;
2016-03-11 00:48:53 +00:00
this . api . asc _enableKeyEvents ( true ) ;
}
return ;
}
var i = 0 ,
saveTxtId = '' ,
saveTxtReplyId = '' ,
comment = null ,
text = '' ,
2018-07-20 14:01:07 +00:00
animate = true ,
comments = [ ] ;
2016-03-11 00:48:53 +00:00
for ( i = 0 ; i < uids . length ; ++ i ) {
saveTxtId = uids [ i ] ;
saveTxtReplyId = uids [ i ] + '-R' ;
comment = this . findComment ( saveTxtId ) ;
2017-10-31 08:51:45 +00:00
if ( ! comment ) continue ;
2016-03-11 00:48:53 +00:00
if ( this . subEditStrings [ saveTxtId ] && ! hint ) {
comment . set ( 'editTextInPopover' , true ) ;
text = this . subEditStrings [ saveTxtId ] ;
}
else if ( this . subEditStrings [ saveTxtReplyId ] && ! hint ) {
comment . set ( 'showReplyInPopover' , true ) ;
text = this . subEditStrings [ saveTxtReplyId ] ;
}
comment . set ( 'hint' , ! _ . isUndefined ( hint ) ? hint : false ) ;
if ( ! hint && this . hintmode ) {
2018-04-06 09:04:20 +00:00
if ( same _uids && ( this . uids . length === 0 ) )
2016-03-11 00:48:53 +00:00
animate = false ;
2018-04-06 09:04:20 +00:00
if ( this . oldUids . length && ( 0 === _ . difference ( this . oldUids , uids ) . length ) && ( 0 === _ . difference ( uids , this . oldUids ) . length ) ) {
2016-03-11 00:48:53 +00:00
animate = false ;
this . oldUids = [ ] ;
}
}
if ( this . animate ) {
animate = this . animate ;
this . animate = false ;
}
2019-11-13 11:47:32 +00:00
this . isSelectedComment = ! apihint || ! this . hintmode ;
2016-03-11 00:48:53 +00:00
this . uids = _ . clone ( uids ) ;
2018-07-20 14:01:07 +00:00
comments . push ( comment ) ;
2016-03-11 00:48:53 +00:00
if ( ! this . _dontScrollToComment )
this . view . commentsView . scrollToRecord ( comment ) ;
this . _dontScrollToComment = false ;
}
2018-07-20 14:01:07 +00:00
comments . sort ( function ( a , b ) {
return a . get ( 'time' ) - b . get ( 'time' ) ;
} ) ;
this . popoverComments . reset ( comments ) ;
2016-03-11 00:48:53 +00:00
2021-03-17 17:08:47 +00:00
if ( this . popoverComments . findWhere ( { hide : false } ) ) {
if ( popover . isVisible ( ) ) {
popover . hide ( ) ;
}
2016-03-11 00:48:53 +00:00
2021-03-17 17:08:47 +00:00
popover . setLeftTop ( posX , posY , leftX ) ;
popover . showComments ( animate , false , true , text ) ;
} else
popover . hideComments ( ) ;
2016-03-11 00:48:53 +00:00
}
2019-01-14 13:51:23 +00:00
this . isModeChanged = false ;
2016-03-11 00:48:53 +00:00
} ,
onApiHideComment : function ( hint ) {
var t = this ;
if ( this . getPopover ( ) ) {
if ( this . isSelectedComment && hint ) {
return ;
}
if ( hint && this . getPopover ( ) . isCommentsViewMouseOver ( ) ) return ;
this . popoverComments . each ( function ( model ) {
if ( model . get ( 'editTextInPopover' ) ) {
t . subEditStrings [ model . get ( 'uid' ) ] = t . getPopover ( ) . getEditText ( ) ;
}
if ( model . get ( 'showReplyInPopover' ) ) {
t . subEditStrings [ model . get ( 'uid' ) + '-R' ] = t . getPopover ( ) . getEditText ( ) ;
}
} ) ;
this . getPopover ( ) . saveText ( true ) ;
2018-06-07 14:09:54 +00:00
this . getPopover ( ) . hideComments ( ) ;
2016-03-11 00:48:53 +00:00
this . collection . clearEditing ( ) ;
this . popoverComments . clearEditing ( ) ;
this . oldUids = _ . clone ( this . uids ) ;
this . isSelectedComment = false ;
this . uids = [ ] ;
this . popoverComments . reset ( ) ;
}
} ,
onApiUpdateCommentPosition : function ( uids , posX , posY , leftX ) {
var i , useAnimation = false ,
comment = null ,
text = undefined ,
saveTxtId = '' ,
saveTxtReplyId = '' ;
if ( this . getPopover ( ) ) {
this . getPopover ( ) . saveText ( ) ;
this . getPopover ( ) . hideTips ( ) ;
if ( posY < 0 || this . getPopover ( ) . sdkBounds . height < posY || ( ! _ . isUndefined ( leftX ) && this . getPopover ( ) . sdkBounds . width < leftX ) ) {
this . getPopover ( ) . hide ( ) ;
} else {
if ( this . isModeChanged )
this . onApiShowComment ( uids , posX , posY , leftX ) ;
if ( 0 === this . popoverComments . length ) {
2018-07-20 14:01:07 +00:00
var comments = [ ] ;
2016-03-11 00:48:53 +00:00
for ( i = 0 ; i < uids . length ; ++ i ) {
saveTxtId = uids [ i ] ;
saveTxtReplyId = uids [ i ] + '-R' ;
comment = this . findComment ( saveTxtId ) ;
2017-10-31 08:51:45 +00:00
if ( ! comment ) continue ;
2016-03-11 00:48:53 +00:00
if ( this . subEditStrings [ saveTxtId ] ) {
comment . set ( 'editTextInPopover' , true ) ;
text = this . subEditStrings [ saveTxtId ] ;
}
else if ( this . subEditStrings [ saveTxtReplyId ] ) {
comment . set ( 'showReplyInPopover' , true ) ;
text = this . subEditStrings [ saveTxtReplyId ] ;
}
2018-07-20 14:01:07 +00:00
comments . push ( comment ) ;
2016-03-11 00:48:53 +00:00
}
2018-07-20 14:01:07 +00:00
comments . sort ( function ( a , b ) {
return a . get ( 'time' ) - b . get ( 'time' ) ;
} ) ;
this . popoverComments . reset ( comments ) ;
2016-03-11 00:48:53 +00:00
2021-03-17 17:08:47 +00:00
if ( this . popoverComments . findWhere ( { hide : false } ) ) {
useAnimation = true ;
this . getPopover ( ) . showComments ( useAnimation , undefined , undefined , text ) ;
} else
this . getPopover ( ) . hideComments ( ) ;
} else if ( ! this . getPopover ( ) . isVisible ( ) && this . popoverComments . findWhere ( { hide : false } ) ) {
2018-06-07 14:09:54 +00:00
this . getPopover ( ) . showComments ( false , undefined , undefined , text ) ;
2016-03-11 00:48:53 +00:00
}
this . getPopover ( ) . setLeftTop ( posX , posY , leftX , undefined , true ) ;
// if (this.isSelectedComment && (0 === _.difference(this.uids, uids).length)) {
//NOTE: click to sdk view ?
// if (this.api) {
// this.view.txtComment.blur();
// this.getPopover().commentsView.setFocusToTextBox(true);
// this.api.asc_enableKeyEvents(true);
// }
// }
}
}
} ,
onDocumentPlaceChanged : function ( ) {
if ( this . isDummyComment && this . getPopover ( ) ) {
if ( this . getPopover ( ) . isVisible ( ) ) {
var anchor = this . api . asc _getAnchorPosition ( ) ;
if ( anchor ) {
this . getPopover ( ) . setLeftTop ( anchor . asc _getX ( ) + anchor . asc _getWidth ( ) ,
anchor . asc _getY ( ) ,
this . hintmode ? anchor . asc _getX ( ) : undefined ) ;
}
}
}
} ,
2021-03-23 15:41:11 +00:00
onDeleteComment : function ( id , comment ) {
if ( this . api ) {
this . api . asc _RemoveAllComments ( ! this . mode . canDeleteComments , true ) ; // 1 param = true if remove only my comments, 2 param - remove current comments
}
} ,
2016-03-11 00:48:53 +00:00
// internal
2019-02-18 13:02:32 +00:00
updateComments : function ( needRender , disableSort , loadText ) {
2016-07-25 11:49:35 +00:00
var me = this ;
me . updateCommentsTime = new Date ( ) ;
if ( me . timerUpdateComments === undefined )
me . timerUpdateComments = setInterval ( function ( ) {
if ( ( new Date ( ) ) - me . updateCommentsTime > 100 ) {
clearInterval ( me . timerUpdateComments ) ;
me . timerUpdateComments = undefined ;
2019-02-18 13:02:32 +00:00
me . updateCommentsView ( needRender , disableSort , loadText ) ;
2016-07-25 11:49:35 +00:00
}
} , 25 ) ;
} ,
2019-02-18 13:02:32 +00:00
updateCommentsView : function ( needRender , disableSort , loadText ) {
2018-11-16 13:44:11 +00:00
if ( needRender && ! this . view . isVisible ( ) ) {
this . view . needRender = needRender ;
this . onUpdateFilter ( this . filter , true ) ;
return ;
}
2016-03-11 00:48:53 +00:00
var i , end = true ;
2021-07-06 19:58:36 +00:00
if ( ! disableSort ) {
2016-03-11 00:48:53 +00:00
this . collection . sort ( ) ;
}
if ( needRender ) {
2018-11-16 13:44:11 +00:00
this . onUpdateFilter ( this . filter , true ) ;
2016-03-11 00:48:53 +00:00
for ( i = this . collection . length - 1 ; i >= 0 ; -- i ) {
if ( end ) {
this . collection . at ( i ) . set ( 'last' , true , { silent : true } ) ;
} else {
if ( this . collection . at ( i ) . get ( 'last' ) ) {
this . collection . at ( i ) . set ( 'last' , false , { silent : true } ) ;
}
}
end = false ;
}
this . view . render ( ) ;
2018-02-15 08:57:48 +00:00
this . view . needRender = false ;
2016-03-11 00:48:53 +00:00
}
this . view . update ( ) ;
2019-02-18 13:02:32 +00:00
loadText && this . view . loadText ( ) ;
2016-03-11 00:48:53 +00:00
} ,
2018-11-16 13:44:11 +00:00
findComment : function ( uid ) {
2016-03-11 00:48:53 +00:00
return this . collection . findWhere ( { uid : uid } ) ;
} ,
findPopupComment : function ( id ) {
return this . popoverComments . findWhere ( { id : id } ) ;
} ,
2018-11-16 13:44:11 +00:00
findCommentInGroup : function ( id ) {
for ( var name in this . groupCollection ) {
var store = this . groupCollection [ name ] ,
model = store . findWhere ( { uid : id } ) ;
if ( model ) return model ;
}
} ,
2016-03-11 00:48:53 +00:00
closeEditing : function ( id ) {
var t = this ;
if ( ! _ . isUndefined ( id ) ) {
var comment2 = this . findPopupComment ( id ) ;
if ( comment2 ) {
comment2 . set ( 'editTextInPopover' , false ) ;
comment2 . set ( 'showReplyInPopover' , false ) ;
}
if ( this . subEditStrings [ id ] ) { delete this . subEditStrings [ id ] ; }
if ( this . subEditStrings [ id + '-R' ] ) { delete this . subEditStrings [ id + '-R' ] ; }
}
this . collection . clearEditing ( ) ;
this . collection . each ( function ( model ) {
var replies = _ . clone ( model . get ( 'replys' ) ) ;
model . get ( 'replys' ) . length = 0 ;
replies . forEach ( function ( reply ) {
if ( reply . get ( 'editText' ) )
reply . set ( 'editText' , false ) ;
if ( reply . get ( 'editTextInPopover' ) )
reply . set ( 'editTextInPopover' , false ) ;
} ) ;
model . set ( 'replys' , replies ) ;
} ) ;
this . view . showEditContainer ( false ) ;
this . view . update ( ) ;
} ,
disableHint : function ( comment ) {
if ( comment && this . mode . canComments ) {
comment . set ( 'hint' , false ) ;
this . api . asc _showComment ( comment . get ( 'uid' ) , false ) ;
this . isSelectedComment = true ;
}
} ,
blockPopover : function ( flag ) {
this . isSelectedComment = flag ;
if ( flag ) {
if ( this . getPopover ( ) . isVisible ( ) ) {
this . getPopover ( ) . hide ( ) ;
}
}
} ,
2018-06-07 14:09:54 +00:00
2016-03-11 00:48:53 +00:00
getPopover : function ( ) {
2018-06-07 14:09:54 +00:00
if ( _ . isUndefined ( this . popover ) ) {
this . popover = Common . Views . ReviewPopover . prototype . getPopover ( {
commentsStore : this . popoverComments ,
2018-10-30 08:13:23 +00:00
renderTo : this . sdkViewName ,
2019-06-26 11:04:02 +00:00
canRequestUsers : ( this . mode ) ? this . mode . canRequestUsers : undefined ,
2019-12-23 12:51:00 +00:00
canRequestSendNotify : ( this . mode ) ? this . mode . canRequestSendNotify : undefined ,
mentionShare : ( this . mode ) ? this . mode . mentionShare : true
2018-06-07 14:09:54 +00:00
} ) ;
this . popover . setCommentsStore ( this . popoverComments ) ;
}
return this . popover ;
2016-03-11 00:48:53 +00:00
} ,
// helpers
2018-06-04 11:45:22 +00:00
onUpdateUsers : function ( ) {
2018-11-16 13:44:11 +00:00
var users = this . userCollection ,
hasGroup = false ;
for ( var name in this . groupCollection ) {
hasGroup = true ;
this . groupCollection [ name ] . each ( function ( model ) {
2019-02-26 13:17:05 +00:00
var user = users . findOriginalUser ( model . get ( 'userid' ) ) ,
color = ( user ) ? user . get ( 'color' ) : null ,
needrender = false ;
if ( color !== model . get ( 'usercolor' ) ) {
needrender = true ;
model . set ( 'usercolor' , color , { silent : true } ) ;
}
2018-11-16 13:44:11 +00:00
model . get ( 'replys' ) . forEach ( function ( reply ) {
user = users . findOriginalUser ( reply . get ( 'userid' ) ) ;
2019-02-26 13:17:05 +00:00
color = ( user ) ? user . get ( 'color' ) : null ;
if ( color !== reply . get ( 'usercolor' ) ) {
needrender = true ;
reply . set ( 'usercolor' , color , { silent : true } ) ;
}
2018-11-16 13:44:11 +00:00
} ) ;
2019-02-26 13:17:05 +00:00
if ( needrender )
model . trigger ( 'change' ) ;
2018-11-16 13:44:11 +00:00
} ) ;
}
! hasGroup && this . collection . each ( function ( model ) {
2019-02-26 13:17:05 +00:00
var user = users . findOriginalUser ( model . get ( 'userid' ) ) ,
color = ( user ) ? user . get ( 'color' ) : null ,
needrender = false ;
if ( color !== model . get ( 'usercolor' ) ) {
needrender = true ;
model . set ( 'usercolor' , color , { silent : true } ) ;
}
2018-06-04 11:45:22 +00:00
model . get ( 'replys' ) . forEach ( function ( reply ) {
user = users . findOriginalUser ( reply . get ( 'userid' ) ) ;
2019-02-26 13:17:05 +00:00
color = ( user ) ? user . get ( 'color' ) : null ;
if ( color !== reply . get ( 'usercolor' ) ) {
needrender = true ;
reply . set ( 'usercolor' , color , { silent : true } ) ;
2019-02-18 13:02:32 +00:00
}
} ) ;
2019-02-26 13:17:05 +00:00
if ( needrender )
model . trigger ( 'change' ) ;
} ) ;
2018-06-04 11:45:22 +00:00
} ,
2016-03-11 00:48:53 +00:00
readSDKComment : function ( id , data ) {
2017-08-04 08:18:37 +00:00
var date = ( data . asc _getOnlyOfficeTime ( ) ) ? new Date ( this . stringOOToLocalDate ( data . asc _getOnlyOfficeTime ( ) ) ) :
( ( data . asc _getTime ( ) == '' ) ? new Date ( ) : new Date ( this . stringUtcToLocalDate ( data . asc _getTime ( ) ) ) ) ;
2018-11-16 13:44:11 +00:00
var user = this . userCollection . findOriginalUser ( data . asc _getUserId ( ) ) ,
2018-12-14 14:53:05 +00:00
groupname = id . substr ( 0 , id . lastIndexOf ( '_' ) + 1 ) . match ( /^(doc|sheet[0-9_]+)_/ ) ;
2016-03-11 00:48:53 +00:00
var comment = new Common . Models . Comment ( {
uid : id ,
2019-07-16 12:50:55 +00:00
guid : data . asc _getGuid ( ) ,
2016-03-11 00:48:53 +00:00
userid : data . asc _getUserId ( ) ,
username : data . asc _getUserName ( ) ,
2021-07-06 19:58:36 +00:00
parsedName : AscCommon . UserInfoParser . getParsedName ( data . asc _getUserName ( ) ) ,
2018-06-04 11:45:22 +00:00
usercolor : ( user ) ? user . get ( 'color' ) : null ,
2016-03-11 00:48:53 +00:00
date : this . dateToLocaleTimeString ( date ) ,
quote : data . asc _getQuoteText ( ) ,
comment : data . asc _getText ( ) ,
resolved : data . asc _getSolved ( ) ,
unattached : ! _ . isUndefined ( data . asc _getDocumentFlag ) ? data . asc _getDocumentFlag ( ) : false ,
2020-08-31 11:27:54 +00:00
userdata : data . asc _getUserData ( ) ,
2016-03-11 00:48:53 +00:00
id : Common . UI . getId ( ) ,
time : date . getTime ( ) ,
showReply : false ,
editText : false ,
last : undefined ,
editTextInPopover : ( this . editPopover ? true : false ) ,
showReplyInPopover : false ,
hideAddReply : ! _ . isUndefined ( this . hidereply ) ? this . hidereply : ( this . showPopover ? true : false ) ,
2017-04-11 13:43:31 +00:00
scope : this . view ,
2021-03-26 11:29:16 +00:00
editable : ( this . mode . canEditComments || ( data . asc _getUserId ( ) == this . currentUserId ) ) && AscCommon . UserInfoParser . canEditComment ( data . asc _getUserName ( ) ) ,
removable : ( this . mode . canDeleteComments || ( data . asc _getUserId ( ) == this . currentUserId ) ) && AscCommon . UserInfoParser . canDeleteComment ( data . asc _getUserName ( ) ) ,
hide : ! AscCommon . UserInfoParser . canViewComment ( data . asc _getUserName ( ) ) ,
2018-12-17 08:37:43 +00:00
hint : ! this . mode . canComments ,
2018-11-16 13:44:11 +00:00
groupName : ( groupname && groupname . length > 1 ) ? groupname [ 1 ] : null
2016-03-11 00:48:53 +00:00
} ) ;
if ( comment ) {
var replies = this . readSDKReplies ( data ) ;
if ( replies . length ) {
comment . set ( 'replys' , replies ) ;
}
}
return comment ;
} ,
readSDKReplies : function ( data ) {
var i = 0 ,
replies = [ ] ,
date = null ;
var repliesCount = data . asc _getRepliesCount ( ) ;
if ( repliesCount ) {
for ( i = 0 ; i < repliesCount ; ++ i ) {
2017-08-04 08:18:37 +00:00
date = ( data . asc _getReply ( i ) . asc _getOnlyOfficeTime ( ) ) ? new Date ( this . stringOOToLocalDate ( data . asc _getReply ( i ) . asc _getOnlyOfficeTime ( ) ) ) :
( ( data . asc _getReply ( i ) . asc _getTime ( ) == '' ) ? new Date ( ) : new Date ( this . stringUtcToLocalDate ( data . asc _getReply ( i ) . asc _getTime ( ) ) ) ) ;
2016-03-11 00:48:53 +00:00
2018-06-04 11:45:22 +00:00
var user = this . userCollection . findOriginalUser ( data . asc _getReply ( i ) . asc _getUserId ( ) ) ;
2016-03-11 00:48:53 +00:00
replies . push ( new Common . Models . Reply ( {
id : Common . UI . getId ( ) ,
userid : data . asc _getReply ( i ) . asc _getUserId ( ) ,
username : data . asc _getReply ( i ) . asc _getUserName ( ) ,
2021-07-06 19:58:36 +00:00
parsedName : AscCommon . UserInfoParser . getParsedName ( data . asc _getReply ( i ) . asc _getUserName ( ) ) ,
2018-06-04 11:45:22 +00:00
usercolor : ( user ) ? user . get ( 'color' ) : null ,
2016-03-11 00:48:53 +00:00
date : this . dateToLocaleTimeString ( date ) ,
reply : data . asc _getReply ( i ) . asc _getText ( ) ,
2020-08-31 11:27:54 +00:00
userdata : data . asc _getReply ( i ) . asc _getUserData ( ) ,
2016-03-11 00:48:53 +00:00
time : date . getTime ( ) ,
editText : false ,
editTextInPopover : false ,
showReplyInPopover : false ,
2017-04-11 13:43:31 +00:00
scope : this . view ,
2021-03-26 11:29:16 +00:00
editable : ( this . mode . canEditComments || ( data . asc _getReply ( i ) . asc _getUserId ( ) == this . currentUserId ) ) && AscCommon . UserInfoParser . canEditComment ( data . asc _getReply ( i ) . asc _getUserName ( ) ) ,
2021-05-18 12:18:58 +00:00
removable : ( this . mode . canDeleteComments || ( data . asc _getReply ( i ) . asc _getUserId ( ) == this . currentUserId ) ) && AscCommon . UserInfoParser . canDeleteComment ( data . asc _getReply ( i ) . asc _getUserName ( ) )
2016-03-11 00:48:53 +00:00
} ) ) ;
}
}
return replies ;
} ,
// dummy comment
addDummyComment : function ( ) {
if ( this . api ) {
var me = this , anchor = null , date = new Date ( ) , dialog = this . getPopover ( ) ;
if ( dialog ) {
2019-02-25 16:10:03 +00:00
if ( this . popoverComments . length ) { // can add new comment to text with other comments
if ( this . isDummyComment ) { //don't hide previous dummy comment
_ . delay ( function ( ) {
dialog . commentsView . setFocusToTextBox ( ) ;
} , 200 ) ;
return ;
} else
this . closeEditing ( ) ; // add dummy comment and close editing for existing comment
2016-03-11 00:48:53 +00:00
}
2018-06-04 11:45:22 +00:00
var user = this . userCollection . findOriginalUser ( this . currentUserId ) ;
2016-03-11 00:48:53 +00:00
var comment = new Common . Models . Comment ( {
id : - 1 ,
time : date . getTime ( ) ,
date : this . dateToLocaleTimeString ( date ) ,
userid : this . currentUserId ,
2021-03-26 11:29:16 +00:00
username : AscCommon . UserInfoParser . getCurrentName ( ) ,
2021-07-06 20:24:44 +00:00
parsedName : AscCommon . UserInfoParser . getParsedName ( AscCommon . UserInfoParser . getCurrentName ( ) ) ,
2018-06-04 11:45:22 +00:00
usercolor : ( user ) ? user . get ( 'color' ) : null ,
2016-03-11 00:48:53 +00:00
editTextInPopover : true ,
showReplyInPopover : false ,
hideAddReply : true ,
scope : this . view ,
dummy : true
} ) ;
this . popoverComments . reset ( ) ;
this . popoverComments . push ( comment ) ;
this . uids = [ ] ;
this . isSelectedComment = true ;
this . isDummyComment = true ;
if ( ! _ . isUndefined ( this . api . asc _SetDocumentPlaceChangedEnabled ) ) {
me . api . asc _SetDocumentPlaceChangedEnabled ( true ) ;
}
dialog . handlerHide = ( function ( ) {
} ) ;
if ( dialog . isVisible ( ) ) {
dialog . hide ( ) ;
}
2019-04-11 14:43:28 +00:00
dialog . handlerHide = ( function ( clear ) {
me . clearDummyComment ( clear ) ;
2016-03-11 00:48:53 +00:00
} ) ;
anchor = this . api . asc _getAnchorPosition ( ) ;
if ( anchor ) {
dialog . setLeftTop ( anchor . asc _getX ( ) + anchor . asc _getWidth ( ) ,
anchor . asc _getY ( ) ,
this . hintmode ? anchor . asc _getX ( ) : undefined ) ;
2019-04-15 11:06:41 +00:00
Common . NotificationCenter . trigger ( 'comments:showdummy' ) ;
2019-04-11 14:43:28 +00:00
dialog . showComments ( true , false , true , dialog . getDummyText ( ) ) ;
2016-03-11 00:48:53 +00:00
}
}
}
} ,
onAddDummyComment : function ( commentVal ) {
if ( this . api && commentVal && commentVal . length > 0 ) {
var comment = buildCommentData ( ) ; // new asc_CCommentData(null);
if ( comment ) {
this . showPopover = true ;
this . editPopover = false ;
this . hidereply = false ;
this . isSelectedComment = false ;
this . uids = [ ] ;
this . popoverComments . reset ( ) ;
2016-03-16 08:44:48 +00:00
if ( this . getPopover ( ) . isVisible ( ) ) {
2018-06-07 14:09:54 +00:00
this . getPopover ( ) . hideComments ( ) ;
2016-03-16 08:44:48 +00:00
}
2019-04-11 14:43:28 +00:00
this . isDummyComment = false ;
2016-03-11 00:48:53 +00:00
comment . asc _putText ( commentVal ) ;
comment . asc _putTime ( this . utcDateToString ( new Date ( ) ) ) ;
2017-08-04 08:18:37 +00:00
comment . asc _putOnlyOfficeTime ( this . ooDateToString ( new Date ( ) ) ) ;
2016-03-11 00:48:53 +00:00
comment . asc _putUserId ( this . currentUserId ) ;
2021-03-26 11:29:16 +00:00
comment . asc _putUserName ( AscCommon . UserInfoParser . getCurrentName ( ) ) ;
2016-03-11 00:48:53 +00:00
comment . asc _putSolved ( false ) ;
if ( ! _ . isUndefined ( comment . asc _putDocumentFlag ) )
comment . asc _putDocumentFlag ( false ) ;
2019-07-16 12:50:55 +00:00
this . api . asc _addComment ( comment ) ;
2016-03-11 00:48:53 +00:00
this . view . showEditContainer ( false ) ;
2019-12-20 14:40:15 +00:00
this . mode && this . mode . canRequestSendNotify && this . view . pickEMail ( comment . asc _getGuid ( ) , commentVal ) ;
2016-03-11 00:48:53 +00:00
if ( ! _ . isUndefined ( this . api . asc _SetDocumentPlaceChangedEnabled ) ) {
this . api . asc _SetDocumentPlaceChangedEnabled ( false ) ;
}
}
}
} ,
2019-04-11 14:43:28 +00:00
clearDummyComment : function ( clear ) {
2016-03-11 00:48:53 +00:00
if ( this . isDummyComment ) {
this . isDummyComment = false ;
this . showPopover = true ;
this . editPopover = false ;
this . hidereply = false ;
this . isSelectedComment = false ;
this . uids = [ ] ;
var dialog = this . getPopover ( ) ;
if ( dialog ) {
2019-04-11 14:43:28 +00:00
clear && dialog . clearDummyText ( ) ;
dialog . saveDummyText ( ) ;
2016-03-11 00:48:53 +00:00
dialog . handlerHide = ( function ( ) {
} ) ;
if ( dialog . isVisible ( ) ) {
2018-06-07 14:09:54 +00:00
dialog . hideComments ( ) ;
2016-03-11 00:48:53 +00:00
}
}
this . popoverComments . reset ( ) ;
if ( ! _ . isUndefined ( this . api . asc _SetDocumentPlaceChangedEnabled ) ) {
this . api . asc _SetDocumentPlaceChangedEnabled ( false ) ;
}
2019-04-12 12:15:06 +00:00
Common . NotificationCenter . trigger ( 'comments:cleardummy' ) ;
2016-03-11 00:48:53 +00:00
}
} ,
//
onEditComments : function ( comments ) {
if ( this . api ) {
var i = 0 ,
t = this ,
comment = null ;
var anchor = this . api . asc _getAnchorPosition ( ) ;
if ( anchor ) {
this . isSelectedComment = true ;
this . popoverComments . reset ( ) ;
for ( i = 0 ; i < comments . length ; ++ i ) {
comment = this . findComment ( comments [ i ] . asc _getId ( ) ) ;
2016-11-13 09:42:27 +00:00
if ( comment ) {
2021-03-26 11:29:16 +00:00
comment . set ( 'editTextInPopover' , t . mode . canEditComments && AscCommon . UserInfoParser . canEditComment ( comment . username ) ) ; // dont't edit comment when customization->commentAuthorOnly is true or when permissions.editCommentAuthorOnly is true
2016-11-13 09:42:27 +00:00
comment . set ( 'hint' , false ) ;
this . popoverComments . push ( comment ) ;
}
2016-03-11 00:48:53 +00:00
}
2021-03-17 17:08:47 +00:00
if ( this . getPopover ( ) && this . popoverComments . length > 0 && this . popoverComments . findWhere ( { hide : false } ) ) {
2016-03-11 00:48:53 +00:00
if ( this . getPopover ( ) . isVisible ( ) ) {
this . getPopover ( ) . hide ( ) ;
}
this . getPopover ( ) . setLeftTop ( anchor . asc _getX ( ) + anchor . asc _getWidth ( ) ,
anchor . asc _getY ( ) ,
this . hintmode ? anchor . asc _getX ( ) : undefined ) ;
2018-06-07 14:09:54 +00:00
this . getPopover ( ) . showComments ( true , false , true ) ;
2016-03-11 00:48:53 +00:00
}
}
}
} ,
onAfterShow : function ( ) {
if ( this . view && this . api ) {
var panel = $ ( '.new-comment-ct' , this . view . el ) ;
if ( panel && panel . length ) {
if ( 'none' !== panel . css ( 'display' ) ) {
this . view . txtComment . focus ( ) ;
}
}
2018-12-17 08:37:43 +00:00
if ( this . view . needRender )
this . updateComments ( true ) ;
else if ( this . view . needUpdateFilter )
this . onUpdateFilter ( this . view . needUpdateFilter ) ;
this . view . update ( ) ;
2016-03-11 00:48:53 +00:00
}
} ,
onBeforeHide : function ( ) {
if ( this . view ) {
this . view . showEditContainer ( false ) ;
}
} ,
// utils
timeZoneOffsetInMs : ( new Date ( ) ) . getTimezoneOffset ( ) * 60000 ,
2017-08-04 08:18:37 +00:00
stringOOToLocalDate : function ( date ) {
if ( typeof date === 'string' )
return parseInt ( date ) ;
return 0 ;
} ,
ooDateToString : function ( date ) {
if ( Object . prototype . toString . call ( date ) === '[object Date]' )
return ( date . getTime ( ) ) . toString ( ) ;
return '' ;
} ,
2016-03-11 00:48:53 +00:00
stringUtcToLocalDate : function ( date ) {
if ( typeof date === 'string' )
return parseInt ( date ) + this . timeZoneOffsetInMs ;
return 0 ;
} ,
utcDateToString : function ( date ) {
if ( Object . prototype . toString . call ( date ) === '[object Date]' )
return ( date . getTime ( ) - this . timeZoneOffsetInMs ) . toString ( ) ;
return '' ;
} ,
dateToLocaleTimeString : function ( date ) {
function format ( date ) {
var strTime ,
hours = date . getHours ( ) ,
minutes = date . getMinutes ( ) ,
ampm = hours >= 12 ? 'pm' : 'am' ;
hours = hours % 12 ;
hours = hours ? hours : 12 ; // the hour '0' should be '12'
minutes = minutes < 10 ? '0' + minutes : minutes ;
strTime = hours + ':' + minutes + ' ' + ampm ;
return strTime ;
}
// MM/dd/yyyy hh:mm AM
return ( date . getMonth ( ) + 1 ) + '/' + ( date . getDate ( ) ) + '/' + date . getFullYear ( ) + ' ' + format ( date ) ;
2017-03-29 16:27:44 +00:00
} ,
getView : function ( name ) {
return ! name && this . view ?
this . view : Backbone . Controller . prototype . getView . call ( this , name ) ;
2017-09-01 12:25:31 +00:00
} ,
setPreviewMode : function ( mode ) {
2019-01-14 13:51:23 +00:00
if ( this . viewmode === mode ) return ;
this . viewmode = mode ;
if ( mode )
this . prevcanComments = this . mode . canComments ;
this . mode . canComments = ( mode ) ? false : this . prevcanComments ;
this . closeEditing ( ) ;
this . setMode ( this . mode ) ;
this . updateComments ( true ) ;
2017-09-01 12:25:31 +00:00
if ( this . getPopover ( ) )
2019-02-13 10:33:28 +00:00
mode ? this . getPopover ( ) . hide ( ) : this . getPopover ( ) . update ( true ) ;
2019-02-05 12:11:22 +00:00
} ,
clearCollections : function ( ) {
this . collection . reset ( ) ;
this . groupCollection = [ ] ;
2016-03-11 00:48:53 +00:00
}
2017-09-01 12:25:31 +00:00
2016-03-11 00:48:53 +00:00
} , Common . Controllers . Comments || { } ) ) ;
} ) ;