Commit 84a3ebc6 authored by Sergey.Luzyanin's avatar Sergey.Luzyanin Committed by Alexander.Trofimov

Правка бага 21411 - [CoEdit] Не происходит "лок" комментариев в режиме совместного редактирования

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@50786 954022d7-b5bf-4e40-9824-e11837661b57
parent 90aed9c9
......@@ -159,7 +159,8 @@ function CTableId()
case historyitem_type_GraphicFrame : Element = new CGraphicFrame(); break;
case historyitem_type_SlideMaster : Element = new MasterSlide(); break;
case historyitem_type_Theme : Element = new CTheme(); break;
case historyitem_type_ChartTitle : Element = new CChartTitle();
case historyitem_type_ChartTitle : Element = new CChartTitle(); break;
case historyitem_type_SlideComments : Element = new SlideComments(); break;
}
Element.Read_FromBinary2(Reader);
......@@ -680,6 +681,10 @@ function CCollaborativeEditing()
}
}
}
if(Class instanceof CComment)
{
editor.sync_UnLockComment(Class.Get_Id());
}
}
else if ( locktype_Other3 === CurLockType )
{
......
......@@ -1326,7 +1326,7 @@ CPresentation.prototype =
Add_FlowTable : function(Cols, Rows)
{
if(this.Document_Is_SelectionLocked(changestype_AddSp) === false)
if(this.Document_Is_SelectionLocked(changestype_AddShape) === false)
{
var X = 0;
var Y = 0;
......@@ -6290,7 +6290,7 @@ CPresentation.prototype =
}
}
if(CheckType === changestype_AddShape)
if(CheckType === changestype_AddShape || CheckType === changestype_AddComment)
{
if(cur_slide.deleteLock.Lock.Type !== locktype_Mine && cur_slide.deleteLock.Lock.Type !== locktype_None)
return true;
......@@ -6320,36 +6320,58 @@ CPresentation.prototype =
}
}
if(CheckType === changestype_AddSp || CheckType === changestype_AddComment)
if(CheckType === changestype_MoveComment)
{
if(cur_slide.deleteLock.Lock.Type !== locktype_Mine && cur_slide.deleteLock.Lock.Type !== locktype_None)
var comment = g_oTableId.Get_ById(AdditionalData);
if(isRealObject(comment))
{
var slides = this.Slides;
var check_slide = null;
for(var i = 0; i < slides.length; ++i)
{
if(slides[i].slideComments)
{
var comments = slides[i].slideComments.comments;
for(var j = 0; j < comments.length; ++j)
{
if(comments[j] === comment)
{
check_slide = slides[i];
break;
}
}
if(j < comments.length)
{
break;
}
}
}
if(isRealObject(check_slide))
{
if(check_slide.deleteLock.Lock.Type !== locktype_Mine && check_slide.deleteLock.Lock.Type !== locktype_None)
return true;
/*var generated_id = "new_object" + (new Date().getTime()) + editor.User.id;
var check_obj =
{
"type": c_oAscLockTypeElemPresentation.Object,
"slideId": slide_id,
"objId": generated_id,
"guid": generated_id
"objId": comment.Get_Id(),
"guid": comment.Get_Id()
};
CollaborativeEditing.Add_CheckLock( check_obj );*/
comment.Lock.Check(check_obj);
}
if(CheckType === changestype_MoveComment)
else
{
if(cur_slide.deleteLock.Lock.Type !== locktype_Mine && cur_slide.deleteLock.Lock.Type !== locktype_None)
return true;
if(isRealObject(AdditionalData))
{
var check_obj =
}
}
else
{
"type": c_oAscLockTypeElemPresentation.Object,
"slideId": slide_id,
"objId": AdditionalData.Get_Id(),
"guid": AdditionalData.Get_Id()
};
AdditionalData.Lock.Check(check_obj);
return true;
}
}
if(CheckType === changestype_SlideBg)
......@@ -6758,17 +6780,17 @@ CPresentation.prototype =
// Функции для работы с комментариями
//-----------------------------------------------------------------------------------
Add_Comment : function(CommentData)
{
if(this.Document_Is_SelectionLocked(changestype_AddComment) === false)
{
History.Create_NewPoint();
for(var i = this.Slides[this.CurPage].comments.length - 1; i > -1; --i)
{
this.Slides[this.CurPage].comments[i].selected = false;
}
var Comment = new CComment( this.Comments, CommentData );
Comment.selected = true;
Comment.setPosition(this.Slides[this.CurPage].commentX, this.Slides[this.CurPage].commentY);
if(this.Document_Is_SelectionLocked(changestype_AddComment, Comment) === false)
{
for(var i = this.Slides[this.CurPage].slideComments.comments.length - 1; i > -1; --i)
{
this.Slides[this.CurPage].slideComments.comments[i].selected = false;
}
this.Slides[this.CurPage].commentX += COMMENT_WIDTH;
this.Slides[this.CurPage].commentY += COMMENT_HEIGHT;
this.Slides[this.CurPage].addComment(Comment);
......@@ -6777,16 +6799,55 @@ CPresentation.prototype =
this.DrawingDocument.OnEndRecalculate();
return Comment;
}
else
{
this.Document_Undo();
}
},
Change_Comment : function(Id, CommentData)
{
if(this.Document_Is_SelectionLocked(changestype_MoveComment) === false)
if(this.Document_Is_SelectionLocked(changestype_MoveComment, Id) === false)
{
History.Create_NewPoint();
var comment = g_oTableId.Get_ById(Id);
if(isRealObject(comment))
{
var slides = this.Slides;
var check_slide = null;
var slide_num = null;
for(var i = 0; i < slides.length; ++i)
{
if(slides[i].slideComments)
{
var comments = slides[i].slideComments.comments;
for(var j = 0; j < comments.length; ++j)
{
if(comments[j] === comment)
{
check_slide = slides[i];
slide_num = i;
break;
}
}
if(j < comments.length)
{
break;
}
}
}
if(isRealObject(check_slide))
{
this.DrawingDocument.m_oWordControl.GoToPage(slide_num);
this.Slides[this.CurPage].changeComment( Id, CommentData );
this.Recalculate()
}
else
{
return true;
}
}
}
},
......@@ -6797,7 +6858,7 @@ CPresentation.prototype =
for(var i = 0; i < this.Slides.length; ++i)
{
var comments = this.Slides[i].comments;
var comments = this.Slides[i].slideComments.comments;
for(var j = 0; j < comments.length; ++j)
{
if(comments[j].Id === Id)
......@@ -6831,7 +6892,7 @@ CPresentation.prototype =
for(var i = 0; i < this.Slides.length; ++i)
{
var comments = this.Slides[i].comments;
var comments = this.Slides[i].slideComments.comments;
for(var j = 0; j < comments.length; ++j)
{
if(comments[j].Id === Id)
......@@ -6954,7 +7015,7 @@ CPresentation.prototype =
{
this.Slides[_sldIdx].writecomments = [];
var _comments = this.Slides[_sldIdx].comments;
var _comments = this.Slides[_sldIdx].slideComments.comments;
var _commentsCount = _comments.length;
for (var i = 0; i < _commentsCount; i++)
......
......@@ -908,6 +908,7 @@ function Slide(presentation, slideLayout, slideNum)
if(presentation)
{
this.setSlideComments(new SlideComments());
this.setLocks(new PropLocker(this.Id), new PropLocker(this.Id), new PropLocker(this.Id), new PropLocker(this.Id), new PropLocker(this.Id));
}
......@@ -924,34 +925,33 @@ function Slide(presentation, slideLayout, slideNum)
Slide.prototype =
{
setSlideComments: function(comments)
{
History.Add(this, {Type:historyitem_SetSlideComments, oldPr: this.slideComments, newPr: comments});
this.slideComments = comments;
},
addComment: function(comment)
{
History.Add(this, {Type: historyitem_AddComment, objectId: comment.Get_Id(), pos:this.comments.length});
this.comments.splice(this.comments.length, 0, comment);
if(isRealObject(this.slideComments))
{
this.slideComments.addComment(comment);
}
},
changeComment: function(id, commentData)
{
for(var i = 0; i < this.comments.length; ++i)
if(isRealObject(this.slideComments))
{
if(this.comments[i].Get_Id() === id)
{
this.comments[i].Set_Data(commentData);
return;
}
this.slideComments.changeComment(id, commentData);
}
},
removeComment: function(id)
{
for(var i = 0; i < this.comments.length; ++i)
if(isRealObject(this.slideComments))
{
if(this.comments[i].Get_Id() === id)
{
History.Add(this, {Type: historyitem_RemoveComment, index: i, id: id});
this.comments.splice(i, 1);
return;
}
this.slideComments.removeComment(id);
}
},
......@@ -1186,9 +1186,13 @@ Slide.prototype =
{
this.cSld.spTree[i].draw(graphics);
}
for(var i=0; i < this.comments.length; ++i)
if(this.slideComments)
{
var comments = this.slideComments.comments;
for(var i=0; i < comments.length; ++i)
{
this.comments[i].draw(graphics);
comments[i].draw(graphics);
}
}
},
......@@ -1540,6 +1544,12 @@ Slide.prototype =
break;
}
case historyitem_SetSlideComments:
{
this.slideComments = data.oldPr;
break;
}
case historyitem_RemoveFromSpTree:
{
this.cSld.spTree.splice(data.Pos, 0, g_oTableId.Get_ById(data.id));
......@@ -1642,6 +1652,12 @@ Slide.prototype =
editor.sync_RemoveComment(data.id);
break;
}
case historyitem_SetSlideComments:
{
this.slideComments = data.newPr;
break;
}
case historyitem_RemoveFromSpTree:
{
this.cSld.spTree.splice(data.Pos, 1);
......@@ -1752,6 +1768,16 @@ Slide.prototype =
w.WriteLong(data.index);
break;
}
case historyitem_SetSlideComments:
{
w.WriteBool(isRealObject(data.newPr));
if(isRealObject(data.newPr))
{
w.WriteString2(data.newPr.Get_Id());
}
break;
}
case historyitem_RemoveFromSpTree:
{
var Pos = data.UseArray ? data.PosArray[0] : data.Pos;
......@@ -1874,6 +1900,18 @@ Slide.prototype =
editor.sync_RemoveComment(comment.Id);
break;
}
case historyitem_SetSlideComments:
{
if(r.GetBool())
{
this.slideComments = g_oTableId.Get_ById(r.GetString2());
}
else
{
this.slideComments = null;
}
break;
}
case historyitem_RemoveFromSpTree:
{
var pos = this.m_oContentChanges.Check( contentchanges_Remove, r.GetLong());
......@@ -2189,3 +2227,168 @@ PropLocker.prototype = {
{}
};
function SlideComments()
{
this.comments = [];
this.m_oContentChanges = new CContentChanges(); // список изменений(добавление/удаление элементов)
this.Id = g_oIdCounter.Get_NewId();
g_oTableId.Add(this, this.Id);
}
SlideComments.prototype =
{
Get_Id: function()
{
return this.Id;
},
Clear_ContentChanges : function()
{
this.m_oContentChanges.Clear();
},
Add_ContentChanges : function(Changes)
{
this.m_oContentChanges.Add( Changes );
},
Refresh_ContentChanges : function()
{
this.m_oContentChanges.Refresh();
},
addComment: function(comment)
{
History.Add(this, {Type: historyitem_AddComment, objectId: comment.Get_Id(), Pos:this.comments.length});
this.comments.splice(this.comments.length, 0, comment);
},
changeComment: function(id, commentData)
{
for(var i = 0; i < this.comments.length; ++i)
{
if(this.comments[i].Get_Id() === id)
{
this.comments[i].Set_Data(commentData);
return;
}
}
},
removeComment: function(id)
{
for(var i = 0; i < this.comments.length; ++i)
{
if(this.comments[i].Get_Id() === id)
{
History.Add(this, {Type: historyitem_RemoveComment, Pos: i, id: id});
this.comments.splice(i, 1);
return;
}
}
},
Write_ToBinary2: function(w)
{
w.WriteLong(historyitem_type_SlideComments);
w.WriteString2(this.Id);
},
Read_FromBinary2: function(r)
{
this.Id = r.GetString2();
},
Save_Changes: function(data, w)
{
w.WriteLong(data.Type);
switch(data.Type)
{
case historyitem_AddComment:
{
var Pos = data.UseArray ? data.PosArray[0] : data.Pos;
w.WriteLong(Pos);
w.WriteString2(data.objectId);
break;
}
case historyitem_RemoveComment:
{
var Pos = data.UseArray ? data.PosArray[0] : data.Pos;
w.WriteLong(Pos);
break;
}
}
},
Load_Changes: function(r)
{
var type = r.GetLong();
switch(type)
{
case historyitem_AddComment:
{
var pos = r.GetLong();
var id = r.GetString2();
var pos2 = this.m_oContentChanges.Check( contentchanges_Add, pos);
this.comments.splice(pos2, 0, g_oTableId.Get_ById(id));
editor.sync_AddComment( id, this.comments[pos].Data);
break;
}
case historyitem_RemoveComment:
{
var pos = r.GetLong();
var pos2 = this.m_oContentChanges.Check( contentchanges_Remove, pos);
var comment = this.comments.splice(pos, 1)[0];
editor.sync_RemoveComment(comment.Id);
break;
}
}
},
Undo: function(data)
{
switch(data.Type)
{
case historyitem_AddComment:
{
this.comments.splice(data.Pos, 1);
editor.sync_RemoveComment( data.objectId );
break;
}
case historyitem_RemoveComment:
{
this.comments.splice(data.Pos, 0, g_oTableId.Get_ById(data.id));
editor.sync_AddComment( this.comments[data.index].Get_Id(), this.comments[data.index].Data);
break;
}
}
},
Redo: function(data)
{
switch(data.Type)
{
case historyitem_AddComment:
{
this.comments.splice(data.Pos, 0, g_oTableId.Get_ById(data.objectId));
editor.sync_AddComment( data.objectId, this.comments[data.pos].Data);
break;
}
case historyitem_RemoveComment:
{
this.comments.splice(data.Pos, 1);
editor.sync_RemoveComment(data.id);
break;
}
}
}
};
\ No newline at end of file
......@@ -2831,12 +2831,34 @@ CGraphicObjects.prototype = {
break;
}
case STATES_ID_NULL:
{
if(this.selectedObjects.length > 0)
{
if(editor.WordControl.m_oLogicDocument.Document_Is_SelectionLocked(changestype_Drawing_Props) === false)
{
History.Create_NewPoint();
this.slide.removeSelectedObjects();
}
}
else
{
if(this.slide.slideComments)
{
var comments = this.slide.slideComments.comments;
for(var i = 0; i < comments.length; ++i)
{
if(comments[i].selected)
{
if ( false === this.WordControl.m_oLogicDocument.Document_Is_SelectionLocked(changestype_MoveComment, comments[i].Id ) )
{
editor.WordControl.m_oLogicDocument.Create_NewHistoryPoint();
editor.WordControl.m_oLogicDocument.Remove_Comment(comments[i].Id, true);
}
break;
}
}
}
}
break;
}
case STATES_ID_GROUP:
......
......@@ -236,6 +236,8 @@ var historyitem_SetLayoutMatchingName = 18;
var historyitem_SetLayoutMaster = 19;
var historyitem_SetLayoutType = 20;
var historyitem_SetMasterTheme = 21;
var historyitem_SetSlideComments = 22
......@@ -443,6 +445,8 @@ var historyitem_type_TextBody = 32;
var historyitem_type_GraphicFrame = 33;
var historyitem_type_Theme = 34;
var historyitem_type_SlideMaster = 35;
var historyitem_type_SlideComments = 36;
......@@ -626,9 +630,10 @@ CHistory.prototype =
this.Points[this.Index].Items.push( Item );
if ( ( Class instanceof CPresentation && ( historyitem_Presenattion_AddSlide === Data.Type || historyitem_Presenattion_RemoveSlide === Data.Type ) )
|| (Class instanceof Slide && ( historyitem_RemoveFromSpTree === Data.Type || historyitem_AddToSlideSpTree === Data.Type || historyitem_ShapeAdd === Data.Type)))
|| (Class instanceof Slide && ( historyitem_RemoveFromSpTree === Data.Type || historyitem_AddToSlideSpTree === Data.Type || historyitem_ShapeAdd === Data.Type))
|| Class instanceof SlideComments)
{
var bAdd = ( ( Class instanceof CPresentation && historyitem_Presenattion_AddSlide === Data.Type )
var bAdd = ( ( Class instanceof CPresentation && historyitem_Presenattion_AddSlide === Data.Type ) || ( Class instanceof SlideComments && historyitem_AddComment === Data.Type )
||(Class instanceof Slide && ( historyitem_AddToSlideSpTree === Data.Type || historyitem_ShapeAdd === Data.Type))) ? true : false;
var Count = 1;
......
......@@ -57,16 +57,16 @@ function NullState(drawingObjectsController, drawingObjects)
this.onMouseDown = function(e, x, y)
{
this.drawingObjectsController.hideComment();
for(var i = drawingObjects.comments.length - 1; i > -1; --i)
for(var i = drawingObjects.slideComments.comments.length - 1; i > -1; --i)
{
drawingObjects.comments[i].selected = false;
drawingObjects.slideComments.comments[i].selected = false;
}
for(var i = drawingObjects.comments.length - 1; i > -1; --i)
for(var i = drawingObjects.slideComments.comments.length - 1; i > -1; --i)
{
if(drawingObjects.comments[i].hit(x, y))
if(drawingObjects.slideComments.comments[i].hit(x, y))
{
drawingObjects.comments[i].selected = true;
this.drawingObjectsController.addPreTrackObject(new MoveComment(drawingObjects.comments[i]));
drawingObjects.slideComments.comments[i].selected = true;
this.drawingObjectsController.addPreTrackObject(new MoveComment(drawingObjects.slideComments.comments[i]));
this.drawingObjectsController.changeCurrentState(new PreMoveCommentState(this.drawingObjectsController, this.drawingObjects, x, y));
editor.WordControl.m_oDrawingDocument.OnRecalculatePage(this.drawingObjects.num, this.drawingObjects);
editor.WordControl.m_oDrawingDocument.OnEndRecalculate();
......@@ -948,7 +948,7 @@ function MoveCommentState(drawingObjectsController, drawingObjects, startX, star
this.onMouseUp = function(e, x, y)
{
if(this.drawingObjects.presentation.Document_Is_SelectionLocked(changestype_Drawing_Props, this.drawingObjectsController.arrTrackObjects[0].comment) === false)
if(this.drawingObjects.presentation.Document_Is_SelectionLocked(changestype_MoveComment, this.drawingObjectsController.arrTrackObjects[0].comment.Get_Id()) === false)
{
History.Create_NewPoint();
this.drawingObjectsController.trackEnd();
......
......@@ -305,6 +305,10 @@ asc_docs_api.prototype._coAuthoringInit = function () {
}
}
}
if(Class instanceof CComment)
{
editor.sync_LockComment(Class.Get_Id(), e["user"]);
}
// TODO: Здесь для ускорения надо сделать проверку, является ли текущим элемент с
// заданным Id. Если нет, тогда и не надо обновлять состояние.
......@@ -3392,7 +3396,7 @@ asc_docs_api.prototype.asc_removeComment = function(Id)
if (null == this.WordControl.m_oLogicDocument)
return;
if ( false === this.WordControl.m_oLogicDocument.Document_Is_SelectionLocked(changestype_None, { Type : changestype_2_Comment, Id : Id } ) )
if ( false === this.WordControl.m_oLogicDocument.Document_Is_SelectionLocked(changestype_MoveComment, Id ) )
{
this.WordControl.m_oLogicDocument.Create_NewHistoryPoint();
this.WordControl.m_oLogicDocument.Remove_Comment( Id, true );
......@@ -3404,7 +3408,7 @@ asc_docs_api.prototype.asc_changeComment = function(Id, AscCommentData)
if (null == this.WordControl.m_oLogicDocument)
return;
if ( false === this.WordControl.m_oLogicDocument.Document_Is_SelectionLocked(changestype_None, { Type : changestype_2_Comment, Id : Id } ) )
if ( false === this.WordControl.m_oLogicDocument.Document_Is_SelectionLocked(changestype_MoveComment, Id ) )
{
var CommentData = new CCommentData();
CommentData.Read_FromAscCommentData(AscCommentData);
......@@ -3691,14 +3695,17 @@ asc_docs_api.prototype.OpenDocumentEndCallback = function()
var _slidesCount = _slides.length;
for (var i = 0; i < _slidesCount; i++)
{
var _comments = _slides[i].comments;
var slideComments = _slides[i].slideComments;
if(slideComments)
{
var _comments = slideComments.comments;
var _commentsCount = _comments.length;
for (var j = 0; j < _commentsCount; j++)
{
this.sync_AddComment(_comments[j].Get_Id(), _comments[j].Data );
}
}
}
this.WordControl.InitControl();
......
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