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
/ * *
* LeftMenu . js
*
* Controller
*
* Created by Maxim Kadushkin on 19 February 2014
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
*
* /
define ( [
'core' ,
'common/main/lib/util/Shortcuts' ,
2018-09-27 10:52:15 +00:00
'common/main/lib/view/SaveAsDlg' ,
2016-03-11 00:48:53 +00:00
'documenteditor/main/app/view/LeftMenu' ,
'documenteditor/main/app/view/FileMenu'
] , function ( ) {
'use strict' ;
DE . Controllers . LeftMenu = Backbone . Controller . extend ( _ . extend ( {
views : [
'LeftMenu' ,
'FileMenu'
] ,
initialize : function ( ) {
this . addListeners ( {
'Common.Views.Chat' : {
'hide' : _ . bind ( this . onHideChat , this )
} ,
2017-03-13 16:29:05 +00:00
'Common.Views.Header' : {
2017-03-16 10:24:03 +00:00
'click:users' : _ . bind ( this . clickStatusbarUsers , this ) ,
2018-03-21 11:28:28 +00:00
'file:settings' : _ . bind ( this . clickToolbarSettings , this ) ,
2017-03-16 10:24:03 +00:00
'history:show' : function ( ) {
if ( ! this . leftMenu . panelHistory . isVisible ( ) )
this . clickMenuFileItem ( 'header' , 'history' ) ;
} . bind ( this )
2016-03-11 00:48:53 +00:00
} ,
'Common.Views.About' : {
'show' : _ . bind ( this . aboutShowHide , this , false ) ,
'hide' : _ . bind ( this . aboutShowHide , this , true )
} ,
2017-08-11 11:01:27 +00:00
'Common.Views.Plugins' : {
2017-12-06 11:25:29 +00:00
'plugin:open' : _ . bind ( this . onPluginOpen , this ) ,
'hide' : _ . bind ( this . onHidePlugins , this )
2017-08-11 11:01:27 +00:00
} ,
'LeftMenu' : {
'comments:show' : _ . bind ( this . commentsShowHide , this , 'show' ) ,
'comments:hide' : _ . bind ( this . commentsShowHide , this , 'hide' )
} ,
2016-03-11 00:48:53 +00:00
'FileMenu' : {
2017-05-01 11:30:44 +00:00
'menu:hide' : _ . bind ( this . menuFilesShowHide , this , 'hide' ) ,
'menu:show' : _ . bind ( this . menuFilesShowHide , this , 'show' ) ,
2016-03-11 00:48:53 +00:00
'item:click' : _ . bind ( this . clickMenuFileItem , this ) ,
'saveas:format' : _ . bind ( this . clickSaveAsFormat , this ) ,
2018-08-22 08:13:37 +00:00
'savecopy:format' : _ . bind ( this . clickSaveCopyAsFormat , this ) ,
2016-03-11 00:48:53 +00:00
'settings:apply' : _ . bind ( this . applySettings , this ) ,
'create:new' : _ . bind ( this . onCreateNew , this ) ,
2017-11-15 12:52:37 +00:00
'recent:open' : _ . bind ( this . onOpenRecent , this )
2016-03-11 00:48:53 +00:00
} ,
'Toolbar' : {
2017-02-20 14:54:12 +00:00
'file:settings' : _ . bind ( this . clickToolbarSettings , this ) ,
'file:open' : this . clickToolbarTab . bind ( this , 'file' ) ,
2018-02-15 23:56:17 +00:00
'file:close' : this . clickToolbarTab . bind ( this , 'other' ) ,
'save:disabled' : this . changeToolbarSaveState . bind ( this )
2016-03-11 00:48:53 +00:00
} ,
'SearchDialog' : {
'hide' : _ . bind ( this . onSearchDlgHide , this ) ,
'search:back' : _ . bind ( this . onQuerySearch , this , 'back' ) ,
'search:next' : _ . bind ( this . onQuerySearch , this , 'next' ) ,
'search:replace' : _ . bind ( this . onQueryReplace , this ) ,
'search:replaceall' : _ . bind ( this . onQueryReplaceAll , this ) ,
'search:highlight' : _ . bind ( this . onSearchHighlight , this )
2017-10-10 12:14:27 +00:00
} ,
'Common.Views.ReviewChanges' : {
'collaboration:chat' : _ . bind ( this . onShowHideChat , this )
2016-03-11 00:48:53 +00:00
}
} ) ;
Common . NotificationCenter . on ( 'leftmenu:change' , _ . bind ( this . onMenuChange , this ) ) ;
2017-03-29 16:29:04 +00:00
Common . NotificationCenter . on ( 'app:comment:add' , _ . bind ( this . onAppAddComment , this ) ) ;
2017-10-09 12:37:12 +00:00
Common . NotificationCenter . on ( 'collaboration:history' , _ . bind ( function ( ) {
if ( ! this . leftMenu . panelHistory . isVisible ( ) )
this . clickMenuFileItem ( null , 'history' ) ;
} , this ) ) ;
2016-03-11 00:48:53 +00:00
} ,
onLaunch : function ( ) {
this . leftMenu = this . createView ( 'LeftMenu' ) . render ( ) ;
this . leftMenu . btnSearch . on ( 'toggle' , _ . bind ( this . onMenuSearch , this ) ) ;
Common . util . Shortcuts . delegateShortcuts ( {
shortcuts : {
'command+shift+s,ctrl+shift+s' : _ . bind ( this . onShortcut , this , 'save' ) ,
'command+f,ctrl+f' : _ . bind ( this . onShortcut , this , 'search' ) ,
2018-10-12 11:36:01 +00:00
'ctrl+h' : _ . bind ( this . onShortcut , this , 'replace' ) ,
2016-03-11 00:48:53 +00:00
'alt+f' : _ . bind ( this . onShortcut , this , 'file' ) ,
'esc' : _ . bind ( this . onShortcut , this , 'escape' ) ,
/** coauthoring begin **/
'alt+q' : _ . bind ( this . onShortcut , this , 'chat' ) ,
'command+shift+h,ctrl+shift+h' : _ . bind ( this . onShortcut , this , 'comments' ) ,
/** coauthoring end **/
'f1' : _ . bind ( this . onShortcut , this , 'help' )
}
} ) ;
Common . util . Shortcuts . suspendEvents ( ) ;
} ,
setApi : function ( api ) {
this . api = api ;
this . api . asc _registerCallback ( 'asc_onReplaceAll' , _ . bind ( this . onApiTextReplaced , this ) ) ;
2018-10-25 13:19:29 +00:00
this . api . asc _registerCallback ( 'asc_onCoAuthoringDisconnect' , _ . bind ( this . onApiServerDisconnect , this ) ) ;
2016-03-11 00:48:53 +00:00
Common . NotificationCenter . on ( 'api:disconnect' , _ . bind ( this . onApiServerDisconnect , this ) ) ;
2018-08-22 08:13:37 +00:00
this . api . asc _registerCallback ( 'asc_onDownloadUrl' , _ . bind ( this . onDownloadUrl , this ) ) ;
2016-03-11 00:48:53 +00:00
/** coauthoring begin **/
if ( this . mode . canCoAuthoring ) {
if ( this . mode . canChat )
this . api . asc _registerCallback ( 'asc_onCoAuthoringChatReceiveMessage' , _ . bind ( this . onApiChatMessage , this ) ) ;
if ( this . mode . canComments ) {
this . api . asc _registerCallback ( 'asc_onAddComment' , _ . bind ( this . onApiAddComment , this ) ) ;
this . api . asc _registerCallback ( 'asc_onAddComments' , _ . bind ( this . onApiAddComments , this ) ) ;
var collection = this . getApplication ( ) . getCollection ( 'Common.Collections.Comments' ) ;
for ( var i = 0 ; i < collection . length ; ++ i ) {
if ( collection . at ( i ) . get ( 'userid' ) !== this . mode . user . id ) {
this . leftMenu . markCoauthOptions ( 'comments' , true ) ;
break ;
}
}
}
}
/** coauthoring end **/
this . leftMenu . getMenu ( 'file' ) . setApi ( api ) ;
if ( this . mode . canUseHistory )
this . getApplication ( ) . getController ( 'Common.Controllers.History' ) . setApi ( this . api ) . setMode ( this . mode ) ;
return this ;
} ,
setMode : function ( mode ) {
this . mode = mode ;
this . leftMenu . setMode ( mode ) ;
this . leftMenu . getMenu ( 'file' ) . setMode ( mode ) ;
2017-08-14 11:24:00 +00:00
if ( ! mode . isEdit ) // TODO: unlock 'save as', 'open file menu' for 'view' mode
Common . util . Shortcuts . removeShortcuts ( {
shortcuts : {
'command+shift+s,ctrl+shift+s' : _ . bind ( this . onShortcut , this , 'save' ) ,
'alt+f' : _ . bind ( this . onShortcut , this , 'file' )
}
} ) ;
2016-03-11 00:48:53 +00:00
return this ;
} ,
createDelayedElements : function ( ) {
/** coauthoring begin **/
if ( this . mode . canCoAuthoring ) {
2018-12-17 08:37:43 +00:00
this . leftMenu . btnComments [ ( this . mode . canViewComments && ! this . mode . isLightVersion ) ? 'show' : 'hide' ] ( ) ;
if ( this . mode . canViewComments )
2017-03-29 16:27:44 +00:00
this . leftMenu . setOptionsPanel ( 'comment' , this . getApplication ( ) . getController ( 'Common.Controllers.Comments' ) . getView ( ) ) ;
2016-03-11 00:48:53 +00:00
2016-06-30 08:56:15 +00:00
this . leftMenu . btnChat [ ( this . mode . canChat && ! this . mode . isLightVersion ) ? 'show' : 'hide' ] ( ) ;
2016-03-11 00:48:53 +00:00
if ( this . mode . canChat )
this . leftMenu . setOptionsPanel ( 'chat' , this . getApplication ( ) . getController ( 'Common.Controllers.Chat' ) . getView ( 'Common.Views.Chat' ) ) ;
} else {
this . leftMenu . btnChat . hide ( ) ;
this . leftMenu . btnComments . hide ( ) ;
}
/** coauthoring end **/
if ( this . mode . canUseHistory )
this . leftMenu . setOptionsPanel ( 'history' , this . getApplication ( ) . getController ( 'Common.Controllers.History' ) . getView ( 'Common.Views.History' ) ) ;
2017-12-19 13:30:58 +00:00
this . leftMenu . setOptionsPanel ( 'navigation' , this . getApplication ( ) . getController ( 'Navigation' ) . getView ( 'Navigation' ) ) ;
2017-10-25 14:36:59 +00:00
this . mode . trialMode && this . leftMenu . setDeveloperMode ( this . mode . trialMode ) ;
2017-04-12 07:54:47 +00:00
2016-05-19 09:46:21 +00:00
Common . util . Shortcuts . resumeEvents ( ) ;
return this ;
} ,
enablePlugins : function ( ) {
2016-05-18 11:41:30 +00:00
if ( this . mode . canPlugins ) {
2017-08-11 11:01:27 +00:00
// this.leftMenu.btnPlugins.show();
2016-05-17 15:38:54 +00:00
this . leftMenu . setOptionsPanel ( 'plugins' , this . getApplication ( ) . getController ( 'Common.Controllers.Plugins' ) . getView ( 'Common.Views.Plugins' ) ) ;
2016-05-18 11:41:30 +00:00
} else
2016-05-17 15:38:54 +00:00
this . leftMenu . btnPlugins . hide ( ) ;
2017-10-25 14:36:59 +00:00
this . mode . trialMode && this . leftMenu . setDeveloperMode ( this . mode . trialMode ) ;
2016-03-11 00:48:53 +00:00
} ,
clickMenuFileItem : function ( menu , action , isopts ) {
var close _menu = true ;
switch ( action ) {
case 'back' :
break ;
case 'save' : this . api . asc _Save ( ) ; break ;
case 'save-desktop' : this . api . asc _DownloadAs ( ) ; break ;
case 'saveas' :
if ( isopts ) close _menu = false ;
else this . clickSaveAsFormat ( undefined ) ;
break ;
2018-08-22 08:13:37 +00:00
case 'save-copy' :
if ( isopts ) close _menu = false ;
else this . clickSaveCopyAsFormat ( undefined ) ;
break ;
2016-03-11 00:48:53 +00:00
case 'print' : this . api . asc _Print ( Common . Utils . isChrome || Common . Utils . isSafari || Common . Utils . isOpera ) ; break ;
case 'exit' : Common . NotificationCenter . trigger ( 'goback' ) ; break ;
case 'edit' :
this . getApplication ( ) . getController ( 'Statusbar' ) . setStatusCaption ( this . requestEditRightsText ) ;
Common . Gateway . requestEditRights ( ) ;
break ;
case 'new' :
if ( isopts ) close _menu = false ;
else this . onCreateNew ( undefined , 'blank' ) ;
break ;
case 'history' :
if ( ! this . leftMenu . panelHistory . isVisible ( ) ) {
if ( this . api . isDocumentModified ( ) ) {
var me = this ;
this . api . asc _stopSaving ( ) ;
Common . UI . warning ( {
closable : false ,
width : 500 ,
title : this . notcriticalErrorTitle ,
msg : this . leavePageText ,
buttons : [ 'ok' , 'cancel' ] ,
primary : 'ok' ,
callback : function ( btn ) {
if ( btn == 'ok' ) {
me . api . asc _undoAllChanges ( ) ;
me . showHistory ( ) ;
} else
me . api . asc _continueSaving ( ) ;
}
} ) ;
} else
this . showHistory ( ) ;
}
break ;
2016-09-27 12:09:32 +00:00
case 'rename' :
var me = this ,
documentCaption = me . api . asc _getDocumentName ( ) ;
( new Common . Views . RenameDialog ( {
filename : documentCaption ,
handler : function ( result , value ) {
if ( result == 'ok' && ! _ . isEmpty ( value . trim ( ) ) && documentCaption !== value . trim ( ) ) {
Common . Gateway . requestRename ( value ) ;
}
Common . NotificationCenter . trigger ( 'edit:complete' , me ) ;
}
} ) ) . show ( ) ;
break ;
2016-03-11 00:48:53 +00:00
default : close _menu = false ;
}
2017-10-09 12:37:12 +00:00
if ( close _menu && menu ) {
2016-03-11 00:48:53 +00:00
menu . hide ( ) ;
}
} ,
clickSaveAsFormat : function ( menu , format ) {
if ( menu ) {
2018-04-18 13:20:59 +00:00
if ( format == Asc . c _oAscFileType . TXT || format == Asc . c _oAscFileType . RTF ) {
2016-03-11 00:48:53 +00:00
Common . UI . warning ( {
closable : false ,
title : this . notcriticalErrorTitle ,
2018-04-18 13:20:59 +00:00
msg : ( format == Asc . c _oAscFileType . TXT ) ? this . warnDownloadAs : this . warnDownloadAsRTF ,
2016-03-11 00:48:53 +00:00
buttons : [ 'ok' , 'cancel' ] ,
callback : _ . bind ( function ( btn ) {
if ( btn == 'ok' ) {
this . api . asc _DownloadAs ( format ) ;
menu . hide ( ) ;
}
} , this )
} ) ;
} else {
this . api . asc _DownloadAs ( format ) ;
menu . hide ( ) ;
}
} else
this . api . asc _DownloadOrigin ( ) ;
} ,
2018-08-22 08:13:37 +00:00
clickSaveCopyAsFormat : function ( menu , format , ext ) {
if ( menu ) {
if ( format == Asc . c _oAscFileType . TXT || format == Asc . c _oAscFileType . RTF ) {
Common . UI . warning ( {
closable : false ,
title : this . notcriticalErrorTitle ,
msg : ( format == Asc . c _oAscFileType . TXT ) ? this . warnDownloadAs : this . warnDownloadAsRTF ,
buttons : [ 'ok' , 'cancel' ] ,
callback : _ . bind ( function ( btn ) {
if ( btn == 'ok' ) {
this . isFromFileDownloadAs = ext ;
this . api . asc _DownloadAs ( format , true ) ;
menu . hide ( ) ;
}
} , this )
} ) ;
} else {
this . isFromFileDownloadAs = ext ;
this . api . asc _DownloadAs ( format , true ) ;
menu . hide ( ) ;
}
} else {
this . isFromFileDownloadAs = true ;
this . api . asc _DownloadOrigin ( true ) ;
}
} ,
onDownloadUrl : function ( url ) {
if ( this . isFromFileDownloadAs ) {
var me = this ,
defFileName = this . getApplication ( ) . getController ( 'Viewport' ) . getView ( 'Common.Views.Header' ) . getDocumentCaption ( ) ;
! defFileName && ( defFileName = me . txtUntitled ) ;
if ( typeof this . isFromFileDownloadAs == 'string' ) {
var idx = defFileName . lastIndexOf ( '.' ) ;
if ( idx > 0 )
defFileName = defFileName . substring ( 0 , idx ) + this . isFromFileDownloadAs ;
}
2018-09-27 10:52:15 +00:00
me . _saveCopyDlg = new Common . Views . SaveAsDlg ( {
saveFolderUrl : me . mode . saveAsUrl ,
saveFileUrl : url ,
2018-08-22 08:13:37 +00:00
defFileName : defFileName
} ) ;
2018-09-27 10:52:15 +00:00
me . _saveCopyDlg . on ( 'saveaserror' , function ( obj , err ) {
2018-08-22 08:13:37 +00:00
var config = {
closable : false ,
2018-09-27 13:12:19 +00:00
title : me . notcriticalErrorTitle ,
2018-08-22 08:13:37 +00:00
msg : err ,
iconCls : 'warn' ,
buttons : [ 'ok' ] ,
callback : function ( btn ) {
Common . NotificationCenter . trigger ( 'edit:complete' , me ) ;
}
} ;
Common . UI . alert ( config ) ;
} ) . on ( 'close' , function ( obj ) {
me . _saveCopyDlg = undefined ;
} ) ;
me . _saveCopyDlg . show ( ) ;
}
this . isFromFileDownloadAs = false ;
} ,
2016-03-11 00:48:53 +00:00
applySettings : function ( menu ) {
2017-06-16 11:53:29 +00:00
var value ;
2017-10-03 11:22:33 +00:00
value = Common . localStorage . getBool ( "de-settings-inputmode" ) ;
Common . Utils . InternalSettings . set ( "de-settings-inputmode" , value ) ;
this . api . SetTextBoxInputMode ( value ) ;
2016-03-11 00:48:53 +00:00
/** coauthoring begin **/
2016-12-20 14:29:37 +00:00
if ( this . mode . isEdit && ! this . mode . isOffline && this . mode . canCoAuthoring ) {
2017-06-16 11:53:29 +00:00
var fast _coauth = Common . localStorage . getBool ( "de-settings-coauthmode" , true ) ;
2017-10-03 11:22:33 +00:00
Common . Utils . InternalSettings . set ( "de-settings-coauthmode" , fast _coauth ) ;
2016-03-25 07:48:19 +00:00
this . api . asc _SetFastCollaborative ( fast _coauth ) ;
2016-03-11 00:48:53 +00:00
value = Common . localStorage . getItem ( ( fast _coauth ) ? "de-settings-showchanges-fast" : "de-settings-showchanges-strict" ) ;
2018-05-07 12:47:44 +00:00
Common . Utils . InternalSettings . set ( ( fast _coauth ) ? "de-settings-showchanges-fast" : "de-settings-showchanges-strict" , value ) ;
2016-03-11 00:48:53 +00:00
switch ( value ) {
2016-04-05 11:52:34 +00:00
case 'all' : value = Asc . c _oAscCollaborativeMarksShowType . All ; break ;
case 'none' : value = Asc . c _oAscCollaborativeMarksShowType . None ; break ;
case 'last' : value = Asc . c _oAscCollaborativeMarksShowType . LastChanges ; break ;
default : value = ( fast _coauth ) ? Asc . c _oAscCollaborativeMarksShowType . None : Asc . c _oAscCollaborativeMarksShowType . LastChanges ;
2016-03-11 00:48:53 +00:00
}
this . api . SetCollaborativeMarksShowType ( value ) ;
}
2017-10-03 11:22:33 +00:00
value = Common . localStorage . getBool ( "de-settings-livecomment" , true ) ;
Common . Utils . InternalSettings . set ( "de-settings-livecomment" , value ) ;
2018-04-26 12:17:02 +00:00
var resolved = Common . localStorage . getBool ( "de-settings-resolvedcomment" ) ;
2017-10-03 11:22:33 +00:00
Common . Utils . InternalSettings . set ( "de-settings-resolvedcomment" , resolved ) ;
2018-12-17 08:37:43 +00:00
if ( this . mode . canViewComments && this . leftMenu . panelComments . isVisible ( ) )
2017-10-03 11:22:33 +00:00
value = resolved = true ;
( value ) ? this . api . asc _showComments ( resolved ) : this . api . asc _hideComments ( ) ;
2016-03-11 00:48:53 +00:00
/** coauthoring end **/
value = Common . localStorage . getItem ( "de-settings-fontrender" ) ;
2017-10-03 11:22:33 +00:00
Common . Utils . InternalSettings . set ( "de-settings-fontrender" , value ) ;
2016-03-11 00:48:53 +00:00
switch ( value ) {
case '1' : this . api . SetFontRenderingMode ( 1 ) ; break ;
case '2' : this . api . SetFontRenderingMode ( 2 ) ; break ;
case '0' : this . api . SetFontRenderingMode ( 3 ) ; break ;
}
2017-06-16 07:29:15 +00:00
if ( this . mode . isEdit ) {
2017-10-03 11:22:33 +00:00
value = parseInt ( Common . localStorage . getItem ( "de-settings-autosave" ) ) ;
Common . Utils . InternalSettings . set ( "de-settings-autosave" , value ) ;
this . api . asc _setAutoSaveGap ( value ) ;
2016-03-11 00:48:53 +00:00
2017-10-03 11:22:33 +00:00
value = Common . localStorage . getBool ( "de-settings-spellcheck" , true ) ;
Common . Utils . InternalSettings . set ( "de-settings-spellcheck" , value ) ;
this . api . asc _setSpellCheck ( value ) ;
2017-06-16 07:29:15 +00:00
}
2016-03-11 00:48:53 +00:00
2017-10-04 15:44:01 +00:00
this . api . put _ShowSnapLines ( Common . Utils . InternalSettings . get ( "de-settings-showsnaplines" ) ) ;
2016-03-11 00:48:53 +00:00
menu . hide ( ) ;
} ,
onCreateNew : function ( menu , type ) {
2017-04-10 13:11:09 +00:00
var newDocumentPage = window . open ( type == 'blank' ? this . mode . createUrl : type , "_blank" ) ;
if ( newDocumentPage ) newDocumentPage . focus ( ) ;
2016-03-11 00:48:53 +00:00
if ( menu ) {
menu . hide ( ) ;
}
} ,
onOpenRecent : function ( menu , url ) {
if ( menu ) {
menu . hide ( ) ;
}
var recentDocPage = window . open ( url ) ;
if ( recentDocPage )
recentDocPage . focus ( ) ;
Common . component . Analytics . trackEvent ( 'Open Recent' ) ;
} ,
clickToolbarSettings : function ( obj ) {
2017-02-20 14:54:12 +00:00
this . leftMenu . showMenu ( 'file:opts' ) ;
} ,
clickToolbarTab : function ( tab , e ) {
if ( tab == 'file' )
this . leftMenu . showMenu ( 'file' ) ; else
2017-04-20 10:29:44 +00:00
this . leftMenu . menuFile . hide ( ) ;
2016-03-11 00:48:53 +00:00
} ,
2018-02-15 23:56:17 +00:00
changeToolbarSaveState : function ( state ) {
2018-07-25 08:21:18 +00:00
var btnSave = this . leftMenu . menuFile . getButton ( 'save' ) ;
btnSave && btnSave . setDisabled ( state ) ;
2018-02-15 23:56:17 +00:00
} ,
2016-03-11 00:48:53 +00:00
/** coauthoring begin **/
clickStatusbarUsers : function ( ) {
2017-02-20 14:54:12 +00:00
this . leftMenu . menuFile . panels [ 'rights' ] . changeAccessRights ( ) ;
2016-03-11 00:48:53 +00:00
} ,
onHideChat : function ( ) {
$ ( this . leftMenu . btnChat . el ) . blur ( ) ;
Common . NotificationCenter . trigger ( 'layout:changed' , 'leftmenu' ) ;
} ,
2017-12-06 11:25:29 +00:00
onHidePlugins : function ( ) {
Common . NotificationCenter . trigger ( 'layout:changed' , 'leftmenu' ) ;
} ,
2016-03-11 00:48:53 +00:00
/** coauthoring end **/
onQuerySearch : function ( d , w , opts ) {
if ( opts . textsearch && opts . textsearch . length ) {
if ( ! this . api . asc _findText ( opts . textsearch , d != 'back' , opts . matchcase , opts . matchword ) ) {
var me = this ;
Common . UI . info ( {
msg : this . textNoTextFound ,
callback : function ( ) {
me . dlgSearch . focus ( ) ;
}
} ) ;
}
}
} ,
onQueryReplace : function ( w , opts ) {
if ( ! _ . isEmpty ( opts . textsearch ) ) {
if ( ! this . api . asc _replaceText ( opts . textsearch , opts . textreplace , false , opts . matchcase , opts . matchword ) ) {
var me = this ;
Common . UI . info ( {
msg : this . textNoTextFound ,
callback : function ( ) {
me . dlgSearch . focus ( ) ;
}
} ) ;
}
}
} ,
onQueryReplaceAll : function ( w , opts ) {
if ( ! _ . isEmpty ( opts . textsearch ) ) {
this . api . asc _replaceText ( opts . textsearch , opts . textreplace , true , opts . matchcase , opts . matchword ) ;
}
} ,
onSearchHighlight : function ( w , highlight ) {
this . api . asc _selectSearchingResults ( highlight ) ;
} ,
showSearchDlg : function ( show , action ) {
if ( ! this . dlgSearch ) {
this . dlgSearch = ( new Common . UI . SearchDialog ( {
matchcase : true ,
markresult : { applied : true }
} ) ) ;
}
if ( show ) {
2019-02-13 09:57:02 +00:00
var mode = this . mode . isEdit && ! this . viewmode ? ( action || undefined ) : 'no-replace' ;
2016-03-11 00:48:53 +00:00
if ( this . dlgSearch . isVisible ( ) ) {
this . dlgSearch . setMode ( mode ) ;
2018-11-15 12:02:50 +00:00
this . dlgSearch . setSearchText ( this . api . asc _GetSelectedText ( ) ) ;
2016-03-11 00:48:53 +00:00
this . dlgSearch . focus ( ) ;
} else {
2018-11-15 12:02:50 +00:00
this . dlgSearch . show ( mode , this . api . asc _GetSelectedText ( ) ) ;
2016-03-11 00:48:53 +00:00
}
} else this . dlgSearch [ 'hide' ] ( ) ;
} ,
onMenuSearch : function ( obj , show ) {
this . showSearchDlg ( show ) ;
} ,
onSearchDlgHide : function ( ) {
this . leftMenu . btnSearch . toggle ( false , true ) ;
this . api . asc _selectSearchingResults ( false ) ;
$ ( this . leftMenu . btnSearch . el ) . blur ( ) ;
this . api . asc _enableKeyEvents ( true ) ;
} ,
onApiTextReplaced : function ( found , replaced ) {
var me = this ;
if ( found ) {
! ( found - replaced > 0 ) ?
Common . UI . info ( { msg : Common . Utils . String . format ( this . textReplaceSuccess , replaced ) } ) :
Common . UI . warning ( { msg : Common . Utils . String . format ( this . textReplaceSkipped , found - replaced ) } ) ;
} else {
Common . UI . info ( { msg : this . textNoTextFound } ) ;
}
} ,
2018-10-25 13:19:29 +00:00
onApiServerDisconnect : function ( enableDownload ) {
2016-03-11 00:48:53 +00:00
this . mode . isEdit = false ;
this . leftMenu . close ( ) ;
/** coauthoring begin **/
this . leftMenu . btnComments . setDisabled ( true ) ;
this . leftMenu . btnChat . setDisabled ( true ) ;
/** coauthoring end **/
2016-05-18 11:41:30 +00:00
this . leftMenu . btnPlugins . setDisabled ( true ) ;
2017-12-19 13:30:58 +00:00
this . leftMenu . btnNavigation . setDisabled ( true ) ;
2016-03-11 00:48:53 +00:00
2018-10-25 13:19:29 +00:00
this . leftMenu . getMenu ( 'file' ) . setMode ( { isDisconnected : true , enableDownload : ! ! enableDownload } ) ;
2016-03-11 00:48:53 +00:00
if ( this . dlgSearch ) {
this . leftMenu . btnSearch . toggle ( false , true ) ;
this . dlgSearch [ 'hide' ] ( ) ;
}
} ,
2019-02-13 09:57:02 +00:00
setPreviewMode : function ( mode ) {
if ( this . viewmode === mode ) return ;
this . viewmode = mode ;
this . dlgSearch && this . dlgSearch . setMode ( this . viewmode ? 'no-replace' : 'search' ) ;
} ,
2016-03-11 00:48:53 +00:00
SetDisabled : function ( disable , disableFileMenu ) {
this . mode . isEdit = ! disable ;
if ( disable ) this . leftMenu . close ( ) ;
/** coauthoring begin **/
this . leftMenu . btnComments . setDisabled ( disable ) ;
2019-02-05 12:11:22 +00:00
var comments = this . getApplication ( ) . getController ( 'Common.Controllers.Comments' ) ;
if ( comments )
comments . setPreviewMode ( disable ) ;
2019-02-13 09:57:02 +00:00
this . setPreviewMode ( disable ) ;
2016-03-11 00:48:53 +00:00
this . leftMenu . btnChat . setDisabled ( disable ) ;
/** coauthoring end **/
2016-05-18 11:41:30 +00:00
this . leftMenu . btnPlugins . setDisabled ( disable ) ;
2017-12-19 13:30:58 +00:00
this . leftMenu . btnNavigation . setDisabled ( disable ) ;
2016-03-11 00:48:53 +00:00
if ( disableFileMenu ) this . leftMenu . getMenu ( 'file' ) . SetDisabled ( disable ) ;
} ,
/** coauthoring begin **/
onApiChatMessage : function ( ) {
this . leftMenu . markCoauthOptions ( 'chat' ) ;
} ,
onApiAddComment : function ( id , data ) {
if ( data && data . asc _getUserId ( ) !== this . mode . user . id )
this . leftMenu . markCoauthOptions ( 'comments' ) ;
} ,
onApiAddComments : function ( data ) {
for ( var i = 0 ; i < data . length ; ++ i ) {
2016-05-31 15:42:12 +00:00
if ( data [ i ] . asc _getUserId ( ) !== this . mode . user . id ) {
2016-03-11 00:48:53 +00:00
this . leftMenu . markCoauthOptions ( 'comments' ) ;
break ;
}
}
} ,
2017-03-29 16:29:04 +00:00
onAppAddComment : function ( sender ) {
var me = this ;
if ( this . api . can _AddQuotedComment ( ) === false ) {
( new Promise ( function ( resolve , reject ) {
resolve ( ) ;
} ) ) . then ( function ( ) {
Common . UI . Menu . Manager . hideAll ( ) ;
me . leftMenu . showMenu ( 'comments' ) ;
var ctrl = DE . getController ( 'Common.Controllers.Comments' ) ;
ctrl . getView ( ) . showEditContainer ( true ) ;
ctrl . onAfterShow ( ) ;
} ) ;
}
} ,
2016-03-11 00:48:53 +00:00
commentsShowHide : function ( mode ) {
2017-10-03 11:22:33 +00:00
var value = Common . Utils . InternalSettings . get ( "de-settings-livecomment" ) ,
resolved = Common . Utils . InternalSettings . get ( "de-settings-resolvedcomment" ) ;
2017-06-16 11:53:29 +00:00
if ( ! value || ! resolved ) {
( mode === 'show' ) ? this . api . asc _showComments ( true ) : ( ( value ) ? this . api . asc _showComments ( resolved ) : this . api . asc _hideComments ( ) ) ;
2016-03-11 00:48:53 +00:00
}
if ( mode === 'show' ) {
this . getApplication ( ) . getController ( 'Common.Controllers.Comments' ) . onAfterShow ( ) ;
}
$ ( this . leftMenu . btnComments . el ) . blur ( ) ;
} ,
/** coauthoring end **/
aboutShowHide : function ( value ) {
if ( this . api )
this . api . asc _enableKeyEvents ( value ) ;
if ( value ) $ ( this . leftMenu . btnAbout . el ) . blur ( ) ;
2017-08-18 14:08:45 +00:00
if ( value && this . leftMenu . _state . pluginIsRunning ) {
this . leftMenu . panelPlugins . show ( ) ;
if ( this . mode . canCoAuthoring ) {
2018-12-17 08:37:43 +00:00
this . mode . canViewComments && this . leftMenu . panelComments [ 'hide' ] ( ) ;
2017-08-18 14:08:45 +00:00
this . mode . canChat && this . leftMenu . panelChat [ 'hide' ] ( ) ;
}
}
2016-03-11 00:48:53 +00:00
} ,
2017-05-01 11:30:44 +00:00
menuFilesShowHide : function ( state ) {
if ( this . dlgSearch ) {
if ( state == 'show' )
this . dlgSearch . suspendKeyEvents ( ) ;
else
2017-06-20 09:53:18 +00:00
Common . Utils . asyncCall ( this . dlgSearch . resumeKeyEvents , this . dlgSearch ) ;
2017-05-01 11:30:44 +00:00
}
2017-09-04 13:21:52 +00:00
if ( this . api && state == 'hide' )
this . api . asc _enableKeyEvents ( true ) ;
2016-03-11 00:48:53 +00:00
} ,
onMenuChange : function ( value ) {
if ( 'hide' === value ) {
if ( this . leftMenu . btnComments . isActive ( ) && this . api ) {
this . leftMenu . btnComments . toggle ( false ) ;
this . leftMenu . onBtnMenuClick ( this . leftMenu . btnComments ) ;
// focus to sdk
this . api . asc _enableKeyEvents ( true ) ;
}
}
} ,
onShortcut : function ( s , e ) {
2018-02-06 10:54:40 +00:00
if ( ! this . mode ) return ;
2016-03-11 00:48:53 +00:00
switch ( s ) {
case 'replace' :
case 'search' :
Common . UI . Menu . Manager . hideAll ( ) ;
this . showSearchDlg ( true , s ) ;
this . leftMenu . btnSearch . toggle ( true , true ) ;
this . leftMenu . btnAbout . toggle ( false ) ;
2017-06-27 08:40:15 +00:00
// this.leftMenu.menuFile.hide();
2016-03-11 00:48:53 +00:00
return false ;
case 'save' :
if ( this . mode . canDownload || this . mode . canDownloadOrigin ) {
if ( this . mode . isDesktopApp && this . mode . isOffline ) this . api . asc _DownloadAs ( ) ;
else {
if ( this . mode . canDownload ) {
Common . UI . Menu . Manager . hideAll ( ) ;
this . leftMenu . showMenu ( 'file:saveas' ) ;
} else
this . api . asc _DownloadOrigin ( ) ;
}
}
return false ;
case 'help' :
2018-04-19 14:26:42 +00:00
if ( this . mode . isEdit && this . mode . canHelp ) { // TODO: unlock 'help' for 'view' mode
2017-08-09 16:59:54 +00:00
Common . UI . Menu . Manager . hideAll ( ) ;
this . leftMenu . showMenu ( 'file:help' ) ;
}
2016-03-11 00:48:53 +00:00
return false ;
case 'file' :
Common . UI . Menu . Manager . hideAll ( ) ;
this . leftMenu . showMenu ( 'file' ) ;
return false ;
case 'escape' :
// if (!this.leftMenu.isOpened()) return true;
2017-04-20 10:29:44 +00:00
if ( this . leftMenu . menuFile . isVisible ( ) ) {
this . leftMenu . menuFile . hide ( ) ;
return false ;
}
2016-03-11 00:48:53 +00:00
var statusbar = DE . getController ( 'Statusbar' ) ;
var menu _opened = statusbar . statusbar . $el . find ( '.open > [data-toggle="dropdown"]' ) ;
if ( menu _opened . length ) {
$ . fn . dropdown . Constructor . prototype . keydown . call ( menu _opened [ 0 ] , e ) ;
return false ;
}
2016-06-28 09:27:00 +00:00
if ( this . mode . canPlugins && this . leftMenu . panelPlugins ) {
menu _opened = this . leftMenu . panelPlugins . $el . find ( '#menu-plugin-container.open > [data-toggle="dropdown"]' ) ;
if ( menu _opened . length ) {
$ . fn . dropdown . Constructor . prototype . keydown . call ( menu _opened [ 0 ] , e ) ;
return false ;
}
}
2017-04-20 10:29:44 +00:00
if ( this . leftMenu . btnAbout . pressed || this . leftMenu . btnPlugins . pressed ||
$ ( e . target ) . parents ( '#left-menu' ) . length ) {
2016-03-11 00:48:53 +00:00
this . leftMenu . close ( ) ;
Common . NotificationCenter . trigger ( 'layout:changed' , 'leftmenu' ) ;
return false ;
}
break ;
/** coauthoring begin **/
case 'chat' :
2016-06-30 08:56:15 +00:00
if ( this . mode . canCoAuthoring && this . mode . canChat && ! this . mode . isLightVersion ) {
2016-03-11 00:48:53 +00:00
Common . UI . Menu . Manager . hideAll ( ) ;
this . leftMenu . showMenu ( 'chat' ) ;
}
return false ;
case 'comments' :
2018-12-17 08:37:43 +00:00
if ( this . mode . canCoAuthoring && this . mode . canViewComments && ! this . mode . isLightVersion ) {
2016-03-11 00:48:53 +00:00
Common . UI . Menu . Manager . hideAll ( ) ;
this . leftMenu . showMenu ( 'comments' ) ;
this . getApplication ( ) . getController ( 'Common.Controllers.Comments' ) . onAfterShow ( ) ;
}
return false ;
/** coauthoring end **/
}
} ,
2017-08-11 11:01:27 +00:00
onPluginOpen : function ( panel , type , action ) {
if ( type == 'onboard' ) {
if ( action == 'open' ) {
2017-08-18 12:17:25 +00:00
this . leftMenu . close ( ) ;
2017-08-11 11:01:27 +00:00
this . leftMenu . panelPlugins . show ( ) ;
this . leftMenu . onBtnMenuClick ( { pressed : true , options : { action : 'plugins' } } ) ;
2017-08-18 14:08:45 +00:00
this . leftMenu . _state . pluginIsRunning = true ;
2017-08-11 11:01:27 +00:00
} else {
2017-08-18 14:08:45 +00:00
this . leftMenu . _state . pluginIsRunning = false ;
2017-08-11 11:01:27 +00:00
this . leftMenu . close ( ) ;
}
}
} ,
2016-03-11 00:48:53 +00:00
showHistory : function ( ) {
var maincontroller = DE . getController ( 'Main' ) ;
if ( ! maincontroller . loadMask )
maincontroller . loadMask = new Common . UI . LoadMask ( { owner : $ ( '#viewport' ) } ) ;
maincontroller . loadMask . setTitle ( this . textLoadHistory ) ;
maincontroller . loadMask . show ( ) ;
Common . Gateway . requestHistory ( ) ;
} ,
2017-10-10 12:14:27 +00:00
onShowHideChat : function ( state ) {
if ( this . mode . canCoAuthoring && this . mode . canChat && ! this . mode . isLightVersion ) {
if ( state ) {
Common . UI . Menu . Manager . hideAll ( ) ;
this . leftMenu . showMenu ( 'chat' ) ;
} else {
this . leftMenu . btnChat . toggle ( false , true ) ;
this . leftMenu . onBtnMenuClick ( this . leftMenu . btnChat ) ;
}
}
} ,
2016-03-11 00:48:53 +00:00
textNoTextFound : 'Text not found' ,
newDocumentTitle : 'Unnamed document' ,
requestEditRightsText : 'Requesting editing rights...' ,
textReplaceSuccess : 'Search has been done. {0} occurrences have been replaced' ,
textReplaceSkipped : 'The replacement has been made. {0} occurrences were skipped.' ,
textLoadHistory : 'Loading versions history...' ,
notcriticalErrorTitle : 'Warning' ,
leavePageText : 'All unsaved changes in this document will be lost.<br> Click \'Cancel\' then \'Save\' to save them. Click \'OK\' to discard all the unsaved changes.' ,
2018-04-18 13:20:59 +00:00
warnDownloadAs : 'If you continue saving in this format all features except the text will be lost.<br>Are you sure you want to continue?' ,
2018-08-22 08:13:37 +00:00
warnDownloadAsRTF : 'If you continue saving in this format some of the formatting might be lost.<br>Are you sure you want to continue?' ,
txtUntitled : 'Untitled'
2016-03-11 00:48:53 +00:00
} , DE . Controllers . LeftMenu || { } ) ) ;
} ) ;