2016-11-18 16:21:25 +00:00
/ *
*
2019-01-17 13:05:03 +00:00
* ( c ) Copyright Ascensio System SIA 2010 - 2019
2016-11-18 16:21:25 +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-11-18 16:21:25 +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
*
* /
/ * *
* Toolbar . js
2016-12-05 15:25:58 +00:00
* Spreadsheet Editor
2016-11-18 16:21:25 +00:00
*
* Created by Maxim Kadushkin on 11 / 15 / 16
2018-03-01 12:16:38 +00:00
* Copyright ( c ) 2018 Ascensio System SIA . All rights reserved .
2016-11-18 16:21:25 +00:00
*
* /
define ( [
'core' ,
2016-12-05 15:25:58 +00:00
'jquery' ,
'underscore' ,
'backbone' ,
2016-11-18 16:21:25 +00:00
'spreadsheeteditor/mobile/app/view/Toolbar'
2016-12-05 15:25:58 +00:00
] , function ( core , $ , _ , Backbone ) {
2016-11-18 16:21:25 +00:00
'use strict' ;
2016-12-05 15:25:58 +00:00
SSE . Controllers . Toolbar = Backbone . Controller . extend ( _ . extend ( ( function ( ) {
2016-11-18 16:21:25 +00:00
// private
2017-01-09 08:56:40 +00:00
var locked = {
book : false ,
sheet : false
} ;
2020-11-01 11:27:08 +00:00
var _users = [ ] ;
2020-11-10 20:33:06 +00:00
var _displayCollaboration = false ;
2016-11-18 16:21:25 +00:00
return {
models : [ ] ,
collections : [ ] ,
views : [
'Toolbar'
] ,
initialize : function ( ) {
Common . Gateway . on ( 'init' , _ . bind ( this . loadConfig , this ) ) ;
} ,
loadConfig : function ( data ) {
if ( data && data . config && data . config . canBackToFolder !== false &&
2019-11-27 07:22:25 +00:00
data . config . customization && data . config . customization . goback && ( data . config . customization . goback . url || data . config . customization . goback . requestClose && data . config . canRequestClose ) ) {
2016-11-18 16:21:25 +00:00
$ ( '#document-back' ) . show ( ) . single ( 'click' , _ . bind ( this . onBack , this ) ) ;
}
} ,
setApi : function ( api ) {
this . api = api ;
2016-12-02 15:08:45 +00:00
this . api . asc _registerCallback ( 'asc_onCanUndoChanged' , _ . bind ( this . onApiCanRevert , this , 'undo' ) ) ;
this . api . asc _registerCallback ( 'asc_onCanRedoChanged' , _ . bind ( this . onApiCanRevert , this , 'redo' ) ) ;
2017-01-09 08:56:40 +00:00
this . api . asc _registerCallback ( 'asc_onSelectionChanged' , this . onApiSelectionChanged . bind ( this ) ) ;
this . api . asc _registerCallback ( 'asc_onWorkbookLocked' , _ . bind ( this . onApiWorkbookLocked , this ) ) ;
this . api . asc _registerCallback ( 'asc_onWorksheetLocked' , _ . bind ( this . onApiWorksheetLocked , this ) ) ;
this . api . asc _registerCallback ( 'asc_onActiveSheetChanged' , _ . bind ( this . onApiActiveSheetChanged , this ) ) ;
2018-05-23 11:43:30 +00:00
this . api . asc _registerCallback ( 'asc_onCoAuthoringDisconnect' , _ . bind ( this . onCoAuthoringDisconnect , this ) ) ;
2020-11-01 11:27:08 +00:00
this . api . asc _registerCallback ( 'asc_onAuthParticipantsChanged' , _ . bind ( this . onUsersChanged , this ) ) ;
this . api . asc _registerCallback ( 'asc_onParticipantsChanged' , _ . bind ( this . onUsersChanged , this ) ) ;
this . api . asc _registerCallback ( 'asc_onConnectionStateChanged' , _ . bind ( this . onUserConnection , this ) ) ;
2017-11-23 09:16:04 +00:00
Common . NotificationCenter . on ( 'api:disconnect' , _ . bind ( this . onCoAuthoringDisconnect , this ) ) ;
2017-01-09 08:56:40 +00:00
Common . NotificationCenter . on ( 'sheet:active' , this . onApiActiveSheetChanged . bind ( this ) ) ;
2016-11-18 16:21:25 +00:00
} ,
setMode : function ( mode ) {
2020-11-01 11:27:08 +00:00
this . mode = mode ;
2016-11-18 16:21:25 +00:00
this . getView ( 'Toolbar' ) . setMode ( mode ) ;
} ,
onLaunch : function ( ) {
var me = this ;
me . createView ( 'Toolbar' ) . render ( ) ;
$ ( '#toolbar-undo' ) . single ( 'click' , _ . bind ( me . onUndo , me ) ) ;
$ ( '#toolbar-redo' ) . single ( 'click' , _ . bind ( me . onRedo , me ) ) ;
} ,
setDocumentTitle : function ( title ) {
$ ( '#toolbar-title' ) . html ( title ) ;
} ,
2016-12-05 15:25:58 +00:00
// Handlers
2016-11-18 16:21:25 +00:00
onBack : function ( e ) {
var me = this ;
if ( me . api . asc _isDocumentModified ( ) ) {
uiApp . modal ( {
title : me . dlgLeaveTitleText ,
text : me . dlgLeaveMsgText ,
verticalButtons : true ,
buttons : [
{
text : me . leaveButtonText ,
onClick : function ( ) {
2019-11-27 07:22:25 +00:00
Common . NotificationCenter . trigger ( 'goback' , true ) ;
2016-11-18 16:21:25 +00:00
}
} ,
{
text : me . stayButtonText ,
bold : true
}
]
} ) ;
} else {
2019-11-27 07:22:25 +00:00
Common . NotificationCenter . trigger ( 'goback' , true ) ;
2016-11-18 16:21:25 +00:00
}
} ,
onUndo : function ( e ) {
if ( this . api ) this . api . asc _Undo ( ) ;
} ,
onRedo : function ( e ) {
if ( this . api ) this . api . asc _Redo ( ) ;
} ,
// API handlers
2017-01-09 08:56:40 +00:00
onApiWorkbookLocked : function ( l ) {
locked . book = l ;
2017-02-10 12:12:55 +00:00
this . onApiSelectionChanged ( ) ;
2017-01-09 08:56:40 +00:00
} ,
onApiWorksheetLocked : function ( l ) {
locked . sheet = l ;
2017-02-10 12:12:55 +00:00
this . onApiSelectionChanged ( ) ;
2017-01-09 08:56:40 +00:00
} ,
onApiActiveSheetChanged : function ( index ) {
locked . sheet = this . api . asc _isWorksheetLockedOrDeleted ( index ) ;
2019-07-18 08:08:26 +00:00
Common . NotificationCenter . trigger ( 'comments:filterchange' , [ 'doc' , 'sheet' + this . api . asc _getWorksheetId ( index ) ] , false ) ;
2017-01-09 08:56:40 +00:00
} ,
2016-11-18 16:21:25 +00:00
onApiCanRevert : function ( which , can ) {
2017-11-23 09:16:04 +00:00
if ( this . isDisconnected ) return ;
2016-11-18 16:21:25 +00:00
if ( which == 'undo' ) {
$ ( '#toolbar-undo' ) . toggleClass ( 'disabled' , ! can ) ;
} else {
$ ( '#toolbar-redo' ) . toggleClass ( 'disabled' , ! can ) ;
}
} ,
2017-01-09 08:56:40 +00:00
onApiSelectionChanged : function ( info ) {
2017-11-23 09:16:04 +00:00
if ( this . isDisconnected ) return ;
2017-02-10 12:12:55 +00:00
if ( ! info ) info = this . api . asc _getCellInfo ( ) ;
var islocked = false ;
2020-05-14 08:39:04 +00:00
switch ( info . asc _getSelectionType ( ) ) {
2017-02-10 12:12:55 +00:00
case Asc . c _oAscSelectionType . RangeChart :
case Asc . c _oAscSelectionType . RangeImage :
case Asc . c _oAscSelectionType . RangeShape :
case Asc . c _oAscSelectionType . RangeChartText :
case Asc . c _oAscSelectionType . RangeShapeText :
var objects = this . api . asc _getGraphicObjectProps ( ) ;
for ( var i in objects ) {
if ( objects [ i ] . asc _getObjectType ( ) == Asc . c _oAscTypeSelectElement . Image ) {
if ( ( islocked = objects [ i ] . asc _getObjectValue ( ) . asc _getLocked ( ) ) )
break ;
2017-01-09 08:56:40 +00:00
}
}
2017-02-10 12:12:55 +00:00
break ;
default :
islocked = info . asc _getLocked ( ) ;
2017-01-09 08:56:40 +00:00
}
this . getView ( 'Toolbar' ) . disableControl ( [ 'add' , 'edit' ] , islocked ) ;
} ,
2017-07-07 08:41:19 +00:00
activateControls : function ( ) {
2019-06-05 14:15:24 +00:00
$ ( '#toolbar-settings, #toolbar-search, #document-back, #toolbar-edit-document, #toolbar-collaboration' ) . removeClass ( 'disabled' ) ;
2017-07-07 08:41:19 +00:00
} ,
2017-11-23 09:16:04 +00:00
activateViewControls : function ( ) {
2019-06-05 14:15:24 +00:00
$ ( '#toolbar-search, #document-back, #toolbar-collaboration' ) . removeClass ( 'disabled' ) ;
2017-11-23 09:16:04 +00:00
} ,
deactivateEditControls : function ( ) {
$ ( '#toolbar-edit, #toolbar-add, #toolbar-settings' ) . addClass ( 'disabled' ) ;
} ,
onCoAuthoringDisconnect : function ( ) {
this . isDisconnected = true ;
2018-05-23 11:43:30 +00:00
this . deactivateEditControls ( ) ;
$ ( '#toolbar-undo' ) . toggleClass ( 'disabled' , true ) ;
$ ( '#toolbar-redo' ) . toggleClass ( 'disabled' , true ) ;
SSE . getController ( 'AddContainer' ) . hideModal ( ) ;
SSE . getController ( 'EditContainer' ) . hideModal ( ) ;
SSE . getController ( 'Settings' ) . hideModal ( ) ;
2017-11-23 09:16:04 +00:00
} ,
2020-11-01 11:27:08 +00:00
displayCollaboration : function ( ) {
if ( _users !== undefined ) {
2019-06-07 07:29:43 +00:00
var length = 0 ;
2020-11-01 11:27:08 +00:00
_ . each ( _users , function ( item ) {
if ( ( item . asc _getState ( ) !== false ) && ! item . asc _getView ( ) )
2019-06-07 07:29:43 +00:00
length ++ ;
} ) ;
2020-11-10 20:33:06 +00:00
_displayCollaboration = ( length >= 1 || ! this . mode || this . mode . canViewComments ) ;
_displayCollaboration ? $ ( '#toolbar-collaboration' ) . show ( ) : $ ( '#toolbar-collaboration' ) . hide ( ) ;
2020-11-01 11:27:08 +00:00
}
} ,
onUsersChanged : function ( users ) {
_users = users ;
this . displayCollaboration ( ) ;
} ,
onUserConnection : function ( change ) {
var changed = false ;
for ( var uid in _users ) {
if ( undefined !== uid ) {
var user = _users [ uid ] ;
if ( user && user . asc _getId ( ) == change . asc _getId ( ) ) {
_users [ uid ] = change ;
changed = true ;
}
2019-06-07 07:29:43 +00:00
}
}
2020-11-01 11:27:08 +00:00
! changed && change && ( _users [ change . asc _getId ( ) ] = change ) ;
this . displayCollaboration ( ) ;
2019-06-07 07:29:43 +00:00
} ,
2020-11-10 20:33:06 +00:00
getDisplayCollaboration : function ( ) {
return _displayCollaboration ;
} ,
2016-11-18 16:21:25 +00:00
dlgLeaveTitleText : 'You leave the application' ,
dlgLeaveMsgText : 'You have unsaved changes in this document. Click \'Stay on this Page\' to await the autosave of the document. Click \'Leave this Page\' to discard all the unsaved changes.' ,
leaveButtonText : 'Leave this Page' ,
2016-12-05 15:25:58 +00:00
stayButtonText : 'Stay on this Page'
2016-11-18 16:21:25 +00:00
}
2016-12-05 15:25:58 +00:00
} ) ( ) , SSE . Controllers . Toolbar || { } ) )
2016-11-18 16:21:25 +00:00
} ) ;