Commit f2a366fc authored by Alexander.Trofimov's avatar Alexander.Trofimov

move autosave timer to base api

parent 3685f419
......@@ -111,10 +111,7 @@ var editor;
this.collaborativeEditing = null;
// AutoSave
this.lastSaveTime = null; // Время последнего сохранения
this.autoSaveGapRealTime = 30; // Интервал быстрого автосохранения (когда выставлен флаг realtime) - 30 мс.
this.autoSaveGapFast = 2000; // Интервал быстрого автосохранения (когда человек один) - 2 сек.
this.autoSaveGapSlow = 10 * 60 * 1000; // Интервал медленного автосохранения (когда совместно) - 10 минут
// Shapes
this.isStartAddShape = false;
......
......@@ -1256,8 +1256,6 @@ function DrawingObjects() {
_this.showDrawingObjectsEx(lastTask.params.clearCanvas, lastTask.params.graphicOption, lastTask.params.printOptions);
aDrawTasks.splice(0, (taskLen - 1 > 0) ? taskLen - 1 : 1);
}
api._autoSave();
}
//-----------------------------------------------------------------------------------
......
......@@ -96,6 +96,15 @@
// AutoSave
this.autoSaveGap = 0; // Интервал автосохранения (0 - означает, что автосохранения нет) в милесекундах
this.lastSaveTime = null; // Время последнего сохранения
this.autoSaveGapFast = 2000; // Интервал быстрого автосохранения (когда человек один) - 2 сек.
this.autoSaveGapSlow = 10 * 60 * 1000; // Интервал медленного автосохранения (когда совместно) - 10 минут
this.intervalWaitAutoSave = 1000;
// Unlock document
this.canUnlockDocument = false;
this.canUnlockDocument2 = false; // Дублирующий флаг, только для saveChanges или unLockDocument
this.canStartCoAuthoring = false;
this.isDocumentCanSave = false; // Флаг, говорит о возможности сохранять документ (активна кнопка save или нет)
......@@ -477,6 +486,9 @@
{
this.CoAuthoringApi.forceSave()
};
// Функция автосохранения. Переопределяется во всех редакторах
baseEditorsApi.prototype._autoSave = function () {
};
// Выставление интервала автосохранения (0 - означает, что автосохранения нет)
baseEditorsApi.prototype.asc_setAutoSaveGap = function(autoSaveGap)
{
......@@ -982,6 +994,10 @@
}
this.pluginsManager = Asc.createPluginsManager(this);
if (!window['IS_NATIVE_EDITOR']) {
setInterval(function() {t._autoSave();}, 40);
}
};
baseEditorsApi.prototype.sendStandartTextures = function()
......
......@@ -329,11 +329,6 @@ function CEditorPage(api)
this.IsUseNullThumbnailsSplitter = false;
this.m_nIntervalSlowAutosave = 600000;
this.m_nIntervalFastAutosave = 2000;
this.m_nIntervalWaitAutoSave = 1000;
this.m_nLastAutosaveTime = -1;
this.NoneRepaintPages = false;
this.m_oApi = api;
......@@ -3137,8 +3132,6 @@ function CEditorPage(api)
return;
}
oWordControl.m_nTimeDrawingLast = new Date().getTime();
var isRepaint = oWordControl.m_bIsScroll;
if (oWordControl.m_bIsScroll)
{
......@@ -3166,36 +3159,6 @@ function CEditorPage(api)
oWordControl.m_oDrawingDocument.Collaborative_TargetsUpdate(isRepaint);
if (oWordControl.m_oApi.autoSaveGap != 0 && !oWordControl.m_oApi.isViewMode)
{
var _curTime = new Date().getTime();
if (-1 == oWordControl.m_nLastAutosaveTime)
{
oWordControl.m_nLastAutosaveTime = _curTime;
}
var _bIsWaitScheme = false;
if (History.Points && History.Index >= 0 && History.Index < History.Points.length)
{
if ((_curTime - History.Points[History.Index].Time) < oWordControl.m_nIntervalWaitAutoSave)
_bIsWaitScheme = true;
}
if (!_bIsWaitScheme)
{
var _interval = (AscCommon.CollaborativeEditing.m_nUseType <= 0) ? oWordControl.m_nIntervalSlowAutosave : oWordControl.m_nIntervalFastAutosave;
if ((_curTime - oWordControl.m_nLastAutosaveTime) > _interval && !oWordControl.m_oDrawingDocument.TransitionSlide.IsPlaying() && !oWordControl.m_oApi.isLongAction())
{
if (History.Have_Changes(true) == true)
{
oWordControl.m_oApi.asc_Save(true);
}
oWordControl.m_nLastAutosaveTime = _curTime;
}
}
}
oWordControl.m_nPaintTimerId = setTimeout(oWordControl.onTimerScroll, oWordControl.m_nTimerScrollInterval);
//window.requestAnimationFrame(oWordControl.onTimerScroll);
};
......@@ -3203,7 +3166,6 @@ function CEditorPage(api)
this.onTimerScroll_sync = function(isThUpdateSync)
{
var oWordControl = oThis;
oWordControl.m_nTimeDrawingLast = new Date().getTime();
var isRepaint = oWordControl.m_bIsScroll;
if (oWordControl.m_bIsScroll)
{
......
......@@ -1892,7 +1892,40 @@ background-repeat: no-repeat;\
}
}
};
asc_docs_api.prototype._autoSave = function () {
if ((this.canUnlockDocument || this.autoSaveGap != 0) && !this.isViewMode) {
var _curTime = new Date().getTime();
if (-1 === this.lastSaveTime) {
this.lastSaveTime = _curTime;
}
if (this.canUnlockDocument) {
this.asc_Save(true);
this.lastSaveTime = _curTime;
} else {
var _bIsWaitScheme = false;
if (this.WordControl.m_oDrawingDocument &&
!this.WordControl.m_oDrawingDocument.TransitionSlide.IsPlaying() && History.Points &&
History.Index >= 0 && History.Index < History.Points.length) {
if ((_curTime - History.Points[History.Index].Time) < this.intervalWaitAutoSave) {
_bIsWaitScheme = true;
}
}
if (!_bIsWaitScheme) {
var _interval = (AscCommon.CollaborativeEditing.m_nUseType <= 0) ? this.autoSaveGapSlow :
this.autoSaveGapFast;
if ((_curTime - this.lastSaveTime) > _interval) {
if (History.Have_Changes(true) == true) {
this.asc_Save(true);
}
this.lastSaveTime = _curTime;
}
}
}
}
};
asc_docs_api.prototype.asc_Save = function(isAutoSave)
{
this.IsUserSave = !isAutoSave;
......
......@@ -201,18 +201,12 @@ function CEditorPage(api)
this.m_oScrollHorApi = null;
this.m_oScrollVerApi = null;
this.m_nIntervalSlowAutosave = 600000;
this.m_nIntervalFastAutosave = 2000;
this.m_nIntervalWaitAutoSave = 1000;
this.m_nLastAutosaveTime = -1;
this.arrayEventHandlers = [];
this.m_oTimerScrollSelect = -1;
this.IsFocus = true;
this.m_bIsMouseLock = false;
this.m_nTimeDrawingLast = 0;
this.DrawingFreeze = false;
this.m_oHorRuler.m_oWordControl = this;
......@@ -3574,7 +3568,6 @@ function CEditorPage(api)
if (oWordControl.m_oApi.isLongAction())
return;
oWordControl.m_nTimeDrawingLast = new Date().getTime();
var isRepaint = oWordControl.m_bIsScroll;
if (oWordControl.m_bIsScroll)
{
......@@ -3597,36 +3590,6 @@ function CEditorPage(api)
oWordControl.m_oDrawingDocument.Collaborative_TargetsUpdate(isRepaint);
if (oWordControl.m_oApi.autoSaveGap != 0 && !oWordControl.m_oApi.isViewMode)
{
var _curTime = new Date().getTime();
if (-1 == oWordControl.m_nLastAutosaveTime)
{
oWordControl.m_nLastAutosaveTime = _curTime;
}
var _bIsWaitScheme = false;
if (History.Points && History.Index >= 0 && History.Index < History.Points.length)
{
if ((_curTime - History.Points[History.Index].Time) < oWordControl.m_nIntervalWaitAutoSave)
_bIsWaitScheme = true;
}
if (!_bIsWaitScheme)
{
var _interval = (AscCommon.CollaborativeEditing.m_nUseType <= 0) ? oWordControl.m_nIntervalSlowAutosave : oWordControl.m_nIntervalFastAutosave;
if ((_curTime - oWordControl.m_nLastAutosaveTime) > _interval)
{
if (History.Have_Changes(true) == true)
{
oWordControl.m_oApi.asc_Save(true);
}
oWordControl.m_nLastAutosaveTime = _curTime;
}
}
}
oWordControl.m_oApi.sendEvent("asc_onPaintTimer");
//window.requestAnimationFrame(oWordControl.onTimerScroll2);
};
......@@ -3651,7 +3614,6 @@ function CEditorPage(api)
if (!oWordControl.m_oApi.bInit_word_control || oWordControl.m_oApi.isOnlyReaderMode)
return;
oWordControl.m_nTimeDrawingLast = new Date().getTime();
var isRepaint = oWordControl.m_bIsScroll;
if (oWordControl.m_bIsScroll)
{
......
......@@ -1872,7 +1872,38 @@ background-repeat: no-repeat;\
}
}
};
asc_docs_api.prototype._autoSave = function () {
if ((this.canUnlockDocument || this.autoSaveGap != 0) && !this.isViewMode) {
var _curTime = new Date().getTime();
if (-1 === this.lastSaveTime) {
this.lastSaveTime = _curTime;
}
if (this.canUnlockDocument) {
this.asc_Save(true);
this.lastSaveTime = _curTime;
} else {
var _bIsWaitScheme = false;
if (History.Points && History.Index >= 0 && History.Index < History.Points.length) {
if ((_curTime - History.Points[History.Index].Time) < this.intervalWaitAutoSave) {
_bIsWaitScheme = true;
}
}
if (!_bIsWaitScheme) {
var _interval = (AscCommon.CollaborativeEditing.m_nUseType <= 0) ? this.autoSaveGapSlow :
this.autoSaveGapFast;
if ((_curTime - this.lastSaveTime) > _interval) {
if (History.Have_Changes(true) == true) {
this.asc_Save(true);
}
this.lastSaveTime = _curTime;
}
}
}
}
};
asc_docs_api.prototype.asc_Save = function(isAutoSave, isUndoRequest)
{
this.IsUserSave = !isAutoSave;
......
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