2016-12-20 09:51:21 +00:00
/ *
*
2019-01-17 13:05:03 +00:00
* ( c ) Copyright Ascensio System SIA 2010 - 2019
2016-12-20 09:51:21 +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-12-20 09:51:21 +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
*
* /
/ * *
* DocumentHolder . js
* Presentation Editor
*
* Created by Julia Radzhabova on 12 / 19 / 16
2018-03-01 12:16:38 +00:00
* Copyright ( c ) 2018 Ascensio System SIA . All rights reserved .
2016-12-20 09:51:21 +00:00
*
* /
define ( [
'core' ,
2016-12-22 11:06:59 +00:00
'jquery' ,
'underscore' ,
'backbone' ,
2016-12-20 09:51:21 +00:00
'presentationeditor/mobile/app/view/DocumentHolder'
2016-12-22 14:28:19 +00:00
] , function ( core , $ , _ , Backbone ) {
2016-12-20 09:51:21 +00:00
'use strict' ;
PE . Controllers . DocumentHolder = Backbone . Controller . extend ( _ . extend ( ( function ( ) {
// private
var _stack ,
2016-12-22 11:06:59 +00:00
_view ,
2017-04-11 11:05:56 +00:00
_actionSheets = [ ] ,
2016-12-22 11:06:59 +00:00
_isEdit = false ,
2020-04-10 15:58:59 +00:00
_isPopMenuHidden = false ,
_isComments = false ,
_canViewComments = true ;
2016-12-20 09:51:21 +00:00
return {
models : [ ] ,
collections : [ ] ,
views : [
'DocumentHolder'
] ,
initialize : function ( ) {
this . addListeners ( {
'DocumentHolder' : {
'contextmenu:click' : this . onContextMenuClick
}
} ) ;
} ,
setApi : function ( api ) {
2016-12-22 11:06:59 +00:00
var me = this ;
me . api = api ;
2016-12-20 09:51:21 +00:00
2017-02-03 08:42:53 +00:00
me . api . asc _registerCallback ( 'asc_onShowPopMenu' , _ . bind ( me . onApiShowPopMenu , me ) ) ;
me . api . asc _registerCallback ( 'asc_onHidePopMenu' , _ . bind ( me . onApiHidePopMenu , me ) ) ;
me . api . asc _registerCallback ( 'asc_onDocumentContentReady' , _ . bind ( me . onApiDocumentContentReady , me ) ) ;
2017-11-23 09:01:27 +00:00
Common . NotificationCenter . on ( 'api:disconnect' , _ . bind ( me . onCoAuthoringDisconnect , me ) ) ;
2018-05-23 11:43:30 +00:00
me . api . asc _registerCallback ( 'asc_onCoAuthoringDisconnect' , _ . bind ( me . onCoAuthoringDisconnect , me ) ) ;
2020-04-10 15:58:59 +00:00
me . api . asc _registerCallback ( 'asc_onShowComment' , _ . bind ( me . onApiShowComment , me ) ) ;
me . api . asc _registerCallback ( 'asc_onHideComment' , _ . bind ( me . onApiHideComment , me ) ) ;
} ,
onApiShowComment : function ( comments ) {
_isComments = comments && comments . length > 0 ;
} ,
onApiHideComment : function ( ) {
_isComments = false ;
2016-12-20 09:51:21 +00:00
} ,
setMode : function ( mode ) {
2017-05-25 09:55:29 +00:00
_isEdit = mode . isEdit ;
2020-04-10 15:58:59 +00:00
_canViewComments = mode . canViewComments ;
2016-12-20 09:51:21 +00:00
} ,
// When our application is ready, lets get started
onLaunch : function ( ) {
var me = this ;
2016-12-22 11:06:59 +00:00
_view = me . createView ( 'DocumentHolder' ) . render ( ) ;
2016-12-20 09:51:21 +00:00
$$ ( window ) . on ( 'resize' , _ . bind ( me . onEditorResize , me ) ) ;
} ,
// Handlers
onContextMenuClick : function ( view , eventName ) {
var me = this ;
if ( 'cut' == eventName ) {
2020-02-19 08:15:17 +00:00
var res = me . api . Cut ( ) ;
if ( ! res ) {
_view . hideMenu ( ) ;
uiApp . modal ( {
title : me . textCopyCutPasteActions ,
text : me . errorCopyCutPaste ,
buttons : [ { text : 'OK' } ]
} ) ;
}
2016-12-20 09:51:21 +00:00
} else if ( 'copy' == eventName ) {
2020-02-19 08:15:17 +00:00
var res = me . api . Copy ( ) ;
if ( ! res ) {
_view . hideMenu ( ) ;
uiApp . modal ( {
title : me . textCopyCutPasteActions ,
text : me . errorCopyCutPaste ,
buttons : [ { text : 'OK' } ]
} ) ;
}
2016-12-20 09:51:21 +00:00
} else if ( 'paste' == eventName ) {
2020-02-19 08:15:17 +00:00
var res = me . api . Paste ( ) ;
if ( ! res ) {
_view . hideMenu ( ) ;
uiApp . modal ( {
title : me . textCopyCutPasteActions ,
text : me . errorCopyCutPaste ,
buttons : [ { text : 'OK' } ]
} ) ;
}
2016-12-20 09:51:21 +00:00
} else if ( 'delete' == eventName ) {
me . api . asc _Remove ( ) ;
} else if ( 'edit' == eventName ) {
2016-12-22 11:06:59 +00:00
_view . hideMenu ( ) ;
2016-12-20 09:51:21 +00:00
PE . getController ( 'EditContainer' ) . showModal ( ) ;
} else if ( 'addlink' == eventName ) {
2016-12-22 11:06:59 +00:00
_view . hideMenu ( ) ;
2016-12-20 09:51:21 +00:00
PE . getController ( 'AddContainer' ) . showModal ( ) ;
uiApp . showTab ( '#add-link' ) ;
// PE.getController('AddLink').getView('AddLink').showLink();
} else if ( 'openlink' == eventName ) {
_ . some ( _stack , function ( item ) {
if ( item . get _ObjectType ( ) == Asc . c _oAscTypeSelectElement . Hyperlink ) {
me . _openLink ( item . get _ObjectValue ( ) . get _Value ( ) ) ;
return true ;
}
} ) ;
2020-04-10 15:58:59 +00:00
} else if ( 'viewcomment' == eventName ) {
var getCollaboration = PE . getController ( 'Common.Controllers.Collaboration' ) ;
getCollaboration . showCommentModal ( ) ;
} else if ( 'addcomment' == eventName ) {
_view . hideMenu ( ) ;
PE . getController ( 'AddContainer' ) . showModal ( ) ;
PE . getController ( 'AddOther' ) . getView ( 'AddOther' ) . showPageComment ( false ) ;
2017-04-11 11:05:56 +00:00
} else if ( 'showActionSheet' == eventName && _actionSheets . length > 0 ) {
_ . delay ( function ( ) {
_ . each ( _actionSheets , function ( action ) {
action . text = action . caption
action . onClick = function ( ) {
me . onContextMenuClick ( null , action . event )
}
} ) ;
uiApp . actions ( [ _actionSheets , [
{
text : me . sheetCancel ,
bold : true
}
] ] ) ;
} , 100 ) ;
2016-12-20 09:51:21 +00:00
}
2016-12-22 11:06:59 +00:00
_view . hideMenu ( ) ;
} ,
stopApiPopMenu : function ( ) {
_isPopMenuHidden = true ;
this . onApiHidePopMenu ( ) ;
} ,
startApiPopMenu : function ( ) {
_isPopMenuHidden = false ;
2016-12-20 09:51:21 +00:00
} ,
// API Handlers
onEditorResize : function ( cmp ) {
// Hide context menu
} ,
onApiShowPopMenu : function ( posX , posY ) {
2017-04-11 11:05:56 +00:00
if ( _isPopMenuHidden || $ ( '.popover.settings, .popup.settings, .picker-modal.settings, .modal-in, .actions-modal' ) . length > 0 )
2016-12-23 11:04:03 +00:00
return ;
2016-12-22 11:06:59 +00:00
2016-12-20 09:51:21 +00:00
var me = this ,
items ;
_stack = me . api . getSelectedElements ( ) ;
items = me . _initMenu ( _stack ) ;
2016-12-22 11:06:59 +00:00
_view . showMenu ( items , posX , posY ) ;
2016-12-20 09:51:21 +00:00
} ,
onApiHidePopMenu : function ( ) {
2016-12-22 11:06:59 +00:00
_view && _view . hideMenu ( ) ;
2016-12-20 09:51:21 +00:00
} ,
2017-02-03 08:42:53 +00:00
onApiDocumentContentReady : function ( ) {
_view = this . createView ( 'DocumentHolder' ) . render ( ) ;
} ,
2016-12-20 09:51:21 +00:00
// Internal
_openLink : function ( url ) {
if ( this . api . asc _getUrlType ( url ) > 0 ) {
var newDocumentPage = window . open ( url , '_blank' ) ;
if ( newDocumentPage ) {
newDocumentPage . focus ( ) ;
}
} else
2017-04-11 11:05:56 +00:00
this . api . asc _GoToInternalHyperlink ( url ) ;
2016-12-20 09:51:21 +00:00
} ,
_initMenu : function ( stack ) {
var me = this ,
2019-07-09 08:49:41 +00:00
arrItems = [ ] ,
arrItemsIcon = [ ] ,
2017-02-07 09:06:05 +00:00
canCopy = me . api . can _CopyCut ( ) ;
2016-12-20 09:51:21 +00:00
2017-04-11 11:05:56 +00:00
_actionSheets = [ ] ;
2016-12-20 09:51:21 +00:00
var isText = false ,
isTable = false ,
isImage = false ,
isChart = false ,
isShape = false ,
isLink = false ,
isSlide = false ,
isObject = false ;
_ . each ( stack , function ( item ) {
var objectType = item . get _ObjectType ( ) ,
objectValue = item . get _ObjectValue ( ) ;
if ( objectType == Asc . c _oAscTypeSelectElement . Paragraph ) {
isText = true ;
} else if ( objectType == Asc . c _oAscTypeSelectElement . Image ) {
isImage = true ;
} else if ( objectType == Asc . c _oAscTypeSelectElement . Chart ) {
isChart = true ;
} else if ( objectType == Asc . c _oAscTypeSelectElement . Shape ) {
isShape = true ;
} else if ( objectType == Asc . c _oAscTypeSelectElement . Table ) {
isTable = true ;
} else if ( objectType == Asc . c _oAscTypeSelectElement . Hyperlink ) {
isLink = true ;
} else if ( objectType == Asc . c _oAscTypeSelectElement . Slide ) {
isSlide = true ;
}
} ) ;
isObject = isText || isImage || isChart || isShape || isTable ;
if ( canCopy && isObject ) {
2019-07-09 08:49:41 +00:00
arrItemsIcon . push ( {
2016-12-20 09:51:21 +00:00
caption : me . menuCopy ,
2019-07-09 08:49:41 +00:00
event : 'copy' ,
icon : 'icon-copy'
2016-12-20 09:51:21 +00:00
} ) ;
}
2020-04-10 15:58:59 +00:00
if ( _canViewComments && _isComments && ! _isEdit ) {
arrItems . push ( {
caption : me . menuViewComment ,
event : 'viewcomment'
} ) ;
}
2016-12-20 09:51:21 +00:00
if ( stack . length > 0 ) {
var topObject = stack [ stack . length - 1 ] ,
topObjectType = topObject . get _ObjectType ( ) ,
topObjectValue = topObject . get _ObjectValue ( ) ,
objectLocked = _ . isFunction ( topObjectValue . get _Locked ) ? topObjectValue . get _Locked ( ) : false ;
! objectLocked && ( objectLocked = _ . isFunction ( topObjectValue . get _LockDelete ) ? topObjectValue . get _LockDelete ( ) : false ) ;
var swapItems = function ( items , indexBefore , indexAfter ) {
items [ indexAfter ] = items . splice ( indexBefore , 1 , items [ indexAfter ] ) [ 0 ] ;
} ;
2017-11-23 09:01:27 +00:00
if ( ! objectLocked && _isEdit && ! me . isDisconnected ) {
2016-12-20 09:51:21 +00:00
if ( canCopy && isObject ) {
2019-07-09 08:49:41 +00:00
arrItemsIcon . push ( {
2016-12-20 09:51:21 +00:00
caption : me . menuCut ,
2019-07-09 08:49:41 +00:00
event : 'cut' ,
icon : 'icon-cut'
2016-12-20 09:51:21 +00:00
} ) ;
// Swap 'Copy' and 'Cut'
2019-07-09 08:49:41 +00:00
swapItems ( arrItemsIcon , 0 , 1 ) ;
2016-12-20 09:51:21 +00:00
}
2019-07-09 08:49:41 +00:00
arrItemsIcon . push ( {
2016-12-20 09:51:21 +00:00
caption : me . menuPaste ,
2019-07-09 08:49:41 +00:00
event : 'paste' ,
icon : 'icon-paste'
2016-12-20 09:51:21 +00:00
} ) ;
if ( isObject )
2019-07-09 08:49:41 +00:00
arrItems . push ( {
2016-12-20 09:51:21 +00:00
caption : me . menuDelete ,
event : 'delete'
} ) ;
2019-07-09 08:49:41 +00:00
arrItems . push ( {
2016-12-20 09:51:21 +00:00
caption : me . menuEdit ,
event : 'edit'
} ) ;
if ( ! isLink && me . api . can _AddHyperlink ( ) !== false ) {
2019-07-09 08:49:41 +00:00
arrItems . push ( {
2016-12-20 09:51:21 +00:00
caption : me . menuAddLink ,
event : 'addlink'
} ) ;
}
2020-04-10 15:58:59 +00:00
if ( _isComments && _canViewComments ) {
arrItems . push ( {
caption : me . menuViewComment ,
event : 'viewcomment'
} ) ;
}
2020-04-15 16:50:15 +00:00
var hideAddComment = ( isText && isChart ) || me . api . can _AddQuotedComment ( ) === false || ! _canViewComments ;
if ( ! hideAddComment ) {
2020-04-10 15:58:59 +00:00
arrItems . push ( {
caption : me . menuAddComment ,
event : 'addcomment'
} ) ;
}
2016-12-20 09:51:21 +00:00
}
}
if ( isLink ) {
2019-07-09 08:49:41 +00:00
arrItems . push ( {
2016-12-20 09:51:21 +00:00
caption : me . menuOpenLink ,
event : 'openlink'
} ) ;
}
2019-07-09 08:49:41 +00:00
if ( Common . SharedSettings . get ( 'phone' ) && arrItems . length > 2 ) {
_actionSheets = arrItems . slice ( 2 ) ;
2017-04-11 11:05:56 +00:00
2019-07-09 08:49:41 +00:00
arrItems = arrItems . slice ( 0 , 2 ) ;
arrItems . push ( {
2017-04-11 11:05:56 +00:00
caption : me . menuMore ,
event : 'showActionSheet'
} ) ;
}
2019-07-09 08:49:41 +00:00
var menuItems = { itemsIcon : arrItemsIcon , items : arrItems } ;
2016-12-20 09:51:21 +00:00
return menuItems ;
} ,
2017-11-23 09:01:27 +00:00
onCoAuthoringDisconnect : function ( ) {
this . isDisconnected = true ;
} ,
2016-12-20 09:51:21 +00:00
menuCut : 'Cut' ,
menuCopy : 'Copy' ,
menuPaste : 'Paste' ,
menuEdit : 'Edit' ,
menuDelete : 'Delete' ,
menuAddLink : 'Add Link' ,
2017-04-11 11:05:56 +00:00
menuOpenLink : 'Open Link' ,
menuMore : 'More' ,
2020-04-10 15:58:59 +00:00
menuViewComment : 'View Comment' ,
menuAddComment : 'Add Comment' ,
2020-02-19 08:15:17 +00:00
sheetCancel : 'Cancel' ,
textCopyCutPasteActions : 'Copy, Cut and Paste Actions' ,
errorCopyCutPaste : 'Copy, cut and paste actions using the context menu will be performed within the current file only. You cannot copy or paste to or from other applications.'
2016-12-20 09:51:21 +00:00
}
} ) ( ) , PE . Controllers . DocumentHolder || { } ) )
} ) ;