From b33f00e0a76414f517589cdfa224ee8ad3a09cf0 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Mon, 19 Sep 2016 10:41:02 +0300 Subject: [PATCH] [DE] Restore from changes in versions history. --- apps/common/Gateway.js | 5 +++-- apps/common/main/lib/controller/History.js | 14 +++++++++++++- apps/common/main/lib/model/HistoryVersion.js | 3 ++- apps/documenteditor/main/app/controller/Main.js | 9 +++++++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/apps/common/Gateway.js b/apps/common/Gateway.js index b46785fa4..b8dcd4305 100644 --- a/apps/common/Gateway.js +++ b/apps/common/Gateway.js @@ -162,10 +162,11 @@ Common.Gateway = new(function() { }); }, - requestRestore: function(revision) { + requestRestore: function(revision, url) { _postMessage({ event: 'onRequestRestore', - data: revision + data: revision, + url: url }); }, diff --git a/apps/common/main/lib/controller/History.js b/apps/common/main/lib/controller/History.js index ebf163707..52cebac6f 100644 --- a/apps/common/main/lib/controller/History.js +++ b/apps/common/main/lib/controller/History.js @@ -72,6 +72,7 @@ define([ setApi: function(api) { this.api = api; + this.api.asc_registerCallback('asc_onDownloadUrl', _.bind(this.onDownloadUrl, this)); return this; }, @@ -87,11 +88,22 @@ define([ historyView.btnBackToDocument.on('click', _.bind(this.onClickBackToDocument, this)); }, + onDownloadUrl: function(url) { + if (this.isFromSelectRevision !== undefined) + Common.Gateway.requestRestore(this.isFromSelectRevision, url); + this.isFromSelectRevision = undefined; + }, + onSelectRevision: function(picker, item, record, e) { if (e) { var btn = $(e.target); if (btn && btn.hasClass('revision-restore')) { - Common.Gateway.requestRestore(record.get('revision')); + if (record.get('isRevision')) + Common.Gateway.requestRestore(record.get('revision')); + else { + this.isFromSelectRevision = record.get('revision'); + this.api.asc_DownloadAs(Asc.c_oAscFileType.DOCX, true); + } return; } } diff --git a/apps/common/main/lib/model/HistoryVersion.js b/apps/common/main/lib/model/HistoryVersion.js index 2007f459b..dc031eb63 100644 --- a/apps/common/main/lib/model/HistoryVersion.js +++ b/apps/common/main/lib/model/HistoryVersion.js @@ -66,7 +66,8 @@ define([ docIdPrev: '', arrColors: [], // array of user colors for all changes of current version markedAsVersion: false, - canRestore: false + canRestore: false, + isRevision: true } } }); diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 4bf6cbecd..14ed0f1fb 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -324,6 +324,7 @@ define([ }, onDownloadAs: function() { + this._state.isFromGatewayDownloadAs = true; var type = /^(?:(pdf|djvu|xps))$/.exec(this.document.fileType); (type && typeof type[1] === 'string') ? this.api.asc_DownloadOrigin(true) : this.api.asc_DownloadAs(Asc.c_oAscFileType.DOCX, true); }, @@ -443,7 +444,9 @@ define([ created: change.created, docId: version.key, docIdPrev: docIdPrev, - selected: false + selected: false, + canRestore: this.appOptions.canHistoryRestore, + isRevision: false })); arrColors.push(user.get('colorval')); } @@ -1425,7 +1428,9 @@ define([ }, onDownloadUrl: function(url) { - Common.Gateway.downloadAs(url); + if (this._state.isFromGatewayDownloadAs) + Common.Gateway.downloadAs(url); + this._state.isFromGatewayDownloadAs = false; }, onUpdateVersion: function(callback) {