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