Commit ed36c9c2 authored by konovalovsergey's avatar konovalovsergey

History.Is_Modified->Have_Changes, onDisconnect error interface, session idle/absolute timeout

parent 6ef43c8b
......@@ -74,7 +74,7 @@ var c_oAscError = Asc.c_oAscError;
DesktopOfflineUpdateLocalName(this);
this.onUpdateDocumentModified(AscCommon.History.Is_Modified());
this.onUpdateDocumentModified(AscCommon.History.Have_Changes());
};
asc['spreadsheet_api'].prototype._onNeedParams = function(data, opt_isPassword)
......@@ -162,7 +162,7 @@ AscCommon.CHistory.prototype.Reset_SavedIndex = function(IsUserSave)
}
};
AscCommon.CHistory.prototype.Is_Modified = function(IsNotUserSave, IsNoSavedNoModifyed)
AscCommon.CHistory.prototype.Have_Changes = function(IsNotUserSave, IsNoSavedNoModifyed)
{
var checkIndex = (this.Is_UserSaveMode() && !IsNotUserSave) ? this.UserSavedIndex : this.SavedIndex;
if (-1 === this.Index && null === checkIndex && false === this.ForceSave)
......@@ -198,7 +198,7 @@ window["Asc"]['spreadsheet_api'].prototype.onUpdateDocumentModified = function(b
this._onUpdateDocumentCanSave();
if (undefined !== window["AscDesktopEditor"]) {
window["AscDesktopEditor"]["onDocumentModifiedChanged"](AscCommon.History ? AscCommon.History.Is_Modified(undefined, true) : bValue);
window["AscDesktopEditor"]["onDocumentModifiedChanged"](AscCommon.History ? AscCommon.History.Have_Changes(undefined, true) : bValue);
}
}
};
......@@ -260,7 +260,7 @@ window["DesktopOfflineAppDocumentEndSave"] = function(error)
else
AscCommon.History.UserSavedIndex = window["Asc"]["editor"].LastUserSavedIndex;
window["Asc"]["editor"].onUpdateDocumentModified(AscCommon.History.Is_Modified());
window["Asc"]["editor"].onUpdateDocumentModified(AscCommon.History.Have_Changes());
window["Asc"]["editor"].LastUserSavedIndex = undefined;
if (2 == error)
......
......@@ -874,8 +874,8 @@ var editor;
if (!this.canSave || this.asc_getCellEditMode()) {
// Пока идет сохранение или редактирование ячейки, мы не закрываем документ
return true;
} else if (History && History.Is_Modified) {
return History.Is_Modified();
} else if (History && History.Have_Changes) {
return History.Have_Changes();
}
return false;
};
......@@ -1532,7 +1532,7 @@ var editor;
t.sync_EndAction(c_oAscAsyncActionType.Information, c_oAscAsyncAction.Save);
// Обновляем состояние возможности сохранения документа
t.onUpdateDocumentModified(History.Is_Modified());
t.onUpdateDocumentModified(History.Have_Changes());
if (undefined !== window["AscDesktopEditor"]) {
window["AscDesktopEditor"]["OnSave"]();
......@@ -3051,7 +3051,7 @@ var editor;
!History.IsEndTransaction() || !this.canSave) {
return;
}
if (!History.Is_Modified(true) && !(this.collaborativeEditing.getCollaborativeEditing() && 0 !== this.collaborativeEditing.getOwnLocksLength())) {
if (!History.Have_Changes(true) && !(this.collaborativeEditing.getCollaborativeEditing() && 0 !== this.collaborativeEditing.getOwnLocksLength())) {
if (this.collaborativeEditing.getFast() && this.collaborativeEditing.haveOtherChanges()) {
AscCommon.CollaborativeEditing.Clear_CollaborativeMarks();
......@@ -3078,7 +3078,7 @@ var editor;
spreadsheet_api.prototype._onUpdateDocumentCanSave = function() {
// Можно модифицировать это условие на более быстрое (менять самим состояние в аргументах, а не запрашивать каждый раз)
var tmp = History.Is_Modified() || (this.collaborativeEditing.getCollaborativeEditing() && 0 !== this.collaborativeEditing.getOwnLocksLength());
var tmp = History.Have_Changes() || (this.collaborativeEditing.getCollaborativeEditing() && 0 !== this.collaborativeEditing.getOwnLocksLength());
if (tmp !== this.isDocumentCanSave) {
this.isDocumentCanSave = tmp;
this.handlers.trigger('asc_onDocumentCanSaveChanged', this.isDocumentCanSave);
......
......@@ -173,6 +173,12 @@ CHistory.prototype.init = function(workbook) {
CHistory.prototype.Is_UserSaveMode = function() {
return this.UserSaveMode;
};
CHistory.prototype.Is_Clear = function() {
if ( this.Points.length <= 0 )
return true;
return false;
};
CHistory.prototype.Clear = function()
{
this.Index = -1;
......@@ -709,7 +715,7 @@ CHistory.prototype._sendCanUndoRedo = function()
{
this.workbook.handlers.trigger("setCanUndo", this.Can_Undo());
this.workbook.handlers.trigger("setCanRedo", this.Can_Redo());
this.workbook.handlers.trigger("setDocumentModified", this.Is_Modified());
this.workbook.handlers.trigger("setDocumentModified", this.Have_Changes());
};
CHistory.prototype.SetSelection = function(range)
{
......@@ -835,7 +841,7 @@ CHistory.prototype.Get_DeleteIndex = function () {
return DeleteIndex;
};
/** @returns {boolean} */
CHistory.prototype.Is_Modified = function(IsNotUserSave) {
CHistory.prototype.Have_Changes = function(IsNotUserSave) {
var checkIndex = (this.Is_UserSaveMode() && !IsNotUserSave) ? this.UserSavedIndex : this.SavedIndex;
if (-1 === this.Index && null === checkIndex && false === this.ForceSave) {
return false;
......
......@@ -589,14 +589,21 @@
this.CoAuthoringApi.onSession = function(data) {
var code = data["code"];
var reason = data["reason"];
var interval = data["interval"];
var extendSession = true;
if (c_oCloseCode.sessionIdle == code) {
extendSession = false;
var lastTime = new Date().getTime();
var idleTime = new Date().getTime() - lastTime;
if (idleTime < interval) {
t.CoAuthoringApi.extendSession(idleTime);
} else {
extendSession = false;
}
} else if (c_oCloseCode.sessionAbsolute == code) {
extendSession = false;
}
if (!extendSession) {
if (true != History.Is_Clear()) {
if (History.Have_Changes()) {
//enter view mode because save async
t.sendEvent('asc_onCoAuthoringDisconnect');
t.asc_setViewMode(true);
......@@ -606,8 +613,13 @@
t.CoAuthoringApi.disconnect(code, reason);
};
AscCommon.CollaborativeEditing.Apply_Changes();
AscCommon.CollaborativeEditing.Send_Changes();
if (t.collaborativeEditing.applyChanges) {
t.collaborativeEditing.applyChanges();
t.collaborativeEditing.sendChanges();
} else {
AscCommon.CollaborativeEditing.Apply_Changes();
AscCommon.CollaborativeEditing.Send_Changes();
}
} else {
t.CoAuthoringApi.disconnect(code, reason);
}
......@@ -619,19 +631,19 @@
* @param {Bool} isDisconnectAtAll окончательно ли отсоединяемся(true) или будем пробовать сделать reconnect(false) + сами отключились
* @param {Bool} isCloseCoAuthoring
*/
this.CoAuthoringApi.onDisconnect = function(e, isDisconnectAtAll, isCloseCoAuthoring)
this.CoAuthoringApi.onDisconnect = function(e, errorCode)
{
if (AscCommon.ConnectionState.None === t.CoAuthoringApi.get_state())
{
t.asyncServerIdEndLoaded();
}
if (isDisconnectAtAll)
if (null != errorCode)
{
// Посылаем наверх эвент об отключении от сервера
t.sendEvent('asc_onCoAuthoringDisconnect');
// И переходим в режим просмотра т.к. мы не можем сохранить файл
t.asc_setViewMode(true);
t.sendEvent('asc_onError', isCloseCoAuthoring ? c_oAscError.ID.UserDrop : c_oAscError.ID.CoAuthoringDisconnect, c_oAscError.Level.NoCritical);
t.sendEvent('asc_onError', errorCode, c_oAscError.Level.NoCritical);
}
};
this.CoAuthoringApi.onDocumentOpen = function(inputWrap)
......
......@@ -102,8 +102,8 @@
this._CoAuthoringApi.onLocksReleasedEnd = function() {
t.callback_OnLocksReleasedEnd();
};
this._CoAuthoringApi.onDisconnect = function(e, isDisconnectAtAll, isCloseCoAuthoring) {
t.callback_OnDisconnect(e, isDisconnectAtAll, isCloseCoAuthoring);
this._CoAuthoringApi.onDisconnect = function(e, errorCode) {
t.callback_OnDisconnect(e, errorCode);
};
this._CoAuthoringApi.onWarning = function(e) {
t.callback_OnWarning(e);
......@@ -328,9 +328,9 @@
}
};
CDocsCoApi.prototype.extendSession = function() {
CDocsCoApi.prototype.extendSession = function(idleTime) {
if (this._CoAuthoringApi && this._onlineWork) {
this._CoAuthoringApi.extendSession();
this._CoAuthoringApi.extendSession(idleTime);
}
};
......@@ -394,9 +394,9 @@
* @param {Bool} isDisconnectAtAll окончательно ли отсоединяемся(true) или будем пробовать сделать reconnect(false) + сами отключились
* @param {Bool} isCloseCoAuthoring
*/
CDocsCoApi.prototype.callback_OnDisconnect = function(e, isDisconnectAtAll, isCloseCoAuthoring) {
CDocsCoApi.prototype.callback_OnDisconnect = function(e, errorCode) {
if (this.onDisconnect) {
this.onDisconnect(e, isDisconnectAtAll, isCloseCoAuthoring);
this.onDisconnect(e, errorCode);
}
};
......@@ -786,8 +786,8 @@
}
};
DocsCoApi.prototype.extendSession = function() {
this._send({'type': 'extendSession'});
DocsCoApi.prototype.extendSession = function(idleTime) {
this._send({'type': 'extendSession', 'idletime': idleTime});
};
DocsCoApi.prototype.openDocument = function(data) {
......@@ -1162,7 +1162,7 @@
DocsCoApi.prototype._onDrop = function(data) {
this.disconnect();
this.onDisconnect(data ? data['description'] : '', true, this.isCloseCoAuthoring);
this.onDisconnect(data ? data['description'] : '', this._getDisconnectErrorCode());
};
DocsCoApi.prototype._onWarning = function(data) {
......@@ -1301,6 +1301,7 @@
'block': this.ownedLockBlocks,
'sessionId': this._id,
'sessionTimeConnect': this._sessionTimeConnect,
'sessionTimeIdle': 0,
'documentFormatSave': this._documentFormatSave,
'view': this._isViewer,
'isCloseCoAuthoring': this.isCloseCoAuthoring,
......@@ -1404,11 +1405,13 @@
t._state = ConnectionState.Reconnect;
var bIsDisconnectAtAll = (c_oCloseCode.serverShutdown === evt.code || c_oCloseCode.sessionIdle === evt.code ||
c_oCloseCode.sessionAbsolute === evt.code || t.attemptCount >= t.maxAttemptCount);
var errorCode = null;
if (bIsDisconnectAtAll) {
t._state = ConnectionState.ClosedAll;
errorCode = t._getDisconnectErrorCode(evt.code);
}
if (t.onDisconnect) {
t.onDisconnect(evt.reason, bIsDisconnectAtAll, t.isCloseCoAuthoring);
t.onDisconnect(evt.reason, errorCode);
}
//Try reconect
if (!bIsDisconnectAtAll) {
......@@ -1437,6 +1440,17 @@
return window['SockJS'] ? window['SockJS'] : require('sockjs');
};
DocsCoApi.prototype._getDisconnectErrorCode = function(opt_closeCode) {
if(c_oCloseCode.serverShutdown === opt_closeCode) {
return Asc.c_oAscError.ID.CoAuthoringDisconnect;
} else if(c_oCloseCode.sessionIdle === opt_closeCode){
return Asc.c_oAscError.ID.CoAuthoringDisconnect;
} else if(c_oCloseCode.sessionAbsolute === opt_closeCode){
return Asc.c_oAscError.ID.CoAuthoringDisconnect;
}
return this.isCloseCoAuthoring ? Asc.c_oAscError.ID.UserDrop : Asc.c_oAscError.ID.CoAuthoringDisconnect;
};
//----------------------------------------------------------export----------------------------------------------------
window['AscCommon'] = window['AscCommon'] || {};
window['AscCommon'].CDocsCoApi = CDocsCoApi;
......
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