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 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(); var ws = t.wb.getWorksheet();
ws.objectRender.addImageDrawingObject(firstUrl, null); ws.objectRender.addImageDrawingObject('jio:' + url, null);
} else { };
}
//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.handlers.trigger("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
} //t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
} 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);
}; };
...@@ -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,
"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); 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
* *
...@@ -438,11 +439,6 @@ ...@@ -438,11 +439,6 @@
this.bIsLoadDocumentImagesNoByOrder = true; this.bIsLoadDocumentImagesNoByOrder = true;
this.nNoByOrderCounter = 0; this.nNoByOrderCounter = 0;
this.loadImageCallBackCounter = 0;
this.loadImageCallBackCounterMax = 0;
this.loadImageCallBack = null;
this.loadImageCallBackArgs = null;
var oThis = this; var oThis = this;
this.put_Api = function(_api) this.put_Api = function(_api)
...@@ -462,223 +458,132 @@ ...@@ -462,223 +458,132 @@
this.LoadDocumentImages = function(_images, isUrl) this.LoadDocumentImages = function(_images, isUrl)
{ {
// сначала заполним массив var oThis = this,
if (this.ThemeLoader == null) images = [],
id;
if (this.ThemeLoader === null)
this.Api.asyncImagesDocumentStartLoaded(); this.Api.asyncImagesDocumentStartLoaded();
else else
this.ThemeLoader.asyncImagesStartLoaded(); this.ThemeLoader.asyncImagesStartLoaded();
if (!this.bIsAsyncLoadDocumentImages) {
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.nNoByOrderCounter = 0;
this._LoadImages(); for (id in _images) {
images.push(AscCommon.getFullImageSrc2(_images[id]));
} }
else return RSVP.all(images.map(function (image_id) {
{ return oThis._LoadImage(image_id)
var _len = this.images_loading.length; .push(function () {
for (var i = 0; i < _len; i++) if (oThis.bIsLoadDocumentFirst === true) {
{ oThis.Api.OpenDocumentProgress.CurrentImage++;
this.LoadImageAsync(i); oThis.Api.SendOpenProgress();
} }
this.images_loading.splice(0, _len); });
}))
if (this.ThemeLoader == null) .then(function () {
this.Api.asyncImagesDocumentEndLoaded(); if (oThis.ThemeLoader === null)
oThis.Api.asyncImagesDocumentEndLoaded();
else else
this.ThemeLoader.asyncImagesEndLoaded(); oThis.ThemeLoader.asyncImagesEndLoaded();
} })
}; .then(undefined, function (error) {
console.log(error);
this._LoadImages = function() throw error;
{ });
var _count_images = this.images_loading.length; } else {
for (id in _images) {
if (0 == _count_images) this._LoadImage(AscCommon.getFullImageSrc2(_images[id]))
{ .push(oThis.Api.asyncImageEndLoadedBackground);
this.nNoByOrderCounter = 0; }
if (this.ThemeLoader == null) if (this.ThemeLoader === null)
this.Api.asyncImagesDocumentEndLoaded(); this.Api.asyncImagesDocumentEndLoaded();
else else
this.ThemeLoader.asyncImagesEndLoaded(); this.ThemeLoader.asyncImagesEndLoaded();
return;
} }
};
for (var i = 0; i < _count_images; i++) this._LoadImage = function (image_id, Type)
{ {
var _id = this.images_loading[i]; var start = image_id.slice(0, 4),
var oImage = new CImage(_id); 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.Status = ImageLoadStatus.Loading;
oImage.Image = new Image(); oImage.Image = new Image();
oThis.map_image_index[oImage.src] = oImage; oThis.map_image_index[image_id] = oImage;
oImage.Image.parentImage = oImage; oImage.Image.onload = function () {
oImage.Image.onload = function () oImage.Status = ImageLoadStatus.Complete;
{
this.parentImage.Status = ImageLoadStatus.Complete;
oThis.nNoByOrderCounter++; oThis.nNoByOrderCounter++;
resolve(oImage);
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 () oImage.Image.onerror = function () {
{ oImage.Status = ImageLoadStatus.Complete;
this.parentImage.Status = ImageLoadStatus.Complete; oImage.Image = null;
this.parentImage.Image = null;
oThis.nNoByOrderCounter++; oThis.nNoByOrderCounter++;
resolve(oImage);
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.crossOrigin = 'anonymous';
oImage.Image.src = oImage.src; oImage.Image.src = url;
});
if (!oThis.bIsLoadDocumentImagesNoByOrder) });
return; return queue;
}
}; };
this.LoadImage = function(src, Type) this.LoadImage = function(src, Type)
{ {
var _image = this.map_image_index[src]; var _image = this.map_image_index[src],
if (undefined != _image) oThis = this;
if (undefined !== _image)
return _image; return _image;
this.Api.asyncImageStartLoaded(); this.Api.asyncImageStartLoaded();
this._LoadImage(src, Type)
var oImage = new CImage(src); .push(function (oImage) {
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); oThis.Api.asyncImageEndLoaded(oImage);
}; });
//oImage.Image.crossOrigin = 'anonymous';
oImage.Image.src = oImage.src;
return null;
};
this.LoadImageAsync = function(i) return null;
{
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) this.LoadImagesWithCallback = function(arr, loadImageCallBack, loadImageCallBackArgs)
{ {
var arrAsync = []; var arrAsync = [];
var i = 0; var i;
for (i = 0; i < arr.length; i++) for (i = 0; i < arr.length; i++)
{ {
if (this.map_image_index[arr[i]] === undefined) if (this.map_image_index[arr[i]] === undefined)
arrAsync.push(arr[i]); arrAsync.push(arr[i]);
} }
if (arrAsync.length == 0) if (arrAsync.length === 0)
{ {
loadImageCallBack.call(this.Api, loadImageCallBackArgs); loadImageCallBack.call(this.Api, loadImageCallBackArgs);
return; return;
} }
this.loadImageCallBackCounter = 0; return RSVP.all(arrAsync.map(this._LoadImage))
this.loadImageCallBackCounterMax = arrAsync.length; .then(function ()
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); loadImageCallBack.call(oThis.Api, loadImageCallBackArgs);
this.loadImageCallBack = null; });
this.loadImageCallBackArgs = null;
this.loadImageCallBackCounterMax = 0;
this.loadImageCallBackCounter = 0;
}; };
} }
......
...@@ -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);
}); });
} }
}; };
......
...@@ -1324,38 +1324,16 @@ ...@@ -1324,38 +1324,16 @@
if (files.length > 0) if (files.length > 0)
{ {
var file = files[0]; var file = files[0];
var url = sUploadServiceLocalUrl + '/' + documentId + '/' + documentUserId + '/' + g_oDocumentUrls.getMaxIndex(); Common.Gateway.jio_putAttachment(documentId, undefined, file)
if (jwt) .push(function (image_url)
{
url += '/' + jwt;
}
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', file.type || 'application/octet-stream');
xhr.onreadystatechange = function ()
{
if (4 == this.readyState)
{
if ((this.status == 200 || this.status == 1223))
{ {
var urls = JSON.parse(this.responseText); callback(Asc.c_oAscError.ID.No, 'jio:' + image_url);
g_oDocumentUrls.addUrls(urls); })
var firstUrl; .push(undefined, function (error)
for (var i in urls)
{
if (urls.hasOwnProperty(i))
{ {
firstUrl = urls[i]; console.log(error);
break;
}
}
callback(Asc.c_oAscError.ID.No, firstUrl);
}
else
callback(Asc.c_oAscError.ID.UplImageFileCount); callback(Asc.c_oAscError.ID.UplImageFileCount);
} });
};
xhr.send(file);
} }
else else
{ {
......
...@@ -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"])
{
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(); 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);
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; queue.push(function () {
} return url;
} });
g_oDocumentUrls.addUrls(urls); //this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
if (firstUrl) if (0 !== start.indexOf('data:')) {
{ queue.push(AscCommon.downloadUrlAsBlob)
t.AddImageUrlAction(firstUrl); }
} return queue.push(function (blob) {
else return Common.Gateway.jio_putAttachment(t.documentId, undefined, blob);
{ })
t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical); .push(callback)
} //.push(function () {t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);})
} .push(undefined, function (error) {
else console.log(error);
{
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.sendEvent("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);
} }
}; };
...@@ -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;
{
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(); 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;
}
}
g_oDocumentUrls.addUrls(urls);
if (firstUrl)
{
t.AddImageUrlAction(firstUrl, imgProp);
}
else
{
t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical); t.sendEvent("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
} //t.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
} });
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",
"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(); 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