2021-09-04 22:40:13 +00:00
/ *
*
* ( c ) Copyright Ascensio System SIA 2010 - 2019
*
* 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 20 A - 12 Ernesta Birznieka - Upisha
* street , Riga , Latvia , EU , LV - 1050.
*
* 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
*
* /
PE . ApplicationController = new ( function ( ) {
var me ,
api ,
config = { } ,
docConfig = { } ,
permissions = { } ,
2021-09-13 01:38:49 +00:00
created = false ;
2021-09-04 22:40:13 +00:00
var LoadingDocument = - 256 ;
2021-09-13 01:38:49 +00:00
// Check browser
2021-09-04 22:40:13 +00:00
// -------------------------
if ( typeof isBrowserSupported !== 'undefined' && ! isBrowserSupported ( ) ) {
2021-09-13 01:38:49 +00:00
//Common.Gateway.reportError(undefined, this.unsupportedBrowserErrorText);
console . error ( this . unsupportedBrowserErrorText ) ;
2021-09-04 22:40:13 +00:00
return ;
}
common . localStorage . setId ( 'text' ) ;
common . localStorage . setKeysFilter ( 'pe-,asc.presentation' ) ;
common . localStorage . sync ( ) ;
// Handlers
// -------------------------
function loadConfig ( data ) {
config = $ . extend ( config , data . config ) ;
config . canBackToFolder = ( config . canBackToFolder !== false ) && config . customization && config . customization . goback &&
( config . customization . goback . url || config . customization . goback . requestClose && config . canRequestClose ) ;
}
function loadDocument ( data ) {
docConfig = data . doc ;
if ( docConfig ) {
permissions = $ . extend ( permissions , docConfig . permissions ) ;
var _permissions = $ . extend ( { } , docConfig . permissions ) ,
docInfo = new Asc . asc _CDocInfo ( ) ,
_user = new Asc . asc _CUserInfo ( ) ;
var canRenameAnonymous = ! ( ( typeof ( config . customization ) == 'object' ) && ( typeof ( config . customization . anonymous ) == 'object' ) && ( config . customization . anonymous . request === false ) ) ,
guestName = ( typeof ( config . customization ) == 'object' ) && ( typeof ( config . customization . anonymous ) == 'object' ) &&
( typeof ( config . customization . anonymous . label ) == 'string' ) && config . customization . anonymous . label . trim ( ) !== '' ?
common . utils . htmlEncode ( config . customization . anonymous . label ) : me . textGuest ,
value = canRenameAnonymous ? common . localStorage . getItem ( "guest-username" ) : null ,
user = common . utils . fillUserInfo ( config . user , config . lang , value ? ( value + ' (' + guestName + ')' ) : me . textAnonymous ,
common . localStorage . getItem ( "guest-id" ) || ( 'uid-' + Date . now ( ) ) ) ;
user . anonymous && common . localStorage . setItem ( "guest-id" , user . id ) ;
_user . put _Id ( user . id ) ;
_user . put _FullName ( user . fullname ) ;
_user . put _IsAnonymousUser ( user . anonymous ) ;
docInfo . put _Id ( docConfig . key ) ;
docInfo . put _Url ( docConfig . url ) ;
docInfo . put _Title ( docConfig . title ) ;
docInfo . put _Format ( docConfig . fileType ) ;
docInfo . put _VKey ( docConfig . vkey ) ;
docInfo . put _UserInfo ( _user ) ;
docInfo . put _Token ( docConfig . token ) ;
docInfo . put _Permissions ( _permissions ) ;
docInfo . put _EncryptedInfo ( config . encryptionKeys ) ;
2021-09-13 01:38:49 +00:00
docInfo . asc _putIsEnabledMacroses ( false ) ;
docInfo . asc _putIsEnabledPlugins ( false ) ;
/ * v a r e n a b l e = ! c o n f i g . c u s t o m i z a t i o n | | ( c o n f i g . c u s t o m i z a t i o n . m a c r o s ! = = f a l s e ) ;
2021-09-04 22:40:13 +00:00
docInfo . asc _putIsEnabledMacroses ( ! ! enable ) ;
enable = ! config . customization || ( config . customization . plugins !== false ) ;
2021-09-13 01:38:49 +00:00
docInfo . asc _putIsEnabledPlugins ( ! ! enable ) ; * /
2021-09-04 22:40:13 +00:00
if ( api ) {
api . asc _registerCallback ( 'asc_onGetEditorPermissions' , onEditorPermissions ) ;
2021-09-13 01:38:49 +00:00
//api.asc_registerCallback('asc_onRunAutostartMacroses', onRunAutostartMacroses);
2021-09-04 22:40:13 +00:00
api . asc _setDocInfo ( docInfo ) ;
api . asc _getEditorPermissions ( config . licenseUrl , config . customerId ) ;
api . asc _enableKeyEvents ( true ) ;
}
}
}
function onLongActionBegin ( type , id ) {
var text = '' ;
switch ( id )
{
case LoadingDocument :
text = me . textLoadingDocument + ' ' ;
break ;
default :
text = me . waitText ;
break ;
}
if ( type == Asc . c _oAscAsyncActionType [ 'BlockInteraction' ] ) {
if ( ! me . loadMask )
me . loadMask = new common . view . LoadMask ( ) ;
me . loadMask . setTitle ( text ) ;
me . loadMask . show ( ) ;
}
}
function onLongActionEnd ( ) {
me . loadMask && me . loadMask . hide ( ) ;
}
function hidePreloader ( ) {
$ ( '#loading-mask' ) . fadeOut ( 'slow' ) ;
}
function onDocumentContentReady ( ) {
api . ShowThumbnails ( true ) ;
hidePreloader ( ) ;
onLongActionEnd ( Asc . c _oAscAsyncActionType [ 'BlockInteraction' ] , LoadingDocument ) ;
api . asc _registerCallback ( 'asc_onHyperlinkClick' , common . utils . openLink ) ;
api . asc _registerCallback ( 'asc_onStartAction' , onLongActionBegin ) ;
api . asc _registerCallback ( 'asc_onEndAction' , onLongActionEnd ) ;
2021-09-05 00:28:25 +00:00
// api.asc_registerCallback('asc_onEndDemonstration', onPlayStop);
//.asc_registerCallback('asc_onDemonstrationSlideChanged', onPlaySlideChanged);
2021-09-04 22:40:13 +00:00
Common . Gateway . on ( 'processmouse' , onProcessMouse ) ;
Common . Gateway . on ( 'downloadas' , onDownloadAs ) ;
Common . Gateway . on ( 'requestclose' , onRequestClose ) ;
$ ( '#editor_sdk' ) . on ( 'click' , function ( e ) {
if ( e . target . localName == 'canvas' ) {
e . currentTarget . focus ( ) ;
}
} ) ;
Common . Gateway . documentReady ( ) ;
}
function onEditorPermissions ( params ) {
onLongActionBegin ( Asc . c _oAscAsyncActionType [ 'BlockInteraction' ] , LoadingDocument ) ;
api . asc _setViewMode ( false ) ;
api . asc _LoadDocument ( ) ;
api . Resize ( ) ;
}
function onOpenDocument ( progress ) {
var proc = ( progress . asc _getCurrentFont ( ) + progress . asc _getCurrentImage ( ) ) / ( progress . asc _getFontsCount ( ) + progress . asc _getImagesCount ( ) ) ;
me . loadMask && me . loadMask . setTitle ( me . textLoadingDocument + ': ' + common . utils . fixedDigits ( Math . min ( Math . round ( proc * 100 ) , 100 ) , 3 , " " ) + '%' ) ;
}
2021-09-13 01:38:49 +00:00
/ * v a r i s p l a y m o d e ;
function onPlayStart ( e ) {
if ( ! isplaymode ) {
$ ( '#box-preview' ) . show ( ) ;
api . StartDemonstration ( 'id-preview' , currentPage ) ;
} else {
isplaymode == 'play' ?
api . DemonstrationPause ( ) : api . DemonstrationPlay ( ) ;
}
isplaymode != 'play' ? ( $ ( '#btn-play button' ) . addClass ( 'pause' ) , isplaymode = 'play' ) :
( $ ( '#btn-play button' ) . removeClass ( 'pause' ) , isplaymode = 'pause' ) ;
2021-09-04 22:40:13 +00:00
}
2021-09-13 01:38:49 +00:00
function onPlayStop ( ) {
2021-09-04 22:40:13 +00:00
isplaymode = undefined ;
$ ( '#page-number' ) . val ( currentPage + 1 ) ;
2021-09-05 00:28:25 +00:00
//$('#btn-play button').removeClass('pause');
2021-09-04 22:40:13 +00:00
$ ( '#box-preview' ) . hide ( ) ;
}
function onPlaySlideChanged ( number ) {
if ( number ++ < maxPages )
$ ( '#page-number' ) . val ( number ) ;
2021-09-05 00:28:25 +00:00
} * /
2021-09-04 22:40:13 +00:00
function onError ( id , level , errData ) {
if ( id == Asc . c _oAscError . ID . LoadingScriptError ) {
2021-09-05 00:28:25 +00:00
/ * $ ( ' # i d - c r i t i c a l - e r r o r - t i t l e ' ) . t e x t ( m e . c r i t i c a l E r r o r T i t l e ) ;
2021-09-04 22:40:13 +00:00
$ ( '#id-critical-error-message' ) . text ( me . scriptLoadError ) ;
$ ( '#id-critical-error-close' ) . text ( me . txtClose ) . off ( ) . on ( 'click' , function ( ) {
window . location . reload ( ) ;
} ) ;
2021-09-05 00:28:25 +00:00
$ ( '#id-critical-error-dialog' ) . css ( 'z-index' , 20002 ) . modal ( 'show' ) ; * /
console . error ( me . scriptLoadError ) ;
2021-09-04 22:40:13 +00:00
return ;
}
hidePreloader ( ) ;
onLongActionEnd ( Asc . c _oAscAsyncActionType [ 'BlockInteraction' ] , LoadingDocument ) ;
var message ;
switch ( id )
{
case Asc . c _oAscError . ID . Unknown :
message = me . unknownErrorText ;
break ;
case Asc . c _oAscError . ID . ConvertationTimeout :
message = me . convertationTimeoutText ;
break ;
case Asc . c _oAscError . ID . ConvertationError :
message = me . convertationErrorText ;
break ;
case Asc . c _oAscError . ID . DownloadError :
message = me . downloadErrorText ;
break ;
case Asc . c _oAscError . ID . ConvertationPassword :
message = me . errorFilePassProtect ;
break ;
case Asc . c _oAscError . ID . UserDrop :
message = me . errorUserDrop ;
break ;
case Asc . c _oAscError . ID . ConvertationOpenLimitError :
message = me . errorFileSizeExceed ;
break ;
case Asc . c _oAscError . ID . UpdateVersion :
message = me . errorUpdateVersionOnDisconnect ;
break ;
case Asc . c _oAscError . ID . AccessDeny :
message = me . errorAccessDeny ;
break ;
case Asc . c _oAscError . ID . ForceSaveButton :
case Asc . c _oAscError . ID . ForceSaveTimeout :
message = me . errorForceSave ;
break ;
case Asc . c _oAscError . ID . LoadingFontError :
message = me . errorLoadingFont ;
break ;
default :
message = me . errorDefaultMessage . replace ( '%1' , id ) ;
break ;
}
if ( level == Asc . c _oAscError . Level . Critical ) {
// report only critical errors
2021-09-05 00:28:25 +00:00
console . error ( id , message ) ;
/ * C o m m o n . G a t e w a y . r e p o r t E r r o r ( i d , m e s s a g e ) ;
2021-09-04 22:40:13 +00:00
2021-09-05 00:28:25 +00:00
$ ( '#id-crical-error-title' ) . text ( me . criticalErrorTitle ) ;
2021-09-04 22:40:13 +00:00
$ ( '#id-critical-error-message' ) . html ( message ) ;
$ ( '#id-critical-error-close' ) . text ( me . txtClose ) . off ( ) . on ( 'click' , function ( ) {
window . location . reload ( ) ;
2021-09-05 00:28:25 +00:00
} ) ; * /
2021-09-04 22:40:13 +00:00
}
else {
2021-09-05 00:28:25 +00:00
console . warn ( id , message ) ;
/ * C o m m o n . G a t e w a y . r e p o r t W a r n i n g ( i d , m e s s a g e ) ;
2021-09-04 22:40:13 +00:00
$ ( '#id-critical-error-title' ) . text ( me . notcriticalErrorTitle ) ;
$ ( '#id-critical-error-message' ) . html ( message ) ;
$ ( '#id-critical-error-close' ) . text ( me . txtClose ) . off ( ) . on ( 'click' , function ( ) {
$ ( '#id-critical-error-dialog' ) . modal ( 'hide' ) ;
2021-09-05 00:28:25 +00:00
} ) ; * /
2021-09-04 22:40:13 +00:00
}
2021-09-05 00:28:25 +00:00
//$('#id-critical-error-dialog').modal('show');
//Common.Analytics.trackEvent('Internal Error', id.toString());
}
2021-09-09 02:55:43 +00:00
function onExternalMessage ( error ) {
if ( error ) {
2021-09-13 01:38:49 +00:00
hidePreloader ( ) ;
/ * $ ( ' # i d - e r r o r - m a s k - t i t l e ' ) . t e x t ( m e . c r i t i c a l E r r o r T i t l e ) ;
$ ( '#id-error-mask-text' ) . text ( error . msg ) ;
$ ( '#id-error-mask' ) . css ( 'display' , 'block' ) ; * /
2021-09-09 02:55:43 +00:00
console . error ( error . msg ) ;
2021-09-05 00:28:25 +00:00
2021-09-13 01:38:49 +00:00
//Common.Analytics.trackEvent('External Error');
2021-09-09 02:55:43 +00:00
}
}
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
function onProcessMouse ( data ) {
if ( data . type == 'mouseup' ) {
var e = document . getElementById ( 'editor_sdk' ) ;
if ( e ) {
var r = e . getBoundingClientRect ( ) ;
api . OnMouseUp (
data . x - r . left ,
data . y - r . top
) ;
}
}
}
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
function onRequestClose ( ) {
Common . Gateway . requestClose ( ) ;
}
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
function onDownloadAs ( ) {
if ( permissions . download === false ) {
//Common.Gateway.reportError(Asc.c_oAscError.ID.AccessDeny, me.errorAccessDeny);
console . error ( Asc . c _oAscError . ID . AccessDeny , me . errorAccessDeny ) ;
return ;
}
if ( api ) api . asc _DownloadAs ( new Asc . asc _CDownloadOptions ( Asc . c _oAscFileType . PPTX , false ) ) ;
}
2021-09-05 00:28:25 +00:00
2021-09-13 01:38:49 +00:00
function onRunAutostartMacroses ( ) {
2021-09-09 02:55:43 +00:00
if ( ! config . customization || ( config . customization . macros !== false ) )
if ( api ) api . asc _runAutostartMacroses ( ) ;
}
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
function onBeforeUnload ( ) {
common . localStorage . save ( ) ;
}
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
// Helpers
// -------------------------
function onDocumentResize ( ) {
if ( api ) {
api . Resize ( ) ;
}
}
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
function createController ( ) {
if ( created ) return me ;
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
me = this ;
created = true ;
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
// popover ui handlers
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
$ ( window ) . resize ( function ( ) {
onDocumentResize ( ) ;
} ) ;
window . onbeforeunload = onBeforeUnload ;
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
api = new Asc . asc _docs _api ( {
'id-view' : 'editor_sdk' ,
'embedded' : true
} ) ;
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
if ( api ) {
api . SetThemesPath ( "../../../../sdkjs/slide/themes/" ) ;
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
api . asc _registerCallback ( 'asc_onError' , onError ) ;
api . asc _registerCallback ( 'asc_onDocumentContentReady' , onDocumentContentReady ) ;
api . asc _registerCallback ( 'asc_onOpenDocumentProgress' , onOpenDocument ) ;
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
// Initialize api gateway
Common . Gateway . on ( 'init' , loadConfig ) ;
Common . Gateway . on ( 'opendocument' , loadDocument ) ;
Common . Gateway . on ( 'showmessage' , onExternalMessage ) ;
Common . Gateway . appReady ( ) ;
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
}
2021-09-05 00:28:25 +00:00
2021-09-09 02:55:43 +00:00
return me ;
}
return {
create : createController ,
errorDefaultMessage : 'Error code: %1' ,
unknownErrorText : 'Unknown error.' ,
convertationTimeoutText : 'Conversion timeout exceeded.' ,
convertationErrorText : 'Conversion failed.' ,
downloadErrorText : 'Download failed.' ,
criticalErrorTitle : 'Error' ,
notcriticalErrorTitle : 'Warning' ,
scriptLoadError : 'The connection is too slow, some of the components could not be loaded. Please reload the page.' ,
errorFilePassProtect : 'The file is password protected and cannot be opened.' ,
errorAccessDeny : 'You are trying to perform an action you do not have rights for.<br>Please contact your Document Server administrator.' ,
errorUserDrop : 'The file cannot be accessed right now.' ,
unsupportedBrowserErrorText : 'Your browser is not supported.' ,
downloadTextText : 'Downloading presentation...' ,
waitText : 'Please, wait...' ,
textLoadingDocument : 'Loading presentation' ,
txtClose : 'Close' ,
errorFileSizeExceed : 'The file size exceeds the limitation set for your server.<br>Please contact your Document Server administrator for details.' ,
errorUpdateVersionOnDisconnect : 'Internet connection has been restored, and the file version has been changed.<br>Before you can continue working, you need to download the file or copy its content to make sure nothing is lost, and then reload this page.' ,
textGuest : 'Guest' ,
textAnonymous : 'Anonymous' ,
errorForceSave : "An error occurred while saving the file. Please use the 'Download as' option to save the file to your computer hard drive or try again later." ,
errorLoadingFont : 'Fonts are not loaded.<br>Please contact your Document Server administrator.'
}
2021-09-04 22:40:13 +00:00
} ) ( ) ;