define([
'core',
'irregularstack',
'gateway',
'common/main/lib/component/Window',
'common/main/lib/component/LoadMask',
'common/main/lib/component/Tooltip',
'common/main/lib/component/SynchronizeTip',
'common/main/lib/component/DataView',
'common/main/lib/component/Calendar',
'common/main/lib/util/LocalStorage',
'common/main/lib/util/Shortcuts',
'common/main/lib/view/CopyWarningDialog',
'common/main/lib/view/ImageFromUrlDialog',
'common/main/lib/view/SelectFileDlg',
'common/main/lib/view/SaveAsDlg',
'common/main/lib/view/OpenDialog',
'common/forms/lib/view/modals',
'documenteditor/forms/app/view/ApplicationView'
], function (Viewport) {
'use strict';
var LoadingDocument = -256,
maxPages = 0,
labelDocName,
_submitFail,
screenTip,
mouseMoveData = null,
isTooltipHiding = false,
bodyWidth = 0,
ttOffset = [0, -10];
DE.Controllers.ApplicationController = Backbone.Controller.extend(_.assign({
views: [
'ApplicationView'
],
initialize: function() {
},
onLaunch: function() {
var me = this;
if (!Common.Utils.isBrowserSupported()){
Common.Utils.showBrowserRestriction();
$('#editor_sdk').hide().remove();
$('#toolbar').hide().remove();
Common.Gateway.reportError(undefined, this.unsupportedBrowserErrorText);
return;
}
this.stackLongActions = new Common.IrregularStack({
strongCompare : function(obj1, obj2){return obj1.id === obj2.id && obj1.type === obj2.type;},
weakCompare : function(obj1, obj2){return obj1.type === obj2.type;}
});
this._state = {isDisconnected: false, licenseType: false, isDocModified: false};
this.view = this.createView('ApplicationView').render();
window["flat_desine"] = true;
var translationTable = {
'Your text here': this.txtArt,
"Choose an item": this.txtChoose,
"Enter a date": this.txtEnterDate,
"Click to load image": this.txtClickToLoad
}
this.api = new Asc.asc_docs_api({
'id-view' : 'editor_sdk',
'embedded' : true,
'translate': translationTable
});
Common.UI.Themes.init(this.api);
$(window).on('resize', this.onDocumentResize.bind(this));
this.boxSdk = $('#editor_sdk');
this.boxSdk.on('click', function(e) {
if (e.target.localName == 'canvas') {
if (me._preventClick)
me._preventClick = false;
else
me.boxSdk.focus();
}
});
this.boxSdk.on('mousedown', function(e){
if (e.target.localName == 'canvas')
Common.UI.Menu.Manager.hideAll();
});
this.editorConfig = {};
this.embedConfig = {};
this.appOptions = {};
this.internalFormObj = null;
if (this.api){
this.api.asc_registerCallback('asc_onError', this.onError.bind(this));
this.api.asc_registerCallback('asc_onDocumentContentReady', this.onDocumentContentReady.bind(this));
this.api.asc_registerCallback('asc_onOpenDocumentProgress', this.onOpenDocument.bind(this));
this.api.asc_registerCallback('asc_onDocumentUpdateVersion', this.onUpdateVersion.bind(this));
this.api.asc_registerCallback('asc_onServerVersion', this.onServerVersion.bind(this));
this.api.asc_registerCallback('asc_onAdvancedOptions', this.onAdvancedOptions.bind(this));
this.api.asc_registerCallback('asc_onCountPages', this.onCountPages.bind(this));
this.api.asc_registerCallback('asc_onCurrentPage', this.onCurrentPage.bind(this));
this.api.asc_registerCallback('asc_onDocumentModifiedChanged', _.bind(this.onDocumentModifiedChanged, this));
this.api.asc_registerCallback('asc_onZoomChange', this.onApiZoomChange.bind(this));
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect', _.bind(this.onApiServerDisconnect, this));
Common.NotificationCenter.on('api:disconnect', _.bind(this.onApiServerDisconnect, this));
// Initialize api gateway
Common.Gateway.on('init', this.loadConfig.bind(this));
Common.Gateway.on('opendocument', this.loadDocument.bind(this));
Common.Gateway.on('showmessage', this.onExternalMessage.bind(this));
Common.NotificationCenter.on('showmessage', this.onExternalMessage.bind(this));
Common.Gateway.appReady();
}
Common.NotificationCenter.on({
'modal:show': function(){
if (screenTip) {
screenTip.toolTip.hide();
screenTip.isVisible = false;
}
Common.Utils.ModalWindow.show();
me.api.asc_enableKeyEvents(false);
},
'modal:close': function(dlg) {
Common.Utils.ModalWindow.close();
if (!Common.Utils.ModalWindow.isVisible())
me.api.asc_enableKeyEvents(true);
},
'modal:hide': function(dlg) {
Common.Utils.ModalWindow.close();
if (!Common.Utils.ModalWindow.isVisible())
me.api.asc_enableKeyEvents(true);
},
'dataview:blur': function(e){
if (!Common.Utils.ModalWindow.isVisible()) {
me.api.asc_enableKeyEvents(true);
}
},
'menu:hide': function(e, isFromInputControl){
if (!Common.Utils.ModalWindow.isVisible() && !isFromInputControl)
me.api.asc_enableKeyEvents(true);
}
});
$(document.body).on('blur', 'input, textarea', function(e) {
if (!Common.Utils.ModalWindow.isVisible()) {
if (!/area_id/.test(e.target.id) ) {
me.api.asc_enableKeyEvents(true);
}
}
});
window.onbeforeunload = _.bind(this.onBeforeUnload, this);
this.warnNoLicense = this.warnNoLicense.replace(/%1/g, '{{COMPANY_NAME}}');
this.warnNoLicenseUsers = this.warnNoLicenseUsers.replace(/%1/g, '{{COMPANY_NAME}}');
this.textNoLicenseTitle = this.textNoLicenseTitle.replace(/%1/g, '{{COMPANY_NAME}}');
this.warnLicenseExceeded = this.warnLicenseExceeded.replace(/%1/g, '{{COMPANY_NAME}}');
this.warnLicenseUsersExceeded = this.warnLicenseUsersExceeded.replace(/%1/g, '{{COMPANY_NAME}}');
},
onDocumentResize: function() {
this.api && this.api.Resize();
bodyWidth = $('body').width();
},
onBeforeUnload: function() {
Common.localStorage.save();
},
onError: function(id, level, errData) {
if (id == Asc.c_oAscError.ID.LoadingScriptError) {
this.showTips([this.scriptLoadError]);
this.tooltip && this.tooltip.getBSTip().$tip.css('z-index', 10000);
return;
}
this.hidePreloader();
this.onLongActionEnd(Asc.c_oAscAsyncActionType['BlockInteraction'], LoadingDocument);
var config = {
closable: true
};
switch (id)
{
case Asc.c_oAscError.ID.Unknown:
config.msg = this.unknownErrorText;
break;
case Asc.c_oAscError.ID.ConvertationTimeout:
config.msg = this.convertationTimeoutText;
break;
case Asc.c_oAscError.ID.ConvertationError:
config.msg = this.convertationErrorText;
break;
case Asc.c_oAscError.ID.ConvertationOpenError:
config.msg = this.openErrorText;
break;
case Asc.c_oAscError.ID.DownloadError:
config.msg = this.downloadErrorText;
break;
case Asc.c_oAscError.ID.UplImageSize:
config.msg = this.uploadImageSizeMessage;
break;
case Asc.c_oAscError.ID.UplImageExt:
config.msg = this.uploadImageExtMessage;
break;
case Asc.c_oAscError.ID.ConvertationPassword:
config.msg = this.errorFilePassProtect;
break;
case Asc.c_oAscError.ID.UserDrop:
config.msg = this.errorUserDrop;
break;
case Asc.c_oAscError.ID.ConvertationOpenLimitError:
config.msg = this.errorFileSizeExceed;
break;
case Asc.c_oAscError.ID.UpdateVersion:
config.msg = this.errorUpdateVersionOnDisconnect;
config.maxwidth = 600;
break;
case Asc.c_oAscError.ID.AccessDeny:
config.msg = this.errorAccessDeny;
break;
case Asc.c_oAscError.ID.Submit:
config.msg = this.errorSubmit;
_submitFail = true;
this.submitedTooltip && this.submitedTooltip.hide();
break;
case Asc.c_oAscError.ID.EditingError:
config.msg = (this.appOptions.isDesktopApp && this.appOptions.isOffline) ? this.errorEditingSaveas : this.errorEditingDownloadas;
break;
case Asc.c_oAscError.ID.ForceSaveButton:
case Asc.c_oAscError.ID.ForceSaveTimeout:
config.msg = this.errorForceSave;
config.maxwidth = 600;
break;
case Asc.c_oAscError.ID.LoadingFontError:
config.msg = this.errorLoadingFont;
break;
case Asc.c_oAscError.ID.Warning:
config.msg = this.errorConnectToServer;
config.closable = false;
break;
case Asc.c_oAscError.ID.VKeyEncrypt:
config.msg = this.errorToken;
break;
case Asc.c_oAscError.ID.KeyExpire:
config.msg = this.errorTokenExpire;
break;
case Asc.c_oAscError.ID.CoAuthoringDisconnect:
config.msg = this.errorViewerDisconnect;
break;
case Asc.c_oAscError.ID.SessionAbsolute:
config.msg = this.errorSessionAbsolute;
break;
case Asc.c_oAscError.ID.SessionIdle:
config.msg = this.errorSessionIdle;
break;
case Asc.c_oAscError.ID.SessionToken:
config.msg = this.errorSessionToken;
break;
case Asc.c_oAscError.ID.UplImageUrl:
config.msg = this.errorBadImageUrl;
break;
case Asc.c_oAscError.ID.DataEncrypted:
config.msg = this.errorDataEncrypted;
break;
case Asc.c_oAscError.ID.ConvertationSaveError:
config.msg = (this.appOptions.isDesktopApp && this.appOptions.isOffline) ? this.saveErrorTextDesktop : this.saveErrorText;
break;
case Asc.c_oAscError.ID.TextFormWrongFormat:
config.msg = this.errorTextFormWrongFormat;
break;
default:
config.msg = (typeof id == 'string') ? id : this.errorDefaultMessage.replace('%1', id);
break;
}
if (level == Asc.c_oAscError.Level.Critical) {
// report only critical errors
Common.Gateway.reportError(id, config.msg);
config.title = this.criticalErrorTitle;
config.iconCls = 'error';
config.closable = false;
config.callback = _.bind(function(btn){
window.location.reload();
}, this);
if (id == Asc.c_oAscError.ID.DataEncrypted) {
this.api.asc_coAuthoringDisconnect();
Common.NotificationCenter.trigger('api:disconnect');
}
}
else {
Common.Gateway.reportWarning(id, config.msg);
config.title = this.notcriticalErrorTitle;
config.iconCls = 'warn';
config.buttons = ['ok'];
config.callback = _.bind(function(btn){
if (id == Asc.c_oAscError.ID.Warning && btn == 'ok' && this.appOptions.canDownload) {
Common.UI.Menu.Manager.hideAll();
if (this.appOptions.isDesktopApp && this.appOptions.isOffline)
this.api.asc_DownloadAs();
else {
var me = this;
setTimeout(function() {
$('button', me.view.btnOptions.cmpEl).click();
}, 10);
}
} else if (id == Asc.c_oAscError.ID.EditingError) {
Common.NotificationCenter.trigger('api:disconnect', true); // enable download and print
}
}, this);
}
if (!Common.Utils.ModalWindow.isVisible() || $('.asc-window.modal.alert[data-value=' + id + ']').length<1)
Common.UI.alert(config).$window.attr('data-value', id);
(id!==undefined) && Common.component.Analytics.trackEvent('Internal Error', id.toString());
},
hidePreloader: function() {
$('#loading-mask').fadeOut('slow');
},
onOpenDocument: function(progress) {
var elem = document.getElementById('loadmask-text');
var proc = (progress.asc_getCurrentFont() + progress.asc_getCurrentImage())/(progress.asc_getFontsCount() + progress.asc_getImagesCount());
proc = this.textLoadingDocument + ': ' + Common.Utils.String.fixedDigits(Math.min(Math.round(proc*100), 100), 3, " ") + "%";
elem ? elem.innerHTML = proc : this.loadMask && this.loadMask.setTitle(proc);
},
onCountPages: function(count) {
if (maxPages !== count) {
maxPages = count;
$('#pages').text(this.textOf + " " + count);
}
},
onCurrentPage: function(number) {
this.view.txtGoToPage.setValue(number + 1);
},
updateWindowTitle: function(force) {
var isModified = this.api.isDocumentModified();
if (this._state.isDocModified !== isModified || force) {
this._isDocReady && (this._state.isDocModified !== isModified) && Common.Gateway.setDocumentModified(isModified);
this._state.isDocModified = isModified;
}
},
onDocumentModifiedChanged: function() {
var isModified = this.api.asc_isDocumentCanSave();
if (this._state.isDocModified !== isModified) {
this._isDocReady && Common.Gateway.setDocumentModified(this.api.isDocumentModified());
}
this.updateWindowTitle();
},
loadConfig: function(data) {
this.editorConfig = $.extend(this.editorConfig, data.config);
this.embedConfig = $.extend(this.embedConfig, data.config.embedded);
$('#toolbar').addClass('top');
this.boxSdk.addClass('top');
ttOffset[1] = 40;
this.appOptions.customization = this.editorConfig.customization;
this.appOptions.canRenameAnonymous = !((typeof (this.appOptions.customization) == 'object') && (typeof (this.appOptions.customization.anonymous) == 'object') && (this.appOptions.customization.anonymous.request===false));
this.appOptions.guestName = (typeof (this.appOptions.customization) == 'object') && (typeof (this.appOptions.customization.anonymous) == 'object') &&
(typeof (this.appOptions.customization.anonymous.label) == 'string') && this.appOptions.customization.anonymous.label.trim()!=='' ?
Common.Utils.String.htmlEncode(this.appOptions.customization.anonymous.label) : this.textGuest;
var value;
if (this.appOptions.canRenameAnonymous) {
value = Common.localStorage.getItem("guest-username");
Common.Utils.InternalSettings.set("guest-username", value);
Common.Utils.InternalSettings.set("save-guest-username", !!value);
}
this.editorConfig.user =
this.appOptions.user = Common.Utils.fillUserInfo(this.editorConfig.user, this.editorConfig.lang, value ? (value + ' (' + this.appOptions.guestName + ')' ) : this.textAnonymous,
Common.localStorage.getItem("guest-id") || ('uid-' + Date.now()));
this.appOptions.user.anonymous && Common.localStorage.setItem("guest-id", this.appOptions.user.id);
this.appOptions.canRequestClose = this.editorConfig.canRequestClose;
this.appOptions.canBackToFolder = (this.editorConfig.canBackToFolder!==false) && (typeof (this.editorConfig.customization) == 'object') && (typeof (this.editorConfig.customization.goback) == 'object')
&& (!_.isEmpty(this.editorConfig.customization.goback.url) || this.editorConfig.customization.goback.requestClose && this.appOptions.canRequestClose);
this.appOptions.canRequestInsertImage = this.editorConfig.canRequestInsertImage;
this.appOptions.fileChoiceUrl = this.editorConfig.fileChoiceUrl;
this.appOptions.saveAsUrl = this.editorConfig.saveAsUrl;
this.appOptions.canRequestSaveAs = this.editorConfig.canRequestSaveAs;
this.appOptions.isDesktopApp = this.editorConfig.targetApp == 'desktop';
this.appOptions.lang = this.editorConfig.lang;
this.appOptions.canPlugins = false;
},
onExternalMessage: function(msg) {
if (msg && msg.msg) {
msg.msg = (msg.msg).toString();
this.showTips([msg.msg.charAt(0).toUpperCase() + msg.msg.substring(1)]);
Common.component.Analytics.trackEvent('External Error');
}
},
showTips: function(strings) {
var me = this;
if (!strings.length) return;
if (typeof(strings)!='object') strings = [strings];
function showNextTip() {
var str_tip = strings.shift();
if (str_tip) {
str_tip += '\n' + me.textCloseTip;
tooltip.setTitle(str_tip);
tooltip.show();
}
}
if (!this.tooltip) {
this.tooltip = new Common.UI.Tooltip({
owner: $('#toolbar'),
hideonclick: true,
placement: 'bottom',
cls: 'main-info',
offset: 30
});
}
var tooltip = this.tooltip;
tooltip.on('tooltip:hide', function(){
setTimeout(showNextTip, 300);
});
showNextTip();
},
loadDocument: function(data) {
this.permissions = {};
this.document = data.doc;
var docInfo = {};
if (data.doc) {
this.permissions = $.extend(this.permissions, data.doc.permissions);
var _options = $.extend({}, data.doc.options, this.editorConfig.actionLink || {});
var _user = new Asc.asc_CUserInfo();
_user.put_Id(this.appOptions.user.id);
_user.put_FullName(this.appOptions.user.fullname);
_user.put_IsAnonymousUser(!!this.appOptions.user.anonymous);
docInfo = new Asc.asc_CDocInfo();
docInfo.put_Id(data.doc.key);
docInfo.put_Url(data.doc.url);
docInfo.put_DirectUrl(data.doc.directUrl);
docInfo.put_Title(data.doc.title);
docInfo.put_Format(data.doc.fileType);
docInfo.put_VKey(data.doc.vkey);
docInfo.put_Options(_options);
docInfo.put_UserInfo(_user);
docInfo.put_CallbackUrl(this.editorConfig.callbackUrl);
docInfo.put_Token(data.doc.token);
docInfo.put_Permissions(data.doc.permissions);
docInfo.put_EncryptedInfo(this.editorConfig.encryptionKeys);
docInfo.put_Lang(this.editorConfig.lang);
docInfo.put_Mode(this.editorConfig.mode);
var enable = !this.editorConfig.customization || (this.editorConfig.customization.macros!==false);
docInfo.asc_putIsEnabledMacroses(!!enable);
enable = !this.editorConfig.customization || (this.editorConfig.customization.plugins!==false);
docInfo.asc_putIsEnabledPlugins(!!enable);
var type = /^(?:(pdf|djvu|xps|oxps))$/.exec(data.doc.fileType);
if (type && typeof type[1] === 'string') {
this.permissions.edit = this.permissions.review = false;
}
}
labelDocName = $('#title-doc-name');
if (data.doc) {
labelDocName.text(data.doc.title || '');
this.embedConfig.docTitle = data.doc.title;
}
this.api.asc_registerCallback('asc_onGetEditorPermissions', _.bind(this.onEditorPermissions, this));
this.api.asc_registerCallback('asc_onRunAutostartMacroses', _.bind(this.onRunAutostartMacroses, this));
this.api.asc_registerCallback('asc_onLicenseChanged', _.bind(this.onLicenseChanged, this));
this.api.asc_setDocInfo(docInfo);
this.api.asc_getEditorPermissions(this.editorConfig.licenseUrl, this.editorConfig.customerId);
this.api.asc_enableKeyEvents(true);
Common.Analytics.trackEvent('Load', 'Start');
},
onRunAutostartMacroses: function() {
if (!this.editorConfig.customization || (this.editorConfig.customization.macros!==false)) {
this.api.asc_runAutostartMacroses();
}
},
onEditorPermissions: function(params) {
var licType = params.asc_getLicenseType();
if (Asc.c_oLicenseResult.Expired === licType || Asc.c_oLicenseResult.Error === licType || Asc.c_oLicenseResult.ExpiredTrial === licType) {
Common.UI.warning({
title: this.titleLicenseExp,
msg: this.warnLicenseExp,
buttons: [],
closable: false
});
return;
}
if (Asc.c_oLicenseResult.ExpiredLimited === licType)
this._state.licenseType = licType;
if ( this.onServerVersion(params.asc_getBuildVersion())) return;
this.permissions.review = (this.permissions.review === undefined) ? (this.permissions.edit !== false) : this.permissions.review;
if (params.asc_getRights() !== Asc.c_oRights.Edit)
this.permissions.edit = this.permissions.review = false;
this.appOptions.isOffline = this.api.asc_isOffline();
this.appOptions.trialMode = params.asc_getLicenseMode();
this.appOptions.isBeta = params.asc_getIsBeta();
this.appOptions.canLicense = (licType === Asc.c_oLicenseResult.Success || licType === Asc.c_oLicenseResult.SuccessLimit);
this.appOptions.canSubmitForms = this.appOptions.canLicense && (typeof (this.editorConfig.customization) == 'object') && !!this.editorConfig.customization.submitForm && !this.appOptions.isOffline;
var type = /^(?:(oform))$/.exec(this.document.fileType); // can fill forms only in oform format
this.appOptions.isOFORM = !!(type && typeof type[1] === 'string');
this.appOptions.canFillForms = this.appOptions.canLicense && this.appOptions.isOFORM && ((this.permissions.fillForms===undefined) ? (this.permissions.edit !== false) : this.permissions.fillForms) && (this.editorConfig.mode !== 'view');
this.api.asc_setViewMode(!this.appOptions.canFillForms);
this.appOptions.canBranding = params.asc_getCustomization();
this.appOptions.canBranding && this.setBranding(this.appOptions.customization);
this.appOptions.canDownload = this.permissions.download !== false;
this.appOptions.canPrint = (this.permissions.print !== false);
this.appOptions.fileKey = this.document.key;
AscCommon.UserInfoParser.setParser(true);
AscCommon.UserInfoParser.setCurrentName(this.appOptions.user.fullname);
DE.getController('Plugins').setMode(this.appOptions, this.api);
var me = this;
me.view.btnSubmit.setVisible(this.appOptions.canFillForms && this.appOptions.canSubmitForms);
me.view.btnDownload.setVisible(this.appOptions.canDownload && this.appOptions.canFillForms && !this.appOptions.canSubmitForms);
if (me.appOptions.isOffline || me.appOptions.canRequestSaveAs || !!me.appOptions.saveAsUrl) {
me.view.btnDownload.setCaption(me.appOptions.isOffline ? me.textSaveAsDesktop : me.textSaveAs);
me.view.btnDownload.updateHint('');
}
if (!this.appOptions.canFillForms) {
me.view.btnPrev.setVisible(false);
me.view.btnNext.setVisible(false);
me.view.btnClear.setVisible(false);
} else {
me.view.btnPrev.on('click', function(){
me.api.asc_MoveToFillingForm(false);
});
me.view.btnNext.on('click', function(){
me.api.asc_MoveToFillingForm(true);
});
me.view.btnClear.on('click', function(){
me.api.asc_ClearAllSpecialForms();
});
me.view.btnSubmit.on('click', function(){
me.api.asc_SendForm();
});
me.view.btnDownload.on('click', function(){
if (me.appOptions.canDownload) {
if (me.appOptions.isOffline)
me.api.asc_DownloadAs(new Asc.asc_CDownloadOptions(Asc.c_oAscFileType.PDF));
else {
me.isFromBtnDownload = me.appOptions.canRequestSaveAs || !!me.appOptions.saveAsUrl;
me.api.asc_DownloadAs(new Asc.asc_CDownloadOptions(Asc.c_oAscFileType.PDF, me.isFromBtnDownload));
}
}
});
this.api.asc_setRestriction(Asc.c_oAscRestrictionType.OnlyForms);
this.api.asc_SetFastCollaborative(true);
this.api.asc_setAutoSaveGap(1);
this.api.SetCollaborativeMarksShowType(Asc.c_oAscCollaborativeMarksShowType.None);
}
this.onLongActionBegin(Asc.c_oAscAsyncActionType['BlockInteraction'], LoadingDocument);
this.api.asc_LoadDocument();
this.api.Resize();
},
onServerVersion: function(buildVersion) {
if (this.changeServerVersion) return true;
if (DocsAPI.DocEditor.version() !== buildVersion && !window.compareVersions) {
this.changeServerVersion = true;
Common.UI.warning({
title: this.titleServerVersion,
msg: this.errorServerVersion,
callback: function() {
_.defer(function() {
Common.Gateway.updateVersion();
})
}
});
return true;
}
return false;
},
onUpdateVersion: function(callback) {
var me = this;
me.needToUpdateVersion = true;
me.onLongActionEnd(Asc.c_oAscAsyncActionType['BlockInteraction'], LoadingDocument);
Common.UI.warning({
title: this.titleUpdateVersion,
msg: this.errorUpdateVersion,
callback: function() {
_.defer(function() {
Common.Gateway.updateVersion();
if (callback) callback.call(me);
me.onLongActionBegin(Asc.c_oAscAsyncActionType['BlockInteraction'], LoadingDocument);
})
}
});
},
onLicenseChanged: function(params) {
var licType = params.asc_getLicenseType();
if (licType !== undefined && this.appOptions.canFillForms &&
(licType===Asc.c_oLicenseResult.Connections || licType===Asc.c_oLicenseResult.UsersCount || licType===Asc.c_oLicenseResult.ConnectionsOS || licType===Asc.c_oLicenseResult.UsersCountOS
|| licType===Asc.c_oLicenseResult.SuccessLimit && (this.appOptions.trialMode & Asc.c_oLicenseMode.Limited) !== 0))
this._state.licenseType = licType;
if (this._isDocReady)
this.applyLicense();
},
applyLicense: function() {
if (this._state.licenseType) {
var license = this._state.licenseType,
buttons = ['ok'],
primary = 'ok';
if ((this.appOptions.trialMode & Asc.c_oLicenseMode.Limited) !== 0 &&
(license===Asc.c_oLicenseResult.SuccessLimit || license===Asc.c_oLicenseResult.ExpiredLimited || this.appOptions.permissionsLicense===Asc.c_oLicenseResult.SuccessLimit)) {
license = (license===Asc.c_oLicenseResult.ExpiredLimited) ? this.warnLicenseLimitedNoAccess : this.warnLicenseLimitedRenewed;
} else if (license===Asc.c_oLicenseResult.Connections || license===Asc.c_oLicenseResult.UsersCount) {
license = (license===Asc.c_oLicenseResult.Connections) ? this.warnLicenseExceeded : this.warnLicenseUsersExceeded;
} else {
license = (license===Asc.c_oLicenseResult.ConnectionsOS) ? this.warnNoLicense : this.warnNoLicenseUsers;
buttons = [{value: 'buynow', caption: this.textBuyNow}, {value: 'contact', caption: this.textContactUs}];
primary = 'buynow';
}
if (this._state.licenseType!==Asc.c_oLicenseResult.SuccessLimit && this.appOptions.canFillForms) {
Common.NotificationCenter.trigger('api:disconnect');
}
var value = Common.localStorage.getItem("de-license-warning");
value = (value!==null) ? parseInt(value) : 0;
var now = (new Date).getTime();
if (now - value > 86400000) {
Common.UI.info({
maxwidth: 500,
title: this.textNoLicenseTitle,
msg : license,
buttons: buttons,
primary: primary,
callback: function(btn) {
Common.localStorage.setItem("de-license-warning", now);
if (btn == 'buynow')
window.open('{{PUBLISHER_URL}}', "_blank");
else if (btn == 'contact')
window.open('mailto:{{SALES_EMAIL}}', "_blank");
}
});
}
}
},
setBranding: function (value) {
if ( value && value.logo) {
var logo = $('#header-logo');
if (value.logo.image || value.logo.imageDark) {
var image = Common.UI.Themes.isDarkTheme() ? (value.logo.imageDark || value.logo.image) : (value.logo.image || value.logo.imageDark);
logo.html('');
logo.css({'background-image': 'none', width: 'auto', height: 'auto'});
}
if (value.logo.url) {
logo.attr('href', value.logo.url);
} else if (value.logo.url!==undefined) {
logo.removeAttr('href');logo.removeAttr('target');
}
}
},
onLongActionBegin: function(type, id) {
var action = {id: id, type: type};
this.stackLongActions.push(action);
this.setLongActionView(action);
},
setLongActionView: function(action) {
var title = '', text = '', force = false;
switch (action.id)
{
case Asc.c_oAscAsyncAction['Print']:
text = this.downloadTextText;
break;
case Asc.c_oAscAsyncAction['Submit']:
_submitFail = false;
this.submitedTooltip && this.submitedTooltip.hide();
this.view.btnSubmit.setDisabled(true);
this.view.btnSubmit.cmpEl.css("pointer-events", "none");
break;
case LoadingDocument:
text = this.textLoadingDocument + ' ';
break;
default:
text = this.waitText;
break;
}
if (action.type == Asc.c_oAscAsyncActionType['BlockInteraction']) {
if (!this.loadMask)
this.loadMask = new Common.UI.LoadMask({owner: $(document.body)});
this.loadMask.setTitle(text);
this.loadMask.show();
}
},
onLongActionEnd: function(type, id){
var action = {id: id, type: type};
this.stackLongActions.pop(action);
this.updateWindowTitle(true);
action = this.stackLongActions.get({type: Asc.c_oAscAsyncActionType.Information});
action && this.setLongActionView(action);
action = this.stackLongActions.get({type: Asc.c_oAscAsyncActionType.BlockInteraction});
action ? this.setLongActionView(action) : this.loadMask && this.loadMask.hide();
if (id==Asc.c_oAscAsyncAction['Submit']) {
this.view.btnSubmit.setDisabled(false);
this.view.btnSubmit.cmpEl.css("pointer-events", "auto");
if (!_submitFail) {
if (!this.submitedTooltip) {
var me = this;
this.submitedTooltip = $('