Commit d2909037 authored by Boris Kocherov's avatar Boris Kocherov

use jio storrage for save document images

disable "image upload blocking" on image jio save (probably it wrong)
use modified jio_putAttachment to save image:
* if attachId undefined then attachId = mimeType,sha1hashOfFile
* not save in jio storage if attach with checksumm already exist
* return attachId
* allow dataUri instead blob
use modified jio_getAttachment allow get attachment as dataUrl or
blobUrl (ooffice use blobUrl)
parent 5b7ac7d1
......@@ -80,26 +80,6 @@ var c_oAscError = Asc.c_oAscError;
cp['encodings'] = AscCommon.getEncodingParams();
this.handlers.trigger("asc_onAdvancedOptions", new AscCommon.asc_CAdvancedOptions(Asc.c_oAscAdvancedOptionsID.CSV, cp), AscCommon.c_oAscAdvancedOptionsAction.Open);
};
asc['spreadsheet_api'].prototype.asc_addImageDrawingObject = function(url)
{
var _url = window["AscDesktopEditor"]["LocalFileGetImageUrl"](url);
var ws = this.wb.getWorksheet();
if (ws)
{
var _url = window["AscDesktopEditor"]["LocalFileGetImageUrl"](url);
ws.objectRender.addImageDrawingObject(AscCommon.g_oDocumentUrls.getImageUrl(_url) , null);
}
};
asc['spreadsheet_api'].prototype.asc_showImageFileDialog = function()
{
window["AscDesktopEditor"]["LocalFileGetImageUrlFromOpenFileDialog"]();
};
asc['spreadsheet_api'].prototype.asc_addImage = function()
{
window["AscDesktopEditor"]["LocalFileGetImageUrlFromOpenFileDialog"]();
};
})(jQuery, window);
window["Asc"]['spreadsheet_api'].prototype.asc_setAdvancedOptions = function(idOption, option)
......
......@@ -2356,49 +2356,31 @@ var editor;
return ret;
};
spreadsheet_api.prototype.asc_addImageDrawingObject = function (imageUrl) {
var rData = {
"id": this.documentId,
"userid": this.documentUserId,
"c": "imgurl",
"saveindex": g_oDocumentUrls.getMaxIndex(),
"data": imageUrl
};
spreadsheet_api.prototype.asc_addImageDrawingObject = function(imageUrl, callback) {
var t = this;
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
this.fCurCallback = function (input) {
if (null != input && "imgurl" == input["type"]) {
if ("ok" == input["status"]) {
var data = input["data"];
var urls = {};
var firstUrl;
for (var i = 0; i < data.length; ++i) {
var elem = data[i];
if (elem.url) {
if (!firstUrl) {
firstUrl = elem.url;
}
urls[elem.path] = elem.url;
}
}
g_oDocumentUrls.addUrls(urls);
if (firstUrl) {
var ws = t.wb.getWorksheet();
ws.objectRender.addImageDrawingObject(firstUrl, null);
} else {
t.handlers.trigger("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
} else {
t.handlers.trigger("asc_onError", mapAscServerErrorToAscError(parseInt(input["data"])),
c_oAscError.Level.NoCritical);
}
} else {
if (!callback) {
callback = function (url) {
//g_oDocumentUrls.addUrls(urls);
var ws = t.wb.getWorksheet();
ws.objectRender.addImageDrawingObject('jio:' + url, null);
};
}
//this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
return new RSVP.Queue()
.push(function () {
return imageUrl;
})
.push(AscCommon.downloadUrlAsBlob)
.push(function (blob) {
return Common.Gateway.jio_putAttachment(t.documentId, undefined, blob);
})
.push(callback)
//.push(function () {t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);})
.push(undefined, function (error) {
console.log(error);
t.handlers.trigger("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
};
sendCommand(this, null, rData);
//t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
});
};
......@@ -2662,46 +2644,10 @@ var editor;
return;
}
var rData = {
"id": this.documentId,
"userid": this.documentUserId,
"c": "imgurl",
"saveindex": g_oDocumentUrls.getMaxIndex(),
"data": sImageUrl};
var t = this;
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
this.fCurCallback = function(input) {
if (null != input && "imgurl" == input["type"]) {
if ("ok" == input["status"]) {
var data = input["data"];
var urls = {};
var firstUrl;
for (var i = 0; i < data.length; ++i) {
var elem = data[i];
if (elem.url) {
if (!firstUrl) {
firstUrl = elem.url;
}
urls[elem.path] = elem.url;
}
}
g_oDocumentUrls.addUrls(urls);
if (firstUrl) {
fReplaceCallback(firstUrl);
ws.objectRender.setGraphicObjectProps(props);
} else {
t.handlers.trigger("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
} else {
t.handlers.trigger("asc_onError", mapAscServerErrorToAscError(parseInt(input["data"])), c_oAscError.Level.NoCritical);
}
} else {
t.handlers.trigger("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
};
sendCommand(this, null, rData);
this.asc_addImageDrawingObject(sImageUrl, function (url) {
fReplaceCallback('jio:' + url);
ws.objectRender.setGraphicObjectProps(props);
});
}
else{
ws.objectRender.setGraphicObjectProps(props);
......
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
"use strict";
(function(window, document){
// Import
var g_fontApplication = AscFonts.g_fontApplication;
var CFontFileLoader = AscFonts.CFontFileLoader;
var FONT_TYPE_EMBEDDED = AscFonts.FONT_TYPE_EMBEDDED;
var CFontInfo = AscFonts.CFontInfo;
var ImageLoadStatus = AscFonts.ImageLoadStatus;
var CImage = AscFonts.CImage;
function CGlobalFontLoader()
{
// сначала хотел писать "вытеснение" из этого мапа.
// но тогда нужно хранить base64 строки. Это не круто. По памяти - даже
// выигрыш будет. Не особо то шрифты жмутся lzw или deflate
// поэтому лучше из памяти будем удалять base64 строки
this.fonts_streams = [];
// теперь вся информация о всех возможных шрифтах. Они во всех редакторах должны быть одни и те же
this.fontFilesPath = "fonts/ttf";
this.fontFiles = AscFonts.g_font_files;
this.fontInfos = AscFonts.g_font_infos;
this.map_font_index = AscFonts.g_map_font_index;
// теперь вся информация о всех встроенных шрифтах. Они должны удаляться при подгрузке нового файла
this.embeddedFilesPath = "";
this.embeddedFontFiles = [];
this.embeddedFontInfos = [];
// динамическая подгрузка шрифтов
this.ThemeLoader = null;
this.Api = null;
this.fonts_loading = [];
this.fonts_loading_after_style = [];
this.bIsLoadDocumentFirst = false;
this.currentInfoLoaded = null;
this.loadFontCallBack = null;
this.loadFontCallBackArgs = null;
this.IsLoadDocumentFonts2 = false;
this.put_Api = function(_api)
{
this.Api = _api;
};
this.LoadEmbeddedFonts = function(url, _fonts)
{
this.embeddedFilesPath = url;
var _count = _fonts.length;
if (0 == _count)
return;
this.embeddedFontInfos = new Array(_count);
var map_files = {};
for (var i = 0; i < _count; i++)
map_files[_fonts[i].id] = _fonts[i].id;
var index = 0;
for (var i in map_files)
{
this.embeddedFontFiles[index] = new CFontFileLoader(map_files[i]);
this.embeddedFontFiles[index].CanUseOriginalFormat = false;
this.embeddedFontFiles[index].IsNeedAddJSToFontPath = false;
map_files[i] = index++;
}
for (var i = 0; i < _count; i++)
{
var lStyle = 0;//_fonts[i].Style;
if (0 == lStyle)
this.embeddedFontInfos[i] = new CFontInfo(_fonts[i].name, "", FONT_TYPE_EMBEDDED, map_files[_fonts[i].id], 0, -1, -1, -1, -1, -1, -1);
else if (2 == lStyle)
this.embeddedFontInfos[i] = new CFontInfo(_fonts[i].name, "", FONT_TYPE_EMBEDDED, -1, -1, map_files[_fonts[i].id], _fonts[i].faceindex, -1, -1, -1, -1);
else if (1 == lStyle)
this.embeddedFontInfos[i] = new CFontInfo(_fonts[i].name, "", FONT_TYPE_EMBEDDED, -1, -1, -1, -1, map_files[_fonts[i].id], _fonts[i].faceindex, -1, -1);
else
this.embeddedFontInfos[i] = new CFontInfo(_fonts[i].name, "", FONT_TYPE_EMBEDDED, -1, -1, -1, -1, -1, -1, map_files[_fonts[i].id], _fonts[i].faceindex);
}
var _count_infos_ = this.fontInfos.length;
for (var i = 0; i < _count; i++)
{
this.map_font_index[_fonts[i].name] = i + _count_infos_;
this.fontInfos[i + _count_infos_] = this.embeddedFontInfos[i];
}
};
this.SetStandartFonts = function()
{
//В стандартных шрифтах закоментированы те шрифты, которые были добавлены на docs.teamlab.com
var standarts = window["standarts"];
if (undefined == standarts)
{
standarts = [];
for (var i = 0; i < this.fontInfos.length; i++)
{
if (this.fontInfos[i].Name != "ASCW3")
standarts.push(this.fontInfos[i].Name);
}
}
var _count = standarts.length;
var _infos = this.fontInfos;
var _map = this.map_font_index;
for (var i = 0; i < _count; i++)
{
_infos[_map[standarts[i]]].Type = AscFonts.FONT_TYPE_STANDART;
}
};
this.AddLoadFonts = function(name, need_styles)
{
var fontinfo = g_fontApplication.GetFontInfo(name);
this.fonts_loading[this.fonts_loading.length] = fontinfo;
this.fonts_loading[this.fonts_loading.length - 1].NeedStyles = (need_styles == undefined) ? 0x0F : need_styles;
return fontinfo;
};
this.AddLoadFontsNotPick = function(info, need_styles)
{
this.fonts_loading[this.fonts_loading.length] = info;
this.fonts_loading[this.fonts_loading.length - 1].NeedStyles = (need_styles == undefined) ? 0x0F : need_styles;
};
this.LoadDocumentFonts = function(_fonts, is_default)
{
if (this.IsLoadDocumentFonts2)
return this.LoadDocumentFonts2(_fonts);
// в конце метода нужно отдать список шрифтов
var gui_fonts = [];
var gui_count = 0;
for (var i = 0; i < this.fontInfos.length; i++)
{
var info = this.fontInfos[i];
if (AscFonts.FONT_TYPE_STANDART == info.Type)
{
var __font = new AscFonts.CFont(info.Name, "", info.Type, info.Thumbnail);
gui_fonts[gui_count++] = __font;
}
}
// сначала заполняем массив this.fonts_loading объекстами fontinfo
for (var i in _fonts)
{
if (_fonts[i].type != FONT_TYPE_EMBEDDED)
{
var info = this.AddLoadFonts(_fonts[i].name, _fonts[i].NeedStyles);
if (info.Type == AscFonts.FONT_TYPE_ADDITIONAL)
{
if (info.name != "ASCW3")
{
var __font = new AscFonts.CFont(info.Name, "", info.Type, info.Thumbnail);
gui_fonts[gui_count++] = __font;
}
}
}
else
{
var ind = -1;
for (var j = 0; j < this.embeddedFontInfos.length; j++)
{
if (this.embeddedFontInfos[j].Name == _fonts[i].name)
{
this.AddLoadFontsNotPick(this.embeddedFontInfos[j], 0x0F);
break;
}
}
}
}
this.Api.sync_InitEditorFonts(gui_fonts);
// но только если редактор!!!
if (this.Api.IsNeedDefaultFonts())
{
// теперь добавим шрифты, без которых редактор как без рук (спецсимволы + дефолтовые стили документа)
this.AddLoadFonts("Arial", 0x0F);
this.AddLoadFonts("Symbol", 0x0F);
this.AddLoadFonts("Wingdings", 0x0F);
this.AddLoadFonts("Courier New", 0x0F);
this.AddLoadFonts("Times New Roman", 0x0F);
}
this.Api.asyncFontsDocumentStartLoaded();
this.bIsLoadDocumentFirst = true;
this.CheckFontsNeedLoadingLoad();
this._LoadFonts();
};
this.CheckFontsNeedLoadingLoad = function()
{
var _fonts = this.fonts_loading;
var _fonts_len = _fonts.length;
var _need = false;
for (var i = 0; i < _fonts_len; i++)
{
if (true == _fonts[i].CheckFontLoadStyles(this))
_need = true;
}
return _need;
};
this.CheckFontsNeedLoading = function(_fonts)
{
for (var i in _fonts)
{
var info = g_fontApplication.GetFontInfo(_fonts[i].name);
var _isNeed = info.CheckFontLoadStylesNoLoad(this);
if (_isNeed === true)
return true;
}
return false;
};
this.LoadDocumentFonts2 = function(_fonts)
{
// сначала заполняем массив this.fonts_loading объекстами fontinfo
for (var i in _fonts)
{
this.AddLoadFonts(_fonts[i].name, 0x0F);
}
if (null == this.ThemeLoader)
this.Api.asyncFontsDocumentStartLoaded();
else
this.ThemeLoader.asyncFontsStartLoaded();
this.CheckFontsNeedLoadingLoad();
this._LoadFonts();
};
var oThis = this;
this._LoadFonts = function()
{
if (0 == this.fonts_loading.length)
{
if (null == this.ThemeLoader)
this.Api.asyncFontsDocumentEndLoaded();
else
this.ThemeLoader.asyncFontsEndLoaded();
if (this.bIsLoadDocumentFirst === true)
{
var _count = this.fonts_loading_after_style.length;
for (var i = 0; i < _count; i++)
{
var _info = this.fonts_loading_after_style[i];
_info.NeedStyles = 0x0F;
_info.CheckFontLoadStyles(this);
}
this.fonts_loading_after_style.splice(0, this.fonts_loading_after_style.length);
this.bIsLoadDocumentFirst = false;
}
return;
}
var fontinfo = this.fonts_loading[0];
var IsNeed = fontinfo.CheckFontLoadStyles(this);
if (IsNeed)
{
setTimeout(oThis._check_loaded, 50);
//setTimeout(__global_check_load_fonts, 50);
}
else
{
if (this.bIsLoadDocumentFirst === true)
{
this.Api.OpenDocumentProgress.CurrentFont++;
this.Api.SendOpenProgress();
}
this.fonts_loading_after_style[this.fonts_loading_after_style.length] = this.fonts_loading[0];
this.fonts_loading.shift();
this._LoadFonts();
}
};
this._check_loaded = function()
{
var IsNeed = false;
if (0 == oThis.fonts_loading.length)
{
// значит асинхронно удалилось
oThis._LoadFonts();
return;
}
var current = oThis.fonts_loading[0];
var IsNeed = current.CheckFontLoadStyles(oThis);
if (true === IsNeed)
{
setTimeout(oThis._check_loaded, 50);
}
else
{
if (oThis.bIsLoadDocumentFirst === true)
{
oThis.Api.OpenDocumentProgress.CurrentFont++;
oThis.Api.SendOpenProgress();
}
oThis.fonts_loading_after_style[oThis.fonts_loading_after_style.length] = oThis.fonts_loading[0];
oThis.fonts_loading.shift();
oThis._LoadFonts();
}
};
this.LoadFont = function(fontinfo, loadFontCallBack, loadFontCallBackArgs)
{
this.currentInfoLoaded = fontinfo;
this.currentInfoLoaded = fontinfo;
this.currentInfoLoaded.NeedStyles = 15; // все стили
var IsNeed = this.currentInfoLoaded.CheckFontLoadStyles(this);
if ( undefined === loadFontCallBack )
{
this.loadFontCallBack = this.Api.asyncFontEndLoaded;
this.loadFontCallBackArgs = this.currentInfoLoaded;
}
else
{
this.loadFontCallBack = loadFontCallBack;
this.loadFontCallBackArgs = loadFontCallBackArgs;
}
if (IsNeed)
{
this.Api.asyncFontStartLoaded();
setTimeout(this.check_loaded, 20);
return true;
}
else
{
this.currentInfoLoaded = null;
return false;
}
};
this.check_loaded = function()
{
var current = oThis.currentInfoLoaded;
if (null == current)
return;
var IsNeed = current.CheckFontLoadStyles(oThis);
if (IsNeed)
{
setTimeout(oThis.check_loaded, 50);
}
else
{
oThis.loadFontCallBack.call( oThis.Api, oThis.loadFontCallBackArgs );
oThis.currentInfoLoaded = null;
}
};
this.LoadFontsFromServer = function(_fonts)
{
var _count = _fonts.length;
for (var i = 0; i < _count; i++)
{
var _info = g_fontApplication.GetFontInfo(_fonts[i]);
if (undefined !== _info)
{
_info.LoadFontsFromServer(this);
}
}
}
}
CGlobalFontLoader.prototype.SetStreamIndexEmb = function(font_index, stream_index)
{
this.embeddedFontFiles[font_index].SetStreamIndex(stream_index);
};
function CGlobalImageLoader()
{
this.map_image_index = {};
// loading
this.Api = null;
this.ThemeLoader = null;
this.images_loading = null;
this.bIsLoadDocumentFirst = false;
this.bIsAsyncLoadDocumentImages = false;
this.bIsLoadDocumentImagesNoByOrder = true;
this.nNoByOrderCounter = 0;
this.loadImageCallBackCounter = 0;
this.loadImageCallBackCounterMax = 0;
this.loadImageCallBack = null;
this.loadImageCallBackArgs = null;
var oThis = this;
this.put_Api = function(_api)
{
this.Api = _api;
if (this.Api.IsAsyncOpenDocumentImages !== undefined)
{
this.bIsAsyncLoadDocumentImages = this.Api.IsAsyncOpenDocumentImages();
if (this.bIsAsyncLoadDocumentImages)
{
if (undefined === this.Api.asyncImageEndLoadedBackground)
this.bIsAsyncLoadDocumentImages = false;
}
}
};
this.LoadDocumentImages = function(_images, isUrl)
{
// сначала заполним массив
if (this.ThemeLoader == null)
this.Api.asyncImagesDocumentStartLoaded();
else
this.ThemeLoader.asyncImagesStartLoaded();
this.images_loading = [];
for (var id in _images)
{
this.images_loading[this.images_loading.length] = AscCommon.getFullImageSrc2(_images[id]);
}
if (!this.bIsAsyncLoadDocumentImages)
{
this.nNoByOrderCounter = 0;
this._LoadImages();
}
else
{
var _len = this.images_loading.length;
for (var i = 0; i < _len; i++)
{
this.LoadImageAsync(i);
}
this.images_loading.splice(0, _len);
if (this.ThemeLoader == null)
this.Api.asyncImagesDocumentEndLoaded();
else
this.ThemeLoader.asyncImagesEndLoaded();
}
};
this._LoadImages = function()
{
var _count_images = this.images_loading.length;
if (0 == _count_images)
{
this.nNoByOrderCounter = 0;
if (this.ThemeLoader == null)
this.Api.asyncImagesDocumentEndLoaded();
else
this.ThemeLoader.asyncImagesEndLoaded();
return;
}
for (var i = 0; i < _count_images; i++)
{
var _id = this.images_loading[i];
var oImage = new CImage(_id);
oImage.Status = ImageLoadStatus.Loading;
oImage.Image = new Image();
oThis.map_image_index[oImage.src] = oImage;
oImage.Image.parentImage = oImage;
oImage.Image.onload = function ()
{
this.parentImage.Status = ImageLoadStatus.Complete;
oThis.nNoByOrderCounter++;
if (oThis.bIsLoadDocumentFirst === true)
{
oThis.Api.OpenDocumentProgress.CurrentImage++;
oThis.Api.SendOpenProgress();
}
if (!oThis.bIsLoadDocumentImagesNoByOrder)
{
oThis.images_loading.shift();
oThis._LoadImages();
}
else if (oThis.nNoByOrderCounter == oThis.images_loading.length)
{
oThis.images_loading = [];
oThis._LoadImages();
}
};
oImage.Image.onerror = function ()
{
this.parentImage.Status = ImageLoadStatus.Complete;
this.parentImage.Image = null;
oThis.nNoByOrderCounter++;
if (oThis.bIsLoadDocumentFirst === true)
{
oThis.Api.OpenDocumentProgress.CurrentImage++;
oThis.Api.SendOpenProgress();
}
if (!oThis.bIsLoadDocumentImagesNoByOrder)
{
oThis.images_loading.shift();
oThis._LoadImages();
}
else if (oThis.nNoByOrderCounter == oThis.images_loading.length)
{
oThis.images_loading = [];
oThis._LoadImages();
}
};
//oImage.Image.crossOrigin = 'anonymous';
oImage.Image.src = oImage.src;
if (!oThis.bIsLoadDocumentImagesNoByOrder)
return;
}
};
this.LoadImage = function(src, Type)
{
var _image = this.map_image_index[src];
if (undefined != _image)
return _image;
this.Api.asyncImageStartLoaded();
var oImage = new CImage(src);
oImage.Type = Type;
oImage.Image = new Image();
oImage.Status = ImageLoadStatus.Loading;
oThis.map_image_index[oImage.src] = oImage;
oImage.Image.onload = function(){
oImage.Status = ImageLoadStatus.Complete;
oThis.Api.asyncImageEndLoaded(oImage);
};
oImage.Image.onerror = function(){
oImage.Image = null;
oImage.Status = ImageLoadStatus.Complete;
oThis.Api.asyncImageEndLoaded(oImage);
};
//oImage.Image.crossOrigin = 'anonymous';
oImage.Image.src = oImage.src;
return null;
};
this.LoadImageAsync = function(i)
{
var _id = oThis.images_loading[i];
var oImage = new CImage(_id);
oImage.Status = ImageLoadStatus.Loading;
oImage.Image = new Image();
oThis.map_image_index[oImage.src] = oImage;
oImage.Image.onload = function(){
oImage.Status = ImageLoadStatus.Complete;
oThis.Api.asyncImageEndLoadedBackground(oImage);
};
oImage.Image.onerror = function(){
oImage.Status = ImageLoadStatus.Complete;
oImage.Image = null;
oThis.Api.asyncImageEndLoadedBackground(oImage);
};
//oImage.Image.crossOrigin = 'anonymous';
oImage.Image.src = oImage.src;
};
this.LoadImagesWithCallback = function(arr, loadImageCallBack, loadImageCallBackArgs)
{
var arrAsync = [];
var i = 0;
for (i = 0; i < arr.length; i++)
{
if (this.map_image_index[arr[i]] === undefined)
arrAsync.push(arr[i]);
}
if (arrAsync.length == 0)
{
loadImageCallBack.call(this.Api, loadImageCallBackArgs);
return;
}
this.loadImageCallBackCounter = 0;
this.loadImageCallBackCounterMax = arrAsync.length;
this.loadImageCallBack = loadImageCallBack;
this.loadImageCallBackArgs = loadImageCallBackArgs;
for (i = 0; i < arrAsync.length; i++)
{
var oImage = new CImage(arrAsync[i]);
oImage.Image = new Image();
oImage.Image.parentImage = oImage;
oImage.Status = ImageLoadStatus.Loading;
this.map_image_index[oImage.src] = oImage;
oImage.Image.onload = function ()
{
this.parentImage.Status = ImageLoadStatus.Complete;
oThis.loadImageCallBackCounter++;
if (oThis.loadImageCallBackCounter == oThis.loadImageCallBackCounterMax)
oThis.LoadImagesWithCallbackEnd();
};
oImage.Image.onerror = function ()
{
this.parentImage.Image = null;
this.parentImage.Status = ImageLoadStatus.Complete;
if (oThis.loadImageCallBackCounter == oThis.loadImageCallBackCounterMax)
oThis.LoadImagesWithCallbackEnd();
};
//oImage.Image.crossOrigin = 'anonymous';
oImage.Image.src = oImage.src;
}
};
this.LoadImagesWithCallbackEnd = function()
{
this.loadImageCallBack.call(this.Api, this.loadImageCallBackArgs);
this.loadImageCallBack = null;
this.loadImageCallBackArgs = null;
this.loadImageCallBackCounterMax = 0;
this.loadImageCallBackCounter = 0;
};
}
var g_flow_anchor = new Image();
g_flow_anchor.asc_complete = false;
g_flow_anchor.onload = function(){
g_flow_anchor.asc_complete = true;
};
g_flow_anchor.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPBAMAAADNDVhEAAAAIVBMVEUAAAANDQ0NDQ0NDQ0NDQ0NDQ0AAAANDQ0NDQ0NDQ0NDQ1jk7YPAAAACnRSTlMAGkD4mb9c5s9TDghpXQAAAFZJREFUCNdjYGBgW8YABlxcIBLBZ1gAEfZa5QWiGRkWMAIpAaA4iHQE0YwODEtANMsChkIwv4BBWQBICyswMC1iWADEDAzKoUuDFUAGNC9uABvIaQkkABpxD6lFb9lRAAAAAElFTkSuQmCC";
var g_flow_anchor2 = new Image();
g_flow_anchor2.asc_complete = false;
g_flow_anchor2.onload = function(){
g_flow_anchor2.asc_complete = true;
};
g_flow_anchor2.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAeCAMAAAAFBf7qAAAAOVBMVEUAAAAAAAAAAAAAAAAJCQkAAAAJCQkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJCQknI0ZQAAAAEnRSTlMAx9ITlAfyPHxn68yecTAl5qt6y0BvAAAAt0lEQVQoz8WS0QrDIAxFk0ajtlXb+/8fuzAprltg7Gnn4aIcvAgJTSSoBiGPoIAGV60qoquvIIL110IJgPONmKIlMI73MiwGRoZvahbKVSizcDKU8QeVPDXEIr6ShVB9VUEn2FOMkwL8VwjUtuypvDWiHeVTFeyWkZHfVQZHGm4XMhKQyJB9GKMxuHQSBlioF7u2q7kzgO2AcWwW3F8mWRmGKgyu91mK1Tzh4ixVVkBzJI/EnGjyACbfCaO3eIWRAAAAAElFTkSuQmCC";
//---------------------------------------------------------export---------------------------------------------------
window['AscCommon'] = window['AscCommon'] || {};
window['AscCommon'].g_font_loader = new CGlobalFontLoader();
window['AscCommon'].g_image_loader = new CGlobalImageLoader();
window['AscCommon'].g_flow_anchor = g_flow_anchor;
window['AscCommon'].g_flow_anchor2 = g_flow_anchor2;
})(window, window.document);
/* jshint -W069 */
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
"use strict";
(function(window, document){
// Import
var g_fontApplication = AscFonts.g_fontApplication;
var CFontFileLoader = AscFonts.CFontFileLoader;
var FONT_TYPE_EMBEDDED = AscFonts.FONT_TYPE_EMBEDDED;
var CFontInfo = AscFonts.CFontInfo;
var ImageLoadStatus = AscFonts.ImageLoadStatus;
var CImage = AscFonts.CImage;
function CGlobalFontLoader()
{
// сначала хотел писать "вытеснение" из этого мапа.
// но тогда нужно хранить base64 строки. Это не круто. По памяти - даже
// выигрыш будет. Не особо то шрифты жмутся lzw или deflate
// поэтому лучше из памяти будем удалять base64 строки
this.fonts_streams = [];
// теперь вся информация о всех возможных шрифтах. Они во всех редакторах должны быть одни и те же
this.fontFilesPath = "fonts/ttf";
this.fontFiles = AscFonts.g_font_files;
this.fontInfos = AscFonts.g_font_infos;
this.map_font_index = AscFonts.g_map_font_index;
// теперь вся информация о всех встроенных шрифтах. Они должны удаляться при подгрузке нового файла
this.embeddedFilesPath = "";
this.embeddedFontFiles = [];
this.embeddedFontInfos = [];
// динамическая подгрузка шрифтов
this.ThemeLoader = null;
this.Api = null;
this.fonts_loading = [];
this.fonts_loading_after_style = [];
this.bIsLoadDocumentFirst = false;
this.currentInfoLoaded = null;
this.loadFontCallBack = null;
this.loadFontCallBackArgs = null;
this.IsLoadDocumentFonts2 = false;
this.put_Api = function(_api)
{
this.Api = _api;
};
this.LoadEmbeddedFonts = function(url, _fonts)
{
this.embeddedFilesPath = url;
var _count = _fonts.length;
if (0 == _count)
return;
this.embeddedFontInfos = new Array(_count);
var map_files = {};
for (var i = 0; i < _count; i++)
map_files[_fonts[i].id] = _fonts[i].id;
var index = 0;
for (var i in map_files)
{
this.embeddedFontFiles[index] = new CFontFileLoader(map_files[i]);
this.embeddedFontFiles[index].CanUseOriginalFormat = false;
this.embeddedFontFiles[index].IsNeedAddJSToFontPath = false;
map_files[i] = index++;
}
for (var i = 0; i < _count; i++)
{
var lStyle = 0;//_fonts[i].Style;
if (0 == lStyle)
this.embeddedFontInfos[i] = new CFontInfo(_fonts[i].name, "", FONT_TYPE_EMBEDDED, map_files[_fonts[i].id], 0, -1, -1, -1, -1, -1, -1);
else if (2 == lStyle)
this.embeddedFontInfos[i] = new CFontInfo(_fonts[i].name, "", FONT_TYPE_EMBEDDED, -1, -1, map_files[_fonts[i].id], _fonts[i].faceindex, -1, -1, -1, -1);
else if (1 == lStyle)
this.embeddedFontInfos[i] = new CFontInfo(_fonts[i].name, "", FONT_TYPE_EMBEDDED, -1, -1, -1, -1, map_files[_fonts[i].id], _fonts[i].faceindex, -1, -1);
else
this.embeddedFontInfos[i] = new CFontInfo(_fonts[i].name, "", FONT_TYPE_EMBEDDED, -1, -1, -1, -1, -1, -1, map_files[_fonts[i].id], _fonts[i].faceindex);
}
var _count_infos_ = this.fontInfos.length;
for (var i = 0; i < _count; i++)
{
this.map_font_index[_fonts[i].name] = i + _count_infos_;
this.fontInfos[i + _count_infos_] = this.embeddedFontInfos[i];
}
};
this.SetStandartFonts = function()
{
//В стандартных шрифтах закоментированы те шрифты, которые были добавлены на docs.teamlab.com
var standarts = window["standarts"];
if (undefined == standarts)
{
standarts = [];
for (var i = 0; i < this.fontInfos.length; i++)
{
if (this.fontInfos[i].Name != "ASCW3")
standarts.push(this.fontInfos[i].Name);
}
}
var _count = standarts.length;
var _infos = this.fontInfos;
var _map = this.map_font_index;
for (var i = 0; i < _count; i++)
{
_infos[_map[standarts[i]]].Type = AscFonts.FONT_TYPE_STANDART;
}
};
this.AddLoadFonts = function(name, need_styles)
{
var fontinfo = g_fontApplication.GetFontInfo(name);
this.fonts_loading[this.fonts_loading.length] = fontinfo;
this.fonts_loading[this.fonts_loading.length - 1].NeedStyles = (need_styles == undefined) ? 0x0F : need_styles;
return fontinfo;
};
this.AddLoadFontsNotPick = function(info, need_styles)
{
this.fonts_loading[this.fonts_loading.length] = info;
this.fonts_loading[this.fonts_loading.length - 1].NeedStyles = (need_styles == undefined) ? 0x0F : need_styles;
};
this.LoadDocumentFonts = function(_fonts, is_default)
{
if (this.IsLoadDocumentFonts2)
return this.LoadDocumentFonts2(_fonts);
// в конце метода нужно отдать список шрифтов
var gui_fonts = [];
var gui_count = 0;
for (var i = 0; i < this.fontInfos.length; i++)
{
var info = this.fontInfos[i];
if (AscFonts.FONT_TYPE_STANDART == info.Type)
{
var __font = new AscFonts.CFont(info.Name, "", info.Type, info.Thumbnail);
gui_fonts[gui_count++] = __font;
}
}
// сначала заполняем массив this.fonts_loading объекстами fontinfo
for (var i in _fonts)
{
if (_fonts[i].type != FONT_TYPE_EMBEDDED)
{
var info = this.AddLoadFonts(_fonts[i].name, _fonts[i].NeedStyles);
if (info.Type == AscFonts.FONT_TYPE_ADDITIONAL)
{
if (info.name != "ASCW3")
{
var __font = new AscFonts.CFont(info.Name, "", info.Type, info.Thumbnail);
gui_fonts[gui_count++] = __font;
}
}
}
else
{
var ind = -1;
for (var j = 0; j < this.embeddedFontInfos.length; j++)
{
if (this.embeddedFontInfos[j].Name == _fonts[i].name)
{
this.AddLoadFontsNotPick(this.embeddedFontInfos[j], 0x0F);
break;
}
}
}
}
this.Api.sync_InitEditorFonts(gui_fonts);
// но только если редактор!!!
if (this.Api.IsNeedDefaultFonts())
{
// теперь добавим шрифты, без которых редактор как без рук (спецсимволы + дефолтовые стили документа)
this.AddLoadFonts("Arial", 0x0F);
this.AddLoadFonts("Symbol", 0x0F);
this.AddLoadFonts("Wingdings", 0x0F);
this.AddLoadFonts("Courier New", 0x0F);
this.AddLoadFonts("Times New Roman", 0x0F);
}
this.Api.asyncFontsDocumentStartLoaded();
this.bIsLoadDocumentFirst = true;
this.CheckFontsNeedLoadingLoad();
this._LoadFonts();
};
this.CheckFontsNeedLoadingLoad = function()
{
var _fonts = this.fonts_loading;
var _fonts_len = _fonts.length;
var _need = false;
for (var i = 0; i < _fonts_len; i++)
{
if (true == _fonts[i].CheckFontLoadStyles(this))
_need = true;
}
return _need;
};
this.CheckFontsNeedLoading = function(_fonts)
{
for (var i in _fonts)
{
var info = g_fontApplication.GetFontInfo(_fonts[i].name);
var _isNeed = info.CheckFontLoadStylesNoLoad(this);
if (_isNeed === true)
return true;
}
return false;
};
this.LoadDocumentFonts2 = function(_fonts)
{
// сначала заполняем массив this.fonts_loading объекстами fontinfo
for (var i in _fonts)
{
this.AddLoadFonts(_fonts[i].name, 0x0F);
}
if (null == this.ThemeLoader)
this.Api.asyncFontsDocumentStartLoaded();
else
this.ThemeLoader.asyncFontsStartLoaded();
this.CheckFontsNeedLoadingLoad();
this._LoadFonts();
};
var oThis = this;
this._LoadFonts = function()
{
if (0 == this.fonts_loading.length)
{
if (null == this.ThemeLoader)
this.Api.asyncFontsDocumentEndLoaded();
else
this.ThemeLoader.asyncFontsEndLoaded();
if (this.bIsLoadDocumentFirst === true)
{
var _count = this.fonts_loading_after_style.length;
for (var i = 0; i < _count; i++)
{
var _info = this.fonts_loading_after_style[i];
_info.NeedStyles = 0x0F;
_info.CheckFontLoadStyles(this);
}
this.fonts_loading_after_style.splice(0, this.fonts_loading_after_style.length);
this.bIsLoadDocumentFirst = false;
}
return;
}
var fontinfo = this.fonts_loading[0];
var IsNeed = fontinfo.CheckFontLoadStyles(this);
if (IsNeed)
{
setTimeout(oThis._check_loaded, 50);
//setTimeout(__global_check_load_fonts, 50);
}
else
{
if (this.bIsLoadDocumentFirst === true)
{
this.Api.OpenDocumentProgress.CurrentFont++;
this.Api.SendOpenProgress();
}
this.fonts_loading_after_style[this.fonts_loading_after_style.length] = this.fonts_loading[0];
this.fonts_loading.shift();
this._LoadFonts();
}
};
this._check_loaded = function()
{
var IsNeed = false;
if (0 == oThis.fonts_loading.length)
{
// значит асинхронно удалилось
oThis._LoadFonts();
return;
}
var current = oThis.fonts_loading[0];
var IsNeed = current.CheckFontLoadStyles(oThis);
if (true === IsNeed)
{
setTimeout(oThis._check_loaded, 50);
}
else
{
if (oThis.bIsLoadDocumentFirst === true)
{
oThis.Api.OpenDocumentProgress.CurrentFont++;
oThis.Api.SendOpenProgress();
}
oThis.fonts_loading_after_style[oThis.fonts_loading_after_style.length] = oThis.fonts_loading[0];
oThis.fonts_loading.shift();
oThis._LoadFonts();
}
};
this.LoadFont = function(fontinfo, loadFontCallBack, loadFontCallBackArgs)
{
this.currentInfoLoaded = fontinfo;
this.currentInfoLoaded = fontinfo;
this.currentInfoLoaded.NeedStyles = 15; // все стили
var IsNeed = this.currentInfoLoaded.CheckFontLoadStyles(this);
if ( undefined === loadFontCallBack )
{
this.loadFontCallBack = this.Api.asyncFontEndLoaded;
this.loadFontCallBackArgs = this.currentInfoLoaded;
}
else
{
this.loadFontCallBack = loadFontCallBack;
this.loadFontCallBackArgs = loadFontCallBackArgs;
}
if (IsNeed)
{
this.Api.asyncFontStartLoaded();
setTimeout(this.check_loaded, 20);
return true;
}
else
{
this.currentInfoLoaded = null;
return false;
}
};
this.check_loaded = function()
{
var current = oThis.currentInfoLoaded;
if (null == current)
return;
var IsNeed = current.CheckFontLoadStyles(oThis);
if (IsNeed)
{
setTimeout(oThis.check_loaded, 50);
}
else
{
oThis.loadFontCallBack.call( oThis.Api, oThis.loadFontCallBackArgs );
oThis.currentInfoLoaded = null;
}
};
this.LoadFontsFromServer = function(_fonts)
{
var _count = _fonts.length;
for (var i = 0; i < _count; i++)
{
var _info = g_fontApplication.GetFontInfo(_fonts[i]);
if (undefined !== _info)
{
_info.LoadFontsFromServer(this);
}
}
}
}
CGlobalFontLoader.prototype.SetStreamIndexEmb = function(font_index, stream_index)
{
this.embeddedFontFiles[font_index].SetStreamIndex(stream_index);
};
function CGlobalImageLoader()
{
this.map_image_index = {};
// loading
this.Api = null;
this.ThemeLoader = null;
this.images_loading = null;
this.bIsLoadDocumentFirst = false;
this.bIsAsyncLoadDocumentImages = false;
this.bIsLoadDocumentImagesNoByOrder = true;
this.nNoByOrderCounter = 0;
var oThis = this;
this.put_Api = function(_api)
{
this.Api = _api;
if (this.Api.IsAsyncOpenDocumentImages !== undefined)
{
this.bIsAsyncLoadDocumentImages = this.Api.IsAsyncOpenDocumentImages();
if (this.bIsAsyncLoadDocumentImages)
{
if (undefined === this.Api.asyncImageEndLoadedBackground)
this.bIsAsyncLoadDocumentImages = false;
}
}
};
this.LoadDocumentImages = function(_images, isUrl)
{
var oThis = this,
images = [],
id;
if (this.ThemeLoader === null)
this.Api.asyncImagesDocumentStartLoaded();
else
this.ThemeLoader.asyncImagesStartLoaded();
if (!this.bIsAsyncLoadDocumentImages) {
this.nNoByOrderCounter = 0;
for (id in _images) {
images.push(AscCommon.getFullImageSrc2(_images[id]));
}
return RSVP.all(images.map(function (image_id) {
return oThis._LoadImage(image_id)
.push(function () {
if (oThis.bIsLoadDocumentFirst === true) {
oThis.Api.OpenDocumentProgress.CurrentImage++;
oThis.Api.SendOpenProgress();
}
});
}))
.then(function () {
if (oThis.ThemeLoader === null)
oThis.Api.asyncImagesDocumentEndLoaded();
else
oThis.ThemeLoader.asyncImagesEndLoaded();
})
.then(undefined, function (error) {
console.log(error);
throw error;
});
} else {
for (id in _images) {
this._LoadImage(AscCommon.getFullImageSrc2(_images[id]))
.push(oThis.Api.asyncImageEndLoadedBackground);
}
if (this.ThemeLoader === null)
this.Api.asyncImagesDocumentEndLoaded();
else
this.ThemeLoader.asyncImagesEndLoaded();
}
};
this._LoadImage = function (image_id, Type)
{
var start = image_id.slice(0, 4),
queue,
oThis = this;
if (0 === start.indexOf('jio:')) {
queue = Common.Gateway.jio_getAttachment(this.Api.documentId, image_id.slice(4), 'asBlobURL')
.push(undefined, function (error) {
console.log(error);
return "";
});
} else {
queue = new RSVP.Queue().push(function () {
return image_id;
});
}
queue.push(function (url) {
if (url === "") {
url = image_id;
}
return new RSVP.Promise(function (resolve, reject) {
var oImage = new CImage(image_id);
oImage.Type = Type;
oImage.Status = ImageLoadStatus.Loading;
oImage.Image = new Image();
oThis.map_image_index[image_id] = oImage;
oImage.Image.onload = function () {
oImage.Status = ImageLoadStatus.Complete;
oThis.nNoByOrderCounter++;
resolve(oImage);
};
oImage.Image.onerror = function () {
oImage.Status = ImageLoadStatus.Complete;
oImage.Image = null;
oThis.nNoByOrderCounter++;
resolve(oImage);
};
//oImage.Image.crossOrigin = 'anonymous';
oImage.Image.src = url;
});
});
return queue;
};
this.LoadImage = function(src, Type)
{
var _image = this.map_image_index[src],
oThis = this;
if (undefined !== _image)
return _image;
this.Api.asyncImageStartLoaded();
this._LoadImage(src, Type)
.push(function (oImage) {
oThis.Api.asyncImageEndLoaded(oImage);
});
return null;
};
this.LoadImagesWithCallback = function(arr, loadImageCallBack, loadImageCallBackArgs)
{
var arrAsync = [];
var i;
for (i = 0; i < arr.length; i++)
{
if (this.map_image_index[arr[i]] === undefined)
arrAsync.push(arr[i]);
}
if (arrAsync.length === 0)
{
loadImageCallBack.call(this.Api, loadImageCallBackArgs);
return;
}
return RSVP.all(arrAsync.map(this._LoadImage))
.then(function ()
{
loadImageCallBack.call(oThis.Api, loadImageCallBackArgs);
});
};
}
var g_flow_anchor = new Image();
g_flow_anchor.asc_complete = false;
g_flow_anchor.onload = function(){
g_flow_anchor.asc_complete = true;
};
g_flow_anchor.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPBAMAAADNDVhEAAAAIVBMVEUAAAANDQ0NDQ0NDQ0NDQ0NDQ0AAAANDQ0NDQ0NDQ0NDQ1jk7YPAAAACnRSTlMAGkD4mb9c5s9TDghpXQAAAFZJREFUCNdjYGBgW8YABlxcIBLBZ1gAEfZa5QWiGRkWMAIpAaA4iHQE0YwODEtANMsChkIwv4BBWQBICyswMC1iWADEDAzKoUuDFUAGNC9uABvIaQkkABpxD6lFb9lRAAAAAElFTkSuQmCC";
var g_flow_anchor2 = new Image();
g_flow_anchor2.asc_complete = false;
g_flow_anchor2.onload = function(){
g_flow_anchor2.asc_complete = true;
};
g_flow_anchor2.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAeCAMAAAAFBf7qAAAAOVBMVEUAAAAAAAAAAAAAAAAJCQkAAAAJCQkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJCQknI0ZQAAAAEnRSTlMAx9ITlAfyPHxn68yecTAl5qt6y0BvAAAAt0lEQVQoz8WS0QrDIAxFk0ajtlXb+/8fuzAprltg7Gnn4aIcvAgJTSSoBiGPoIAGV60qoquvIIL110IJgPONmKIlMI73MiwGRoZvahbKVSizcDKU8QeVPDXEIr6ShVB9VUEn2FOMkwL8VwjUtuypvDWiHeVTFeyWkZHfVQZHGm4XMhKQyJB9GKMxuHQSBlioF7u2q7kzgO2AcWwW3F8mWRmGKgyu91mK1Tzh4ixVVkBzJI/EnGjyACbfCaO3eIWRAAAAAElFTkSuQmCC";
//---------------------------------------------------------export---------------------------------------------------
window['AscCommon'] = window['AscCommon'] || {};
window['AscCommon'].g_font_loader = new CGlobalFontLoader();
window['AscCommon'].g_image_loader = new CGlobalImageLoader();
window['AscCommon'].g_flow_anchor = g_flow_anchor;
window['AscCommon'].g_flow_anchor2 = g_flow_anchor2;
})(window, window.document);
......@@ -96,63 +96,69 @@
/////////////////////////////////////////////////////////
////////////// IMAGES ////////////////////////
/////////////////////////////////////////////////////////
//var prot = AscCommon.DocumentUrls.prototype;
//prot.mediaPrefix = 'media/';
//prot.init = function(urls) {
//};
//prot.getUrls = function() {
// return this.urls;
//};
//prot.addUrls = function(urls){
//};
//prot.addImageUrl = function(strPath, url){
//};
//prot.getImageUrl = function(strPath){
// if (0 === strPath.indexOf('theme'))
// return null;
//
// if (window.editor && window.editor.ThemeLoader && window.editor.ThemeLoader.ThemesUrl != "" && strPath.indexOf(window.editor.ThemeLoader.ThemesUrl) == 0)
// return null;
//
// return this.documentUrl + "/media/" + strPath;
//};
//prot.getImageLocal = function(url){
// var _first = this.documentUrl + "/media/";
// if (0 == url.indexOf(_first))
// return url.substring(_first.length);
//
// if (window.editor && window.editor.ThemeLoader && 0 == url.indexOf(editor.ThemeLoader.ThemesUrlAbs)) {
// return url.substring(editor.ThemeLoader.ThemesUrlAbs.length);
// }
//
// return null;
//};
//prot.imagePath2Local = function(imageLocal){
// return this.getImageLocal(imageLocal);
//};
//prot.getUrl = function(strPath){
// if (0 === strPath.indexOf('theme'))
// return null;
//
// if (window.editor && window.editor.ThemeLoader && window.editor.ThemeLoader.ThemesUrl != "" && strPath.indexOf(window.editor.ThemeLoader.ThemesUrl) == 0)
// return null;
//
// return this.documentUrl + "/media/" + strPath;
//};
//prot.getLocal = function(url){
// return this.getImageLocal(url);
//};
//
//AscCommon.sendImgUrls = function(api, images, callback)
//{
// var _data = [];
// for (var i = 0; i < images.length; i++)
// {
// var _url = window["AscDesktopEditor"]["LocalFileGetImageUrl"](images[i]);
// _data[i] = { url: images[i], path : AscCommon.g_oDocumentUrls.getImageUrl(_url) };
// }
// callback(_data);
//};
var prot = AscCommon.DocumentUrls.prototype;
prot.mediaPrefix = 'media/';
prot.init = function(urls) {
};
prot.getUrls = function() {
return this.urls;
};
prot.addUrls = function(urls){
};
prot.addImageUrl = function(strPath, url){
};
prot.getImageUrl = function(url){
var _first = "jio:";
if (0 === url.indexOf(_first))
return url;
if (0 === url.indexOf('theme'))
return null;
if (window.editor && window.editor.ThemeLoader && window.editor.ThemeLoader.ThemesUrl !== "" && url.indexOf(window.editor.ThemeLoader.ThemesUrl) === 0)
return null;
return _first + url;
//return this.documentUrl + "/media/" + strPath;
};
prot.getImageLocal = function(url){
//var _first = this.documentUrl + "/media/";
var _first = "jio:";
if (0 === url.indexOf(_first))
return url.substring(_first.length);
if (window.editor && window.editor.ThemeLoader && 0 == url.indexOf(editor.ThemeLoader.ThemesUrlAbs)) {
return url.substring(editor.ThemeLoader.ThemesUrlAbs.length);
}
return null;
};
prot.imagePath2Local = function(imageLocal){
return this.getImageLocal(imageLocal);
};
prot.getUrl = function(strPath){
if (0 === strPath.indexOf('theme'))
return null;
if (window.editor && window.editor.ThemeLoader && window.editor.ThemeLoader.ThemesUrl != "" && strPath.indexOf(window.editor.ThemeLoader.ThemesUrl) == 0)
return null;
return this.documentUrl + "/media/" + strPath;
};
prot.getLocal = function(url){
return this.getImageLocal(url);
};
AscCommon.sendImgUrls = function(api, images, callback)
{
var _data = [];
for (var i = 0; i < images.length; i++)
{
var _url = window["AscDesktopEditor"]["LocalFileGetImageUrl"](images[i]);
_data[i] = { url: images[i], path : AscCommon.g_oDocumentUrls.getImageUrl(_url) };
}
callback(_data);
};
/////////////////////////////////////////////////////////
//////////////// SAVE //////////////////////
......
"use strict";
AscCommon.readBlobAsDataURL = function (blob) {
var fr = new FileReader();
return new RSVP.Promise(function (resolve, reject, notify) {
fr.addEventListener("load", function () {
resolve(fr.result);
});
fr.addEventListener("error", reject);
fr.addEventListener("progress", notify);
fr.readAsDataURL(blob);
}, function () {
fr.abort();
});
};
AscCommon.downloadUrlAsBlob = function (url) {
var xhr = new XMLHttpRequest();
return new RSVP.Promise(function (resolve, reject) {
xhr.open("GET", url);
xhr.responseType = "blob";//force the HTTP response, response-type header to be blob
xhr.onload = function () {
if (this.status === 200) {
resolve(xhr.response);
} else {
reject(this.status)
}
};
xhr.onerror = reject;
xhr.send();
}, function () {
xhr.abort();
});
};
AscCommon.baseEditorsApi.prototype.jio_open = function () {
var t = this;
Common.Gateway.jio_get(t.documentId)
......
......@@ -899,7 +899,6 @@
}
else
{
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
AscCommon.UploadImageFiles(files, this.documentId, this.documentUserId, this.CoAuthoringApi.get_jwt(), function(error, url)
{
if (c_oAscError.ID.No !== error)
......@@ -910,7 +909,6 @@
{
t._addImageUrl(url);
}
t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
});
}
};
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -179,19 +179,6 @@ Asc['asc_docs_api'].prototype.asc_DownloadAs = function(typeFile, bIsDownloadEve
this.asc_Save(false, true);
};
Asc['asc_docs_api'].prototype.AddImageUrl = function(url, imgProp)
{
var _url = window["AscDesktopEditor"]["LocalFileGetImageUrl"](url);
this.AddImageUrlAction(AscCommon.g_oDocumentUrls.getImageUrl(_url), imgProp);
};
Asc['asc_docs_api'].prototype.AddImage = function()
{
window["AscDesktopEditor"]["LocalFileGetImageUrlFromOpenFileDialog"]();
};
Asc['asc_docs_api'].prototype.asc_addImage = function()
{
window["AscDesktopEditor"]["LocalFileGetImageUrlFromOpenFileDialog"]();
};
Asc['asc_docs_api'].prototype.asc_isOffline = function()
{
return true;
......
......@@ -2746,58 +2746,11 @@ background-repeat: no-repeat;\
return;
}
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
this.fCurCallback = function(input)
{
if (null != input && "imgurl" == input["type"])
{
if ("ok" == input["status"])
{
var data = input["data"];
var urls = {};
var firstUrl;
for (var i = 0; i < data.length; ++i)
{
var elem = data[i];
if (elem.url)
{
if (!firstUrl)
{
firstUrl = elem.url;
}
urls[elem.path] = elem.url;
}
}
g_oDocumentUrls.addUrls(urls);
if (firstUrl)
{
image_url = firstUrl;
fApplyCallback();
}
else
{
oApi.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
}
else
{
oApi.sendEvent("asc_onError", mapAscServerErrorToAscError(parseInt(input["data"])), c_oAscError.Level.NoCritical);
}
}
else
{
oApi.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
oApi.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
};
var rData = {
"id" : this.documentId,
"userid" : this.documentUserId,
"c" : "imgurl",
"saveindex" : g_oDocumentUrls.getMaxIndex(),
"data" : sImageUrl
};
sendCommand(this, null, rData);
this.AddImageUrl(sImageUrl, function (url) {
//g_oDocumentUrls.addUrls(urls);
image_url = 'jio:' + url;
fApplyCallback();
});
}
}
else
......@@ -3745,7 +3698,7 @@ background-repeat: no-repeat;\
// ToDo пока временная функция для стыковки.
this.AddImageUrl(url);
};
asc_docs_api.prototype.AddImageUrl = function(url)
asc_docs_api.prototype.AddImageUrl = function(url, callback)
{
if (g_oDocumentUrls.getLocal(url))
{
......@@ -3753,59 +3706,32 @@ background-repeat: no-repeat;\
}
else
{
var rData = {
"id" : this.documentId,
"userid" : this.documentUserId,
"c" : "imgurl",
"saveindex" : g_oDocumentUrls.getMaxIndex(),
"data" : url
};
var t = this;
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
this.fCurCallback = function(input)
{
if (null != input && "imgurl" == input["type"])
{
if ("ok" == input["status"])
{
var data = input["data"];
var urls = {};
var firstUrl;
for (var i = 0; i < data.length; ++i)
{
var elem = data[i];
if (elem.url)
{
if (!firstUrl)
{
firstUrl = elem.url;
}
urls[elem.path] = elem.url;
}
}
g_oDocumentUrls.addUrls(urls);
if (firstUrl)
{
t.AddImageUrlAction(firstUrl);
}
else
{
t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
}
else
{
t.sendEvent("asc_onError", mapAscServerErrorToAscError(parseInt(input["data"])), c_oAscError.Level.NoCritical);
}
}
else
{
t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
};
sendCommand(this, null, rData);
var t = this,
start = url.slice(0, 6),
queue = new RSVP.Queue();
if (!callback) {
callback = function (url) {
//g_oDocumentUrls.addUrls(urls);
t.AddImageUrlAction('jio:' + url);
};
}
queue.push(function () {
return url;
});
//this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
if (0 !== start.indexOf('data:')) {
queue.push(AscCommon.downloadUrlAsBlob)
}
return queue.push(function (blob) {
return Common.Gateway.jio_putAttachment(t.documentId, undefined, blob);
})
.push(callback)
//.push(function () {t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);})
.push(undefined, function (error) {
console.log(error);
t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
//t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
});
}
};
......@@ -3966,70 +3892,11 @@ background-repeat: no-repeat;\
}
else
{
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
if (window["AscDesktopEditor"])
{
var _url = window["AscDesktopEditor"]["LocalFileGetImageUrl"](sImageUrl);
_url = g_oDocumentUrls.getImageUrl(_url);
ImagePr.ImageUrl = _url;
fApplyCallback();
this.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
return;
}
this.fCurCallback = function(input)
{
if (null != input && "imgurl" == input["type"])
{
if ("ok" == input["status"])
{
var data = input["data"];
var urls = {};
var firstUrl;
for (var i = 0; i < data.length; ++i)
{
var elem = data[i];
if (elem.url)
{
if (!firstUrl)
{
firstUrl = elem.url;
}
urls[elem.path] = elem.url;
}
}
g_oDocumentUrls.addUrls(urls);
if (firstUrl)
{
ImagePr.ImageUrl = firstUrl;
fApplyCallback();
}
else
{
oApi.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
}
else
{
oApi.sendEvent("asc_onError", mapAscServerErrorToAscError(parseInt(input["data"])), c_oAscError.Level.NoCritical);
}
}
else
{
oApi.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
oApi.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
};
var rData = {
"id" : this.documentId,
"userid" : this.documentUserId,
"c" : "imgurl",
"saveindex" : g_oDocumentUrls.getMaxIndex(),
"data" : sImageUrl
};
sendCommand(this, null, rData);
this.AddImageUrl(sImageUrl, function (url) {
//g_oDocumentUrls.addUrls(urls);
ImagePr.ImageUrl = 'jio:' + url;
fApplyCallback();
});
}
}
else
......
......@@ -186,19 +186,6 @@ Asc['asc_docs_api'].prototype.asc_DownloadAs = function(typeFile, bIsDownloadEve
this.asc_Save(false, true);
};
Asc['asc_docs_api'].prototype.AddImageUrl = function(url, imgProp)
{
var _url = window["AscDesktopEditor"]["LocalFileGetImageUrl"](url);
this.AddImageUrlAction(AscCommon.g_oDocumentUrls.getImageUrl(_url), imgProp);
};
Asc['asc_docs_api'].prototype.AddImage = function()
{
window["AscDesktopEditor"]["LocalFileGetImageUrlFromOpenFileDialog"]();
};
Asc['asc_docs_api'].prototype.asc_addImage = function()
{
window["AscDesktopEditor"]["LocalFileGetImageUrlFromOpenFileDialog"]();
};
Asc['asc_docs_api'].prototype.asc_isOffline = function()
{
return true;
......
......@@ -4503,7 +4503,7 @@ background-repeat: no-repeat;\
// ToDo пока временная функция для стыковки.
this.AddImageUrl(url);
};
asc_docs_api.prototype.AddImageUrl = function(url, imgProp)
asc_docs_api.prototype.AddImageUrl = function(url, imgProp, callback)
{
if (g_oDocumentUrls.getLocal(url))
{
......@@ -4511,59 +4511,29 @@ background-repeat: no-repeat;\
}
else
{
var rData = {
"id" : this.documentId,
"userid" : this.documentUserId,
"c" : "imgurl",
"saveindex" : g_oDocumentUrls.getMaxIndex(),
"data" : url
};
var t = this;
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
this.fCurCallback = function(input)
{
if (null != input && "imgurl" == input["type"])
{
if ("ok" == input["status"])
{
var data = input["data"];
var urls = {};
var firstUrl;
for (var i = 0; i < data.length; ++i)
{
var elem = data[i];
if (elem.url)
{
if (!firstUrl)
{
firstUrl = elem.url;
}
urls[elem.path] = elem.url;
}
}
g_oDocumentUrls.addUrls(urls);
if (firstUrl)
{
t.AddImageUrlAction(firstUrl, imgProp);
}
else
{
t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
}
else
{
t.sendEvent("asc_onError", mapAscServerErrorToAscError(parseInt(input["data"])), c_oAscError.Level.NoCritical);
}
}
else
{
t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
};
sendCommand(this, null, rData);
if (!callback) {
callback = function (url) {
//g_oDocumentUrls.addUrls(urls);
t.AddImageUrlAction('jio:' + url, imgProp);
};
}
//this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
return new RSVP.Queue()
.push(function () {
return url;
})
.push(AscCommon.downloadUrlAsBlob)
.push(function (blob) {
return Common.Gateway.jio_putAttachment(t.documentId, undefined, blob);
})
.push(callback)
//.push(function () {t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);})
.push(undefined, function (error) {
console.log(error);
t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
//t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
});
}
};
asc_docs_api.prototype.AddImageUrlAction = function(url, imgProp)
......@@ -4873,59 +4843,11 @@ background-repeat: no-repeat;\
return;
}
var rData = {
"id" : this.documentId,
"userid" : this.documentUserId,
"c" : "imgurl",
"saveindex" : g_oDocumentUrls.getMaxIndex(),
"data" : sImageToDownLoad
};
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
this.fCurCallback = function(input)
{
if (null != input && "imgurl" == input["type"])
{
if ("ok" == input["status"])
{
var data = input["data"];
var urls = {};
var firstUrl;
for (var i = 0; i < data.length; ++i)
{
var elem = data[i];
if (elem.url)
{
if (!firstUrl)
{
firstUrl = elem.url;
}
urls[elem.path] = elem.url;
}
}
g_oDocumentUrls.addUrls(urls);
if (firstUrl)
{
fReplaceCallback(firstUrl);
fApplyCallback();
}
else
{
oApi.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
}
else
{
oApi.sendEvent("asc_onError", mapAscServerErrorToAscError(parseInt(input["data"])), c_oAscError.Level.NoCritical);
}
}
else
{
oApi.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
}
oApi.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
};
sendCommand(this, null, rData);
this.AddImageUrl(sImageToDownLoad, undefined, function (url) {
//g_oDocumentUrls.addUrls(urls);
fReplaceCallback('jio:' + url);
fApplyCallback();
});
}
else
{
......
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