Commit dbac6144 authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

Переделал работу с комментариями к документу. Теперь они хранятся в WorkbookView (а не на листе).

Был баг: добавляем комментарий к документу, переходим на другой лист, удаляем комментарий к документу - падаем.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55419 954022d7-b5bf-4e40-9824-e11837661b57
parent 8275ab09
......@@ -2507,13 +2507,21 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
// Cell comment interface
asc_addComment: function(oComment) {
var ws = this.wb.getWorksheet();
ws.cellCommentator.asc_addComment(oComment);
if (oComment.bDocument)
this.wb.cellCommentator.asc_addComment(oComment);
else {
var ws = this.wb.getWorksheet();
ws.cellCommentator.asc_addComment(oComment);
}
},
asc_changeComment: function(id, oComment) {
var ws = this.wb.getWorksheet();
ws.cellCommentator.asc_changeComment(id, oComment);
if (oComment.bDocument)
this.wb.cellCommentator.asc_changeComment(id, oComment);
else {
var ws = this.wb.getWorksheet();
ws.cellCommentator.asc_changeComment(id, oComment);
}
},
asc_selectComment: function(id) {
......@@ -2534,6 +2542,7 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
asc_removeComment: function(id) {
var ws = this.wb.getWorksheet();
ws.cellCommentator.asc_removeComment(id);
this.wb.cellCommentator.asc_removeComment(id);
},
asc_getComments: function(col, row) {
......@@ -2542,8 +2551,7 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
},
asc_getDocumentComments: function() {
var ws = this.wb.getWorksheet();
return ws.cellCommentator.asc_getDocumentComments();
return this.wb.cellCommentator.asc_getDocumentComments();
},
asc_showComments: function() {
......
......@@ -5214,7 +5214,7 @@ function Binary_WorksheetTableReader(stream, wb, aSharedStrings, aCellXfs, Dxfs,
oWorksheet.PagePrintOptions = new Asc.asc_CPageOptions();
res = this.bcr.Read2Spreadsheet(length, function(t,l){
return oThis.ReadPrintOptions(t,l, oWorksheet.PagePrintOptions);
});
});
}
else if ( c_oSerWorksheetsTypes.Hyperlinks == type )
{
......@@ -5815,16 +5815,16 @@ function Binary_WorksheetTableReader(stream, wb, aSharedStrings, aCellXfs, Dxfs,
var elem = aCommentData[i];
elem.asc_putRow(oCommentCoords.asc_getRow());
elem.asc_putCol(oCommentCoords.asc_getCol());
elem.wsId = oWorksheet.Id;
if (elem.asc_getDocumentFlag())
elem.nId = "doc_" + (oWorksheet.aComments.length + 1);
else
if (elem.asc_getDocumentFlag()) {
elem.nId = "doc_" + (this.wb.aComments.length + 1);
this.wb.aComments.push(elem);
} else {
elem.wsId = oWorksheet.Id;
elem.nId = "sheet" + elem.wsId + "_" + (oWorksheet.aComments.length + 1);
oWorksheet.aComments.push(elem);
oWorksheet.aComments.push(elem);
}
}
oWorksheet.aCommentsCoords.push(oCommentCoords);
}
else
res = c_oSerConstants.ReadUnknown;
......
......@@ -3477,37 +3477,35 @@ UndoRedoComment.prototype = {
},
UndoRedo : function (Type, Data, nSheetId, bUndo)
{
var wsModel = this.wb.getWorksheetById(nSheetId);
if ( !wsModel.aComments )
wsModel.aComments = [];
var oModel = ("workbook" === nSheetId) ? this.wb : this.wb.getWorksheetById(nSheetId);
if (!oModel.aComments)
oModel.aComments = [];
var api = window["Asc"]["editor"];
if ( !api.wb )
if (!api.wb)
return;
var ws = api.wb.getWorksheetById(nSheetId);
var ws = ("workbook" === nSheetId) ? api.wb : api.wb.getWorksheetById(nSheetId);
Data.worksheet = ws;
var cellCommentator = ws.cellCommentator;
if ( bUndo == true )
cellCommentator.Undo(Type, Data);
else {
var collaborativeEditing;
// CCommentData
if ( (Data.commentBefore == undefined) && (Data.commentAfter == undefined) ) {
if ( !Data.bDocument ) {
if ( false != this.wb.bCollaborativeChanges ) {
var collaborativeEditing = this.wb.oApi.collaborativeEditing;
collaborativeEditing = this.wb.oApi.collaborativeEditing;
Data.nRow = collaborativeEditing.getLockOtherRow2(nSheetId, Data.nRow);
Data.nCol = collaborativeEditing.getLockOtherColumn2(nSheetId, Data.nCol);
}
}
}
// CompositeCommentData
else {
} else {
// CompositeCommentData
if ( !Data.commentAfter.bDocument ) {
if ( false != this.wb.bCollaborativeChanges ) {
var collaborativeEditing = this.wb.oApi.collaborativeEditing;
collaborativeEditing = this.wb.oApi.collaborativeEditing;
Data.commentAfter.nRow = collaborativeEditing.getLockOtherRow2(nSheetId, Data.commentAfter.nRow);
Data.commentAfter.nCol = collaborativeEditing.getLockOtherColumn2(nSheetId, Data.commentAfter.nCol);
}
......@@ -3517,7 +3515,7 @@ UndoRedoComment.prototype = {
cellCommentator.Redo(Type, Data);
}
}
}
};
var g_oUndoRedoAutoFilters = null;
var g_oUndoRedoAutoFiltersMoveData = null;
......
......@@ -1037,8 +1037,10 @@ function Workbook(sUrlPath, eventsHandlers, oApi){
this.oNameGenerator = new NameGenerator(this);
this.CellStyles = new CCellStyles();
this.TableStyles = new CTableStyles();
this.oStyleManager = new StyleManager(this);
this.oStyleManager = new StyleManager();
this.calcChain = [];
this.aComments = []; // Комментарии к документу
this.aCommentsCoords = [];
this.aWorksheets = [];
this.aWorksheetsById = {};
this.cwf = {};
......@@ -1049,7 +1051,7 @@ function Workbook(sUrlPath, eventsHandlers, oApi){
this.bUndoChanges = false;
this.bRedoChanges = false;
this.aCollaborativeChangeElements = [];
};
}
Workbook.prototype.init=function(){
if(this.nActive < 0)
this.nActive = 0;
......@@ -1074,7 +1076,7 @@ Workbook.prototype.rebuildColors=function(){
g_oColorManager.rebuildColors();
for(var i = 0 , length = this.aWorksheets.length; i < length; ++i)
this.aWorksheets[i].rebuildColors();;
}
};
Workbook.prototype.getDefaultFont=function(){
return g_oDefaultFont.fn;
};
......@@ -1378,10 +1380,10 @@ Workbook.prototype.checkUniqueSheetName=function(name){
return i;
}
return -1;
}
};
Workbook.prototype.checkValidSheetName=function(name){
return name.length < g_nSheetNameMaxLength;
}
};
Workbook.prototype.getUniqueSheetNameFrom=function(name, bCopy){
var nIndex = 1;
var sNewName = "";
......@@ -1474,7 +1476,7 @@ Workbook.prototype.recalcWB = function(isRecalcWB){
}
sortDependency( this );
}
}
};
Workbook.prototype.isDefinedNamesExists = function(name, sheetId){
if(null != sheetId)
{
......@@ -1492,7 +1494,7 @@ Workbook.prototype.isDefinedNamesExists = function(name, sheetId){
return !!this.DefinedNames[name];
}
return false;
}
};
Workbook.prototype.getDefinesNames = function(name, sheetId){
if(null != sheetId)
{
......@@ -1513,7 +1515,7 @@ Workbook.prototype.getDefinesNames = function(name, sheetId){
return oDefName;
}
return false;
}
};
Workbook.prototype.buildDependency = function(){
this.dependencyFormulas.clear();
this.dependencyFormulas = null;
......@@ -1521,7 +1523,7 @@ Workbook.prototype.buildDependency = function(){
for(var i in this.cwf){
this.getWorksheetById(i)._BuildDependencies(this.cwf[i].cells);
}
}
};
Workbook.prototype.recalcDependency = function(f,bad,notRecalc){
if(f.length > 0){
......@@ -1558,7 +1560,7 @@ Workbook.prototype.recalcDependency = function(f,bad,notRecalc){
return sr;
}
}
};
Workbook.prototype.SerializeHistory = function(){
var aRes = [];
//соединяем изменения, которые были до приема данных с теми, что получились после.
......@@ -1593,9 +1595,8 @@ Workbook.prototype.SerializeHistory = function(){
this.aCollaborativeActions = [];
}
return aRes;
}
};
Workbook.prototype.DeserializeHistory = function(aChanges, fCallback){
var bRes = false;
var oThis = this;
//сохраняем те изменения, которые были до приема данных, потому что дальше undo/redo будет очищено
this.aCollaborativeActions = this.aCollaborativeActions.concat(History.GetSerializeArray());
......
......@@ -32,6 +32,17 @@
var asc_SR = asc.StringRender;
var asc_getcvt = asc.getCvtRatio;
var asc_CSP = asc.asc_CStylesPainter;
var asc_CCellComments = asc.asc_CCellCommentator;
function WorkbookCommentsModel (handlers) {
this.workbook = {handlers: handlers};
}
WorkbookCommentsModel.prototype.getId = function () {
return "workbook";
};
WorkbookCommentsModel.prototype.getMergedByCell = function () {
return null;
};
/**
......@@ -113,6 +124,9 @@
this.stringRender = undefined;
this.drawingCtxCharts = undefined;
// Комментарии для всего документа
this.cellCommentator = null;
// Максимальная ширина числа из 0,1,2...,9, померенная в нормальном шрифте(дефалтовый для книги) в px(целое)
// Ecma-376 Office Open XML Part 1, пункт 18.3.1.13
this.maxDigitWidth = 0;
......@@ -432,6 +446,16 @@
});
}
this.cellCommentator = new asc_CCellComments({
model: new WorkbookCommentsModel(this.handlers),
collaborativeEditing: this.collaborativeEditing,
draw: function() {},
handlers: {trigger: function (){return true;}}
});
var commentList = this.cellCommentator.prepareComments(this.model.aComments);
if (0 < commentList.length)
this.handlers.trigger("asc_onAddComments", commentList);
this.clipboard.Api = this.Api;
this.clipboard.init();
......@@ -1671,6 +1695,7 @@
};
WorkbookView.prototype._initCommentsToSave = function () {
var isFirst = true;
for (var wsKey in this.wsViews)
{
var wsView = this.wsViews[wsKey];
......@@ -1678,6 +1703,16 @@
wsView.cellCommentator.prepareCommentsToSave();
wsModel.aComments = wsView.cellCommentator.aComments;
wsModel.aCommentsCoords = wsView.cellCommentator.aCommentCoords;
if (isFirst) {
isFirst = false;
this.cellCommentator.worksheet = wsView;
this.cellCommentator.overlayCtx = wsView.overlayCtx;
this.cellCommentator.drawingCtx = wsView.drawingCtx;
this.cellCommentator.prepareCommentsToSave();
wsModel.aComments = wsModel.aComments.concat(this.cellCommentator.aComments);
wsModel.aCommentsCoords = wsModel.aCommentsCoords.concat(this.cellCommentator.aCommentCoords);
}
}
};
......
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