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