From 0f7b20c9a60496dd62f70c5d10d02be04334bea0 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 23 Mar 2017 16:10:31 +0300 Subject: [PATCH] Changes for fast co-editing mode when count of users>2: always send 'onDocumentStateChange' event , draw '*' in the document caption while user is editing document. --- apps/common/main/lib/view/Header.js | 13 ++++++--- .../main/app/controller/Main.js | 27 +++++++++---------- .../mobile/app/controller/Main.js | 12 +-------- .../main/app/controller/Main.js | 27 +++++++++---------- .../mobile/app/controller/Main.js | 12 +-------- .../main/app/controller/Main.js | 26 +++++++++--------- .../mobile/app/controller/Main.js | 12 +-------- 7 files changed, 51 insertions(+), 78 deletions(-) diff --git a/apps/common/main/lib/view/Header.js b/apps/common/main/lib/view/Header.js index e8e25bbf7..eb1848b38 100644 --- a/apps/common/main/lib/view/Header.js +++ b/apps/common/main/lib/view/Header.js @@ -81,6 +81,7 @@ define([ this.documentCaption = this.options.documentCaption; this.canBack = this.options.canBack; this.branding = this.options.customization; + this.isModified = false; }, render: function () { @@ -155,14 +156,18 @@ define([ return this.headerCaption; }, - setDocumentCaption: function(value, applyOnly) { - if (_.isUndefined(applyOnly)) { - this.documentCaption = value; - } + setDocumentCaption: function(value, isModified) { + if (isModified !== undefined) + this.isModified = isModified; + + this.documentCaption = value; if (!value) value = ''; + if (this.isModified) + value = value + '*'; + var dc = $('#header-documentcaption div'); if (dc) dc.html(Common.Utils.String.htmlEncode(value)); diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 24f23d63c..eba284fa2 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -104,7 +104,7 @@ define([ weakCompare : function(obj1, obj2){return obj1.type === obj2.type;} }); - this._state = {isDisconnected: false, usersCount: 1, fastCoauth: true, startModifyDocument: true, lostEditingRights: false, licenseWarning: false}; + this._state = {isDisconnected: false, usersCount: 1, fastCoauth: true, lostEditingRights: false, licenseWarning: false}; // Initialize viewport @@ -1355,33 +1355,32 @@ define([ title = headerView.getDocumentCaption() + ' - ' + title; if (isModified) { - if (!_.isUndefined(title) && (!this._state.fastCoauth || this._state.usersCount<2 )) { + clearTimeout(this._state.timerCaption); + if (!_.isUndefined(title)) { title = '* ' + title; - headerView.setDocumentCaption(headerView.getDocumentCaption() + '*', true); + headerView.setDocumentCaption(headerView.getDocumentCaption(), true); } } else { - headerView.setDocumentCaption(headerView.getDocumentCaption()); + if (this._state.fastCoauth && this._state.usersCount>1) { + this._state.timerCaption = setTimeout(function () { + headerView.setDocumentCaption(headerView.getDocumentCaption(), false); + }, 500); + } else + headerView.setDocumentCaption(headerView.getDocumentCaption(), false); } if (window.document.title != title) window.document.title = title; - if (!this._state.fastCoauth || this._state.usersCount<2 ) { - Common.Gateway.setDocumentModified(isModified); - if (isModified) - this.getApplication().getController('Statusbar').setStatusCaption('', true); - } else if ( this._state.startModifyDocument!==undefined && this._state.startModifyDocument === isModified){ - Common.Gateway.setDocumentModified(isModified); - this._state.startModifyDocument = (this._state.startModifyDocument) ? !this._state.startModifyDocument : undefined; - } + Common.Gateway.setDocumentModified(isModified); + if (isModified && (!this._state.fastCoauth || this._state.usersCount<2)) + this.getApplication().getController('Statusbar').setStatusCaption('', true); this._state.isDocModified = isModified; } }, onDocumentModifiedChanged: function() { - if (this._state.fastCoauth && this._state.usersCount>1 && this._state.startModifyDocument===undefined ) return; - var isModified = this.api.asc_isDocumentCanSave(); if (this._state.isDocModified !== isModified) { Common.Gateway.setDocumentModified(this.api.isDocumentModified()); diff --git a/apps/documenteditor/mobile/app/controller/Main.js b/apps/documenteditor/mobile/app/controller/Main.js index e2aad2dd6..cca0a0c37 100644 --- a/apps/documenteditor/mobile/app/controller/Main.js +++ b/apps/documenteditor/mobile/app/controller/Main.js @@ -79,7 +79,6 @@ define([ isDisconnected : false, usersCount : 1, fastCoauth : true, - startModifyDocument : true, lostEditingRights : false, licenseWarning : false }; @@ -878,21 +877,12 @@ define([ if (window.document.title != title) window.document.title = title; - if (!this._state.fastCoauth || this._state.usersCount<2 ) - Common.Gateway.setDocumentModified(isModified); - else if ( this._state.startModifyDocument!==undefined && this._state.startModifyDocument === isModified){ - Common.Gateway.setDocumentModified(isModified); - this._state.startModifyDocument = (this._state.startModifyDocument) ? !this._state.startModifyDocument : undefined; - } - + Common.Gateway.setDocumentModified(isModified); this._state.isDocModified = isModified; } }, onDocumentModifiedChanged: function() { - if (this._state.fastCoauth && this._state.usersCount > 1 && this._state.startModifyDocument===undefined ) - return; - var isModified = this.api.asc_isDocumentCanSave(); if (this._state.isDocModified !== isModified) { Common.Gateway.setDocumentModified(this.api.isDocumentModified()); diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index 2c3fd5656..8cbebaeb7 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -98,7 +98,7 @@ define([ onLaunch: function() { var me = this; - this._state = {isDisconnected: false, usersCount: 1, fastCoauth: true, startModifyDocument: true, lostEditingRights: false, licenseWarning: false}; + this._state = {isDisconnected: false, usersCount: 1, fastCoauth: true, lostEditingRights: false, licenseWarning: false}; window.storagename = 'presentation'; @@ -1110,25 +1110,26 @@ define([ title = headerView.getDocumentCaption() + ' - ' + title; if (isModified) { - if (!_.isUndefined(title) && (!this._state.fastCoauth || this._state.usersCount<2 )) { + clearTimeout(this._state.timerCaption); + if (!_.isUndefined(title)) { title = '* ' + title; - headerView.setDocumentCaption(headerView.getDocumentCaption() + '*', true); + headerView.setDocumentCaption(headerView.getDocumentCaption(), true); } } else { - headerView.setDocumentCaption(headerView.getDocumentCaption()); + if (this._state.fastCoauth && this._state.usersCount>1) { + this._state.timerCaption = setTimeout(function () { + headerView.setDocumentCaption(headerView.getDocumentCaption(), false); + }, 500); + } else + headerView.setDocumentCaption(headerView.getDocumentCaption(), false); } if (window.document.title != title) window.document.title = title; - if (!this._state.fastCoauth || this._state.usersCount<2 ) { - Common.Gateway.setDocumentModified(isModified); - if (isModified) - this.getApplication().getController('Statusbar').setStatusCaption('', true); - } else if ( this._state.startModifyDocument!==undefined && this._state.startModifyDocument === isModified){ - Common.Gateway.setDocumentModified(isModified); - this._state.startModifyDocument = (this._state.startModifyDocument) ? !this._state.startModifyDocument : undefined; - } + Common.Gateway.setDocumentModified(isModified); + if (isModified && (!this._state.fastCoauth || this._state.usersCount<2)) + this.getApplication().getController('Statusbar').setStatusCaption('', true); this._state.isDocModified = isModified; } @@ -1138,8 +1139,6 @@ define([ }, onDocumentModifiedChanged: function() { - if (this._state.fastCoauth && this._state.usersCount>1 && this._state.startModifyDocument===undefined ) return; - var isModified = this.api.asc_isDocumentCanSave(); if (this._state.isDocModified !== isModified) { Common.Gateway.setDocumentModified(this.api.isDocumentModified()); diff --git a/apps/presentationeditor/mobile/app/controller/Main.js b/apps/presentationeditor/mobile/app/controller/Main.js index fc8405661..78c189a89 100644 --- a/apps/presentationeditor/mobile/app/controller/Main.js +++ b/apps/presentationeditor/mobile/app/controller/Main.js @@ -79,7 +79,6 @@ define([ isDisconnected : false, usersCount : 1, fastCoauth : true, - startModifyDocument : true, lostEditingRights : false, licenseWarning : false }; @@ -829,21 +828,12 @@ define([ if (window.document.title != title) window.document.title = title; - if (!this._state.fastCoauth || this._state.usersCount<2 ) - Common.Gateway.setDocumentModified(isModified); - else if ( this._state.startModifyDocument!==undefined && this._state.startModifyDocument === isModified){ - Common.Gateway.setDocumentModified(isModified); - this._state.startModifyDocument = (this._state.startModifyDocument) ? !this._state.startModifyDocument : undefined; - } - + Common.Gateway.setDocumentModified(isModified); this._state.isDocModified = isModified; } }, onDocumentModifiedChanged: function() { - if (this._state.fastCoauth && this._state.usersCount > 1 && this._state.startModifyDocument===undefined ) - return; - var isModified = this.api.asc_isDocumentCanSave(); if (this._state.isDocModified !== isModified) { Common.Gateway.setDocumentModified(this.api.isDocumentModified()); diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index ceeedded7..6fcaea23a 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -103,7 +103,7 @@ define([ onLaunch: function() { // $(document.body).css('position', 'absolute'); - this._state = {isDisconnected: false, usersCount: 1, fastCoauth: true, startModifyDocument: true, lostEditingRights: false, licenseWarning: false}; + this._state = {isDisconnected: false, usersCount: 1, fastCoauth: true, lostEditingRights: false, licenseWarning: false}; if (!Common.Utils.isBrowserSupported()){ Common.Utils.showBrowserRestriction(); @@ -1271,24 +1271,26 @@ define([ title = this.headerView.getDocumentCaption() + ' - ' + title; if (change) { - if (!_.isUndefined(title) && (!this._state.fastCoauth || this._state.usersCount<2 )) { + clearTimeout(this._state.timerCaption); + if (!_.isUndefined(title)) { title = '* ' + title; - this.headerView.setDocumentCaption(this.headerView.getDocumentCaption() + '*', true); + this.headerView.setDocumentCaption(this.headerView.getDocumentCaption(), true); } } else { - this.headerView.setDocumentCaption(this.headerView.getDocumentCaption()); + if (this._state.fastCoauth && this._state.usersCount>1) { + var me = this; + this._state.timerCaption = setTimeout(function () { + me.headerView.setDocumentCaption(me.headerView.getDocumentCaption(), false); + }, 500); + } else + this.headerView.setDocumentCaption(this.headerView.getDocumentCaption(), false); } if (window.document.title != title) window.document.title = title; - if (!this._state.fastCoauth || this._state.usersCount<2 ) - Common.Gateway.setDocumentModified(change); - else if ( this._state.startModifyDocument!==undefined && this._state.startModifyDocument === change){ - Common.Gateway.setDocumentModified(change); - this._state.startModifyDocument = (this._state.startModifyDocument) ? !this._state.startModifyDocument : undefined; - } - + Common.Gateway.setDocumentModified(change); + this._state.isDocModified = change; } }, @@ -1297,8 +1299,6 @@ define([ }, onDocumentModifiedChanged: function(change) { - if (this._state.fastCoauth && this._state.usersCount>1 && this._state.startModifyDocument===undefined ) return; - this.updateWindowTitle(change); Common.Gateway.setDocumentModified(change); diff --git a/apps/spreadsheeteditor/mobile/app/controller/Main.js b/apps/spreadsheeteditor/mobile/app/controller/Main.js index c7cb45b81..6ce7f72c7 100644 --- a/apps/spreadsheeteditor/mobile/app/controller/Main.js +++ b/apps/spreadsheeteditor/mobile/app/controller/Main.js @@ -80,7 +80,6 @@ define([ isDisconnected : false, usersCount : 1, fastCoauth : true, - startModifyDocument : true, lostEditingRights : false, licenseWarning : false }; @@ -972,21 +971,12 @@ define([ if (window.document.title != title) window.document.title = title; - if (!this._state.fastCoauth || this._state.usersCount<2 ) - Common.Gateway.setDocumentModified(isModified); - else if ( this._state.startModifyDocument!==undefined && this._state.startModifyDocument === isModified){ - Common.Gateway.setDocumentModified(isModified); - this._state.startModifyDocument = (this._state.startModifyDocument) ? !this._state.startModifyDocument : undefined; - } - + Common.Gateway.setDocumentModified(isModified); this._state.isDocModified = isModified; } }, onDocumentModifiedChanged: function() { - if (this._state.fastCoauth && this._state.usersCount > 1 && this._state.startModifyDocument===undefined ) - return; - var isModified = this.api.asc_isDocumentCanSave(); if (this._state.isDocModified !== isModified) { Common.Gateway.setDocumentModified(this.api.asc_isDocumentModified());