Commit a95b3a41 authored by Ilya Kirillov's avatar Ilya Kirillov

Рефакторинг функций связанных с совместным редактированием.

parent c50ad0a2
......@@ -39,16 +39,16 @@ if(typeof CDocument !== "undefined")
{
CDocument.prototype.Document_Is_SelectionLocked = function(CheckType, AdditionalData, DontLockInFastMode)
{
if ( true === AscCommon.CollaborativeEditing.Get_GlobalLock() )
if (true === AscCommon.CollaborativeEditing.Get_GlobalLock())
return true;
AscCommon.CollaborativeEditing.OnStart_CheckLock();
this.private_DocumentIsSelectionLocked(CheckType);
if ( "undefined" != typeof(AdditionalData) && null != AdditionalData )
if ("undefined" != typeof(AdditionalData) && null != AdditionalData)
{
if ( AscCommon.changestype_2_InlineObjectMove === AdditionalData.Type )
if (AscCommon.changestype_2_InlineObjectMove === AdditionalData.Type)
{
var PageNum = AdditionalData.PageNum;
var X = AdditionalData.X;
......@@ -57,24 +57,24 @@ if(typeof CDocument !== "undefined")
var NearestPara = this.Get_NearestPos(PageNum, X, Y).Paragraph;
NearestPara.Document_Is_SelectionLocked(AscCommon.changestype_Document_Content);
}
else if ( AscCommon.changestype_2_HdrFtr === AdditionalData.Type )
else if (AscCommon.changestype_2_HdrFtr === AdditionalData.Type)
{
this.HdrFtr.Document_Is_SelectionLocked(AscCommon.changestype_HdrFtr);
}
else if ( AscCommon.changestype_2_Comment === AdditionalData.Type )
else if (AscCommon.changestype_2_Comment === AdditionalData.Type)
{
this.Comments.Document_Is_SelectionLocked( AdditionalData.Id );
this.Comments.Document_Is_SelectionLocked(AdditionalData.Id);
}
else if ( AscCommon.changestype_2_Element_and_Type === AdditionalData.Type )
else if (AscCommon.changestype_2_Element_and_Type === AdditionalData.Type)
{
AdditionalData.Element.Document_Is_SelectionLocked( AdditionalData.CheckType, false );
AdditionalData.Element.Document_Is_SelectionLocked(AdditionalData.CheckType, false);
}
else if ( AscCommon.changestype_2_ElementsArray_and_Type === AdditionalData.Type )
else if (AscCommon.changestype_2_ElementsArray_and_Type === AdditionalData.Type)
{
var Count = AdditionalData.Elements.length;
for ( var Index = 0; Index < Count; Index++ )
for (var Index = 0; Index < Count; Index++)
{
AdditionalData.Elements[Index].Document_Is_SelectionLocked( AdditionalData.CheckType, false );
AdditionalData.Elements[Index].Document_Is_SelectionLocked(AdditionalData.CheckType, false);
}
}
else if (AscCommon.changestype_2_AdditionalTypes === AdditionalData.Type)
......@@ -89,7 +89,7 @@ if(typeof CDocument !== "undefined")
var bResult = AscCommon.CollaborativeEditing.OnEnd_CheckLock(DontLockInFastMode);
if ( true === bResult )
if (true === bResult)
{
this.Document_UpdateSelectionState();
this.Document_UpdateInterfaceState();
......@@ -98,55 +98,57 @@ if(typeof CDocument !== "undefined")
return bResult;
};
CDocument.prototype.private_DocumentIsSelectionLocked = function(CheckType)
{
if ( AscCommon.changestype_None != CheckType )
if (AscCommon.changestype_None != CheckType)
{
if ( AscCommon.changestype_Document_SectPr === CheckType )
if (AscCommon.changestype_Document_SectPr === CheckType)
{
this.Lock.Check( this.Get_Id() );
this.Lock.Check(this.Get_Id());
}
else if (AscCommon.changestype_Document_Styles === CheckType)
{
this.Styles.Lock.Check(this.Styles.Get_Id());
}
else if(AscCommon.changestype_ColorScheme === CheckType )
else if (AscCommon.changestype_ColorScheme === CheckType)
{
this.DrawingObjects.Lock.Check( this.DrawingObjects.Get_Id());
this.DrawingObjects.Lock.Check(this.DrawingObjects.Get_Id());
}
else
{
if ( docpostype_HdrFtr === this.CurPos.Type )
{
this.HdrFtr.Document_Is_SelectionLocked(CheckType);
this.Controller.IsSelectionLocked(CheckType);
}
else if ( docpostype_DrawingObjects == this.CurPos.Type )
{
this.DrawingObjects.documentIsSelectionLocked(CheckType);
}
else if ( docpostype_Content == this.CurPos.Type )
};
CDocumentControllerBase.prototype.IsSelectionLocked = function(CheckType)
{
switch ( this.Selection.Flag )
};
CLogicDocumentController.prototype.IsSelectionLocked = function(CheckType)
{
this.LogicDocument.controller_IsSelectionLocked(CheckType);
};
CDocument.prototype.controller_IsSelectionLocked = function(CheckType)
{
switch (this.Selection.Flag)
{
case selectionflag_Common :
{
if ( true === this.Selection.Use )
if (true === this.Selection.Use)
{
var StartPos = ( this.Selection.StartPos > this.Selection.EndPos ? this.Selection.EndPos : this.Selection.StartPos );
var EndPos = ( this.Selection.StartPos > this.Selection.EndPos ? this.Selection.StartPos : this.Selection.EndPos );
if ( StartPos != EndPos && AscCommon.changestype_Delete === CheckType )
if (StartPos != EndPos && AscCommon.changestype_Delete === CheckType)
CheckType = AscCommon.changestype_Remove;
for ( var Index = StartPos; Index <= EndPos; Index++ )
for (var Index = StartPos; Index <= EndPos; Index++)
this.Content[Index].Document_Is_SelectionLocked(CheckType);
}
else
{
var CurElement = this.Content[this.CurPos.ContentPos];
if ( AscCommon.changestype_Document_Content_Add === CheckType && type_Paragraph === CurElement.GetType() && true === CurElement.Cursor_IsEnd() )
if (AscCommon.changestype_Document_Content_Add === CheckType && type_Paragraph === CurElement.GetType() && true === CurElement.Cursor_IsEnd())
AscCommon.CollaborativeEditing.Add_CheckLock(false);
else
this.Content[this.CurPos.ContentPos].Document_Is_SelectionLocked(CheckType);
......@@ -157,9 +159,9 @@ if(typeof CDocument !== "undefined")
case selectionflag_Numbering:
{
var NumPr = this.Content[this.Selection.Data[0]].Numbering_Get();
if ( null != NumPr )
if (null != NumPr)
{
var AbstrNum = this.Numbering.Get_AbstractNum( NumPr.NumId );
var AbstrNum = this.Numbering.Get_AbstractNum(NumPr.NumId);
AbstrNum.Document_Is_SelectionLocked(CheckType);
}
......@@ -168,9 +170,18 @@ if(typeof CDocument !== "undefined")
break;
}
}
}
}
}
};
CHdrFtrController.prototype.IsSelectionLocked = function(CheckType)
{
this.HdrFtr.Document_Is_SelectionLocked(CheckType);
};
CDrawingsController.prototype.IsSelectionLocked = function(CheckType)
{
this.DrawingObjects.documentIsSelectionLocked(CheckType);
};
CFootnotesController.prototype.IsSelectionLocked = function(CheckType)
{
// TODO: Реализовать
};
}
......
......@@ -8730,12 +8730,13 @@ CDocument.prototype.Load_Changes = function(Reader, Reader2)
};
CDocument.prototype.Get_SelectionState2 = function()
{
this.Selection_Remove()
this.Selection_Remove();
// Сохраняем Id ближайшего элемента в текущем классе
var State = new CDocumentSelectionState();
if (docpostype_HdrFtr === this.CurPos.Type)
var nDocPosType = this.Get_DocPosType();
if (docpostype_HdrFtr === nDocPosType)
{
State.Type = docpostype_HdrFtr;
......@@ -8744,7 +8745,7 @@ CDocument.prototype.Get_SelectionState2 = function()
else
State.Id = null;
}
else if (docpostype_DrawingObjects === this.CurPos.Type)
else if (docpostype_DrawingObjects === nDocPosType)
{
// TODO: запрашиваем параграф текущего выделенного элемента
var X = 0;
......@@ -8756,12 +8757,16 @@ CDocument.prototype.Get_SelectionState2 = function()
State.Type = docpostype_Content;
State.Id = this.Content[ContentPos].Get_Id();
}
else // if ( docpostype_Content === this.CurPos.Type )
else if (docpostype_Footnotes === nDocPosType)
{
// TODO: Реализовать для сносок
}
else // if (docpostype_Content === nDocPosType)
{
State.Id = this.Get_Id();
State.Type = docpostype_Content;
var Element = this.Content[this.CurPos.ContentPos]
var Element = this.Content[this.CurPos.ContentPos];
State.Data = Element.Get_SelectionState2();
}
......@@ -8852,61 +8857,7 @@ CDocument.prototype.Add_Comment = function(CommentData)
var Comment = new CComment(this.Comments, CommentData);
this.Comments.Add(Comment);
if (docpostype_HdrFtr === this.CurPos.Type)
{
this.HdrFtr.Add_Comment(Comment);
}
else if (docpostype_DrawingObjects === this.CurPos.Type)
{
if (true != this.DrawingObjects.isSelectedText())
{
var ParaDrawing = this.DrawingObjects.getMajorParaDrawing();
if (null != ParaDrawing)
{
var Paragraph = ParaDrawing.Parent;
Paragraph.Add_Comment2(Comment, ParaDrawing.Get_Id());
}
}
else
{
this.DrawingObjects.addComment(Comment);
}
}
else // if ( docpostype_Content === this.CurPos.Type )
{
if (selectionflag_Numbering === this.Selection.Flag)
return;
if (true === this.Selection.Use)
{
var StartPos, EndPos;
if (this.Selection.StartPos < this.Selection.EndPos)
{
StartPos = this.Selection.StartPos;
EndPos = this.Selection.EndPos;
}
else
{
StartPos = this.Selection.EndPos;
EndPos = this.Selection.StartPos;
}
if (StartPos === EndPos)
{
this.Content[StartPos].Add_Comment(Comment, true, true);
}
else
{
this.Content[StartPos].Add_Comment(Comment, true, false);
this.Content[EndPos].Add_Comment(Comment, false, true);
}
}
else
{
this.Content[this.CurPos.ContentPos].Add_Comment(Comment, true, true);
}
}
this.Controller.AddComment(Comment);
// TODO: Продумать, как избавиться от пересчета
this.Recalculate();
......@@ -8935,7 +8886,7 @@ CDocument.prototype.Remove_Comment = function(Id, bSendEvent, bRecalcula
}
if (true === bSendEvent)
editor.sync_RemoveComment(Id);
this.Api.sync_RemoveComment(Id);
}
};
CDocument.prototype.CanAdd_Comment = function()
......@@ -8943,37 +8894,7 @@ CDocument.prototype.CanAdd_Comment = function()
if (true !== this.Comments.Is_Use())
return false;
// Проверим можно ли добавлять гиперссылку
if (docpostype_HdrFtr === this.CurPos.Type)
return this.HdrFtr.CanAdd_Comment();
else if (docpostype_DrawingObjects == this.CurPos.Type)
{
if (true != this.DrawingObjects.isSelectedText())
return true;
else
return this.DrawingObjects.canAddComment();
}
else //if ( docpostype_Content === this.CurPos.Type )
{
switch (this.Selection.Flag)
{
case selectionflag_Numbering:
return false;
case selectionflag_Common:
{
if (true === this.Selection.Use && this.Selection.StartPos != this.Selection.EndPos)
return true;
else
{
var Pos = ( this.Selection.Use === true ? this.Selection.StartPos : this.CurPos.ContentPos );
var Element = this.Content[Pos];
return Element.CanAdd_Comment();
}
}
}
}
return false;
return this.Controller.CanAddComment();
};
CDocument.prototype.Select_Comment = function(Id, ScrollToComment)
{
......@@ -9007,11 +8928,11 @@ CDocument.prototype.Show_Comment = function(Id)
var Comment_X = this.Get_PageLimits(Comment_PageNum).XLimit;
var Coords = this.DrawingDocument.ConvertCoordsToCursorWR(Comment_X, Comment_Y, Comment_PageNum);
editor.sync_ShowComment(Comment.Get_Id(), Coords.X, Coords.Y);
this.Api.sync_ShowComment(Comment.Get_Id(), Coords.X, Coords.Y);
}
else
{
editor.sync_HideComment();
this.Api.sync_HideComment();
}
};
CDocument.prototype.Show_Comments = function()
......@@ -9040,27 +8961,7 @@ CDocument.prototype.Get_PrevElementEndInfo = function(CurElement)
};
CDocument.prototype.Get_SelectionAnchorPos = function()
{
var Result;
if (docpostype_HdrFtr === this.CurPos.Type)
{
Result = this.HdrFtr.Get_SelectionAnchorPos();
}
else if (docpostype_DrawingObjects === this.CurPos.Type)
{
var ParaDrawing = this.DrawingObjects.getMajorParaDrawing();
Result =
{
X0 : ParaDrawing.GraphicObj.x,
Y : ParaDrawing.GraphicObj.y,
X1 : ParaDrawing.GraphicObj.x + ParaDrawing.GraphicObj.extX,
Page : ParaDrawing.PageNum
};
}
else
{
var Pos = ( true === this.Selection.Use ? ( this.Selection.StartPos < this.Selection.EndPos ? this.Selection.StartPos : this.Selection.EndPos ) : this.CurPos.ContentPos );
Result = this.Content[Pos].Get_SelectionAnchorPos();
}
var Result = this.Controller.GetSelectionAnchorPos();
var PageLimit = this.Get_PageLimits(Result.Page);
Result.X0 = PageLimit.X;
......@@ -15691,6 +15592,61 @@ CDocument.prototype.controller_IsCursorInHyperlink = function(bCheckEnd)
return null;
};
CDocument.prototype.controller_AddComment = function(Comment)
{
if (selectionflag_Numbering === this.Selection.Flag)
return;
if (true === this.Selection.Use)
{
var StartPos, EndPos;
if (this.Selection.StartPos < this.Selection.EndPos)
{
StartPos = this.Selection.StartPos;
EndPos = this.Selection.EndPos;
}
else
{
StartPos = this.Selection.EndPos;
EndPos = this.Selection.StartPos;
}
if (StartPos === EndPos)
{
this.Content[StartPos].Add_Comment(Comment, true, true);
}
else
{
this.Content[StartPos].Add_Comment(Comment, true, false);
this.Content[EndPos].Add_Comment(Comment, false, true);
}
}
else
{
this.Content[this.CurPos.ContentPos].Add_Comment(Comment, true, true);
}
};
CDocument.prototype.controller_CanAddComment = function()
{
if (selectionflag_Common === this.Selection.Flag)
{
if (true === this.Selection.Use && this.Selection.StartPos != this.Selection.EndPos)
return true;
else
{
var Pos = ( this.Selection.Use === true ? this.Selection.StartPos : this.CurPos.ContentPos );
var Element = this.Content[Pos];
return Element.CanAdd_Comment();
}
}
return false;
};
CDocument.prototype.controller_GetSelectionAnchorPos = function()
{
var Pos = ( true === this.Selection.Use ? ( this.Selection.StartPos < this.Selection.EndPos ? this.Selection.StartPos : this.Selection.EndPos ) : this.CurPos.ContentPos );
return this.Content[Pos].Get_SelectionAnchorPos();
}
CDocument.prototype.controller_AddToParagraph = function(ParaItem, bRecalculate)
{
......
......@@ -672,6 +672,21 @@ CDocumentControllerBase.prototype.CanAddHyperlink = function(bCheckInHyperlink){
* @returns {?ParaHyperlink}
*/
CDocumentControllerBase.prototype.IsCursorInHyperlink = function(bCheckEnd){return false;};
/**
* Добавляем комментарий.
* @param Comment
*/
CDocumentControllerBase.prototype.AddComment = function(Comment){};
/**
* Проверяем, можно ли добавить комментарий.
* @returns {boolean}
*/
CDocumentControllerBase.prototype.CanAddComment = function(){return false;};
/**
* Получаем физическую позицию на странице для якоря по селекту.
* @returns {{X0: number, X1: number, Y: number, Page: number}}
*/
CDocumentControllerBase.prototype.GetSelectionAnchorPos = function(){return {X0 : 0, X1 : 0, Y : 0, Page : 0};};
/**
* Добавляем элемент в параграф.
......
......@@ -428,6 +428,39 @@ CDrawingsController.prototype.IsCursorInHyperlink = function(bCheckEnd)
{
return this.DrawingObjects.hyperlinkCheck(bCheckEnd);
};
CDrawingsController.prototype.AddComment = function(Comment)
{
if (true != this.DrawingObjects.isSelectedText())
{
var ParaDrawing = this.DrawingObjects.getMajorParaDrawing();
if (null != ParaDrawing)
{
var Paragraph = ParaDrawing.Parent;
Paragraph.Add_Comment2(Comment, ParaDrawing.Get_Id());
}
}
else
{
this.DrawingObjects.addComment(Comment);
}
};
CDrawingsController.prototype.CanAddComment = function()
{
if (true != this.DrawingObjects.isSelectedText())
return true;
else
return this.DrawingObjects.canAddComment();
};
CDrawingsController.prototype.GetSelectionAnchorPos = function()
{
var ParaDrawing = this.DrawingObjects.getMajorParaDrawing();
return {
X0 : ParaDrawing.GraphicObj.x,
Y : ParaDrawing.GraphicObj.y,
X1 : ParaDrawing.GraphicObj.x + ParaDrawing.GraphicObj.extX,
Page : ParaDrawing.PageNum
};
};
CDrawingsController.prototype.AddToParagraph = function(oItem, bRecalculate)
......
......@@ -1030,6 +1030,24 @@ CFootnotesController.prototype.IsCursorInHyperlink = function(bCheckEnd)
// TODO: Реализовать
return false;
};
CFootnotesController.prototype.AddComment = function(Comment)
{
// TODO: Реализовать
};
CFootnotesController.prototype.CanAddComment = function()
{
// TODO: Реализовать
};
CFootnotesController.prototype.GetSelectionAnchorPos = function()
{
// TODO: Реализовать
return {
X0 : 0,
Y : 0,
X1 : 0,
Page : 0
};
};
CFootnotesController.prototype.AddToParagraph = function(oItem, bRecalculate)
{
......
......@@ -364,7 +364,18 @@ CHdrFtrController.prototype.IsCursorInHyperlink = function(bCheckEnd)
{
return this.HdrFtr.Hyperlink_Check(bCheckEnd);
};
CHdrFtrController.prototype.AddComment = function(Comment)
{
this.HdrFtr.Add_Comment(Comment);
};
CHdrFtrController.prototype.CanAddComment = function()
{
return this.HdrFtr.CanAdd_Comment();
};
CHdrFtrController.prototype.GetSelectionAnchorPos = function()
{
return this.HdrFtr.Get_SelectionAnchorPos();
};
CHdrFtrController.prototype.AddToParagraph = function(oItem, bRecalculate)
......
......@@ -337,6 +337,18 @@ CLogicDocumentController.prototype.IsCursorInHyperlink = function(bCheckEnd)
{
return this.LogicDocument.controller_IsCursorInHyperlink(bCheckEnd);
};
CLogicDocumentController.prototype.AddComment = function(Comment)
{
this.LogicDocument.controller_AddComment(Comment);
};
CLogicDocumentController.prototype.CanAddComment = function()
{
return this.LogicDocument.controller_CanAddComment();
};
CLogicDocumentController.prototype.GetSelectionAnchorPos = function()
{
return this.LogicDocument.controller_GetSelectionAnchorPos();
};
CLogicDocumentController.prototype.AddToParagraph = function(oItem)
......
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