diff --git a/common/HistoryCommon.js b/common/HistoryCommon.js index 7163b83c92..2ad46a58c3 100644 --- a/common/HistoryCommon.js +++ b/common/HistoryCommon.js @@ -4012,6 +4012,7 @@ AscDFH.historyitem_Pdf_Annot_Pos = AscDFH.historyitem_type_Pdf_Annot | 2; AscDFH.historyitem_Pdf_Annot_Contents = AscDFH.historyitem_type_Pdf_Annot | 3; AscDFH.historyitem_Pdf_Annot_Page = AscDFH.historyitem_type_Pdf_Annot | 4; + AscDFH.historyitem_Pdf_Annot_Replies = AscDFH.historyitem_type_Pdf_Annot | 5; // Comment AscDFH.historyitem_Pdf_Comment_Data = AscDFH.historyitem_type_Pdf_Comment | 1; diff --git a/pdf/src/annotations/annotsChanges.js b/pdf/src/annotations/annotsChanges.js index 3ad14fe685..d1ce4dbcc4 100644 --- a/pdf/src/annotations/annotsChanges.js +++ b/pdf/src/annotations/annotsChanges.js @@ -37,9 +37,10 @@ AscDFH.changesFactory[AscDFH.historyitem_Pdf_Ink_Points] = CChangesPDFInkPoints AscDFH.changesFactory[AscDFH.historyitem_Pdf_Ink_FlipV] = CChangesPDFInkFlipV; AscDFH.changesFactory[AscDFH.historyitem_Pdf_Ink_FlipH] = CChangesPDFInkFlipH; AscDFH.changesFactory[AscDFH.historyitem_Pdf_Annot_Rect] = CChangesPDFAnnotRect; -AscDFH.changesFactory[AscDFH.historyitem_Pdf_Annot_Pos] = CChangesPDFAnnotPos; AscDFH.changesFactory[AscDFH.historyitem_Pdf_Annot_Contents] = CChangesPDFAnnotContents; AscDFH.changesFactory[AscDFH.historyitem_Pdf_Annot_Pos] = CChangesPDFAnnotPos; +AscDFH.changesFactory[AscDFH.historyitem_Pdf_Annot_Page] = CChangesPDFAnnotPage; +AscDFH.changesFactory[AscDFH.historyitem_Pdf_Annot_Replies] = CChangesPDFAnnotReplies; /** * @constructor @@ -169,6 +170,23 @@ CChangesPDFAnnotContents.prototype.private_SetValue = function(Value) oAnnot.SetContents(Value); }; +/** + * @constructor + * @extends {AscDFH.CChangesBaseProperty} + */ +function CChangesPDFAnnotReplies(Class, Old, New, Color) +{ + AscDFH.CChangesBaseProperty.call(this, Class, Old, New, Color); +} +CChangesPDFAnnotReplies.prototype = Object.create(AscDFH.CChangesBaseProperty.prototype); +CChangesPDFAnnotReplies.prototype.constructor = CChangesPDFAnnotReplies; +CChangesPDFAnnotReplies.prototype.Type = AscDFH.historyitem_Pdf_Annot_Replies; +CChangesPDFAnnotReplies.prototype.private_SetValue = function(Value) +{ + let oAnnot = this.Class; + oAnnot.SetReplies(Value); +}; + /** * @constructor * @extends {AscDFH.CChangesBaseProperty} @@ -179,7 +197,7 @@ function CChangesPDFAnnotPage(Class, Old, New, Color) } CChangesPDFAnnotPage.prototype = Object.create(AscDFH.CChangesBaseProperty.prototype); CChangesPDFAnnotPage.prototype.constructor = CChangesPDFAnnotPage; -CChangesPDFAnnotPage.prototype.Type = AscDFH.historyitem_Pdf_Annot_Pos; +CChangesPDFAnnotPage.prototype.Type = AscDFH.historyitem_Pdf_Annot_Page; CChangesPDFAnnotPage.prototype.private_SetValue = function(Value) { let oAnnot = this.Class; diff --git a/pdf/src/annotations/base.js b/pdf/src/annotations/base.js index 014942d8d1..a9c34ddc9b 100644 --- a/pdf/src/annotations/base.js +++ b/pdf/src/annotations/base.js @@ -81,7 +81,7 @@ this._rectDiff = undefined; this._popupIdx = undefined; - this._reply = undefined; // тут будут храниться ответы (text аннотация) + this._replies = []; // тут будут храниться ответы (text аннотации) // internal this._bDrawFromStream = false; // нужно ли рисовать из стрима @@ -466,6 +466,7 @@ return true; }; + CAnnotationBase.prototype.GetRect = function() { return this._rect; @@ -554,18 +555,13 @@ oReply.SetReplyTo(this); oReply.SetApIdx(this.GetDocument().GetMaxApIdx() + 2); - if (this.IsComment()) - this._replies.push(oReply); - else { - if (this._reply == null) - this._reply = oReply; - else - this._reply._replies.push(oReply); - } + this._replies.push(oReply); }; CAnnotationBase.prototype._OnAfterSetReply = function() { - let oAscCommData = this.IsComment() ? this.GetAscCommentData() : this._reply.GetAscCommentData(); - editor.sendEvent("asc_onAddComment", this.GetId(), oAscCommData); + if (this.IsInDocument()) { + let oAscCommData = this.GetAscCommentData(); + editor.sendEvent("asc_onAddComment", this.GetId(), oAscCommData); + } }; CAnnotationBase.prototype.SetContents = function(contents) { if (this.GetContents() == contents) @@ -578,30 +574,111 @@ this._contents = contents; if (oDoc.History.UndoRedoInProgress == false && oViewer.IsOpenAnnotsInProgress == false) { - oDoc.CreateNewHistoryPoint(); oDoc.History.Add(new CChangesPDFAnnotContents(this, oCurContents, contents)); - oDoc.TurnOffHistory(); } this.SetWasChanged(true); + if (contents != null) + this._OnAfterSetReply(); + else if (this.IsInDocument()) + editor.sync_RemoveComment(this.GetId()); }; CAnnotationBase.prototype.AddReply = function(oReply) { - this._reply = oReply; - oReply.SetReplyTo(this); - this._OnAfterSetReply(); + let oDoc = this.GetDocument(); + + oDoc.CreateNewHistoryPoint(); + if (this._replies.length == 0) { + this.SetContents(oReply.GetContents()); + } + else { + oReply.SetReplyTo(this); + let aNewReplies = [].concat(this._replies); + aNewReplies.push(oReply); + this.SetReplies(aNewReplies); + } + + oDoc.TurnOffHistory(); + }; + CAnnotationBase.prototype.SetReplies = function(aReplies) { + let oDoc = this.GetDocument(); + let oViewer = editor.getDocumentRenderer(); + + if (oDoc.History.UndoRedoInProgress == false && oViewer.IsOpenAnnotsInProgress == false) { + oDoc.History.Add(new CChangesPDFAnnotReplies(this, this._replies, aReplies)); + } + this._replies = aReplies; }; - CAnnotationBase.prototype.GetReply = function() { - return this._reply; + CAnnotationBase.prototype.GetReply = function(nPos) { + return this._replies[nPos]; }; - CAnnotationBase.prototype.GetAscCommentData = function() { - if (this._reply) - return this._reply.GetAscCommentData(); + CAnnotationBase.prototype.RemoveComment = function() { + let oDoc = this.GetDocument(); - return null; + oDoc.CreateNewHistoryPoint(); + this.SetContents(null); + this.SetReplies([]); + oDoc.TurnOffHistory(); + }; + CAnnotationBase.prototype.EditCommentData = function(oCommentData) { + let oFirstCommToEdit; + if (this.GetApIdx() == oCommentData.m_sUserData) + oFirstCommToEdit = this; + else { + oFirstCommToEdit = this._replies.find(function(oReply) { + return oCommentData.m_sUserData == oReply.GetApIdx(); + }); + } + + oFirstCommToEdit.SetContents(oCommentData.m_sText); + oFirstCommToEdit.SetModDate(oCommentData.m_sOOTime); + + let aReplyToDel = []; + let oReply, oReplyCommentData; + for (let i = 0; i < this._replies.length; i++) { + oReply = this._replies[i]; + if (oFirstCommToEdit == oReply) + continue; + + oReplyCommentData = oCommentData.m_aReplies.find(function(item) { + return item.m_sUserData == oReply.GetApIdx(); + }); + + if (oReplyCommentData) { + oReply.EditCommentData(oReplyCommentData); + } + else { + aReplyToDel.push(oReply); + } + } + + for (let i = aReplyToDel.length - 1; i >= 0; i--) { + this._replies.splice(this._replies.indexOf(aReplyToDel[i]), 1); + } + + for (let i = 0; i < oCommentData.m_aReplies.length; i++) { + oReplyCommentData = oCommentData.m_aReplies[i]; + if (!this._replies.find(function(reply) { + return oReplyCommentData.m_sUserData == reply.GetApIdx(); + })) { + AscPDF.CAnnotationText.prototype.AddReply.call(this, oReplyCommentData); + } + } }; - CAnnotationBase.prototype.EditCommentData = function(CommentData) { - if (this._reply) - this._reply.EditCommentData(CommentData); + CAnnotationBase.prototype.GetAscCommentData = function() { + let oAscCommData = new Asc["asc_CCommentDataWord"](null); + oAscCommData.asc_putText(this.GetContents()); + oAscCommData.asc_putOnlyOfficeTime(this.GetModDate().toString()); + oAscCommData.asc_putUserId(editor.documentUserId); + oAscCommData.asc_putUserName(this.GetAuthor()); + oAscCommData.asc_putSolved(false); + oAscCommData.asc_putQuoteText(""); + oAscCommData.m_sUserData = this.GetApIdx(); + + this._replies.forEach(function(reply) { + oAscCommData.m_aReplies.push(reply.GetAscCommentData()); + }); + + return oAscCommData; }; CAnnotationBase.prototype.GetContents = function() { return this._contents; diff --git a/pdf/src/annotations/circle.js b/pdf/src/annotations/circle.js index 888013f0a9..aedf9ac1b5 100644 --- a/pdf/src/annotations/circle.js +++ b/pdf/src/annotations/circle.js @@ -148,9 +148,9 @@ memory.WriteLong(nEndPos - nStartPos); memory.Seek(nEndPos); - let oReply = this.GetReply(); - if (oReply) - oReply.WriteToBinary(memory); + this._replies.forEach(function(reply) { + reply.WriteToBinary(memory); + }); }; function TurnOffHistory() { diff --git a/pdf/src/annotations/freeText.js b/pdf/src/annotations/freeText.js index 43073bfe3a..d939a2ddcd 100644 --- a/pdf/src/annotations/freeText.js +++ b/pdf/src/annotations/freeText.js @@ -147,6 +147,72 @@ this.content.Recalculate_Page(0, true); } }; + CAnnotationFreeText.prototype.AddReply = function(oReply) { + oReply.SetReplyTo(this); + + let aNewReplies = [].concat(this._replies); + aNewReplies.push(oReply); + this.SetReplies(aNewReplies); + }; + CAnnotationFreeText.prototype.RemoveComment = function() { + let oDoc = this.GetDocument(); + + oDoc.CreateNewHistoryPoint(); + this.SetReplies([]); + oDoc.TurnOffHistory(); + }; + CAnnotationFreeText.prototype.SetContents = function(contents) { + if (this.GetContents() == contents) + return; + + let oViewer = editor.getDocumentRenderer(); + let oDoc = this.GetDocument(); + let oCurContents = this.GetContents(); + + this._contents = contents; + + if (oDoc.History.UndoRedoInProgress == false && oViewer.IsOpenAnnotsInProgress == false) { + oDoc.History.Add(new CChangesPDFAnnotContents(this, oCurContents, contents)); + } + + this.SetWasChanged(true); + }; + CAnnotationFreeText.prototype.SetReplies = function(aReplies) { + let oDoc = this.GetDocument(); + let oViewer = editor.getDocumentRenderer(); + + if (oDoc.History.UndoRedoInProgress == false && oViewer.IsOpenAnnotsInProgress == false) { + oDoc.History.Add(new CChangesPDFAnnotReplies(this, this._replies, aReplies)); + } + this._replies = aReplies; + if (aReplies.length != 0) + this._OnAfterSetReply(); + else + editor.sync_RemoveComment(this.GetId()); + }; + CAnnotationFreeText.prototype.GetAscCommentData = function() { + let oAscCommData = new Asc["asc_CCommentDataWord"](null); + if (this._replies.length == 0) + return oAscCommData; + + let oMainComm = this._replies[0]; + oAscCommData.asc_putText(oMainComm.GetContents()); + oAscCommData.asc_putOnlyOfficeTime(oMainComm.GetModDate().toString()); + oAscCommData.asc_putUserId(editor.documentUserId); + oAscCommData.asc_putUserName(oMainComm.GetAuthor()); + oAscCommData.asc_putSolved(false); + oAscCommData.asc_putQuoteText(""); + oAscCommData.m_sUserData = oMainComm.GetApIdx(); + + this._replies.forEach(function(reply, index) { + if (index == 0) + return; + + oAscCommData.m_aReplies.push(reply.GetAscCommentData()); + }); + + return oAscCommData; + }; CAnnotationFreeText.prototype.WriteToBinary = function(memory) { memory.WriteByte(AscCommon.CommandType.ctAnnotField); @@ -208,9 +274,9 @@ memory.WriteLong(nEndPos - nStartPos); memory.Seek(nEndPos); - let oReply = this.GetReply(); - if (oReply) - oReply.WriteToBinary(memory); + this._replies.forEach(function(reply) { + reply.WriteToBinary(memory); + }); }; function TurnOffHistory() { diff --git a/pdf/src/annotations/highlights.js b/pdf/src/annotations/highlights.js index 3565c95735..601e632b79 100644 --- a/pdf/src/annotations/highlights.js +++ b/pdf/src/annotations/highlights.js @@ -195,9 +195,9 @@ memory.WriteLong(nEndPos - nStartPos); memory.Seek(nEndPos); - let oReply = this.GetReply(); - if (oReply) - oReply.WriteToBinary(memory); + this._replies.forEach(function(reply) { + reply.WriteToBinary(memory); + }); }; /** * Class representing a highlight annotation. @@ -634,9 +634,9 @@ memory.WriteLong(nEndPos - nStartPos); memory.Seek(nEndPos); - let oReply = this.GetReply(); - if (oReply) - oReply.WriteToBinary(memory); + this._replies.forEach(function(reply) { + reply.WriteToBinary(memory); + }); }; function findMaxSideWithRotation(x1, y1, x2, y2, x3, y3, x4, y4) { diff --git a/pdf/src/annotations/ink.js b/pdf/src/annotations/ink.js index acca90ecd3..235da77cc9 100644 --- a/pdf/src/annotations/ink.js +++ b/pdf/src/annotations/ink.js @@ -854,9 +854,9 @@ memory.WriteLong(nEndPos - nStartPos); memory.Seek(nEndPos); - let oReply = this.GetReply(); - if (oReply) - oReply.WriteToBinary(memory); + this._replies.forEach(function(reply) { + reply.WriteToBinary(memory); + }); }; function generateShapeByPoints(arrOfArrPoints, aShapeRect, oParentAnnot) { diff --git a/pdf/src/annotations/line.js b/pdf/src/annotations/line.js index 4b142b9497..f55669f90f 100644 --- a/pdf/src/annotations/line.js +++ b/pdf/src/annotations/line.js @@ -297,9 +297,9 @@ memory.WriteLong(nEndPos - nStartPos); memory.Seek(nEndPos); - let oReply = this.GetReply(); - if (oReply) - oReply.WriteToBinary(memory); + this._replies.forEach(function(reply) { + reply.WriteToBinary(memory); + }); }; function TurnOffHistory() { diff --git a/pdf/src/annotations/polyLine.js b/pdf/src/annotations/polyLine.js index 387dfc06b3..7dd4f1d36a 100644 --- a/pdf/src/annotations/polyLine.js +++ b/pdf/src/annotations/polyLine.js @@ -200,9 +200,9 @@ memory.WriteLong(nEndPos - nStartPos); memory.Seek(nEndPos); - let oReply = this.GetReply(); - if (oReply) - oReply.WriteToBinary(memory); + this._replies.forEach(function(reply) { + reply.WriteToBinary(memory); + }); }; function TurnOffHistory() { if (AscCommon.History.IsOn() == true) diff --git a/pdf/src/annotations/polygon.js b/pdf/src/annotations/polygon.js index 7710327ee6..ac13420c68 100644 --- a/pdf/src/annotations/polygon.js +++ b/pdf/src/annotations/polygon.js @@ -169,9 +169,9 @@ memory.WriteLong(nEndPos - nStartPos); memory.Seek(nEndPos); - let oReply = this.GetReply(); - if (oReply) - oReply.WriteToBinary(memory); + this._replies.forEach(function(reply) { + reply.WriteToBinary(memory); + }); }; function TurnOffHistory() { diff --git a/pdf/src/annotations/square.js b/pdf/src/annotations/square.js index ed0a1a27c8..8a02e68c3a 100644 --- a/pdf/src/annotations/square.js +++ b/pdf/src/annotations/square.js @@ -118,9 +118,6 @@ this.content.YLimit = this._oldContentPos.YLimit = 20000; this.content.Recalculate_Page(0, true); } - // else if (this.IsNeedRecalc()) { - // this.content.Recalculate_Page(0, false); - // } }; CAnnotationSquare.prototype.SetDrawing = function(oDrawing) { @@ -163,9 +160,9 @@ memory.WriteLong(nEndPos - nStartPos); memory.Seek(nEndPos); - let oReply = this.GetReply(); - if (oReply) - oReply.WriteToBinary(memory); + this._replies.forEach(function(reply) { + reply.WriteToBinary(memory); + }); }; function TurnOffHistory() { diff --git a/pdf/src/annotations/text.js b/pdf/src/annotations/text.js index 7e5fb495bf..2955f9c1a4 100644 --- a/pdf/src/annotations/text.js +++ b/pdf/src/annotations/text.js @@ -92,6 +92,7 @@ oReply.SetReplyTo(this.GetReplyTo() || this); oReply.SetApIdx(this.GetDocument().GetMaxApIdx() + 2); + CommentData.m_sUserData = oReply.GetApIdx(); this._replies.push(oReply); }; @@ -257,57 +258,41 @@ editor.sync_ShowComment([this.GetId()], oPos["X"], oPos["Y"]) }; - CAnnotationText.prototype.GetAscCommentData = function() { - let oAscCommData = new Asc["asc_CCommentDataWord"](null); - oAscCommData.asc_putText(this.GetContents()); - oAscCommData.asc_putOnlyOfficeTime(this.GetModDate().toString()); - oAscCommData.asc_putUserId(editor.documentUserId); - oAscCommData.asc_putUserName(this.GetAuthor()); - oAscCommData.asc_putSolved(false); - oAscCommData.asc_putQuoteText(""); - oAscCommData.m_sUserData = this.GetApIdx(); - - this._replies.forEach(function(reply) { - oAscCommData.m_aReplies.push(reply.GetAscCommentData()); - }); - - return oAscCommData; - }; CAnnotationText.prototype.IsComment = function() { return true; }; - CAnnotationText.prototype.EditCommentData = function(oCommentData) { - this.SetContents(oCommentData.m_sText); - this.SetModDate(oCommentData.m_sOOTime); - - let aReplyToDel = []; - let oReply, oReplyCommentData; - for (let i = 0; i < this._replies.length; i++) { - oReply = this._replies[i]; + // CAnnotationText.prototype.EditCommentData = function(oCommentData) { + // this.SetContents(oCommentData.m_sText); + // this.SetModDate(oCommentData.m_sOOTime); + + // let aReplyToDel = []; + // let oReply, oReplyCommentData; + // for (let i = 0; i < this._replies.length; i++) { + // oReply = this._replies[i]; - oReplyCommentData = oCommentData.m_aReplies.find(function(item) { - return item.m_sUserData == oReply.GetApIdx(); - }); - - if (oReplyCommentData) { - oReply.EditCommentData(oReplyCommentData); - } - else { - aReplyToDel.push(oReply); - } - } - - for (let i = aReplyToDel.length - 1; i > 0; i--) { - this._replies.splice(this._replies.indexOf(aReplyToDel[i]), 1); - } - - for (let i = 0; i < oCommentData.m_aReplies.length; i++) { - oReplyCommentData = oCommentData.m_aReplies[i]; - if (!oReplyCommentData.m_sUserData) { - this.AddReply(oReplyCommentData); - } - } - }; + // oReplyCommentData = oCommentData.m_aReplies.find(function(item) { + // return item.m_sUserData == oReply.GetApIdx(); + // }); + + // if (oReplyCommentData) { + // oReply.EditCommentData(oReplyCommentData); + // } + // else { + // aReplyToDel.push(oReply); + // } + // } + + // for (let i = aReplyToDel.length - 1; i > 0; i--) { + // this._replies.splice(this._replies.indexOf(aReplyToDel[i]), 1); + // } + + // for (let i = 0; i < oCommentData.m_aReplies.length; i++) { + // oReplyCommentData = oCommentData.m_aReplies[i]; + // if (!oReplyCommentData.m_sUserData) { + // this.AddReply(oReplyCommentData); + // } + // } + // }; CAnnotationText.prototype.WriteToBinary = function(memory) { memory.WriteByte(AscCommon.CommandType.ctAnnotField); diff --git a/pdf/src/document.js b/pdf/src/document.js index be493c1360..a089058813 100644 --- a/pdf/src/document.js +++ b/pdf/src/document.js @@ -1665,6 +1665,7 @@ var CPresentation = CPresentation || function(){}; } else { oAnnot = this.AddAnnot(oProps); + AscCommentData.m_sUserData = oAnnot.GetApIdx(); editor.sendEvent("asc_onAddComment", oAnnot.GetId(), AscCommentData); } @@ -1762,7 +1763,7 @@ var CPresentation = CPresentation || function(){}; oViewer._paint(); } else { - oAnnot.SetContents(null); + oAnnot.RemoveComment(); } }; CPDFDoc.prototype.RemoveAnnot = function(Id) { diff --git a/pdf/src/viewer.js b/pdf/src/viewer.js index c4e567184f..5fcb616e24 100644 --- a/pdf/src/viewer.js +++ b/pdf/src/viewer.js @@ -1261,7 +1261,7 @@ } for (let apIdx in oAnnotsMap) { - if (oAnnotsMap[apIdx] instanceof AscPDF.CAnnotationText || oAnnotsMap[apIdx].GetReply() instanceof AscPDF.CAnnotationText) + if (oAnnotsMap[apIdx] instanceof AscPDF.CAnnotationText || oAnnotsMap[apIdx].GetReply(0) instanceof AscPDF.CAnnotationText) oAnnotsMap[apIdx]._OnAfterSetReply(); } this.IsOpenAnnotsInProgress = false;