Skip to content

Commit

Permalink
[se] Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
GoshaZotov committed Jul 27, 2023
1 parent a484e41 commit 0d7f399
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 86 deletions.
115 changes: 39 additions & 76 deletions cell/model/HeaderFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,8 @@
this.differentOddEven = null;
this.scaleWithDoc = null;

this.needAddPicturesMap = null;

if (idArr) {
window.Asc.g_header_footer_editor = this;
this.init(idArr, opt_objForSave);
Expand Down Expand Up @@ -1476,19 +1478,16 @@
let isChanged = false;
if(curSection && (curSection.changed || reWrite)) {
curHeaderFooter.parser.tokens[c_oPortionPosition.left] = this._convertFragments(curSection.fragments);
curSection.loadPictureInfo && newPictureSections.push(curSection);
isChanged = true;
}
curSection = this.sections[i][c_oPortionPosition.center];
if(this.sections[i][c_oPortionPosition.center] && (this.sections[i][c_oPortionPosition.center].changed || reWrite)) {
curHeaderFooter.parser.tokens[c_oPortionPosition.center] = this._convertFragments(curSection.fragments);
curSection.loadPictureInfo && newPictureSections.push(curSection);
isChanged = true;
}
curSection = this.sections[i][c_oPortionPosition.right];
if(curSection && (this.sections[i][c_oPortionPosition.right].changed || reWrite)) {
curHeaderFooter.parser.tokens[c_oPortionPosition.right] = this._convertFragments(curSection.fragments);
curSection.loadPictureInfo && newPictureSections.push(curSection);
isChanged = true;
}

Expand All @@ -1513,16 +1512,12 @@
hF.setScaleWithDoc(this.scaleWithDoc);

//save pictures
if (ws && ws.changeLegacyDrawingHFPictures) {
ws.changeLegacyDrawingHFPictures(newPictureSections, function () {
if(isAddHistory) {
History.EndTransaction();
}
});
} else {
if(isAddHistory) {
History.EndTransaction();
}
if (ws && ws.changeLegacyDrawingHFPictures && this.needAddPicturesMap) {
ws.changeLegacyDrawingHFPictures(this.needAddPicturesMap)
}

if(isAddHistory) {
History.EndTransaction();
}
};

Expand Down Expand Up @@ -1632,26 +1627,22 @@
CHeaderFooterEditor.prototype.addPictureField = function () {
let t = this;
let showFileDialog = function (needPushField) {
AscCommon.ShowImageFileDialog(t.api.documentId, t.api.documentUserId, t.api.CoAuthoringApi.get_jwt(), function(error, files)
{
curSection.loadPictureInfo = files;
if (needPushField) {
let textField = convertFieldToMenuText(asc.c_oAscHeaderFooterField.picture);
if(null !== textField) {
t.cellEditor.pasteText(textField);

t.api.asc_addImage({
callback: function (oImage) {
if (oImage) {
if (!t.needAddPicturesMap) {
t.needAddPicturesMap = {};
}
t.needAddPicturesMap[curSection.getStringName()] = oImage;
if (needPushField) {
let textField = convertFieldToMenuText(asc.c_oAscHeaderFooterField.picture);
if (null !== textField) {
t.cellEditor.pasteText(textField);
}
}
}
}
}, function(error)
{
/*if (c_oAscError.ID.No !== error)
{
t.sendEvent("asc_onError", error, c_oAscError.Level.NoCritical);
}
if (obj && obj.sendUrlsToFrameEditor && t.isOpenedChartFrame)
{
t.sendStartUploadImageActionToFrameEditor();
}
t.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);*/
});
};

Expand Down Expand Up @@ -2251,63 +2242,35 @@

};

CLegacyDrawingHF.prototype.changeBySectionsInfo = function (aSectionsInfo, callback) {
let loadFiles = [];
CLegacyDrawingHF.prototype.addPictures = function (picturesMap) {
let t = this;
let api = window["Asc"]["editor"];

for (let i = 0; i < aSectionsInfo.length; i++) {
loadFiles.push(aSectionsInfo[i].loadPictureInfo[0]);
}
for (let i in picturesMap) {
if (picturesMap.hasOwnProperty(i)) {
let sSectionId = i;
let oldHFDrawing = t.getDrawingById(sSectionId);
let newHFDrawing = new CLegacyDrawingHFDrawing();
newHFDrawing.id = sSectionId;

let addLoadedImages = function (imageUrls) {
const ws = api.wb.getWorksheet();

api.ImageLoader.LoadImagesWithCallback(imageUrls, function() {
// CImage
//_this.controller.resetSelection();
//History.Create_NewPoint();
for (var i = 0; i < imageUrls.length; ++i) {
/*var sImageUrl = imageUrls[i];
var _image = api.ImageLoader.LoadImage(sImageUrl, 1);
if (null != _image) {
_this.addImageObjectCallback(_image, options);
} else {
worksheet.model.workbook.handlers.trigger("asc_onError", c_oAscError.ID.UplImageUrl, c_oAscError.Level.NoCritical);
break;
}*/
let url = picturesMap[i].src;
let image = picturesMap[i].Image;

let sSectionId = aSectionsInfo[i].getStringName();
let oldHFDrawing = t.getDrawingById(sSectionId);
let newHFDrawing = new CLegacyDrawingHFDrawing();
newHFDrawing.id = sSectionId;

const ws = api.wb.getWorksheet();
newHFDrawing.graphicObject = ws.objectRender.controller.createImage(imageUrls[i], 0, 0, 0, 0);
var __w = Math.max(parseInt(image.width * AscCommon.g_dKoef_pix_to_mm), 1);
var __h = Math.max(parseInt(image.height * AscCommon.g_dKoef_pix_to_mm), 1);

t.drawings.push(newHFDrawing);
//changeFunction(oldHFDrawing, newHFDrawing);

aSectionsInfo[i].loadPictureInfo = null;
}
newHFDrawing.graphicObject = ws.objectRender.controller.createImage(url, 0, 0, __w, __h);

callback();
});
};
t.drawings.push(newHFDrawing);
//changeFunction(oldHFDrawing, newHFDrawing);

api.sync_StartAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.UploadImage);
AscCommon.UploadImageFiles(loadFiles, api.documentId, api.documentUserId, api.CoAuthoringApi.get_jwt(), function(error, urls)
{
if (c_oAscError.ID.No !== error)
{
//t.sendEvent("asc_onError", error, c_oAscError.Level.NoCritical);
callback();
}
else
{
addLoadedImages(urls/*, obj*/);
delete picturesMap[i];
}
api.sync_EndAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.UploadImage);
});
}
};

CLegacyDrawingHF.prototype.getDrawingById = function (id) {
Expand Down
14 changes: 8 additions & 6 deletions cell/model/Workbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2367,12 +2367,12 @@
this.snapshot = this._getSnapshot();
}
};
Workbook.prototype.addImages = function (aImages, oPlaceholder) {
Workbook.prototype.addImages = function (aImages, obj) {
const oApi = Asc.editor;
if (oPlaceholder && undefined !== oPlaceholder.id && aImages.length === 1 && aImages[0].Image) {
if (obj && undefined !== obj.id && aImages.length === 1 && aImages[0].Image) {
const oController = oApi.getGraphicController();
const oDrawingObjects = oApi.getDrawingObjects();
const oPlaceholderTarget = AscCommon.g_oTableId.Get_ById(oPlaceholder.id);
const oPlaceholderTarget = AscCommon.g_oTableId.Get_ById(obj.id);
if (oPlaceholderTarget) {
if (oPlaceholderTarget.isObjectInSmartArt && oPlaceholderTarget.isObjectInSmartArt()) {
const oSmartArtGroup = oPlaceholderTarget.group.getMainGroup();
Expand All @@ -2381,7 +2381,7 @@
if (bLock) {
History.Create_NewPoint();
oController.resetSelection();
oPlaceholderTarget.applyImagePlaceholderCallback && oPlaceholderTarget.applyImagePlaceholderCallback(aImages, oPlaceholder);
oPlaceholderTarget.applyImagePlaceholderCallback && oPlaceholderTarget.applyImagePlaceholderCallback(aImages, obj);
oController.selectObject(oSmartArtGroup, 0);
oController.selection.groupSelection = oSmartArtGroup;
oSmartArtGroup.selectObject(oPlaceholderTarget, 0);
Expand All @@ -2403,6 +2403,8 @@
});
}
}
} else if (obj && obj.callback && aImages.length === 1 && aImages[0].Image) {
obj.callback(aImages[0]);
}
};
Workbook.prototype.getOleSize = function () {
Expand Down Expand Up @@ -12244,11 +12246,11 @@
this.nColsCount = val;
};

Worksheet.prototype.changeLegacyDrawingHFPictures = function(aSections, callback) {
Worksheet.prototype.changeLegacyDrawingHFPictures = function(picturesMap) {
if (!this.legacyDrawingHF) {
this.legacyDrawingHF = new AscCommonExcel.CLegacyDrawingHF();
}
this.legacyDrawingHF.changeBySectionsInfo(aSections, callback, callback);
this.legacyDrawingHF.addPictures(picturesMap);
};


Expand Down
7 changes: 3 additions & 4 deletions cell/view/WorksheetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -25564,13 +25564,12 @@
return AscBrowser.retinaPixelRatio;
};

WorksheetView.prototype.changeLegacyDrawingHFPictures = function (aSections, callback) {
WorksheetView.prototype.changeLegacyDrawingHFPictures = function (picturesMap) {
//lock?
if (!aSections || !aSections.length) {
callback();
if (!picturesMap) {
return;
}
this.model.changeLegacyDrawingHFPictures(aSections, callback);
this.model.changeLegacyDrawingHFPictures(picturesMap);
};


Expand Down

0 comments on commit 0d7f399

Please sign in to comment.