Commit 482280c2 authored by Alexander.Trofimov's avatar Alexander.Trofimov

fix start co authoring when first user long save and second user connect in this time

parent f2a366fc
......@@ -312,9 +312,10 @@ var editor;
this._asc_downloadAs(typeFile, c_oAscAsyncAction.DownloadAs, {downloadType: bIsDownloadEvent ? DownloadType.Download: DownloadType.None});
};
spreadsheet_api.prototype.asc_Save = function(isAutoSave) {
spreadsheet_api.prototype.asc_Save = function (isAutoSave) {
if (!this.canSave || this.isChartEditor || c_oAscAdvancedOptionsAction.None !== this.advancedOptionsAction ||
this.isLongAction() || !(this.asc_isDocumentCanSave() || this.collaborativeEditing.haveOtherChanges())) {
this.isLongAction() ||
!(this.asc_isDocumentCanSave() || this.collaborativeEditing.haveOtherChanges() || this.canUnlockDocument)) {
return;
}
......@@ -330,7 +331,7 @@ var editor;
this.canSave = false;
var t = this;
this.CoAuthoringApi.askSaveChanges(function(e) {
this.CoAuthoringApi.askSaveChanges(function (e) {
t.onSaveCallback(e);
});
};
......@@ -1180,24 +1181,28 @@ var editor;
t.collaborativeEditing._recalcLockArray(c_oAscLockTypes.kLockTypeOther, oRecalcIndexColumns, oRecalcIndexRows);
}
};
this.CoAuthoringApi.onStartCoAuthoring = function(isStartEvent) {
t.startCollaborationEditing();
this.CoAuthoringApi.onStartCoAuthoring = function (isStartEvent) {
// На старте не нужно ничего делать
if (!isStartEvent) {
if (isStartEvent) {
t.startCollaborationEditing();
} else {
// Когда документ еще не загружен, нужно отпустить lock (при быстром открытии 2-мя пользователями)
if (!t.IsSendDocumentLoadCompleate) {
t.startCollaborationEditing();
t.CoAuthoringApi.unLockDocument(false);
} else {
// Принимаем чужие изменения
t.collaborativeEditing.applyChanges();
// Пересылаем свои изменения
t.collaborativeEditing.sendChanges();
// Сохранять теперь должны на таймере автосохранения. Иначе могли два раза запустить сохранение, не дожидаясь окончания
t.canUnlockDocument = true;
t.canStartCoAuthoring = true;
}
}
};
this.CoAuthoringApi.onEndCoAuthoring = function(isStartEvent) {
this.CoAuthoringApi.onEndCoAuthoring = function (isStartEvent) {
if (t.canUnlockDocument) {
t.canStartCoAuthoring = false;
} else {
t.endCollaborationEditing();
}
};
};
......@@ -1213,11 +1218,12 @@ var editor;
}
}
if (0 < arrChanges.length || null !== deleteIndex || null !== excelAdditionalInfo) {
this.CoAuthoringApi.saveChanges(arrChanges, deleteIndex, excelAdditionalInfo);
this.CoAuthoringApi.saveChanges(arrChanges, deleteIndex, excelAdditionalInfo, this.canUnlockDocument2);
History.CanNotAddChanges = true;
} else {
this.CoAuthoringApi.unLockDocument(true);
this.CoAuthoringApi.unLockDocument(true, this.canUnlockDocument2);
}
this.canUnlockDocument2 = false;
}
};
......@@ -1430,6 +1436,13 @@ var editor;
this.sync_StartAction(c_oAscAsyncActionType.Information, c_oAscAsyncAction.Save);
}
this.canUnlockDocument2 = this.canUnlockDocument;
if (this.canUnlockDocument && this.canStartCoAuthoring) {
this.CoAuthoringApi.onStartCoAuthoring(true);
this.canStartCoAuthoring = false;
this.canUnlockDocument = false;
}
AscCommon.CollaborativeEditing.Clear_CollaborativeMarks();
// Принимаем чужие изменения
this.collaborativeEditing.applyChanges();
......@@ -1454,8 +1467,6 @@ var editor;
window["AscDesktopEditor"]["OnSave"]();
}
};
// Пересылаем всегда, но чистим только если началось совместное редактирование
// Пересылаем свои изменения
this.collaborativeEditing.sendChanges(this.IsUserSave);
} else {
......@@ -2950,11 +2961,17 @@ var editor;
////////////////////////////AutoSave api/////////////////////////////////
/////////////////////////////////////////////////////////////////////////
spreadsheet_api.prototype._autoSave = function() {
if ((0 === this.autoSaveGap && (!this.collaborativeEditing.getFast() || !this.collaborativeEditing.getCollaborativeEditing()))
if ((!this.canUnlockDocument && 0 === this.autoSaveGap && (!this.collaborativeEditing.getFast() || !this.collaborativeEditing.getCollaborativeEditing()))
|| this.asc_getCellEditMode() || this.asc_getIsTrackShape() || this.isOpenedChartFrame ||
!History.IsEndTransaction() || !this.canSave) {
return;
}
if (this.canUnlockDocument) {
this.asc_Save(true);
return;
}
if (!History.Have_Changes(true) && !(this.collaborativeEditing.getCollaborativeEditing() && 0 !== this.collaborativeEditing.getOwnLocksLength())) {
if (this.collaborativeEditing.getFast() && this.collaborativeEditing.haveOtherChanges()) {
AscCommon.CollaborativeEditing.Clear_CollaborativeMarks();
......
......@@ -278,15 +278,17 @@
}
};
CDocsCoApi.prototype.saveChanges = function(arrayChanges, deleteIndex, excelAdditionalInfo) {
CDocsCoApi.prototype.saveChanges = function(arrayChanges, deleteIndex, excelAdditionalInfo, canUnlockDocument) {
if (this._CoAuthoringApi && this._onlineWork) {
this._CoAuthoringApi.canUnlockDocument = canUnlockDocument;
this._CoAuthoringApi.saveChanges(arrayChanges, null, deleteIndex, excelAdditionalInfo);
}
};
CDocsCoApi.prototype.unLockDocument = function(isSave) {
CDocsCoApi.prototype.unLockDocument = function(isSave, canUnlockDocument) {
if (this._CoAuthoringApi && this._onlineWork) {
this._CoAuthoringApi.unLockDocument(isSave);
this._CoAuthoringApi.canUnlockDocument = canUnlockDocument;
this._CoAuthoringApi.unLockDocument(isSave, canUnlockDocument);
}
};
......@@ -561,6 +563,8 @@
this.changesIndex = 0;
// Дополнительная информация для Excel
this.excelAdditionalInfo = null;
// Unlock document
this.canUnlockDocument = false;
this._url = "";
......@@ -796,11 +800,12 @@
this._send({'type': 'saveChanges', 'changes': JSON.stringify(arrayChanges.slice(startIndex, endIndex)),
'startSaveChanges': (startIndex === 0), 'endSaveChanges': (endIndex === arrayChanges.length),
'isCoAuthoring': this.isCoAuthoring, 'isExcel': this._isExcel, 'deleteIndex': this.deleteIndex,
'excelAdditionalInfo': this.excelAdditionalInfo ? JSON.stringify(this.excelAdditionalInfo) : null});
'excelAdditionalInfo': this.excelAdditionalInfo ? JSON.stringify(this.excelAdditionalInfo) : null,
'unlock': this.canUnlockDocument});
};
DocsCoApi.prototype.unLockDocument = function(isSave) {
this._send({'type': 'unLockDocument', 'isSave': isSave});
this._send({'type': 'unLockDocument', 'isSave': isSave, 'unlock': this.canUnlockDocument});
};
DocsCoApi.prototype.getUsers = function() {
......@@ -891,13 +896,13 @@
};
DocsCoApi.prototype._onMessages = function(data, clear) {
if (data["messages"] && this.onMessage) {
if (ConnectionState.Authorized === this._state && data["messages"] && this.onMessage) {
this.onMessage(data["messages"], clear);
}
};
DocsCoApi.prototype._onCursor = function(data) {
if (data["messages"] && this.onCursor) {
if (ConnectionState.Authorized === this._state && data["messages"] && this.onCursor) {
this.onCursor(data["messages"]);
}
};
......@@ -909,7 +914,7 @@
};
DocsCoApi.prototype._onSession = function(data) {
if (data["messages"] && this.onSession) {
if (ConnectionState.Authorized === this._state && data["messages"] && this.onSession) {
this.onSession(data["messages"]);
}
};
......@@ -940,7 +945,7 @@
};
DocsCoApi.prototype._onGetLock = function(data) {
if (data["locks"]) {
if (ConnectionState.Authorized === this._state && data["locks"]) {
for (var key in data["locks"]) {
if (data["locks"].hasOwnProperty(key)) {
var lock = data["locks"][key], blockTmp = (this._isExcel || this._isPresentation) ? lock["block"]["guid"] : key, blockValue = (this._isExcel || this._isPresentation) ? lock["block"] : key;
......@@ -978,7 +983,7 @@
};
DocsCoApi.prototype._onReleaseLock = function(data) {
if (data["locks"]) {
if (ConnectionState.Authorized === this._state && data["locks"]) {
var bSendEnd = false;
for (var block in data["locks"]) {
if (data["locks"].hasOwnProperty(block)) {
......@@ -1004,6 +1009,9 @@
};
DocsCoApi.prototype._onSaveChanges = function(data) {
if (ConnectionState.Authorized !== this._state) {
return;
}
if (data["locks"]) {
var bSendEnd = false;
for (var block in data["locks"]) {
......@@ -1196,6 +1204,9 @@
};
DocsCoApi.prototype._onConnectionStateChanged = function(data) {
if (ConnectionState.Authorized !== this._state) {
return;
}
var userStateChanged = null, userId, stateChanged = false, isEditUser = true;
if (this.onConnectionStateChanged) {
userStateChanged = new AscCommon.asc_CUser(data['user']);
......
......@@ -176,10 +176,11 @@ CCollaborativeEditing.prototype.Send_Changes = function(IsUserSave, AdditionalIn
this.m_aNeedUnlock2.length = 0;
if (0 < aChanges.length || null !== deleteIndex) {
editor.CoAuthoringApi.saveChanges(aChanges, deleteIndex, AdditionalInfo);
editor.CoAuthoringApi.saveChanges(aChanges, deleteIndex, AdditionalInfo, editor.canUnlockDocument2);
AscCommon.History.CanNotAddChanges = true;
} else
editor.CoAuthoringApi.unLockDocument(true);
editor.CoAuthoringApi.unLockDocument(true, editor.canUnlockDocument2);
editor.canUnlockDocument2 = false;
if ( -1 === this.m_nUseType )
{
......
......@@ -960,26 +960,23 @@
};
this.CoAuthoringApi.onStartCoAuthoring = function(isStartEvent)
{
if (t.ParcedDocument)
{
if (t.ParcedDocument) {
if (isStartEvent) {
AscCommon.CollaborativeEditing.Start_CollaborationEditing();
t.asc_setDrawCollaborationMarks(true);
t.WordControl.m_oLogicDocument.DrawingDocument.Start_CollaborationEditing();
if (true != History.Is_Clear())
{
AscCommon.CollaborativeEditing.Apply_Changes();
AscCommon.CollaborativeEditing.Send_Changes();
} else {
// Сохранять теперь должны на таймере автосохранения. Иначе могли два раза запустить сохранение, не дожидаясь окончания
t.canUnlockDocument = true;
t.canStartCoAuthoring = true;
}
else
{
// Изменений нет, но нужно сбросить lock
} else {
t.isStartCoAuthoringOnEndLoad = true;
if (!isStartEvent) {
// Документ еще не подгрузился, но нужно сбросить lock
t.CoAuthoringApi.unLockDocument(false);
}
}
else
{
t.isStartCoAuthoringOnEndLoad = true;
}
};
this.CoAuthoringApi.onEndCoAuthoring = function(isStartEvent)
{
......@@ -1832,6 +1829,13 @@ background-repeat: no-repeat;\
}
this.sync_StartAction(c_oAscAsyncActionType.Information, c_oAscAsyncAction.Save);
this.canUnlockDocument2 = this.canUnlockDocument;
if (this.canUnlockDocument && this.canStartCoAuthoring) {
this.CoAuthoringApi.onStartCoAuthoring(true);
this.canStartCoAuthoring = false;
this.canUnlockDocument = false;
}
if (c_oAscCollaborativeMarksShowType.LastChanges === this.CollaborativeMarksShowType)
{
AscCommon.CollaborativeEditing.Clear_CollaborativeMarks();
......@@ -1930,7 +1934,7 @@ background-repeat: no-repeat;\
{
this.IsUserSave = !isAutoSave;
if (true === this.canSave && !this.isLongAction() && (this.asc_isDocumentCanSave() || History.Have_Changes() ||
AscCommon.CollaborativeEditing.Have_OtherChanges()))
AscCommon.CollaborativeEditing.Have_OtherChanges() || this.canUnlockDocument))
{
this.canSave = false;
......@@ -5863,6 +5867,9 @@ background-repeat: no-repeat;\
{
this.sendEvent("asc_onCloseChartEditor");
};
asc_docs_api.prototype.asc_setDrawCollaborationMarks = function()
{
};
//-----------------------------------------------------------------
// События контекстного меню
......
......@@ -127,13 +127,14 @@ CWordCollaborativeEditing.prototype.Send_Changes = function(IsUserSave, Addition
if (0 < aChanges.length || null !== deleteIndex)
{
this.private_OnSendOwnChanges(aChanges2, deleteIndex);
editor.CoAuthoringApi.saveChanges(aChanges, deleteIndex, AdditionalInfo);
editor.CoAuthoringApi.saveChanges(aChanges, deleteIndex, AdditionalInfo, editor.canUnlockDocument2);
AscCommon.History.CanNotAddChanges = true;
}
else
{
editor.CoAuthoringApi.unLockDocument(true);
editor.CoAuthoringApi.unLockDocument(true, editor.canUnlockDocument2);
}
editor.canUnlockDocument2 = false;
if (-1 === this.m_nUseType)
{
......
......@@ -1182,32 +1182,19 @@ background-repeat: no-repeat;\
};
this.CoAuthoringApi.onStartCoAuthoring = function(isStartEvent)
{
if (t.ParcedDocument) {
if (isStartEvent) {
AscCommon.CollaborativeEditing.Start_CollaborationEditing();
t.asc_setDrawCollaborationMarks(true);
if (t.ParcedDocument)
{
t.WordControl.m_oLogicDocument.DrawingDocument.Start_CollaborationEditing();
if (!isStartEvent)
{
if (true != History.Is_Clear())
{
AscCommon.CollaborativeEditing.Apply_Changes();
AscCommon.CollaborativeEditing.Send_Changes();
}
else
{
// Изменений нет, но нужно сбросить lock
t.CoAuthoringApi.unLockDocument(true);
}
}
} else {
// Сохранять теперь должны на таймере автосохранения. Иначе могли два раза запустить сохранение, не дожидаясь окончания
t.canUnlockDocument = true;
t.canStartCoAuthoring = true;
}
else
{
} else {
t.isStartCoAuthoringOnEndLoad = true;
if (!isStartEvent)
{
if (!isStartEvent) {
// Документ еще не подгрузился, но нужно сбросить lock
t.CoAuthoringApi.unLockDocument(false);
}
......@@ -1215,8 +1202,12 @@ background-repeat: no-repeat;\
};
this.CoAuthoringApi.onEndCoAuthoring = function(isStartEvent)
{
if (t.canUnlockDocument) {
t.canStartCoAuthoring = false;
} else {
AscCommon.CollaborativeEditing.End_CollaborationEditing();
t.asc_setDrawCollaborationMarks(false);
}
};
};
......@@ -1801,6 +1792,13 @@ background-repeat: no-repeat;\
}
this.sync_StartAction(c_oAscAsyncActionType.Information, c_oAscAsyncAction.Save);
this.canUnlockDocument2 = this.canUnlockDocument;
if (this.canUnlockDocument && this.canStartCoAuthoring) {
this.CoAuthoringApi.onStartCoAuthoring(true);
this.canStartCoAuthoring = false;
this.canUnlockDocument = false;
}
if (c_oAscCollaborativeMarksShowType.LastChanges === this.CollaborativeMarksShowType)
{
AscCommon.CollaborativeEditing.Clear_CollaborativeMarks();
......@@ -1908,7 +1906,7 @@ background-repeat: no-repeat;\
{
this.IsUserSave = !isAutoSave;
if (true === this.canSave && !this.isLongAction() && (this.asc_isDocumentCanSave() || History.Have_Changes() ||
AscCommon.CollaborativeEditing.Have_OtherChanges() || true === isUndoRequest))
AscCommon.CollaborativeEditing.Have_OtherChanges() || true === isUndoRequest || this.canUnlockDocument))
{
this.canSave = false;
......
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