2016-04-01 13:17:09 +00:00
/ *
*
* ( c ) Copyright Ascensio System Limited 2010 - 2016
*
* 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
*
* You can contact Ascensio System SIA at Lubanas st . 125 a - 25 , Riga , Latvia ,
* EU , LV - 1021.
*
* 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
Ext . define ( 'DE.controller.Main' , {
extend : 'Ext.app.Controller' ,
editMode : false ,
requires : [
'Ext.Anim' ,
'Ext.LoadMask' ,
'Ext.MessageBox'
] ,
launch : function ( ) {
if ( ! this . _isSupport ( ) ) {
Common . Gateway . reportError ( undefined , this . unsupportedBrowserErrorText ) ;
return ;
}
// Initialize descendants
this . initControl ( ) ;
// Common.component.Analytics.initialize('UA-12442749-13', 'Document Editor Mobile');
// Initialize analytics
// Initialize api
var api = this . api ,
app = this . getApplication ( ) ;
2016-04-05 12:57:51 +00:00
api = new Asc . asc _docs _api ( "id-sdkeditor" ) ;
2016-03-11 00:48:53 +00:00
api . SetMobileVersion ( true ) ;
api . CreateComponents ( ) ;
2016-03-25 13:38:31 +00:00
api . asc _SetFontsPath ( "../../../../sdkjs/fonts/" ) ;
2016-03-11 00:48:53 +00:00
api . Init ( ) ;
api . initEvents2MobileAdvances ( ) ;
api . asc _registerCallback ( 'asc_onStartAction' , Ext . bind ( this . onLongActionBegin , this ) ) ;
api . asc _registerCallback ( 'asc_onError' , Ext . bind ( this . onError , this ) ) ;
api . asc _registerCallback ( 'asc_onEndAction' , Ext . bind ( this . onLongActionEnd , this ) ) ;
api . asc _registerCallback ( 'asc_onDocumentContentReady' , Ext . bind ( this . onDocumentContentReady , this ) ) ;
api . asc _registerCallback ( 'asc_onOpenDocumentProgress' , Ext . bind ( this . onOpenDocument , this ) ) ;
api . asc _registerCallback ( 'asc_onSaveUrl' , Ext . bind ( this . onSaveUrl , this ) ) ;
api . asc _registerCallback ( 'asc_onGetEditorPermissions' , Ext . bind ( this . onEditorPermissions , this ) ) ;
api . asc _registerCallback ( 'asc_onDownloadUrl' , Ext . bind ( this . onDownloadUrl , this ) ) ;
// Initialize descendants
Ext . each ( app . getControllers ( ) , function ( controllerName ) {
var controller = this . getApplication ( ) . getController ( controllerName ) ;
controller && Ext . isFunction ( controller . setApi ) && controller . setApi ( api ) ;
} , this ) ;
this . initApi ( ) ;
// Initialize api gateway
this . editorConfig = { } ;
Common . Gateway . on ( 'init' , Ext . bind ( this . loadConfig , this ) ) ;
Common . Gateway . on ( 'opendocument' , Ext . bind ( this . loadDocument , this ) ) ;
Common . Gateway . on ( 'showmessage' , Ext . bind ( this . onExternalMessage , this ) ) ;
Common . Gateway . on ( 'resetfocus' , Ext . bind ( this . onResetFocus , this ) ) ;
Common . Gateway . on ( 'processsaveresult' , Ext . bind ( this . onProcessSaveResult , this ) ) ;
Common . Gateway . on ( 'processrightschange' , Ext . bind ( this . onProcessRightsChange , this ) ) ;
Common . Gateway . on ( 'downloadas' , Ext . bind ( this . onDownloadAs , this ) ) ;
Common . Gateway . ready ( ) ;
} ,
initControl : function ( ) {
} ,
initApi : function ( ) {
} ,
loadConfig : function ( data ) {
this . editorConfig . user = this . _fillUserInfo ( this . editorConfig . user ) ;
} ,
loadDocument : function ( data ) {
if ( data . doc ) {
this . permissions = data . doc . permissions ;
var _user = new CUserInfo ( ) ;
_user . put _Id ( this . editorConfig . user . id ) ;
_user . put _FirstName ( this . editorConfig . user . firstname ) ;
_user . put _LastName ( this . editorConfig . user . lastname ) ;
_user . put _FullName ( this . editorConfig . user . fullname ) ;
var docInfo = new CDocInfo ( ) ;
docInfo . put _Id ( data . doc . key ) ;
docInfo . put _Url ( data . doc . url ) ;
docInfo . put _Title ( data . doc . title ) ;
docInfo . put _Format ( data . doc . fileType ) ;
docInfo . put _VKey ( data . doc . vkey ) ;
docInfo . put _Options ( data . doc . options ) ;
docInfo . put _UserInfo ( _user ) ;
this . api . asc _setDocInfo ( docInfo ) ;
this . api . asc _getEditorPermissions ( this . editorConfig . licenseUrl , this . editorConfig . customerId ) ;
Common . component . Analytics . trackEvent ( 'Load' , 'Start' ) ;
}
} ,
onEditorPermissions : function ( params ) {
this . permissions . reader !== false && ( this . permissions . reader = params . asc _getCanReaderMode ( ) ) ;
var profile = this . getApplication ( ) . getCurrentProfile ( ) ,
deviceController = this . getApplication ( ) . getController ( 'Main' , profile ? profile . getNamespace ( ) : null ) ,
editMode = ( this . permissions . edit !== false && this . editorConfig . mode !== 'view' ) ,
readerMode = this . permissions . reader === true ;
if ( deviceController ) {
if ( Ext . os . is . Phone ) {
if ( readerMode ) {
this . api . SetReaderModeOnly ( ) ;
editMode = false ;
}
}
if ( Ext . isFunction ( deviceController . setMode ) )
deviceController . setMode ( editMode ? 'edit' : 'view' ) ;
if ( Ext . isFunction ( deviceController . setReadableMode ) )
deviceController . setReadableMode ( readerMode ) ;
}
this . api . asc _setViewMode ( ! editMode ) ;
this . api . asc _LoadDocument ( ) ;
this . api . Resize ( ) ;
} ,
onDocumentContentReady : function ( ) {
if ( this . api ) {
this . api . Resize ( ) ;
this . api . zoomFitToWidth ( ) ;
}
this . _hideLoadSplash ( ) ;
Common . component . Analytics . trackEvent ( 'Load' , 'Complete' ) ;
} ,
onOpenDocument : function ( progress ) {
var elem = document . getElementById ( 'loadmask-text' ) ;
if ( elem ) {
var proc = ( progress . asc _getCurrentFont ( ) + progress . asc _getCurrentImage ( ) ) / ( progress . asc _getFontsCount ( ) + progress . asc _getImagesCount ( ) ) ;
elem . innerHTML = this . loadingDocText + ': ' + Math . min ( Math . round ( proc * 100 ) , 100 ) + '%' ;
}
} ,
onSaveUrl : function ( url ) {
Common . Gateway . save ( url ) ;
} ,
onDownloadUrl : function ( url ) {
Common . Gateway . downloadAs ( url ) ;
} ,
onLongActionBegin : function ( type , id ) {
var text = '' ;
switch ( id ) {
2016-04-05 11:52:34 +00:00
case Asc . c _oAscAsyncAction [ 'Save' ] :
2016-03-11 00:48:53 +00:00
text = this . saveText ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscAsyncAction [ 'Print' ] :
2016-03-11 00:48:53 +00:00
text = this . printText ;
}
2016-04-05 11:52:34 +00:00
if ( type == Asc . c _oAscAsyncActionType [ 'BlockInteraction' ] ) {
2016-03-11 00:48:53 +00:00
Ext . Viewport . setMasked ( {
xtype : 'loadmask' ,
message : text
} ) ;
}
} ,
onLongActionEnd : function ( type ) {
Ext . Viewport . unmask ( ) ;
} ,
onError : function ( id , level , errData ) {
this . _hideLoadSplash ( ) ;
var config = {
closable : false
} ;
switch ( id )
{
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . Unknown :
2016-03-11 00:48:53 +00:00
config . message = this . unknownErrorText ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . ConvertationTimeout :
2016-03-11 00:48:53 +00:00
config . message = this . convertationTimeoutText ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . ConvertationError :
2016-03-11 00:48:53 +00:00
config . message = this . convertationErrorText ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . DownloadError :
2016-03-11 00:48:53 +00:00
config . message = this . downloadErrorText ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . UplImageSize :
2016-03-11 00:48:53 +00:00
config . message = this . uploadImageSizeMessage ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . UplImageExt :
2016-03-11 00:48:53 +00:00
config . message = this . uploadImageExtMessage ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . UplImageFileCount :
2016-03-11 00:48:53 +00:00
config . message = this . uploadImageFileCountMessage ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . SplitCellMaxRows :
2016-03-11 00:48:53 +00:00
config . message = this . splitMaxRowsErrorText . replace ( '%1' , errData . get _Value ( ) ) ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . SplitCellMaxCols :
2016-03-11 00:48:53 +00:00
config . message = this . splitMaxColsErrorText . replace ( '%1' , errData . get _Value ( ) ) ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . SplitCellRowsDivider :
2016-03-11 00:48:53 +00:00
config . message = this . splitDividerErrorText . replace ( '%1' , errData . get _Value ( ) ) ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . VKeyEncrypt :
2016-03-11 00:48:53 +00:00
config . message = this . errorKeyEncrypt ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . KeyExpire :
2016-03-11 00:48:53 +00:00
config . message = this . errorKeyExpire ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . UserCountExceed :
2016-03-11 00:48:53 +00:00
config . message = this . errorUsersExceed ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . CoAuthoringDisconnect :
2016-03-11 00:48:53 +00:00
config . message = this . errorCoAuthoringDisconnect ;
break ;
2016-04-05 11:52:34 +00:00
case Asc . c _oAscError . ID . MobileUnexpectedCharCount :
2016-03-11 00:48:53 +00:00
config . message = this . errorDocTooBig ;
config . out = true ;
break ;
default :
config . message = this . errorDefaultMessage . replace ( '%1' , id ) ;
break ;
}
2016-04-05 11:52:34 +00:00
if ( level == Asc . c _oAscError . Level . Critical ) {
2016-03-11 00:48:53 +00:00
// report only critical errors
Common . Gateway . reportError ( id , config . message ) ;
var me = this ;
config . title = this . criticalErrorTitle ;
config . message += '<br/>' + this . criticalErrorExtText ;
config . buttons = Ext . Msg . OK ;
config . fn = function ( btn ) {
if ( btn == 'ok' ) {
if ( config . out === true ) {
if ( me . editorConfig && me . editorConfig . customization && me . editorConfig . customization . goback && me . editorConfig . customization . goback . url )
window . parent . location . href = me . editorConfig . customization . goback . url ;
} else {
window . location . reload ( ) ;
}
}
}
} else {
config . title = this . notcriticalErrorTitle ;
config . buttons = Ext . Msg . OK ;
config . fn = Ext . emptyFn ;
}
Ext . Msg . show ( config ) ;
Common . component . Analytics . trackEvent ( 'Internal Error' , id . toString ( ) ) ;
} ,
onExternalMessage : function ( msg ) {
if ( msg ) {
this . _hideLoadSplash ( ) ;
Ext . Msg . show ( {
title : msg . title ,
msg : '<br/>' + msg . msg ,
icon : Ext . Msg [ msg . severity . toUpperCase ( ) ] ,
buttons : Ext . Msg . OK
} ) ;
Common . component . Analytics . trackEvent ( 'External Error' , msg . title ) ;
}
} ,
onResetFocus : function ( data ) {
var activeElement = document . activeElement ;
activeElement . focus ( ) ;
} ,
onProcessSaveResult : function ( data ) {
this . api && this . api . asc _OnSaveEnd ( data . result ) ;
} ,
onProcessRightsChange : function ( data ) {
if ( this . api && data && data . enabled === false ) {
this . api . asc _coAuthoringDisconnect ( ) ;
}
} ,
onDownloadAs : function ( ) {
2016-04-05 11:52:34 +00:00
this . api . asc _DownloadAs ( Asc . c _oAscFileType . DOCX , true ) ;
2016-03-11 00:48:53 +00:00
} ,
_hideLoadSplash : function ( ) {
var preloader = Ext . get ( 'loading-mask' ) ;
if ( preloader ) {
Ext . Anim . run ( preloader , 'fade' , {
out : true ,
duration : 250 ,
after : function ( ) {
preloader . destroy ( ) ;
}
} ) ;
}
} ,
_isSupport : function ( ) {
return ( Ext . browser . is . WebKit && ( Ext . os . is . iOS || Ext . os . is . Android || Ext . os . is . Desktop ) ) ;
} ,
_fillUserInfo : function ( info , lang , defname ) {
var _user = info || { } ;
! _user . id && ( _user . id = ( 'uid-' + Date . now ( ) ) ) ;
_ . isEmpty ( _user . firstname ) && _ . isEmpty ( _user . lastname )
&& ( _user . firstname = defname ) ;
_user . fullname = /^ru/ . test ( lang ) ?
_user . lastname + ' ' + _user . firstname : _user . firstname + ' ' + _user . lastname ;
return _user ;
} ,
loadingDocText : 'Loading document' ,
saveText : 'Saving...' ,
printText : 'Printing...' ,
criticalErrorTitle : 'Error' ,
notcriticalErrorTitle : 'Warning' ,
errorDefaultMessage : 'Error code: %1' ,
criticalErrorExtText : 'Press "Ok" to reload view page.' ,
uploadImageSizeMessage : 'Maximium image size limit exceeded.' ,
uploadImageExtMessage : 'Unknown image format.' ,
uploadImageFileCountMessage : 'No images uploaded.' ,
reloadButtonText : 'Reload Page' ,
unknownErrorText : 'Unknown error.' ,
convertationTimeoutText : 'Convertation timeout exceeded.' ,
convertationErrorText : 'Convertation failed.' ,
downloadErrorText : 'Download failed.' ,
unsupportedBrowserErrorText : 'Your browser is not supported.' ,
splitMaxRowsErrorText : 'The number of rows must be less than %1' ,
splitMaxColsErrorText : 'The number of columns must be less than %1' ,
splitDividerErrorText : 'The number of rows must be a divisor of %1' ,
requestEditRightsText : 'Requesting editing rights...' ,
requestEditFailedTitleText : 'Access denied' ,
requestEditFailedMessageText : 'Someone is editing this document right now. Please try again later.' ,
errorKeyEncrypt : 'Unknown key descriptor' ,
errorKeyExpire : 'Key descriptor expired' ,
errorUsersExceed : 'Count of users was exceed' ,
errorCoAuthoringDisconnect : 'Server connection lost. You can\'t edit anymore.' ,
errorDocTooBig : 'The document you are trying to open has more than 30000 characters or 1000 paragraphs in it and cannot by opened on your mobile device. Please try open it using a desktop PC.' ,
textAnonymous : 'Anonymous'
} ) ;