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