Commit b67e646a 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)
disable load images as background
parent b603ac29
/*
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* This program is a free software product. You can redistribute it and/or
......@@ -2339,49 +2339,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);
});
};
......@@ -2645,46 +2627,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);
......
/* jshint -W069 */
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
......@@ -438,11 +439,6 @@
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)
......@@ -462,224 +458,131 @@
this.LoadDocumentImages = function(_images, isUrl)
{
// сначала заполним массив
if (this.ThemeLoader == null)
var oThis = this,
images = [],
id;
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);
// Always load images as foreground
if (true || !this.bIsAsyncLoadDocumentImages) {
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);
}
this.images_loading.splice(0, _len);
if (this.ThemeLoader == null)
if (this.ThemeLoader === null)
this.Api.asyncImagesDocumentEndLoaded();
else
this.ThemeLoader.asyncImagesEndLoaded();
}
};
this._LoadImages = function()
this._LoadImage = function (image_id, Type)
{
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;
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.error(error);
return "";
});
} else {
queue = new RSVP.Queue().push(function () {
return image_id;
});
}
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;
}
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;
resolve(oImage);
};
oImage.Image.onerror = function () {
oImage.Status = ImageLoadStatus.Complete;
oImage.Image = null;
resolve(oImage);
};
//oImage.Image.crossOrigin = 'anonymous';
oImage.Image.src = url;
});
});
return queue;
};
this.LoadImage = function(src, Type)
{
var _image = this.map_image_index[src];
if (undefined != _image)
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);
});
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;
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)
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++;
loadImageCallBack.call(this.Api, loadImageCallBackArgs);
return;
}
if (oThis.loadImageCallBackCounter == oThis.loadImageCallBackCounterMax)
oThis.LoadImagesWithCallbackEnd();
};
oImage.Image.onerror = function ()
return RSVP.all(arrAsync.map(this._LoadImage, this))
.then(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;
};
loadImageCallBack.call(oThis.Api, loadImageCallBackArgs);
});
};
}
var g_flow_anchor = new Image();
......
......@@ -106,18 +106,24 @@ prot.addUrls = function(urls){
};
prot.addImageUrl = function(strPath, url){
};
prot.getImageUrl = function(strPath){
if (0 === strPath.indexOf('theme'))
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 != "" && strPath.indexOf(window.editor.ThemeLoader.ThemesUrl) == 0)
if (window.editor && window.editor.ThemeLoader && window.editor.ThemeLoader.ThemesUrl !== "" && url.indexOf(window.editor.ThemeLoader.ThemesUrl) === 0)
return null;
return this.documentUrl + "/media/" + strPath;
return _first + url;
//return this.documentUrl + "/media/" + strPath;
};
prot.getImageLocal = function(url){
var _first = this.documentUrl + "/media/";
if (0 == url.indexOf(_first))
//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)) {
......
......@@ -891,7 +891,6 @@
}
else
{
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
AscCommon.UploadImageFiles(files, this.documentId, this.documentUserId, this.CoAuthoringApi.get_jwt(), function(error, urls)
{
if (c_oAscError.ID.No !== error)
......@@ -902,7 +901,6 @@
{
t._addImageUrl(urls);
}
t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
});
}
};
......
......@@ -1322,61 +1322,17 @@
{
if (files.length > 0)
{
var url = sUploadServiceLocalUrl + '/' + documentId + '/' + documentUserId + '/' + g_oDocumentUrls.getMaxIndex();
if (jwt)
{
url += '/' + jwt;
}
var aFiles = [];
for(var i = files.length - 1; i > - 1; --i){
aFiles.push(files[i]);
}
var file = aFiles.pop();
var aResultUrls = [];
var fOnReadyChnageState = function(){
if (4 == this.readyState){
if ((this.status == 200 || this.status == 1223)){
var urls = JSON.parse(this.responseText);
g_oDocumentUrls.addUrls(urls);
for (var i in urls)
{
if (urls.hasOwnProperty(i))
{
aResultUrls.push(urls[i]);
break;
}
}
if(aFiles.length === 0){
callback(Asc.c_oAscError.ID.No, aResultUrls);
}
else{
file = aFiles.pop();
var xhr = new XMLHttpRequest();
url = sUploadServiceLocalUrl + '/' + documentId + '/' + documentUserId + '/' + g_oDocumentUrls.getMaxIndex();
if (jwt)
{
url += '/' + jwt;
}
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', file.type || 'application/octet-stream');
xhr.onreadystatechange = fOnReadyChnageState;
xhr.send(file);
}
}
else
callback(Asc.c_oAscError.ID.UplImageFileCount);
}
};
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', file.type || 'application/octet-stream');
xhr.onreadystatechange = fOnReadyChnageState;
xhr.send(file);
var file = files[0];
Common.Gateway.jio_putAttachment(documentId, undefined, file)
.push(function (image_url)
{
callback(Asc.c_oAscError.ID.No, ['jio:' + image_url]);
})
.push(undefined, function (error)
{
console.log(error);
callback(Asc.c_oAscError.ID.UplImageFileCount);
});
}
else
{
......
......@@ -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
......@@ -3764,7 +3717,7 @@ background-repeat: no-repeat;\
}
}
};
asc_docs_api.prototype.AddImageUrl = function(url)
asc_docs_api.prototype.AddImageUrl = function(url, callback)
{
if (g_oDocumentUrls.getLocal(url))
{
......@@ -3772,59 +3725,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);
});
}
};
......@@ -3997,70 +3923,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
......
/*
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* This program is a free software product. You can redistribute it and/or
......@@ -4540,7 +4540,7 @@ background-repeat: no-repeat;\
}
}
};
asc_docs_api.prototype.AddImageUrl = function(url, imgProp)
asc_docs_api.prototype.AddImageUrl = function(url, imgProp, callback)
{
if (g_oDocumentUrls.getLocal(url))
{
......@@ -4548,59 +4548,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)
......@@ -4919,59 +4889,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