web-apps/apps/spreadsheeteditor/embed/js/ApplicationController.js

755 lines
29 KiB
JavaScript
Raw Normal View History

2016-04-01 13:17:09 +00:00
/*
*
* (c) Copyright Ascensio System SIA 2010-2019
2016-04-01 13:17:09 +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
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
2016-04-01 13:17:09 +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
*
*/
SSE.ApplicationController = new(function(){
2016-03-11 00:48:53 +00:00
var me,
api,
config = {},
docConfig = {},
embedConfig = {},
permissions = {},
appOptions = {},
2016-03-11 00:48:53 +00:00
maxPages = 0,
created = false,
iframePrint = null;
var $ttEl,
$tooltip,
2021-05-19 13:35:59 +00:00
ttOffset = [6, -15],
labelDocName;
2016-03-11 00:48:53 +00:00
var LoadingDocument = -256;
2016-03-11 00:48:53 +00:00
// Initialize analytics
// -------------------------
2019-02-22 12:28:39 +00:00
// Common.Analytics.initialize('UA-12442749-13', 'Embedded Spreadsheet Editor');
2016-03-11 00:48:53 +00:00
// Check browser
// -------------------------
if (typeof isBrowserSupported !== 'undefined' && !isBrowserSupported()){
Common.Gateway.reportError(undefined, this.unsupportedBrowserErrorText);
2016-03-11 00:48:53 +00:00
return;
}
common.localStorage.setId('text');
common.localStorage.setKeysFilter('sse-,asc.table');
common.localStorage.sync();
2016-03-11 00:48:53 +00:00
// Handlers
// -------------------------
function loadConfig(data) {
config = $.extend(config, data.config);
embedConfig = $.extend(embedConfig, data.config.embedded);
common.controller.modals.init(embedConfig);
2022-04-27 19:12:59 +00:00
common.controller.SearchBar.init(embedConfig);
2016-03-11 00:48:53 +00:00
// Docked toolbar
if (embedConfig.toolbarDocked === 'bottom') {
2016-03-11 00:48:53 +00:00
$('#toolbar').addClass('bottom');
$('.viewer').addClass('bottom');
$('#box-tools').removeClass('dropdown').addClass('dropup');
ttOffset[1] = -40;
} else {
$('#toolbar').addClass('top');
$('.viewer').addClass('top');
2016-03-11 00:48:53 +00:00
}
2021-05-19 13:35:59 +00:00
config.canBackToFolder = (config.canBackToFolder!==false) && config.customization && config.customization.goback &&
(config.customization.goback.url || config.customization.goback.requestClose && config.canRequestClose);
2022-01-13 15:42:31 +00:00
var reg = (typeof (config.region) == 'string') ? config.region.toLowerCase() : config.region;
reg = Common.util.LanguageInfo.getLanguages().hasOwnProperty(reg) ? reg : Common.util.LanguageInfo.getLocalLanguageCode(reg);
if (reg!==null)
reg = parseInt(reg);
else
reg = (config.lang) ? parseInt(Common.util.LanguageInfo.getLocalLanguageCode(config.lang)) : 0x0409;
api.asc_setLocale(reg);
2016-03-11 00:48:53 +00:00
}
function loadDocument(data) {
docConfig = data.doc;
if (docConfig) {
permissions = $.extend(permissions, docConfig.permissions);
2022-05-16 16:53:13 +00:00
var docInfo = new Asc.asc_CDocInfo(),
2020-10-31 16:53:35 +00:00
_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);
2021-05-25 13:57:56 +00:00
_user.put_IsAnonymousUser(user.anonymous);
2020-10-31 16:53:35 +00:00
2016-03-11 00:48:53 +00:00
docInfo.put_Id(docConfig.key);
docInfo.put_Url(docConfig.url);
2022-07-29 10:44:00 +00:00
docInfo.put_DirectUrl(docConfig.directUrl);
2016-03-11 00:48:53 +00:00
docInfo.put_Title(docConfig.title);
docInfo.put_Format(docConfig.fileType);
docInfo.put_VKey(docConfig.vkey);
2020-10-31 16:53:35 +00:00
docInfo.put_UserInfo(_user);
2021-11-26 11:10:44 +00:00
docInfo.put_CallbackUrl(config.callbackUrl);
2016-11-24 13:44:54 +00:00
docInfo.put_Token(docConfig.token);
2022-05-16 16:53:13 +00:00
docInfo.put_Permissions(docConfig.permissions);
docInfo.put_EncryptedInfo(config.encryptionKeys);
2021-08-31 13:12:30 +00:00
docInfo.put_Lang(config.lang);
docInfo.put_Mode(config.mode);
2016-03-11 00:48:53 +00:00
var enable = !config.customization || (config.customization.macros!==false);
docInfo.asc_putIsEnabledMacroses(!!enable);
enable = !config.customization || (config.customization.plugins!==false);
docInfo.asc_putIsEnabledPlugins(!!enable);
2016-03-11 00:48:53 +00:00
if (api) {
api.asc_registerCallback('asc_onGetEditorPermissions', onEditorPermissions);
api.asc_registerCallback('asc_onRunAutostartMacroses', onRunAutostartMacroses);
2016-03-11 00:48:53 +00:00
api.asc_setDocInfo(docInfo);
api.asc_getEditorPermissions(config.licenseUrl, config.customerId);
api.asc_enableKeyEvents(true);
Common.Analytics.trackEvent('Load', 'Start');
}
2016-11-18 15:00:46 +00:00
embedConfig.docTitle = docConfig.title;
2021-05-19 13:35:59 +00:00
labelDocName = $('#title-doc-name');
labelDocName.text(embedConfig.docTitle || '')
2016-03-11 00:48:53 +00:00
}
}
function setActiveWorkSheet(index) {
var $box = $('#worksheets');
$box.find('> li').removeClass('active');
$box.find('#worksheet' + index).addClass('active');
api.asc_showWorksheet(index);
}
2016-03-11 00:48:53 +00:00
function onSheetsChanged(){
maxPages = api.asc_getWorksheetsCount();
2016-03-11 00:48:53 +00:00
var handleWorksheet = function(e){
var $worksheet = $(this);
var index = $worksheet.attr('id').match(/\d+$/);
2016-03-11 00:48:53 +00:00
if (index.length > 0) {
index = parseInt(index[0]);
if (index > -1 && index < maxPages)
setActiveWorkSheet(index);
}
};
var $box = $('#worksheets');
$box.find('li').off();
$box.empty();
2016-03-11 00:48:53 +00:00
var tpl = '<li id="worksheet{index}">{title}</li>';
for (var i = 0; i < maxPages; i++) {
var item = tpl.replace(/\{index}/, i).replace(/\{title}/,api.asc_getWorksheetName(i).replace(/\s/g,'&nbsp;'));
$(item).appendTo($box).on('click', handleWorksheet);
2016-03-11 00:48:53 +00:00
}
setActiveWorkSheet(api.asc_getActiveWorksheetIndex());
2016-03-11 00:48:53 +00:00
}
function onDownloadUrl(url, fileType) {
Common.Gateway.downloadAs(url, fileType);
2016-03-11 00:48:53 +00:00
}
function onPrint() {
if ( permissions.print!==false )
2021-04-20 15:46:41 +00:00
api.asc_Print(new Asc.asc_CDownloadOptions(null, $.browser.chrome || $.browser.safari || $.browser.opera || $.browser.mozilla && $.browser.versionNumber>86));
2016-03-11 00:48:53 +00:00
}
function onPrintUrl(url) {
2019-07-23 12:07:51 +00:00
common.utils.dialogPrint(url, api);
2016-03-11 00:48:53 +00:00
}
function hidePreloader() {
$('#loading-mask').fadeOut('slow');
}
function onDocumentContentReady() {
hidePreloader();
onLongActionEnd(Asc.c_oAscAsyncActionType['BlockInteraction'], LoadingDocument);
2016-03-11 00:48:53 +00:00
var dividers = $('#box-tools .divider');
var itemsCount = $('#box-tools a').length;
if ( permissions.print === false) {
2020-09-08 17:40:18 +00:00
$('#idt-print').hide();
itemsCount--;
}
2020-09-08 17:40:18 +00:00
if ( !embedConfig.saveUrl || permissions.download === false) {
$('#idt-download').hide();
itemsCount--;
}
if ( !embedConfig.shareUrl ) {
$('#idt-share').hide();
itemsCount--;
}
if (!config.canBackToFolder) {
2021-05-19 14:29:13 +00:00
$('#idt-close').hide();
itemsCount--;
}
if (itemsCount < 7) {
$(dividers[0]).hide();
$(dividers[1]).hide();
}
2021-05-19 13:35:59 +00:00
if ( !embedConfig.embedUrl ) {
$('#idt-embed').hide();
itemsCount--;
}
if ( !embedConfig.fullscreenUrl ) {
2016-11-17 13:01:54 +00:00
$('#idt-fullscreen').hide();
itemsCount--;
}
if (itemsCount < 1)
$('#box-tools').addClass('hidden');
2021-05-19 13:35:59 +00:00
else if (!embedConfig.embedUrl && !embedConfig.fullscreenUrl)
$(dividers[2]).hide();
common.controller.modals.attach({
share: '#idt-share',
embed: '#idt-embed'
});
api.asc_registerCallback('asc_onMouseMove', onApiMouseMove);
api.asc_registerCallback('asc_onHyperlinkClick', common.utils.openLink);
api.asc_registerCallback('asc_onDownloadUrl', onDownloadUrl);
api.asc_registerCallback('asc_onPrint', onPrint);
api.asc_registerCallback('asc_onPrintUrl', onPrintUrl);
api.asc_registerCallback('asc_onStartAction', onLongActionBegin);
Common.Gateway.on('processmouse', onProcessMouse);
Common.Gateway.on('downloadas', onDownloadAs);
Common.Gateway.on('requestclose', onRequestClose);
SSE.ApplicationView.tools.get('#idt-fullscreen')
.on('click', function(){
common.utils.openLink(embedConfig.fullscreenUrl);
});
SSE.ApplicationView.tools.get('#idt-download')
.on('click', function(){
2021-09-29 14:45:40 +00:00
if ( !!embedConfig.saveUrl && permissions.download !== false){
common.utils.openLink(embedConfig.saveUrl);
}
Common.Analytics.trackEvent('Save');
});
2020-09-08 17:40:18 +00:00
SSE.ApplicationView.tools.get('#idt-print')
.on('click', function(){
2021-04-20 15:46:41 +00:00
api.asc_Print(new Asc.asc_CDownloadOptions(null, $.browser.chrome || $.browser.safari || $.browser.opera || $.browser.mozilla && $.browser.versionNumber>86));
2020-09-08 17:40:18 +00:00
Common.Analytics.trackEvent('Print');
});
2021-05-19 13:35:59 +00:00
SSE.ApplicationView.tools.get('#idt-close')
.on('click', function(){
if (config.customization && config.customization.goback) {
if (config.customization.goback.requestClose && config.canRequestClose)
Common.Gateway.requestClose();
2021-11-23 11:35:22 +00:00
else if (config.customization.goback.url) {
if (config.customization.goback.blank!==false) {
window.open(config.customization.goback.url, "_blank");
} else {
window.parent.location.href = config.customization.goback.url;
}
}
2021-05-19 13:35:59 +00:00
}
});
SSE.ApplicationView.tools.get('#idt-search')
.on('click', function(){
common.controller.SearchBar.show();
});
$('#id-btn-zoom-in').on('click', function () {
if (api){
var f = Math.floor(api.asc_getZoom() * 10)/10;
f += .1;
2021-12-01 09:24:07 +00:00
f > 0 && !(f > 5.) && api.asc_setZoom(f);
}
});
$('#id-btn-zoom-out').on('click', function () {
if (api){
var f = Math.ceil(api.asc_getZoom() * 10)/10;
f -= .1;
2022-07-25 10:29:50 +00:00
!(f < .1) && api.asc_setZoom(f);
}
});
var documentMoveTimer;
var ismoved = false;
$(document).mousemove(function(event) {
$('#id-btn-zoom-in').fadeIn();
$('#id-btn-zoom-out').fadeIn();
ismoved = true;
if (!documentMoveTimer) {
documentMoveTimer = setInterval(function () {
if (!ismoved) {
$('#id-btn-zoom-in').fadeOut();
$('#id-btn-zoom-out').fadeOut();
clearInterval(documentMoveTimer);
documentMoveTimer = undefined;
}
ismoved = false;
}, 2000);
}
});
var ismodalshown = false;
$(document.body).on('show.bs.modal', '.modal',
function(e) {
ismodalshown = true;
api.asc_enableKeyEvents(false);
}
).on('hidden.bs.modal', '.modal',
function(e) {
ismodalshown = false;
api.asc_enableKeyEvents(true);
}
).on('hidden.bs.dropdown', '.dropdown',
function(e) {
if ( !ismodalshown )
api.asc_enableKeyEvents(true);
}
).on('blur', 'input, textarea',
function(e) {
if ( !ismodalshown ) {
if (!/area_id/.test(e.target.id) ) {
api.asc_enableKeyEvents(true);
}
}
}
);
$('#editor_sdk').on('click', function(e) {
if ( e.target.localName == 'canvas' ) {
e.currentTarget.focus();
}
});
2016-11-22 12:27:23 +00:00
$(document).on('mousewheel', function (e) {
if ((e.ctrlKey || e.metaKey) && !e.altKey) {
e.preventDefault();
e.stopPropagation();
}
});
Common.Gateway.documentReady();
2016-03-11 00:48:53 +00:00
Common.Analytics.trackEvent('Load', 'Complete');
}
function onEditorPermissions(params) {
appOptions.canBranding = params.asc_getCustomization();
appOptions.canBranding && setBranding(config.customization);
2021-05-19 13:35:59 +00:00
var $parent = labelDocName.parent();
var _left_width = $parent.position().left,
_right_width = $parent.next().outerWidth();
if ( _left_width < _right_width )
$parent.css('padding-left', _right_width - _left_width);
else
$parent.css('padding-right', _left_width - _right_width);
2021-05-19 14:29:13 +00:00
onLongActionBegin(Asc.c_oAscAsyncActionType['BlockInteraction'], LoadingDocument);
2016-03-11 00:48:53 +00:00
api.asc_setViewMode(true);
api.asc_LoadDocument();
}
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, " ") + '%');
2016-03-11 00:48:53 +00:00
}
function onLongActionBegin(type, id){
var text = '';
switch (id)
{
case Asc.c_oAscAsyncAction['Print']:
text = me.downloadTextText;
2016-03-11 00:48:53 +00:00
break;
case LoadingDocument:
text = me.textLoadingDocument + ' ';
break;
2016-03-11 00:48:53 +00:00
default:
text = me.waitText;
2016-03-11 00:48:53 +00:00
break;
}
if (type == Asc.c_oAscAsyncActionType['BlockInteraction']) {
if (!me.loadMask)
me.loadMask = new common.view.LoadMask();
me.loadMask.setTitle(text);
me.loadMask.show();
2016-03-11 00:48:53 +00:00
}
}
function onLongActionEnd(type, id){
if (type === Asc.c_oAscAsyncActionType.BlockInteraction) {
2016-03-11 00:48:53 +00:00
switch (id) {
case Asc.c_oAscAsyncAction.Open:
2016-03-11 00:48:53 +00:00
if (api) {
api.asc_Resize();
var zf = (config.customization && config.customization.zoom ? parseInt(config.customization.zoom)/100 : 1);
api.asc_setZoom(zf>0 ? zf : 1);
2016-03-11 00:48:53 +00:00
}
onDocumentContentReady();
onSheetsChanged();
break;
}
me.loadMask && me.loadMask.hide();
2016-03-11 00:48:53 +00:00
}
}
function onError(id, level, errData) {
2018-10-08 14:06:37 +00:00
if (id == Asc.c_oAscError.ID.LoadingScriptError) {
$('#id-critical-error-title').text(me.criticalErrorTitle);
$('#id-critical-error-message').text(me.scriptLoadError);
$('#id-critical-error-close').text(me.txtClose).off().on('click', function(){
2018-10-08 14:06:37 +00:00
window.location.reload();
});
$('#id-critical-error-dialog').css('z-index', 20002).modal('show');
return;
}
2016-03-11 00:48:53 +00:00
hidePreloader();
onLongActionEnd(Asc.c_oAscAsyncActionType['BlockInteraction'], LoadingDocument);
2016-03-11 00:48:53 +00:00
var message;
switch (id)
{
case Asc.c_oAscError.ID.Unknown:
2016-03-11 00:48:53 +00:00
message = me.unknownErrorText;
break;
case Asc.c_oAscError.ID.ConvertationTimeout:
2016-03-11 00:48:53 +00:00
message = me.convertationTimeoutText;
break;
case Asc.c_oAscError.ID.ConvertationError:
2016-03-11 00:48:53 +00:00
message = me.convertationErrorText;
break;
2021-11-26 11:10:44 +00:00
case Asc.c_oAscError.ID.ConvertationOpenError:
message = me.openErrorText;
break;
case Asc.c_oAscError.ID.DownloadError:
2016-03-11 00:48:53 +00:00
message = me.downloadErrorText;
break;
2018-10-09 11:32:18 +00:00
case Asc.c_oAscError.ID.ConvertationPassword:
message = me.errorFilePassProtect;
break;
case Asc.c_oAscError.ID.UserDrop:
message = me.errorUserDrop;
break;
2019-08-28 14:29:39 +00:00
case Asc.c_oAscError.ID.ConvertationOpenLimitError:
message = me.errorFileSizeExceed;
break;
case Asc.c_oAscError.ID.UpdateVersion:
message = me.errorUpdateVersionOnDisconnect;
break;
2020-04-07 09:26:19 +00:00
case Asc.c_oAscError.ID.AccessDeny:
message = me.errorAccessDeny;
break;
2021-07-27 15:37:37 +00:00
case Asc.c_oAscError.ID.ForceSaveButton:
case Asc.c_oAscError.ID.ForceSaveTimeout:
message = me.errorForceSave;
break;
2021-08-19 19:03:44 +00:00
case Asc.c_oAscError.ID.LoadingFontError:
message = me.errorLoadingFont;
break;
2021-11-01 14:16:20 +00:00
case Asc.c_oAscError.ID.KeyExpire:
message = me.errorTokenExpire;
break;
2022-11-08 17:20:29 +00:00
case Asc.c_oAscError.ID.ConvertationOpenFormat:
if (errData === 'pdf')
message = me.errorInconsistentExtPdf.replace('%1', docConfig.fileType || '');
else if (errData === 'docx')
message = me.errorInconsistentExtDocx.replace('%1', docConfig.fileType || '');
else if (errData === 'xlsx')
message = me.errorInconsistentExtXlsx.replace('%1', docConfig.fileType || '');
else if (errData === 'pptx')
message = me.errorInconsistentExtPptx.replace('%1', docConfig.fileType || '');
else
message = me.errorInconsistentExt;
break;
2016-03-11 00:48:53 +00:00
default:
message = me.errorDefaultMessage.replace('%1', id);
break;
}
if (level == Asc.c_oAscError.Level.Critical) {
2016-03-11 00:48:53 +00:00
// report only critical errors
Common.Gateway.reportError(id, message);
$('#id-critical-error-title').text(me.criticalErrorTitle);
2019-08-28 14:29:39 +00:00
$('#id-critical-error-message').html(message);
$('#id-critical-error-close').text(me.txtClose).off().on('click', function(){
2016-03-11 00:48:53 +00:00
window.location.reload();
});
}
else {
2017-10-07 09:20:39 +00:00
Common.Gateway.reportWarning(id, message);
2016-03-11 00:48:53 +00:00
$('#id-critical-error-title').text(me.notcriticalErrorTitle);
2019-08-28 14:29:39 +00:00
$('#id-critical-error-message').html(message);
$('#id-critical-error-close').text(me.txtClose).off().on('click', function(){
2016-03-11 00:48:53 +00:00
$('#id-critical-error-dialog').modal('hide');
});
}
$('#id-critical-error-dialog').modal('show');
Common.Analytics.trackEvent('Internal Error', id.toString());
}
function onExternalMessage(error) {
2016-03-11 00:48:53 +00:00
if (error) {
hidePreloader();
$('#id-error-mask-title').text(me.criticalErrorTitle);
2016-03-11 00:48:53 +00:00
$('#id-error-mask-text').text(error.msg);
$('#id-error-mask').css('display', 'block');
Common.Analytics.trackEvent('External Error');
2016-03-11 00:48:53 +00:00
}
}
function onProcessMouse(data) {
if (data.type == 'mouseup') {
var editor = document.getElementById('editor_sdk');
if (editor) {
var rect = editor.getBoundingClientRect();
var event = window.event || arguments.callee.caller.arguments[0];
api.asc_onMouseUp(event, data.x - rect.left, data.y - rect.top);
}
}
}
function onRequestClose() {
Common.Gateway.requestClose();
}
2016-03-11 00:48:53 +00:00
function onDownloadAs() {
if ( permissions.download === false) {
Common.Gateway.reportError(Asc.c_oAscError.ID.AccessDeny, me.errorAccessDeny);
return;
}
2019-07-24 08:36:13 +00:00
api.asc_DownloadAs(new Asc.asc_CDownloadOptions(Asc.c_oAscFileType.XLSX, true));
2016-03-11 00:48:53 +00:00
}
function onApiMouseMove(array) {
if ( array.length ) {
var ttdata;
for (var i = array.length; i > 0; i--) {
if (array[i-1].asc_getType() == Asc.c_oAscMouseMoveType.Hyperlink) {
ttdata = array[i - 1];
break;
}
2016-03-11 00:48:53 +00:00
}
if ( ttdata ) {
if (!$ttEl) {
$ttEl = $('.hyperlink-tooltip');
$ttEl.tooltip({'container': 'body', 'trigger': 'manual'});
$ttEl.on('shown.bs.tooltip', function(e) {
$tooltip = $ttEl.data('bs.tooltip').tip();
2016-03-11 00:48:53 +00:00
$tooltip.css({
left: $ttEl.ttpos[0] + ttOffset[0],
top: $ttEl.ttpos[1] + ttOffset[1]
});
2016-03-11 00:48:53 +00:00
$tooltip.find('.tooltip-arrow').css({left: 10});
});
2016-03-11 00:48:53 +00:00
}
if (!$tooltip) {
$ttEl.ttpos = [ttdata.asc_getX(), ttdata.asc_getY()];
$ttEl.tooltip('show');
} else {
$tooltip.css({
left: ttdata.asc_getX() + ttOffset[0],
top: ttdata.asc_getY() + ttOffset[1]
});
}
} else {
if ( $tooltip ) {
$tooltip.tooltip('hide');
$tooltip = false;
}
2016-03-11 00:48:53 +00:00
}
}
}
function onRunAutostartMacroses() {
if (!config.customization || (config.customization.macros!==false))
if (api) api.asc_runAutostartMacroses();
}
function onBeforeUnload () {
common.localStorage.save();
}
function setBranding(value) {
if ( value && value.logo) {
var logo = $('#header-logo');
if (value.logo.image || value.logo.imageEmbedded) {
logo.html('<img src="'+(value.logo.image || value.logo.imageEmbedded)+'" style="max-width:100px; max-height:20px;"/>');
logo.css({'background-image': 'none', width: 'auto', height: 'auto'});
value.logo.imageEmbedded && console.log("Obsolete: The 'imageEmbedded' parameter of the 'customization.logo' section is deprecated. Please use 'image' parameter instead.");
}
if (value.logo.url) {
logo.attr('href', value.logo.url);
} else if (value.logo.url!==undefined) {
logo.removeAttr('href');logo.removeAttr('target');
}
}
}
// Helpers
// -------------------------
2016-03-11 00:48:53 +00:00
function onDocumentResize() {
if (api) api.asc_Resize();
2016-03-11 00:48:53 +00:00
}
function createController(){
if (created)
return me;
me = this;
created = true;
// popover ui handlers
$(window).resize(function(){
onDocumentResize();
});
window.onbeforeunload = onBeforeUnload;
2016-05-13 08:37:54 +00:00
api = new Asc.spreadsheet_api({
'id-view': 'editor_sdk',
'embedded' : true
2016-05-13 08:37:54 +00:00
});
2016-03-11 00:48:53 +00:00
if (api){
api.asc_registerCallback('asc_onEndAction', onLongActionEnd);
api.asc_registerCallback('asc_onError', onError);
api.asc_registerCallback('asc_onOpenDocumentProgress', onOpenDocument);
api.asc_registerCallback('asc_onSheetsChanged', onSheetsChanged);
api.asc_registerCallback('asc_onActiveSheetChanged', setActiveWorkSheet);
2016-03-11 00:48:53 +00:00
// Initialize api gateway
Common.Gateway.on('init', loadConfig);
Common.Gateway.on('opendocument', loadDocument);
Common.Gateway.on('showmessage', onExternalMessage);
Common.Gateway.appReady();
2022-04-27 19:12:59 +00:00
common.controller.SearchBar.setApi(api);
2016-03-11 00:48:53 +00:00
}
return me;
}
return {
create : createController,
errorDefaultMessage : 'Error code: %1',
unknownErrorText : 'Unknown error.',
2019-05-14 13:55:52 +00:00
convertationTimeoutText : 'Conversion timeout exceeded.',
convertationErrorText : 'Conversion failed.',
2016-03-11 00:48:53 +00:00
downloadErrorText : 'Download failed.',
criticalErrorTitle : 'Error',
2018-10-08 14:06:37 +00:00
notcriticalErrorTitle : 'Warning',
2018-10-09 11:32:18 +00:00
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.',
textOf: 'of',
downloadTextText: 'Downloading spreadsheet...',
waitText: 'Please, wait...',
textLoadingDocument: 'Loading spreadsheet',
2019-08-28 14:29:39 +00:00
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',
2021-07-27 15:37:37 +00:00
textAnonymous: 'Anonymous',
2021-08-19 19:03:44 +00:00
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.",
2021-11-01 14:16:20 +00:00
errorLoadingFont: 'Fonts are not loaded.<br>Please contact your Document Server administrator.',
2021-11-26 11:10:44 +00:00
errorTokenExpire: 'The document security token has expired.<br>Please contact your Document Server administrator.',
2022-11-08 17:20:29 +00:00
openErrorText: 'An error has occurred while opening the file',
errorInconsistentExtDocx: 'An error has occurred while opening the file.<br>The file content corresponds to text documents (e.g. docx), but the file has the inconsistent extension: %1.',
errorInconsistentExtXlsx: 'An error has occurred while opening the file.<br>The file content corresponds to spreadsheets (e.g. xlsx), but the file has the inconsistent extension: %1.',
errorInconsistentExtPptx: 'An error has occurred while opening the file.<br>The file content corresponds to presentations (e.g. pptx), but the file has the inconsistent extension: %1.',
errorInconsistentExtPdf: 'An error has occurred while opening the file.<br>The file content corresponds to one of the following formats: pdf/djvu/xps/oxps, but the file has the inconsistent extension: %1.',
errorInconsistentExt: 'An error has occurred while opening the file.<br>The file content does not match the file extension.'
2016-03-11 00:48:53 +00:00
}
})();