Commit 66508d1f authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander.Trofimov

drag&drop картинок в редакторы

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@49377 954022d7-b5bf-4e40-9824-e11837661b57
parent e2351e82
......@@ -4551,15 +4551,7 @@ function DrawingObjects() {
if ( _this.isViewerMode() )
return;
var oImageUploader = document.getElementById("apiImageUpload");
if (!oImageUploader) {
var frame = document.createElement("iframe");
frame.name = "apiImageUpload";
frame.id = "apiImageUpload";
frame.setAttribute("style", "position:absolute;left:-2px;top:-2px;width:1px;height:1px;z-index:-1000;");
document.body.appendChild(frame);
}
var frameWindow = window.frames["apiImageUpload"];
var frameWindow = GetUploadIFrame();
var content = '<html><head></head><body><form action="' + g_sUploadServiceLocalUrl + '?sheetId=' + worksheet.model.getId() + '&key=' + documentId + '" method="POST" enctype="multipart/form-data"><input id="apiiuFile" name="apiiuFile" type="file" size="1"><input id="apiiuSubmit" name="apiiuSubmit" type="submit" style="display:none;"></form></body></html>';
frameWindow.document.open();
frameWindow.document.write(content);
......@@ -4572,43 +4564,15 @@ function DrawingObjects() {
if(e && e.target && e.target.files)
{
var files = e.target.files;
if(files.length > 0)
var nError = ValidateUploadImage(files);
if(c_oAscServerError.NoError == nError)
{
var file = files[0];
//проверяем расширение файла
var sName = file.fileName || file.name;
if(sName)
{
var bSupported = false;
var nIndex = sName.lastIndexOf(".");
if(-1 != nIndex)
{
var ext = sName.substring(nIndex + 1).toLowerCase();
for(var i = 0, length = c_oAscImageUploadProp.SupportedFormats.length; i < length; i++)
{
if(c_oAscImageUploadProp.SupportedFormats[i] == ext)
{
bSupported = true;
break;
}
}
}
if(false == bSupported)
{
worksheet.model.workbook.handlers.trigger("asc_onError", c_oAscError.ID.UplImageExt, c_oAscError.Level.NoCritical);
return;
}
}
var nSize = file.fileSize || file.size;
if(nSize && c_oAscImageUploadProp.MaxFileSize < nSize)
{
worksheet.model.workbook.handlers.trigger("asc_onError", c_oAscError.ID.UplImageSize, c_oAscError.Level.NoCritical);
return;
}
worksheet.model.workbook.handlers.trigger("asc_onStartAction", c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.LoadImage);
fileSubmit.click();
}
else
worksheet.model.workbook.handlers.trigger("asc_onError", api.asc_mapAscServerErrorToAscError(nError), c_oAscError.Level.NoCritical);
}
fileSubmit.click();
worksheet.model.workbook.handlers.trigger("asc_onStartAction", c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.LoadImage);
}
if (window.opera != undefined)
......
var g_sMainServiceLocalUrl = "/CanvasService.ashx";var g_sResourceServiceLocalUrl = "/ResourceService.ashx?path=";var g_sUploadServiceLocalUrl = "/UploadService.ashx";var g_sSpellCheckServiceLocalUrl = "/SpellChecker.ashx"; function fSortAscending(a, b){return a - b;}function fSortDescending(a, b){return b - a;} var c_oEditorId = { Word : 0, Speadsheet : 1, Presentation : 2}; var PostMessageType = { UploadImage : 0, ExtensionExist :1}; var c_oAscServerError = { NoError : 0, Unknown : -1, ReadRequestStream : -3, TaskQueue : -20, TaskResult : -40, Storage : -60, StorageFileNoFound : -61, StorageRead : -62, StorageWrite : -63, StorageRemoveDir : -64, StorageCreateDir : -65, StorageGetInfo : -66, Convert : -80, ConvertDownload : -81, ConvertUnknownFormat : -82, ConvertTimeout : -83, ConvertReadFile : -84, Upload : -100, UploadContentLength : -101, UploadExtension : -102, UploadCountFiles : -103, VKey : -120, VKeyEncrypt : -121, VKeyKeyExpire : -122, VKeyUserCountExceed : -123} var c_oAscImageUploadProp = {// ( ie9), web.common MaxFileSize:25000000, //25 mb SupportedFormats:[ "jpg", "jpeg", "jpe", "png", "gif", "bmp"] };
\ No newline at end of file
var g_sMainServiceLocalUrl = "/CanvasService.ashx";var g_sResourceServiceLocalUrl = "/ResourceService.ashx?path=";var g_sUploadServiceLocalUrl = "/UploadService.ashx";var g_sSpellCheckServiceLocalUrl = "/SpellChecker.ashx"; function fSortAscending(a, b){return a - b;}function fSortDescending(a, b){return b - a;} var c_oEditorId = { Word : 0, Speadsheet : 1, Presentation : 2}; var PostMessageType = { UploadImage : 0, ExtensionExist :1}; var c_oAscServerError = { NoError : 0, Unknown : -1, ReadRequestStream : -3, TaskQueue : -20, TaskResult : -40, Storage : -60, StorageFileNoFound : -61, StorageRead : -62, StorageWrite : -63, StorageRemoveDir : -64, StorageCreateDir : -65, StorageGetInfo : -66, Convert : -80, ConvertDownload : -81, ConvertUnknownFormat : -82, ConvertTimeout : -83, ConvertReadFile : -84, Upload : -100, UploadContentLength : -101, UploadExtension : -102, UploadCountFiles : -103, VKey : -120, VKeyEncrypt : -121, VKeyKeyExpire : -122, VKeyUserCountExceed : -123} var c_oAscImageUploadProp = {//Не все браузеры позволяют получить информацию о файле до загрузки(например ie9), меняя параметры здесь надо поменять аналогичные параметры в web.common MaxFileSize:25000000, //25 mb SupportedFormats:[ "jpg", "jpeg", "jpe", "png", "gif", "bmp"] }; function ValidateUploadImage(files){
var nRes = c_oAscServerError.NoError;
if(1 === files.length )
{
var file = files[0];
//проверяем расширение файла
var sName = file.fileName || file.name;
if(sName)
{
var bSupported = false;
var nIndex = sName.lastIndexOf(".");
if(-1 != nIndex)
{
var ext = sName.substring(nIndex + 1).toLowerCase();
for(var i = 0, length = c_oAscImageUploadProp.SupportedFormats.length; i < length; i++)
{
if(c_oAscImageUploadProp.SupportedFormats[i] == ext)
{
bSupported = true;
break;
}
}
}
if(false == bSupported)
nRes = c_oAscServerError.UploadExtension;
}
if(c_oAscError.ID.No == nRes)
{
var nSize = file.fileSize || file.size;
if(nSize && c_oAscImageUploadProp.MaxFileSize < nSize)
nRes = c_oAscServerError.UploadContentLength;
}
}
else
nRes = c_oAscServerError.UploadCountFiles;
return nRes;
}function CanDropFiles(event) { var bRes = false; if (event.dataTransfer.types && 1 == event.dataTransfer.types.length) { var type = event.dataTransfer.types[0]; if(type == "Files") { if(event.dataTransfer.items) { if (1 == event.dataTransfer.items.length) { var item = event.dataTransfer.items[0]; for(var i = 0, length = c_oAscImageUploadProp.SupportedFormats.length; i < length; i++) { if(item.type && -1 != item.type.indexOf(c_oAscImageUploadProp.SupportedFormats[i])) { bRes = true; break; } } } } else bRes = true; } } return bRes;}function GetUploadIFrame(){ var sIFrameName = "apiImageUpload"; var oImageUploader = document.getElementById(sIFrameName); if(!oImageUploader) { var frame = document.createElement("iframe"); frame.name = sIFrameName; frame.id = sIFrameName; frame.setAttribute("style", "position:absolute;left:-2px;top:-2px;width:1px;height:1px;z-index:-1000;"); document.body.appendChild(frame); } return window.frames[sIFrameName];}
\ No newline at end of file
......
......@@ -150,6 +150,62 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
// Использовать ли обрезанные шрифты
this.isUseEmbeddedCutFonts = ("true" == ASC_DOCS_API_USE_EMBEDDED_FONTS.toLowerCase());
var oThis = this;
if (window.FileReader !== undefined && window.FormData !== undefined) {
//var element = document.body;
var element = document.getElementById(this.HtmlElementName);
if(null != element)
{
element.ondragover = function(e) {
e.preventDefault();
if(CanDropFiles(e))
e.dataTransfer.dropEffect = 'copy';
else
e.dataTransfer.dropEffect = 'none';
return false;
};
element.ondrop = function(e) {
e.preventDefault();
var files = e.dataTransfer.files;
var nError = ValidateUploadImage(files);
if(c_oAscServerError.NoError == nError)
{
var worksheet = null;
if(null != oThis.wbModel)
worksheet = oThis.wbModel.getWorksheet(oThis.wbModel.getActive());
if(null != worksheet)
{
oThis.handlers.trigger("asc_onStartAction", c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.LoadImage);
var file = files[0];
var xhr = new XMLHttpRequest();
var fd = new FormData();
fd.append('file', file);
xhr.open('POST', g_sUploadServiceLocalUrl+'?key=' + oThis.documentId + '&sheetId=' + worksheet.getId());
xhr.onreadystatechange = function(){
if(4 == this.readyState)
{
if((this.status == 200 || this.status == 1223))
{
var frameWindow = GetUploadIFrame();
var content = this.responseText;
frameWindow.document.open();
frameWindow.document.write(content);
frameWindow.document.close();
}
else
oThis.handlers.trigger("asc_onError", c_oAscError.ID.Unknown, c_oAscError.Level.NoCritical);
oThis.handlers.trigger("asc_onEndAction", c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.LoadImage);
}
};
xhr.send(fd);
}
}
else
oThis.handlers.trigger("asc_onError", oThis.asc_mapAscServerErrorToAscError(nError), c_oAscError.Level.NoCritical);
}
}
}
}
spreadsheet_api.prototype = {
......
......@@ -118,6 +118,54 @@ function asc_docs_api(name)
window.addEventListener("message", function(){
oThis.OnHandleMessage.apply(oThis, arguments);
}, false);
if (window.FileReader !== undefined && window.FormData !== undefined) {
//var element = document.body;
var element = document.getElementById(this.HtmlElementName);
if(null != element)
{
element.ondragover = function(e) {
e.preventDefault();
if(CanDropFiles(e))
e.dataTransfer.dropEffect = 'copy';
else
e.dataTransfer.dropEffect = 'none';
return false;
};
element.ondrop = function(e) {
e.preventDefault();
var files = e.dataTransfer.files;
var nError = ValidateUploadImage(files);
if(c_oAscServerError.NoError == nError)
{
oThis.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
var file = files[0];
var xhr = new XMLHttpRequest();
var fd = new FormData();
fd.append('file', file);
xhr.open('POST', g_sUploadServiceLocalUrl+'?key='+documentId);
xhr.onreadystatechange = function(){
if(4 == this.readyState)
{
if((this.status == 200 || this.status == 1223))
{
var frameWindow = GetUploadIFrame();
var content = this.responseText;
frameWindow.document.open();
frameWindow.document.write(content);
frameWindow.document.close();
}
else
oThis.asc_fireCallback("asc_onError",c_oAscError.ID.Unknown,c_oAscError.Level.NoCritical);
oThis.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
}
};
xhr.send(fd);
}
else
oThis.asc_fireCallback("asc_onError",_mapAscServerErrorToAscError(nError),c_oAscError.Level.NoCritical);
};
}
}
}
/////////////////////////////////////////////////////////////////////////
......@@ -2497,7 +2545,7 @@ asc_docs_api.prototype.AddImage = function(){
frame.setAttribute("style", "position:absolute;left:-2px;top:-2px;width:1px;height:1px;z-index:-1000;");
document.body.appendChild(frame);
}
var frameWindow = window.frames["apiImageUpload"];
var frameWindow = GetUploadIFrame();
var content = '<html><head></head><body><form action="'+g_sUploadServiceLocalUrl+'?key='+documentId+'" method="POST" enctype="multipart/form-data"><input id="apiiuFile" name="apiiuFile" type="file" size="1"><input id="apiiuSubmit" name="apiiuSubmit" type="submit" style="display:none;"></form></body></html>';
frameWindow.document.open();
frameWindow.document.write(content);
......@@ -2514,40 +2562,16 @@ asc_docs_api.prototype.AddImage = function(){
if(files.length > 0)
{
var file = files[0];
//проверяем расширение файла
var sName = file.fileName || file.name;
if(sName)
{
var bSupported = false;
var nIndex = sName.lastIndexOf(".");
if(-1 != nIndex)
{
var ext = sName.substring(nIndex + 1).toLowerCase();
for(var i = 0, length = c_oAscImageUploadProp.SupportedFormats.length; i < length; i++)
{
if(c_oAscImageUploadProp.SupportedFormats[i] == ext)
{
bSupported = true;
break;
}
}
}
if(false == bSupported)
{
oThis.asc_fireCallback("asc_onError",c_oAscError.ID.UplImageExt,c_oAscError.Level.NoCritical);
return;
}
}
var nSize = file.fileSize || file.size;
if(nSize && c_oAscImageUploadProp.MaxFileSize < nSize)
{
oThis.asc_fireCallback("asc_onError",c_oAscError.ID.UplImageSize,c_oAscError.Level.NoCritical);
return;
}
var nError = ValidateUploadImage(files);
if(c_oAscServerError.NoError == nError)
{
oThis.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
fileSubmit.click();
}
else
oThis.asc_fireCallback("asc_onError",_mapAscServerErrorToAscError(nError),c_oAscError.Level.NoCritical);
}
}
oThis.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
fileSubmit.click();
};
//todo пересмотреть opera
if (window.opera != undefined)
......@@ -3810,7 +3834,7 @@ asc_docs_api.prototype.OnHandleMessage = function(event)
if(c_oAscServerError.NoError == data.error)
this.AddImageUrl(data.url);
else
t.sync_ErrorCallback(_mapAscServerErrorToAscError(data.error), c_oAscError.Level.NoCritical);
this.sync_ErrorCallback(_mapAscServerErrorToAscError(data.error), c_oAscError.Level.NoCritical);
}
}
}
......
......@@ -610,6 +610,54 @@ function asc_docs_api(name)
window.addEventListener("message", function(){
oThis.OnHandleMessage.apply(oThis, arguments);
}, false);
if (window.FileReader !== undefined && window.FormData !== undefined) {
//var element = document.body;
var element = document.getElementById(this.HtmlElementName);
if(null != element)
{
element.ondragover = function(e) {
e.preventDefault();
if(CanDropFiles(e))
e.dataTransfer.dropEffect = 'copy';
else
e.dataTransfer.dropEffect = 'none';
return false;
};
element.ondrop = function(e) {
e.preventDefault();
var files = e.dataTransfer.files;
var nError = ValidateUploadImage(files);
if(c_oAscServerError.NoError == nError)
{
oThis.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
var file = files[0];
var xhr = new XMLHttpRequest();
var fd = new FormData();
fd.append('file', file);
xhr.open('POST', g_sUploadServiceLocalUrl+'?key='+documentId);
xhr.onreadystatechange = function(){
if(4 == this.readyState)
{
if((this.status == 200 || this.status == 1223))
{
var frameWindow = GetUploadIFrame();
var content = this.responseText;
frameWindow.document.open();
frameWindow.document.write(content);
frameWindow.document.close();
}
else
oThis.asc_fireCallback("asc_onError",c_oAscError.ID.Unknown,c_oAscError.Level.NoCritical);
oThis.sync_EndAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
}
};
xhr.send(fd);
}
else
oThis.asc_fireCallback("asc_onError",_mapAscServerErrorToAscError(nError),c_oAscError.Level.NoCritical);
};
}
}
}
asc_docs_api.prototype.LoadFontsFromServer = function(_fonts)
......@@ -4585,16 +4633,7 @@ asc_docs_api.prototype.AddImage = function(){
}
else
{
var oImageUploader = document.getElementById("apiImageUpload");
if(!oImageUploader)
{
var frame = document.createElement("iframe");
frame.name = "apiImageUpload";
frame.id = "apiImageUpload";
frame.setAttribute("style", "position:absolute;left:-2px;top:-2px;width:1px;height:1px;z-index:-1000;");
document.body.appendChild(frame);
}
var frameWindow = window.frames["apiImageUpload"];
var frameWindow = GetUploadIFrame();
var content = '<html><head></head><body><form action="'+g_sUploadServiceLocalUrl+'?key='+documentId+'" method="POST" enctype="multipart/form-data"><input id="apiiuFile" name="apiiuFile" type="file" size="1"><input id="apiiuSubmit" name="apiiuSubmit" type="submit" style="display:none;"></form></body></html>';
frameWindow.document.open();
frameWindow.document.write(content);
......@@ -4608,43 +4647,15 @@ asc_docs_api.prototype.AddImage = function(){
if(e && e.target && e.target.files)
{
var files = e.target.files;
if(files.length > 0)
var nError = ValidateUploadImage(files);
if(c_oAscServerError.NoError == nError)
{
var file = files[0];
//проверяем расширение файла
var sName = file.fileName || file.name;
if(sName)
{
var bSupported = false;
var nIndex = sName.lastIndexOf(".");
if(-1 != nIndex)
{
var ext = sName.substring(nIndex + 1).toLowerCase();
for(var i = 0, length = c_oAscImageUploadProp.SupportedFormats.length; i < length; i++)
{
if(c_oAscImageUploadProp.SupportedFormats[i] == ext)
{
bSupported = true;
break;
}
}
}
if(false == bSupported)
{
oThis.asc_fireCallback("asc_onError",c_oAscError.ID.UplImageExt,c_oAscError.Level.NoCritical);
return;
}
}
var nSize = file.fileSize || file.size;
if(nSize && c_oAscImageUploadProp.MaxFileSize < nSize)
{
oThis.asc_fireCallback("asc_onError",c_oAscError.ID.UplImageSize,c_oAscError.Level.NoCritical);
return;
}
oThis.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
fileSubmit.click();
}
else
oThis.asc_fireCallback("asc_onError",_mapAscServerErrorToAscError(nError),c_oAscError.Level.NoCritical);
}
oThis.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
fileSubmit.click();
};
//todo пересмотреть opera
if (window.opera != undefined)
......
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