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
*
* /
/ * *
* DocumentHolder . js
*
* 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' ,
2017-01-19 08:37:14 +00:00
'jquery' ,
'underscore' ,
'backbone' ,
2016-11-18 16:21:25 +00:00
'spreadsheeteditor/mobile/app/view/DocumentHolder'
2017-01-19 08:37:14 +00:00
] , function ( core , $ , _ , Backbone ) {
2016-11-18 16:21:25 +00:00
'use strict' ;
2017-01-09 11:39:26 +00:00
SSE . Controllers . DocumentHolder = Backbone . Controller . extend ( _ . extend ( ( function ( ) {
2016-11-18 16:21:25 +00:00
// private
2017-04-11 11:05:56 +00:00
var _actionSheets = [ ] ,
_isEdit = false ;
2016-12-26 07:48:53 +00:00
function openLink ( url ) {
var newDocumentPage = window . open ( url , '_blank' ) ;
if ( newDocumentPage ) {
newDocumentPage . focus ( ) ;
}
}
2016-11-18 16:21:25 +00:00
return {
models : [ ] ,
collections : [ ] ,
views : [
'DocumentHolder'
] ,
initialize : function ( ) {
this . addListeners ( {
'DocumentHolder' : {
'contextmenu:click' : this . onContextMenuClick
}
} ) ;
} ,
setApi : function ( api ) {
this . api = api ;
2016-12-26 07:48:53 +00:00
this . api . asc _registerCallback ( 'asc_onShowPopMenu' , _ . bind ( this . onApiShowPopMenu , this ) ) ;
this . api . asc _registerCallback ( 'asc_onHidePopMenu' , _ . bind ( this . onApiHidePopMenu , this ) ) ;
2017-11-23 09:16:04 +00:00
Common . NotificationCenter . on ( 'api:disconnect' , _ . bind ( this . onCoAuthoringDisconnect , this ) ) ;
2018-05-23 11:43:30 +00:00
this . api . asc _registerCallback ( 'asc_onCoAuthoringDisconnect' , _ . bind ( this . onCoAuthoringDisconnect , this ) ) ;
2016-11-18 16:21:25 +00:00
} ,
setMode : function ( mode ) {
2017-05-25 09:55:29 +00:00
_isEdit = mode . isEdit ;
2019-06-19 06:48:37 +00:00
if ( _isEdit ) {
this . api . asc _registerCallback ( 'asc_onSetAFDialog' , _ . bind ( this . onApiFilterOptions , this ) ) ;
}
2016-11-18 16:21:25 +00:00
} ,
// When our application is ready, lets get started
onLaunch : function ( ) {
var me = this ;
me . view = me . createView ( 'DocumentHolder' ) . render ( ) ;
$$ ( window ) . on ( 'resize' , _ . bind ( me . onEditorResize , me ) ) ;
} ,
// Handlers
2016-12-26 07:48:53 +00:00
onContextMenuClick : function ( view , event ) {
2016-11-18 16:21:25 +00:00
var me = this ;
2016-12-26 07:48:53 +00:00
var info = me . api . asc _getCellInfo ( ) ;
switch ( event ) {
2020-02-19 08:15:17 +00:00
case 'cut' :
var res = me . api . asc _Cut ( ) ;
if ( ! res ) {
me . view . hideMenu ( ) ;
uiApp . modal ( {
title : me . textCopyCutPasteActions ,
text : me . errorCopyCutPaste ,
buttons : [ { text : 'OK' } ]
} ) ;
}
break ;
case 'copy' :
var res = me . api . asc _Copy ( ) ;
if ( ! res ) {
me . view . hideMenu ( ) ;
uiApp . modal ( {
title : me . textCopyCutPasteActions ,
text : me . errorCopyCutPaste ,
buttons : [ { text : 'OK' } ]
} ) ;
}
break ;
case 'paste' :
var res = me . api . asc _Paste ( ) ;
if ( ! res ) {
me . view . hideMenu ( ) ;
uiApp . modal ( {
title : me . textCopyCutPasteActions ,
text : me . errorCopyCutPaste ,
buttons : [ { text : 'OK' } ]
} ) ;
}
break ;
2016-12-26 07:48:53 +00:00
case 'del' : me . api . asc _emptyCells ( Asc . c _oAscCleanOptions . All ) ; break ;
case 'wrap' : me . api . asc _setCellTextWrap ( true ) ; break ;
case 'unwrap' : me . api . asc _setCellTextWrap ( false ) ; break ;
case 'edit' :
2016-11-18 16:21:25 +00:00
me . view . hideMenu ( ) ;
2017-01-09 08:37:53 +00:00
SSE . getController ( 'EditContainer' ) . showModal ( ) ;
2016-12-26 07:48:53 +00:00
// SSE.getController('EditCell').getView('EditCell');
break ;
case 'merge' :
if ( me . api . asc _mergeCellsDataLost ( Asc . c _oAscMergeOptions . Merge ) ) {
2017-01-19 08:37:14 +00:00
_ . defer ( function ( ) {
uiApp . confirm ( me . warnMergeLostData , undefined , function ( ) {
me . api . asc _mergeCells ( Asc . c _oAscMergeOptions . Merge ) ;
} ) ;
2016-12-26 07:48:53 +00:00
} ) ;
} else {
me . api . asc _mergeCells ( Asc . c _oAscMergeOptions . Merge ) ;
}
break ;
case 'unmerge' :
2017-04-11 11:05:56 +00:00
me . api . asc _mergeCells ( Asc . c _oAscMergeOptions . None ) ;
2016-12-26 07:48:53 +00:00
break ;
2017-01-09 08:54:16 +00:00
case 'hide' :
me . api [ info . asc _getFlags ( ) . asc _getSelectionType ( ) == Asc . c _oAscSelectionType . RangeRow ? 'asc_hideRows' : 'asc_hideColumns' ] ( ) ;
break ;
case 'show' :
me . api [ info . asc _getFlags ( ) . asc _getSelectionType ( ) == Asc . c _oAscSelectionType . RangeRow ? 'asc_showRows' : 'asc_showColumns' ] ( ) ;
break ;
2016-12-26 07:48:53 +00:00
case 'addlink' :
2016-11-18 16:21:25 +00:00
me . view . hideMenu ( ) ;
2017-01-11 10:53:59 +00:00
SSE . getController ( 'AddContainer' ) . showModal ( {
panel : 'hyperlink'
} ) ;
2016-12-26 07:48:53 +00:00
break ;
case 'openlink' :
var linkinfo = info . asc _getHyperlink ( ) ;
if ( linkinfo . asc _getType ( ) == Asc . c _oAscHyperlinkType . RangeLink ) {
/* not implemented in sdk */
} else {
var url = linkinfo . asc _getHyperlinkUrl ( ) . replace ( /\s/g , "%20" ) ;
me . api . asc _getUrlType ( url ) > 0 && openLink ( url ) ;
}
break ;
2019-05-07 16:28:51 +00:00
case 'freezePanes' :
me . api . asc _freezePane ( ) ;
break ;
2016-11-18 16:21:25 +00:00
}
2017-04-11 11:05:56 +00:00
if ( 'showActionSheet' == event && _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-11-18 16:21:25 +00:00
me . view . hideMenu ( ) ;
} ,
// API Handlers
onEditorResize : function ( cmp ) {
// Hide context menu
} ,
onApiShowPopMenu : function ( posX , posY ) {
2020-02-03 11:28:33 +00:00
if ( this . isDisconnected ) return ;
2016-12-26 07:48:53 +00:00
2017-04-11 11:05:56 +00:00
if ( $ ( '.popover.settings, .popup.settings, .picker-modal.settings, .modal-in, .actions-modal' ) . length > 0 ) {
2016-12-23 11:31:28 +00:00
return ;
}
2016-11-18 16:21:25 +00:00
var me = this ,
items ;
2016-12-26 07:48:53 +00:00
items = me . _initMenu ( me . api . asc _getCellInfo ( ) ) ;
2016-11-18 16:21:25 +00:00
2017-01-18 13:47:35 +00:00
me . view . showMenu ( items , posX , posY ) ;
2016-11-18 16:21:25 +00:00
} ,
onApiHidePopMenu : function ( ) {
this . view . hideMenu ( ) ;
} ,
// Internal
2016-12-26 07:48:53 +00:00
_initMenu : function ( cellinfo ) {
2019-07-09 08:49:41 +00:00
var me = this ,
arrItems = [ ] ,
arrItemsIcon = [ ] ;
2020-01-16 15:26:47 +00:00
_actionSheets . length = 0 ;
2017-04-11 11:05:56 +00:00
2017-02-06 16:14:48 +00:00
var iscellmenu , isrowmenu , iscolmenu , isallmenu , ischartmenu , isimagemenu , istextshapemenu , isshapemenu , istextchartmenu ;
var iscelllocked = cellinfo . asc _getLocked ( ) ,
seltype = cellinfo . asc _getFlags ( ) . asc _getSelectionType ( ) ;
switch ( seltype ) {
case Asc . c _oAscSelectionType . RangeCells : iscellmenu = true ; break ;
case Asc . c _oAscSelectionType . RangeRow : isrowmenu = true ; break ;
case Asc . c _oAscSelectionType . RangeCol : iscolmenu = true ; break ;
case Asc . c _oAscSelectionType . RangeMax : isallmenu = true ; break ;
case Asc . c _oAscSelectionType . RangeImage : isimagemenu = true ; break ;
case Asc . c _oAscSelectionType . RangeShape : isshapemenu = true ; break ;
case Asc . c _oAscSelectionType . RangeChart : ischartmenu = true ; break ;
case Asc . c _oAscSelectionType . RangeChartText : istextchartmenu = true ; break ;
case Asc . c _oAscSelectionType . RangeShapeText : istextshapemenu = true ; break ;
}
2020-02-03 11:28:33 +00:00
if ( ! _isEdit ) {
if ( iscellmenu || istextchartmenu || istextshapemenu ) {
arrItemsIcon = [ {
caption : me . menuCopy ,
event : 'copy' ,
icon : 'icon-copy'
} ] ;
}
if ( iscellmenu && cellinfo . asc _getHyperlink ( ) ) {
arrItems . push ( {
caption : me . menuOpenLink ,
event : 'openlink'
} ) ;
}
} else {
2017-02-06 16:14:48 +00:00
2020-02-03 11:28:33 +00:00
if ( ! iscelllocked && ( isimagemenu || isshapemenu || ischartmenu || istextshapemenu || istextchartmenu ) ) {
this . api . asc _getGraphicObjectProps ( ) . every ( function ( object ) {
if ( object . asc _getObjectType ( ) == Asc . c _oAscTypeSelectElement . Image ) {
iscelllocked = object . asc _getObjectValue ( ) . asc _getLocked ( ) ;
}
2017-02-06 16:14:48 +00:00
2020-02-03 11:28:33 +00:00
return ! iscelllocked ;
} ) ;
}
if ( iscelllocked || this . api . isCellEdited ) {
arrItemsIcon = [ {
2017-01-20 08:00:37 +00:00
caption : me . menuCopy ,
2019-07-09 08:49:41 +00:00
event : 'copy' ,
icon : 'icon-copy'
2016-12-26 07:48:53 +00:00
} ] ;
2016-11-18 16:21:25 +00:00
2020-02-03 11:28:33 +00:00
} else {
var arrItemsIcon = [ {
2017-01-20 08:00:37 +00:00
caption : me . menuCut ,
2019-07-09 08:49:41 +00:00
event : 'cut' ,
icon : 'icon-cut'
2020-02-03 11:28:33 +00:00
} , {
2017-01-20 08:00:37 +00:00
caption : me . menuCopy ,
2019-07-09 08:49:41 +00:00
event : 'copy' ,
icon : 'icon-copy'
2020-02-03 11:28:33 +00:00
} , {
2017-01-20 08:00:37 +00:00
caption : me . menuPaste ,
2019-07-09 08:49:41 +00:00
event : 'paste' ,
icon : 'icon-paste'
2017-01-09 08:57:45 +00:00
} ] ;
2020-02-03 11:28:33 +00:00
arrItems . push ( {
caption : me . menuDelete ,
event : 'del'
} ) ;
2016-12-26 07:48:53 +00:00
2017-02-06 16:14:48 +00:00
// isTableLocked = cellinfo.asc_getLockedTable()===true;
2016-11-18 16:21:25 +00:00
2020-02-03 11:28:33 +00:00
if ( isimagemenu || isshapemenu || ischartmenu ||
istextshapemenu || istextchartmenu ) {
2019-07-09 08:49:41 +00:00
arrItems . push ( {
2020-02-03 11:28:33 +00:00
caption : me . menuEdit ,
event : 'edit'
} ) ;
} else {
if ( iscolmenu || isrowmenu ) {
arrItems . push ( {
2017-01-20 08:00:37 +00:00
caption : me . menuHide ,
2017-01-09 08:54:16 +00:00
event : 'hide'
2020-02-03 11:28:33 +00:00
} , {
2017-01-20 08:00:37 +00:00
caption : me . menuShow ,
2017-01-09 08:54:16 +00:00
event : 'show'
} ) ;
2020-02-03 11:28:33 +00:00
} else if ( iscellmenu ) {
! iscelllocked &&
arrItems . push ( {
caption : me . menuCell ,
event : 'edit'
} ) ;
2016-12-26 07:48:53 +00:00
2020-02-03 11:28:33 +00:00
( cellinfo . asc _getFlags ( ) . asc _getMerge ( ) == Asc . c _oAscMergeOptions . None ) &&
2019-07-09 08:49:41 +00:00
arrItems . push ( {
2020-02-03 11:28:33 +00:00
caption : me . menuMerge ,
event : 'merge'
2016-12-26 07:48:53 +00:00
} ) ;
2020-02-03 11:28:33 +00:00
( cellinfo . asc _getFlags ( ) . asc _getMerge ( ) == Asc . c _oAscMergeOptions . Merge ) &&
2019-07-09 08:49:41 +00:00
arrItems . push ( {
2020-02-03 11:28:33 +00:00
caption : me . menuUnmerge ,
event : 'unmerge'
2016-12-26 07:48:53 +00:00
} ) ;
2020-02-03 11:28:33 +00:00
arrItems . push (
cellinfo . asc _getFlags ( ) . asc _getWrapText ( ) ?
{
caption : me . menuUnwrap ,
event : 'unwrap'
} :
{
caption : me . menuWrap ,
event : 'wrap'
} ) ;
if ( cellinfo . asc _getHyperlink ( ) && ! cellinfo . asc _getFlags ( ) . asc _getMultiselect ( ) &&
cellinfo . asc _getHyperlink ( ) . asc _getType ( ) == Asc . c _oAscHyperlinkType . WebLink ) {
arrItems . push ( {
caption : me . menuOpenLink ,
event : 'openlink'
} ) ;
} else if ( ! cellinfo . asc _getHyperlink ( ) && ! cellinfo . asc _getFlags ( ) . asc _getMultiselect ( ) &&
! cellinfo . asc _getFlags ( ) . asc _getLockText ( ) && ! ! cellinfo . asc _getText ( ) ) {
arrItems . push ( {
caption : me . menuAddLink ,
event : 'addlink'
} ) ;
}
2016-12-26 07:48:53 +00:00
}
2019-05-08 08:36:06 +00:00
2020-02-03 11:28:33 +00:00
arrItems . push ( {
caption : this . api . asc _getSheetViewSettings ( ) . asc _getIsFreezePane ( ) ? me . menuUnfreezePanes : me . menuFreezePanes ,
event : 'freezePanes'
} ) ;
2019-05-08 08:36:06 +00:00
2020-02-03 11:28:33 +00:00
}
2016-11-18 16:21:25 +00:00
}
2019-05-07 16:28:51 +00:00
2020-02-03 11:28:33 +00:00
if ( Common . SharedSettings . get ( 'phone' ) && arrItems . length > 2 ) {
_actionSheets = arrItems . slice ( 2 ) ;
2019-05-07 16:28:51 +00:00
2020-02-03 11:28:33 +00:00
arrItems = arrItems . slice ( 0 , 2 ) ;
arrItems . push ( {
caption : me . menuMore ,
event : 'showActionSheet'
} ) ;
}
2016-11-18 16:21:25 +00:00
}
2019-07-09 08:49:41 +00:00
var menuItems = { itemsIcon : arrItemsIcon , items : arrItems } ;
2016-11-18 16:21:25 +00:00
return menuItems ;
2016-12-26 07:48:53 +00:00
} ,
2017-11-23 09:16:04 +00:00
onCoAuthoringDisconnect : function ( ) {
this . isDisconnected = true ;
} ,
2019-06-19 06:48:37 +00:00
onApiFilterOptions : function ( config ) {
if ( _isEdit ) {
2019-06-19 10:41:19 +00:00
var rect = config . asc _getCellCoord ( ) ,
posX = rect . asc _getX ( ) + rect . asc _getWidth ( ) - 9 ,
posY = rect . asc _getY ( ) + rect . asc _getHeight ( ) - 9 ;
SSE . getController ( 'FilterOptions' ) . showModal ( posX , posY ) ;
2019-06-19 06:48:37 +00:00
}
} ,
2017-01-20 08:00:37 +00:00
warnMergeLostData : 'Operation can destroy data in the selected cells.<br>Continue?' ,
menuCopy : 'Copy' ,
menuCut : 'Cut' ,
menuPaste : 'Paste' ,
menuDelete : 'Delete' ,
menuAddLink : 'Add Link' ,
menuOpenLink : 'Open Link' ,
menuWrap : 'Wrap' ,
menuUnwrap : 'Unwrap' ,
menuMerge : 'Merge' ,
menuUnmerge : 'Unmerge' ,
menuShow : 'Show' ,
menuHide : 'Hide' ,
menuEdit : 'Edit' ,
2017-04-11 11:05:56 +00:00
menuCell : 'Cell' ,
menuMore : 'More' ,
2019-05-07 16:28:51 +00:00
sheetCancel : 'Cancel' ,
menuFreezePanes : 'Freeze Panes' ,
2020-02-19 08:15:17 +00:00
menuUnfreezePanes : 'Unfreeze Panes' ,
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-11-18 16:21:25 +00:00
}
2017-01-09 11:39:26 +00:00
} ) ( ) , SSE . Controllers . DocumentHolder || { } ) )
2016-11-18 16:21:25 +00:00
} ) ;