Commit a4234ff0 authored by Oleg Korshul's avatar Oleg Korshul

новая схема работы с апи билдера

parent 0957160f
"use strict";
(function(window, undefined){
// Import
var offlineMode = AscCommon.offlineMode;
var c_oEditorId = AscCommon.c_oEditorId;
(function(window, undefined)
{
// Import
var offlineMode = AscCommon.offlineMode;
var c_oEditorId = AscCommon.c_oEditorId;
var c_oAscError = Asc.c_oAscError;
var c_oAscAsyncAction = Asc.c_oAscAsyncAction;
var c_oAscAsyncActionType = Asc.c_oAscAsyncActionType;
var c_oAscError = Asc.c_oAscError;
var c_oAscAsyncAction = Asc.c_oAscAsyncAction;
var c_oAscAsyncActionType = Asc.c_oAscAsyncActionType;
var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
/** @constructor */
function baseEditorsApi(config, editorId) {
/** @constructor */
function baseEditorsApi(config, editorId)
{
this.editorId = editorId;
this.isLoadFullApi = false;
this.openResult = null;
......@@ -116,41 +118,52 @@ function baseEditorsApi(config, editorId) {
this.pluginsManager = null;
return this;
}
baseEditorsApi.prototype._init = function() {
}
baseEditorsApi.prototype._init = function()
{
var t = this;
//Asc.editor = Asc['editor'] = AscCommon['editor'] = AscCommon.editor = this; // ToDo сделать это!
this.HtmlElement = document.getElementById(this.HtmlElementName);
// init OnMessage
AscCommon.InitOnMessage(function(error, url) {
if (c_oAscError.ID.No !== error) {
AscCommon.InitOnMessage(function(error, url)
{
if (c_oAscError.ID.No !== error)
{
t.sendEvent("asc_onError", error, c_oAscError.Level.NoCritical);
} else {
}
else
{
t._addImageUrl(url);
}
t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
});
// init drag&drop
AscCommon.InitDragAndDrop(this.HtmlElement, function(error, files) {
AscCommon.InitDragAndDrop(this.HtmlElement, function(error, files)
{
t._uploadCallback(error, files);
});
AscCommon.loadSdk(this._editorNameById(), function() {
AscCommon.loadSdk(this._editorNameById(), function()
{
t.isLoadFullApi = true;
if (t.DocInfo && t.DocInfo.get_OfflineApp()) {
if (t.DocInfo && t.DocInfo.get_OfflineApp())
{
t._OfflineAppDocumentStartLoad();
}
t._onEndLoadSdk();
t.onEndLoadFile(null);
});
};
baseEditorsApi.prototype._editorNameById = function() {
};
baseEditorsApi.prototype._editorNameById = function()
{
var res = '';
switch (this.editorId) {
switch (this.editorId)
{
case c_oEditorId.Word:
res = 'word';
break;
......@@ -162,22 +175,28 @@ baseEditorsApi.prototype._editorNameById = function() {
break;
}
return res;
};
baseEditorsApi.prototype.getEditorId = function() {
};
baseEditorsApi.prototype.getEditorId = function()
{
return this.editorId;
};
baseEditorsApi.prototype.asc_GetFontThumbnailsPath = function() {
};
baseEditorsApi.prototype.asc_GetFontThumbnailsPath = function()
{
return '../Common/Images/';
};
baseEditorsApi.prototype.asc_getDocumentName = function() {
};
baseEditorsApi.prototype.asc_getDocumentName = function()
{
return this.documentTitle;
};
baseEditorsApi.prototype.asc_setDocInfo = function(oDocInfo) {
if (oDocInfo) {
};
baseEditorsApi.prototype.asc_setDocInfo = function(oDocInfo)
{
if (oDocInfo)
{
this.DocInfo = oDocInfo;
}
if (this.DocInfo) {
if (this.DocInfo)
{
this.documentId = this.DocInfo.get_Id();
this.documentUserId = this.DocInfo.get_UserId();
this.documentUrl = this.DocInfo.get_Url();
......@@ -196,89 +215,117 @@ baseEditorsApi.prototype.asc_setDocInfo = function(oDocInfo) {
this.CoAuthoringApi.setDocId(this.documentId);
}
if (undefined !== window["AscDesktopEditor"] && offlineMode != this.documentUrl) {
if (undefined !== window["AscDesktopEditor"] && offlineMode != this.documentUrl)
{
window["AscDesktopEditor"]["SetDocumentName"](this.documentTitle);
}
};
baseEditorsApi.prototype.asc_enableKeyEvents = function(isEnabled) {
};
// Copy/Past/Cut
baseEditorsApi.prototype.asc_IsFocus = function(bIsNaturalFocus) {
};
// Просмотр PDF
baseEditorsApi.prototype.isPdfViewer = function() {
};
baseEditorsApi.prototype.asc_enableKeyEvents = function(isEnabled)
{
};
// Copy/Past/Cut
baseEditorsApi.prototype.asc_IsFocus = function(bIsNaturalFocus)
{
};
// Просмотр PDF
baseEditorsApi.prototype.isPdfViewer = function()
{
return false;
};
// Events
baseEditorsApi.prototype.sendEvent = function() {
};
baseEditorsApi.prototype.SendOpenProgress = function() {
};
// Events
baseEditorsApi.prototype.sendEvent = function()
{
};
baseEditorsApi.prototype.SendOpenProgress = function()
{
this.sendEvent("asc_onOpenDocumentProgress", this.OpenDocumentProgress);
};
baseEditorsApi.prototype.sync_InitEditorFonts = function(gui_fonts) {
};
baseEditorsApi.prototype.sync_InitEditorFonts = function(gui_fonts)
{
this.sendEvent("asc_onInitEditorFonts", gui_fonts);
};
baseEditorsApi.prototype.sync_StartAction = function(type, id) {
};
baseEditorsApi.prototype.sync_StartAction = function(type, id)
{
this.sendEvent('asc_onStartAction', type, id);
//console.log("asc_onStartAction: type = " + type + " id = " + id);
if (c_oAscAsyncActionType.BlockInteraction === type) {
if (c_oAscAsyncActionType.BlockInteraction === type)
{
this.incrementCounterLongAction();
}
};
baseEditorsApi.prototype.sync_EndAction = function(type, id) {
};
baseEditorsApi.prototype.sync_EndAction = function(type, id)
{
this.sendEvent('asc_onEndAction', type, id);
//console.log("asc_onEndAction: type = " + type + " id = " + id);
if (c_oAscAsyncActionType.BlockInteraction === type) {
if (c_oAscAsyncActionType.BlockInteraction === type)
{
this.decrementCounterLongAction();
}
};
baseEditorsApi.prototype.sync_TryUndoInFastCollaborative = function() {
};
baseEditorsApi.prototype.sync_TryUndoInFastCollaborative = function()
{
this.sendEvent("asc_OnTryUndoInFastCollaborative");
};
baseEditorsApi.prototype.asc_enableKeyEvents = function(val) {};
baseEditorsApi.prototype.asc_setViewMode = function() {
};
baseEditorsApi.prototype.getViewMode = function() {
};
baseEditorsApi.prototype.isLongAction = function() {
};
baseEditorsApi.prototype.asc_enableKeyEvents = function(val)
{
};
baseEditorsApi.prototype.asc_setViewMode = function()
{
};
baseEditorsApi.prototype.getViewMode = function()
{
};
baseEditorsApi.prototype.isLongAction = function()
{
return (0 !== this.IsLongActionCurrent);
};
baseEditorsApi.prototype.incrementCounterLongAction = function() {
};
baseEditorsApi.prototype.incrementCounterLongAction = function()
{
++this.IsLongActionCurrent;
};
baseEditorsApi.prototype.decrementCounterLongAction = function() {
};
baseEditorsApi.prototype.decrementCounterLongAction = function()
{
this.IsLongActionCurrent--;
if (this.IsLongActionCurrent < 0) {
if (this.IsLongActionCurrent < 0)
{
this.IsLongActionCurrent = 0;
}
if (!this.isLongAction()) {
if (!this.isLongAction())
{
var _length = this.LongActionCallbacks.length;
for (var i = 0; i < _length; i++) {
for (var i = 0; i < _length; i++)
{
this.LongActionCallbacks[i](this.LongActionCallbacksParams[i]);
}
this.LongActionCallbacks.splice(0, _length);
this.LongActionCallbacksParams.splice(0, _length);
}
};
baseEditorsApi.prototype.checkLongActionCallback = function(_callback, _param) {
if (this.isLongAction()) {
};
baseEditorsApi.prototype.checkLongActionCallback = function(_callback, _param)
{
if (this.isLongAction())
{
this.LongActionCallbacks[this.LongActionCallbacks.length] = _callback;
this.LongActionCallbacksParams[this.LongActionCallbacksParams.length] = _param;
return false;
} else {
}
else
{
return true;
}
};
/**
};
/**
* Функция для загрузчика шрифтов (нужно ли грузить default шрифты). Для Excel всегда возвращаем false
* @returns {boolean}
*/
baseEditorsApi.prototype.IsNeedDefaultFonts = function() {
baseEditorsApi.prototype.IsNeedDefaultFonts = function()
{
var res = false;
switch (this.editorId) {
switch (this.editorId)
{
case c_oEditorId.Word:
res = !this.isPdfViewer();
break;
......@@ -287,28 +334,32 @@ baseEditorsApi.prototype.IsNeedDefaultFonts = function() {
break;
}
return res;
};
baseEditorsApi.prototype.onPrint = function() {
};
baseEditorsApi.prototype.onPrint = function()
{
this.sendEvent("asc_onPrint");
};
// Open
baseEditorsApi.prototype.asc_LoadDocument = function(isVersionHistory) {
};
// Open
baseEditorsApi.prototype.asc_LoadDocument = function(isVersionHistory)
{
// Меняем тип состояния (на открытие)
this.advancedOptionsAction = AscCommon.c_oAscAdvancedOptionsAction.Open;
var rData = null;
if (offlineMode !== this.documentUrl) {
if (offlineMode !== this.documentUrl)
{
rData = {
"c": 'open',
"id": this.documentId,
"userid": this.documentUserId,
"format": this.documentFormat,
"vkey": this.documentVKey,
"url": this.documentUrl,
"title": this.documentTitle,
"embeddedfonts": this.isUseEmbeddedCutFonts,
"viewmode": this.getViewMode()
};
if (isVersionHistory) {
"c" : 'open',
"id" : this.documentId,
"userid" : this.documentUserId,
"format" : this.documentFormat,
"vkey" : this.documentVKey,
"url" : this.documentUrl,
"title" : this.documentTitle,
"embeddedfonts" : this.isUseEmbeddedCutFonts,
"viewmode" : this.getViewMode()
};
if (isVersionHistory)
{
//чтобы результат пришел только этому соединению, а не всем кто в документе
rData["userconnectionid"] = this.CoAuthoringApi.getUserConnectionId();
}
......@@ -317,123 +368,160 @@ baseEditorsApi.prototype.asc_LoadDocument = function(isVersionHistory) {
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.Open);
if (offlineMode === this.documentUrl) {
if (offlineMode === this.documentUrl)
{
this.documentUrl = '/sdkjs/' + this._editorNameById() + '/document/';
this.DocInfo.asc_putOfflineApp(true);
}
};
baseEditorsApi.prototype._OfflineAppDocumentStartLoad = function() {
};
baseEditorsApi.prototype._OfflineAppDocumentStartLoad = function()
{
var t = this;
var scriptElem = document.createElement('script');
scriptElem.onload = scriptElem.onerror = function() {
scriptElem.onload = scriptElem.onerror = function()
{
t._OfflineAppDocumentEndLoad();
};
scriptElem.setAttribute('src', this.documentUrl + 'editor.js');
scriptElem.setAttribute('type', 'text/javascript');
document.getElementsByTagName('head')[0].appendChild(scriptElem);
};
baseEditorsApi.prototype._onOpenCommand = function(data) {
};
baseEditorsApi.prototype._onNeedParams = function(data) {
};
baseEditorsApi.prototype.asyncServerIdEndLoaded = function() {
};
baseEditorsApi.prototype.asyncFontStartLoaded = function() {
};
baseEditorsApi.prototype._onOpenCommand = function(data)
{
};
baseEditorsApi.prototype._onNeedParams = function(data)
{
};
baseEditorsApi.prototype.asyncServerIdEndLoaded = function()
{
};
baseEditorsApi.prototype.asyncFontStartLoaded = function()
{
// здесь прокинуть евент о заморозке меню
this.sync_StartAction(c_oAscAsyncActionType.Information, c_oAscAsyncAction.LoadFont);
};
baseEditorsApi.prototype.asyncImageStartLoaded = function() {
};
baseEditorsApi.prototype.asyncImageStartLoaded = function()
{
// здесь прокинуть евент о заморозке меню
};
baseEditorsApi.prototype.asyncImagesDocumentStartLoaded = function() {
};
baseEditorsApi.prototype.asyncImagesDocumentStartLoaded = function()
{
// евент о заморозке не нужен... оно и так заморожено
// просто нужно вывести информацию в статус бар (что началась загрузка картинок)
};
// Save
baseEditorsApi.prototype.processSavedFile = function(url, downloadType) {
if (AscCommon.DownloadType.None !== downloadType) {
this.sendEvent(downloadType, url, function(hasError) {
};
// Save
baseEditorsApi.prototype.processSavedFile = function(url, downloadType)
{
if (AscCommon.DownloadType.None !== downloadType)
{
this.sendEvent(downloadType, url, function(hasError)
{
});
} else {
}
else
{
AscCommon.getFile(url);
}
};
// Выставление интервала автосохранения (0 - означает, что автосохранения нет)
baseEditorsApi.prototype.asc_setAutoSaveGap = function(autoSaveGap) {
if (typeof autoSaveGap === "number") {
};
// Выставление интервала автосохранения (0 - означает, что автосохранения нет)
baseEditorsApi.prototype.asc_setAutoSaveGap = function(autoSaveGap)
{
if (typeof autoSaveGap === "number")
{
this.autoSaveGap = autoSaveGap * 1000; // Нам выставляют в секундах
}
};
// send chart message
baseEditorsApi.prototype.asc_coAuthoringChatSendMessage = function(message) {
};
// send chart message
baseEditorsApi.prototype.asc_coAuthoringChatSendMessage = function(message)
{
this.CoAuthoringApi.sendMessage(message);
};
// get chart messages
baseEditorsApi.prototype.asc_coAuthoringChatGetMessages = function() {
};
// get chart messages
baseEditorsApi.prototype.asc_coAuthoringChatGetMessages = function()
{
this.CoAuthoringApi.getMessages();
};
// get users, возвращается массив users
baseEditorsApi.prototype.asc_coAuthoringGetUsers = function() {
};
// get users, возвращается массив users
baseEditorsApi.prototype.asc_coAuthoringGetUsers = function()
{
this.CoAuthoringApi.getUsers();
};
// get permissions
baseEditorsApi.prototype.asc_getEditorPermissions = function() {
};
// get permissions
baseEditorsApi.prototype.asc_getEditorPermissions = function()
{
this._coAuthoringInit();
};
baseEditorsApi.prototype._onEndPermissions = function() {
if (this.isOnFirstConnectEnd && this.isOnLoadLicense) {
};
baseEditorsApi.prototype._onEndPermissions = function()
{
if (this.isOnFirstConnectEnd && this.isOnLoadLicense)
{
this.sendEvent('asc_onGetEditorPermissions', new AscCommon.asc_CAscEditorPermissions());
}
};
// CoAuthoring
baseEditorsApi.prototype._coAuthoringInit = function() {
};
// CoAuthoring
baseEditorsApi.prototype._coAuthoringInit = function()
{
var t = this;
//Если User не задан, отключаем коавторинг.
if (null == this.User || null == this.User.asc_getId()) {
if (null == this.User || null == this.User.asc_getId())
{
this.User = new AscCommon.asc_CUser();
this.User.setId("Unknown");
this.User.setUserName("Unknown");
}
//в обычном серверном режиме портим ссылку, потому что CoAuthoring теперь имеет встроенный адрес
//todo надо использовать проверку get_OfflineApp
if (!(window['NATIVE_EDITOR_ENJINE'] || offlineMode === this.documentUrl)) {
if (!(window['NATIVE_EDITOR_ENJINE'] || offlineMode === this.documentUrl))
{
this.CoAuthoringApi.set_url(null);
}
this.CoAuthoringApi.onMessage = function(e, clear) {
this.CoAuthoringApi.onMessage = function(e, clear)
{
t.sendEvent('asc_onCoAuthoringChatReceiveMessage', e, clear);
};
this.CoAuthoringApi.onAuthParticipantsChanged = function(e, count) {
this.CoAuthoringApi.onAuthParticipantsChanged = function(e, count)
{
t.sendEvent("asc_onAuthParticipantsChanged", e, count);
};
this.CoAuthoringApi.onParticipantsChanged = function(e, CountEditUsers) {
this.CoAuthoringApi.onParticipantsChanged = function(e, CountEditUsers)
{
t.sendEvent("asc_onParticipantsChanged", e, CountEditUsers);
};
this.CoAuthoringApi.onSpellCheckInit = function(e) {
this.CoAuthoringApi.onSpellCheckInit = function(e)
{
t.SpellCheckUrl = e;
t._coSpellCheckInit();
};
this.CoAuthoringApi.onSetIndexUser = function(e) {
this.CoAuthoringApi.onSetIndexUser = function(e)
{
AscCommon.g_oIdCounter.Set_UserId('' + e);
};
this.CoAuthoringApi.onFirstLoadChangesEnd = function() {
this.CoAuthoringApi.onFirstLoadChangesEnd = function()
{
t.asyncServerIdEndLoaded();
};
this.CoAuthoringApi.onFirstConnect = function() {
if (t.isOnFirstConnectEnd) {
this.CoAuthoringApi.onFirstConnect = function()
{
if (t.isOnFirstConnectEnd)
{
t.CoAuthoringApi.auth(t.getViewMode());
} else {
}
else
{
t.isOnFirstConnectEnd = true;
t._onEndPermissions();
}
};
this.CoAuthoringApi.onLicense = function(res) {
this.CoAuthoringApi.onLicense = function(res)
{
t.licenseResult = res;
t.isOnLoadLicense = true;
t._onEndPermissions();
};
this.CoAuthoringApi.onWarning = function(e) {
this.CoAuthoringApi.onWarning = function(e)
{
t.sendEvent('asc_onError', c_oAscError.ID.Warning, c_oAscError.Level.NoCritical);
};
/**
......@@ -442,11 +530,14 @@ baseEditorsApi.prototype._coAuthoringInit = function() {
* @param {Bool} isDisconnectAtAll окончательно ли отсоединяемся(true) или будем пробовать сделать reconnect(false) + сами отключились
* @param {Bool} isCloseCoAuthoring
*/
this.CoAuthoringApi.onDisconnect = function(e, isDisconnectAtAll, isCloseCoAuthoring) {
if (AscCommon.ConnectionState.None === t.CoAuthoringApi.get_state()) {
this.CoAuthoringApi.onDisconnect = function(e, isDisconnectAtAll, isCloseCoAuthoring)
{
if (AscCommon.ConnectionState.None === t.CoAuthoringApi.get_state())
{
t.asyncServerIdEndLoaded();
}
if (isDisconnectAtAll) {
if (isDisconnectAtAll)
{
// Посылаем наверх эвент об отключении от сервера
t.sendEvent('asc_onCoAuthoringDisconnect');
// И переходим в режим просмотра т.к. мы не можем сохранить файл
......@@ -454,29 +545,41 @@ baseEditorsApi.prototype._coAuthoringInit = function() {
t.sendEvent('asc_onError', isCloseCoAuthoring ? c_oAscError.ID.UserDrop : c_oAscError.ID.CoAuthoringDisconnect, c_oAscError.Level.NoCritical);
}
};
this.CoAuthoringApi.onDocumentOpen = function(inputWrap) {
if (inputWrap["data"]) {
this.CoAuthoringApi.onDocumentOpen = function(inputWrap)
{
if (inputWrap["data"])
{
var input = inputWrap["data"];
switch (input["type"]) {
switch (input["type"])
{
case 'reopen':
case 'open':
switch (input["status"]) {
switch (input["status"])
{
case "updateversion":
case "ok":
var urls = input["data"];
AscCommon.g_oDocumentUrls.init(urls);
if (null != urls['Editor.bin']) {
if ('ok' === input["status"] || t.getViewMode()) {
if (null != urls['Editor.bin'])
{
if ('ok' === input["status"] || t.getViewMode())
{
t._onOpenCommand(urls['Editor.bin']);
} else {
t.sendEvent("asc_onDocumentUpdateVersion", function() {
if (t.isCoAuthoringEnable) {
}
else
{
t.sendEvent("asc_onDocumentUpdateVersion", function()
{
if (t.isCoAuthoringEnable)
{
t.asc_coAuthoringDisconnect();
}
t._onOpenCommand(urls['Editor.bin']);
})
}
} else {
}
else
{
t.sendEvent("asc_onError", c_oAscError.ID.ConvertationError, c_oAscError.Level.Critical);
}
break;
......@@ -492,10 +595,13 @@ baseEditorsApi.prototype._coAuthoringInit = function() {
}
break;
default:
if (t.fCurCallback) {
if (t.fCurCallback)
{
t.fCurCallback(input);
t.fCurCallback = null;
} else {
}
else
{
t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
break;
......@@ -505,109 +611,143 @@ baseEditorsApi.prototype._coAuthoringInit = function() {
this._coAuthoringInitEnd();
this.CoAuthoringApi.init(this.User, this.documentId, this.documentCallbackUrl, 'fghhfgsjdgfjs', this.editorId, this.documentFormatSave);
};
baseEditorsApi.prototype._coAuthoringInitEnd = function() {
};
// server disconnect
baseEditorsApi.prototype.asc_coAuthoringDisconnect = function() {
};
baseEditorsApi.prototype._coAuthoringInitEnd = function()
{
};
// server disconnect
baseEditorsApi.prototype.asc_coAuthoringDisconnect = function()
{
this.CoAuthoringApi.disconnect();
this.isCoAuthoringEnable = false;
// Выставляем view-режим
this.asc_setViewMode(true);
};
baseEditorsApi.prototype.asc_stopSaving = function() {
};
baseEditorsApi.prototype.asc_stopSaving = function()
{
this.incrementCounterLongAction();
};
baseEditorsApi.prototype.asc_continueSaving = function() {
};
baseEditorsApi.prototype.asc_continueSaving = function()
{
this.decrementCounterLongAction();
};
// SpellCheck
baseEditorsApi.prototype._coSpellCheckInit = function() {
};
// Images & Charts & TextArts
baseEditorsApi.prototype.asc_setChartTranslate = function(translate) {
};
// SpellCheck
baseEditorsApi.prototype._coSpellCheckInit = function()
{
};
// Images & Charts & TextArts
baseEditorsApi.prototype.asc_setChartTranslate = function(translate)
{
this.chartTranslate = translate;
};
baseEditorsApi.prototype.asc_setTextArtTranslate = function(translate) {
};
baseEditorsApi.prototype.asc_setTextArtTranslate = function(translate)
{
this.textArtTranslate = translate;
};
baseEditorsApi.prototype.asc_getChartPreviews = function(chartType) {
};
baseEditorsApi.prototype.asc_getChartPreviews = function(chartType)
{
return this.chartPreviewManager.getChartPreviews(chartType);
};
baseEditorsApi.prototype.asc_getTextArtPreviews = function() {
};
baseEditorsApi.prototype.asc_getTextArtPreviews = function()
{
return this.textArtPreviewManager.getWordArtStyles();
};
baseEditorsApi.prototype.asc_onOpenChartFrame = function() {
};
baseEditorsApi.prototype.asc_onOpenChartFrame = function()
{
this.isOpenedChartFrame = true;
};
baseEditorsApi.prototype.asc_onCloseChartFrame = function() {
};
baseEditorsApi.prototype.asc_onCloseChartFrame = function()
{
this.isOpenedChartFrame = false;
};
baseEditorsApi.prototype.asc_setInterfaceDrawImagePlaceShape = function(elementId) {
};
baseEditorsApi.prototype.asc_setInterfaceDrawImagePlaceShape = function(elementId)
{
this.shapeElementId = elementId;
};
baseEditorsApi.prototype.asc_getPropertyEditorShapes = function() {
};
baseEditorsApi.prototype.asc_getPropertyEditorShapes = function()
{
return [AscCommon.g_oAutoShapesGroups, AscCommon.g_oAutoShapesTypes];
};
baseEditorsApi.prototype.asc_getPropertyEditorTextArts = function() {
};
baseEditorsApi.prototype.asc_getPropertyEditorTextArts = function()
{
return [AscCommon.g_oPresetTxWarpGroups, AscCommon.g_PresetTxWarpTypes];
};
// Add image
baseEditorsApi.prototype._addImageUrl = function() {
};
baseEditorsApi.prototype.asc_addImage = function() {
};
// Add image
baseEditorsApi.prototype._addImageUrl = function()
{
};
baseEditorsApi.prototype.asc_addImage = function()
{
var t = this;
AscCommon.ShowImageFileDialog(this.documentId, this.documentUserId, function(error, files) {
AscCommon.ShowImageFileDialog(this.documentId, this.documentUserId, function(error, files)
{
t._uploadCallback(error, files);
}, function(error) {
if (c_oAscError.ID.No !== error) {
}, function(error)
{
if (c_oAscError.ID.No !== error)
{
t.sendEvent("asc_onError", error, c_oAscError.Level.NoCritical);
}
t.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
});
};
baseEditorsApi.prototype._uploadCallback = function(error, files) {
};
baseEditorsApi.prototype._uploadCallback = function(error, files)
{
var t = this;
if (c_oAscError.ID.No !== error) {
if (c_oAscError.ID.No !== error)
{
this.sendEvent("asc_onError", error, c_oAscError.Level.NoCritical);
} else {
}
else
{
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
AscCommon.UploadImageFiles(files, this.documentId, this.documentUserId, function(error, url) {
if (c_oAscError.ID.No !== error) {
AscCommon.UploadImageFiles(files, this.documentId, this.documentUserId, function(error, url)
{
if (c_oAscError.ID.No !== error)
{
t.sendEvent("asc_onError", error, c_oAscError.Level.NoCritical);
} else {
}
else
{
t._addImageUrl(url);
}
t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
});
}
};
};
//метод, который подменяет callback загрузки в каждом редакторе, TODO: переделать, сделать одинаково в о всех редакторах
baseEditorsApi.prototype.asc_replaceLoadImageCallback = function(fCallback){
baseEditorsApi.prototype.asc_replaceLoadImageCallback = function(fCallback)
{
};
baseEditorsApi.prototype.asc_loadLocalImageAndAction = function(sLocalImage, fCallback){
baseEditorsApi.prototype.asc_loadLocalImageAndAction = function(sLocalImage, fCallback)
{
this.ImageLoader.LoadImage(AscCommon.getFullImageSrc2(sLocalImage), 1);
this.asc_replaceLoadImageCallback(fCallback);
};
baseEditorsApi.prototype.asc_checkImageUrlAndAction = function(sImageUrl, fCallback){
baseEditorsApi.prototype.asc_checkImageUrlAndAction = function(sImageUrl, fCallback)
{
var sLocalImage = AscCommon.g_oDocumentUrls.getImageLocal(sImageUrl);
if(sLocalImage){
if (sLocalImage)
{
this.asc_loadLocalImageAndAction(sLocalImage, fCallback);
return;
}
var oThis = this;
AscCommon.sendImgUrls(oThis, [sImageUrl], function(data){
if(data[0] && data[0].path != null){
AscCommon.sendImgUrls(oThis, [sImageUrl], function(data)
{
if (data[0] && data[0].path != null)
{
oThis.asc_loadLocalImageAndAction(AscCommon.g_oDocumentUrls.imagePath2Local(data[0].path), fCallback);
}
}, this.editorId === c_oEditorId.Spreadsheet);
};
baseEditorsApi.prototype.asc_addOleObject = function(oPluginData){
baseEditorsApi.prototype.asc_addOleObject = function(oPluginData)
{
Asc.CPluginData_wrap(oPluginData);
var oThis = this;
var oThis = this;
......@@ -618,15 +758,19 @@ baseEditorsApi.prototype._uploadCallback = function(error, files) {
var fHeight = oPluginData.getAttribute("height");
var sData = oPluginData.getAttribute("data");
var sGuid = oPluginData.getAttribute("guid");
if(typeof sImgSrc === "string" && sImgSrc.length > 0 && typeof sData === "string"
if (typeof sImgSrc === "string" && sImgSrc.length > 0 && typeof sData === "string"
&& typeof sGuid === "string" && sGuid.length > 0
&& AscFormat.isRealNumber(nWidthPix) && AscFormat.isRealNumber(nHeightPix)
&& AscFormat.isRealNumber(fWidth) && AscFormat.isRealNumber(fHeight)
)
this.asc_checkImageUrlAndAction(sImgSrc, function(oImage){oThis.asc_addOleObjectAction(AscCommon.g_oDocumentUrls.getImageLocal(oImage.src), sData, sGuid, fWidth, fHeight, nWidthPix, nHeightPix);});
this.asc_checkImageUrlAndAction(sImgSrc, function(oImage)
{
oThis.asc_addOleObjectAction(AscCommon.g_oDocumentUrls.getImageLocal(oImage.src), sData, sGuid, fWidth, fHeight, nWidthPix, nHeightPix);
});
};
baseEditorsApi.prototype.asc_editOleObject = function(oPluginData){
baseEditorsApi.prototype.asc_editOleObject = function(oPluginData)
{
Asc.CPluginData_wrap(oPluginData);
var oThis = this;
var bResize = oPluginData.getAttribute("resize");
......@@ -635,9 +779,13 @@ baseEditorsApi.prototype._uploadCallback = function(error, files) {
var nWidthPix = oPluginData.getAttribute("widthPix");
var nHeightPix = oPluginData.getAttribute("heightPix");
var sData = oPluginData.getAttribute("data");
if(typeof sImgSrc === "string" && sImgSrc.length > 0 && typeof sData === "string"
&& oOleObject && AscFormat.isRealNumber(nWidthPix) && AscFormat.isRealNumber(nHeightPix)){
this.asc_checkImageUrlAndAction(sImgSrc, function(oImage){oThis.asc_editOleObjectAction(bResize, oOleObject, AscCommon.g_oDocumentUrls.getImageLocal(oImage.src), sData, nWidthPix, nHeightPix);});
if (typeof sImgSrc === "string" && sImgSrc.length > 0 && typeof sData === "string"
&& oOleObject && AscFormat.isRealNumber(nWidthPix) && AscFormat.isRealNumber(nHeightPix))
{
this.asc_checkImageUrlAndAction(sImgSrc, function(oImage)
{
oThis.asc_editOleObjectAction(bResize, oOleObject, AscCommon.g_oDocumentUrls.getImageLocal(oImage.src), sData, nWidthPix, nHeightPix);
});
}
};
......@@ -649,37 +797,47 @@ baseEditorsApi.prototype._uploadCallback = function(error, files) {
{
};
// Version History
baseEditorsApi.prototype.asc_showRevision = function(newObj) {
};
baseEditorsApi.prototype.asc_undoAllChanges = function() {
};
/**
// Version History
baseEditorsApi.prototype.asc_showRevision = function(newObj)
{
};
baseEditorsApi.prototype.asc_undoAllChanges = function()
{
};
/**
* Эта функция возвращает true, если есть изменения или есть lock-и в документе
*/
baseEditorsApi.prototype.asc_isDocumentCanSave = function() {
baseEditorsApi.prototype.asc_isDocumentCanSave = function()
{
return this.isDocumentCanSave;
};
// Offline mode
baseEditorsApi.prototype.asc_isOffline = function() {
};
// Offline mode
baseEditorsApi.prototype.asc_isOffline = function()
{
return false;
};
baseEditorsApi.prototype.asc_getUrlType = function(url) {
};
baseEditorsApi.prototype.asc_getUrlType = function(url)
{
return AscCommon.getUrlType(url);
};
};
baseEditorsApi.prototype.openDocument = function() {
baseEditorsApi.prototype.openDocument = function()
{
};
baseEditorsApi.prototype.onEndLoadFile = function(result) {
if (result) {
baseEditorsApi.prototype.onEndLoadFile = function(result)
{
if (result)
{
this.openResult = result;
}
if (this.isLoadFullApi && this.openResult) {
if (this.isLoadFullApi && this.openResult)
{
this.openDocument(this.openResult);
}
};
baseEditorsApi.prototype._onEndLoadSdk = function() {
baseEditorsApi.prototype._onEndLoadSdk = function()
{
AscFonts.g_fontApplication.Init();
this.FontLoader = AscCommon.g_font_loader;
......@@ -695,15 +853,18 @@ baseEditorsApi.prototype.asc_getUrlType = function(url) {
AscFormat.initStyleManager();
if (null !== this.tmpFocus) {
if (null !== this.tmpFocus)
{
this.asc_enableKeyEvents(this.tmpFocus);
}
};
baseEditorsApi.prototype.sendStandartTextures = function() {
baseEditorsApi.prototype.sendStandartTextures = function()
{
var _count = AscCommon.g_oUserTexturePresets.length;
var arr = new Array(_count);
for (var i = 0; i < _count; ++i) {
for (var i = 0; i < _count; ++i)
{
arr[i] = new AscCommon.asc_CTexture();
arr[i].Id = i;
arr[i].Image = AscCommon.g_oUserTexturePresets[i];
......@@ -713,41 +874,45 @@ baseEditorsApi.prototype.asc_getUrlType = function(url) {
this.sendEvent('asc_onInitStandartTextures', arr);
};
// plugins
baseEditorsApi.prototype.asc_pluginsRegister = function(basePath, plugins)
{
// plugins
baseEditorsApi.prototype.asc_pluginsRegister = function(basePath, plugins)
{
if (null != this.pluginsManager)
this.pluginsManager.register(basePath, plugins);
};
baseEditorsApi.prototype.asc_pluginRun = function(guid, variation, pluginData)
{
};
baseEditorsApi.prototype.asc_pluginRun = function(guid, variation, pluginData)
{
if (null != this.pluginsManager)
this.pluginsManager.run(guid, variation, pluginData);
};
baseEditorsApi.prototype.asc_pluginResize = function(pluginData)
{
};
baseEditorsApi.prototype.asc_pluginResize = function(pluginData)
{
if (null != this.pluginsManager)
this.pluginsManager.runResize(pluginData);
};
baseEditorsApi.prototype.asc_pluginButtonClick = function(id)
{
};
baseEditorsApi.prototype.asc_pluginButtonClick = function(id)
{
if (null != this.pluginsManager)
this.pluginsManager.buttonClick(id);
};
};
// Builder
baseEditorsApi.prototype.asc_nativeInitBuilder = function() {
baseEditorsApi.prototype.asc_nativeInitBuilder = function()
{
this.asc_setDocInfo(new Asc.asc_CDocInfo());
};
baseEditorsApi.prototype.asc_SetSilentMode = function() {
baseEditorsApi.prototype.asc_SetSilentMode = function()
{
};
baseEditorsApi.prototype.asc_canPaste = function() {
baseEditorsApi.prototype.asc_canPaste = function()
{
return false;
};
baseEditorsApi.prototype.asc_Recalculate = function() {
baseEditorsApi.prototype.asc_Recalculate = function()
{
};
//----------------------------------------------------------export----------------------------------------------------
window['AscCommon'] = window['AscCommon'] || {};
window['AscCommon'].baseEditorsApi = baseEditorsApi;
......
......@@ -305,9 +305,28 @@
if (value && value != "")
{
try
{
if (window.g_asc_plugins.api.asc_canPaste())
{
var _script = "(function(){ var Api = window.g_asc_plugins.api;\n" + value + "})();";
eval(_script);
var oLogicDocument = window.g_asc_plugins.api.WordControl ? window.g_asc_plugins.api.WordControl.m_oLogicDocument : null;
if (pluginData.getAttribute("recalculate") == true)
{
var _fonts = oLogicDocument.Document_Get_AllFontNames();
var _imagesArray = oLogicDocument.Get_AllImageUrls();
var _images = {};
for (var i = 0; i < _imagesArray.length; i++)
{
_images[_imagesArray[i]] = _imagesArray[i];
}
AscCommon.Check_LoadingDataBeforePrepaste(window.g_asc_plugins.api, _fonts, _images, function()
{
window.g_asc_plugins.api.asc_Recalculate();
});
}
}
}
catch (err)
{
......@@ -495,6 +514,38 @@ function TEST_PLUGINS()
{ text: "Cancel", primary: false } ]
}
]
},
{
"name" : "cbr",
"guid" : "asc.{5F9D4EB4-AF61-46EF-AE25-46C96E75E1DD}",
"variations" : [
{
"description" : "cbr",
"url" : "cbr/index.html",
"icons" : ["cbr/icon.png", "cbr/icon@2x.png"],
// "isViewer" : true,
"isViewer" : false,
"EditorsSupport" : ["word", "cell", "slide"],
// "isVisual" : true,
// "isModal" : true,
"isVisual" : false,
"isModal" : false,
"isInsideMode" : false,
"initDataType" : "none",
"initData" : "",
// "isUpdateOleOnResize" : true,
"isUpdateOleOnResize" : false,
// "buttons" : [ { "text": "Ok", "primary": true },
// { "text": "Cancel", "primary": false } ]
"buttons" : []
}
]
}
];
......
......@@ -7817,8 +7817,81 @@ function CreateImageFromBinary(bin, nW, nH)
return para_drawing;
}
function Check_LoadingDataBeforePrepaste(_api, _fonts, _images, _callback)
{
var aPrepeareFonts = [];
for (var font_family in _fonts)
{
aPrepeareFonts.push(new CFont(font_family, 0, "", 0));
};
var aImagesToDownload = [];
var _mapLocal = {};
for (var image in _images)
{
var src = _images[image];
if (undefined !== window["Native"] && undefined !== window["Native"]["GetImageUrl"])
{
_images[image] = window["Native"]["GetImageUrl"](_images[image]);
}
else if (0 == src.indexOf("file:"))
{
if (window["AscDesktopEditor"] !== undefined)
{
if (window["AscDesktopEditor"]["LocalFileGetImageUrl"] !== undefined)
{
aImagesToDownload.push(src);
}
else
{
var _base64 = window["AscDesktopEditor"]["GetImageBase64"](src);
if (_base64 != "")
{
aImagesToDownload.push(_base64);
_mapLocal[_base64] = src;
}
else
{
_images[image] = "local";
}
}
}
else
_images[image] = "local";
}
else if (!g_oDocumentUrls.getImageLocal(src))
aImagesToDownload.push(src);
}
if (aImagesToDownload.length > 0)
{
AscCommon.sendImgUrls(_api, aImagesToDownload, function (data) {
var image_map = {};
for (var i = 0, length = Math.min(data.length, aImagesToDownload.length); i < length; ++i)
{
var elem = data[i];
var sFrom = aImagesToDownload[i];
if (null != elem.url)
{
var name = g_oDocumentUrls.imagePath2Local(elem.path);
_images[sFrom] = name;
image_map[i] = name;
}
else
{
image_map[i] = sFrom;
}
}
_api.pre_Paste(aPrepeareFonts, image_map, _callback);
});
}
else
_api.pre_Paste(aPrepeareFonts, _images, _callback);
}
//---------------------------------------------------------export---------------------------------------------------
window['AscCommon'] = window['AscCommon'] || {};
window["AscCommon"].Check_LoadingDataBeforePrepaste = Check_LoadingDataBeforePrepaste;
window["AscCommon"].CDocumentReaderMode = CDocumentReaderMode;
window["AscCommon"].GetObjectsForImageDownload = GetObjectsForImageDownload;
window["AscCommon"].ResetNewUrls = ResetNewUrls;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment