Merge pull request #1064 from ONLYOFFICE/feature/download-file-type

Feature/download file type
This commit is contained in:
Julia Radzhabova 2021-08-12 16:01:19 +03:00 committed by GitHub
commit d978dc52e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 64 additions and 37 deletions

View file

@ -203,12 +203,13 @@ if (window.Common === undefined) {
}); });
}, },
requestRestore: function(version, url) { requestRestore: function(version, url, fileType) {
_postMessage({ _postMessage({
event: 'onRequestRestore', event: 'onRequestRestore',
data: { data: {
version: version, version: version,
url: url url: url,
fileType: fileType
} }
}); });
}, },
@ -273,19 +274,23 @@ if (window.Common === undefined) {
_postMessage({ event: 'onOutdatedVersion' }); _postMessage({ event: 'onOutdatedVersion' });
}, },
downloadAs: function(url) { downloadAs: function(url, fileType) {
_postMessage({ _postMessage({
event: 'onDownloadAs', event: 'onDownloadAs',
data: url data: {
url: url,
fileType: fileType
}
}); });
}, },
requestSaveAs: function(url, title) { requestSaveAs: function(url, title, fileType) {
_postMessage({ _postMessage({
event: 'onRequestSaveAs', event: 'onRequestSaveAs',
data: { data: {
url: url, url: url,
title: title title: title,
fileType: fileType
} }
}); });
}, },

View file

@ -92,6 +92,14 @@
str = num.toString(); str = num.toString();
for (var i=str.length; i<digits; i++) strfill += fill; for (var i=str.length; i<digits; i++) strfill += fill;
return strfill + str; return strfill + str;
},
getKeyByValue: function(obj, value) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop)) {
if(obj[prop] === value)
return prop;
}
}
} }
}; };
})(); })();

View file

@ -100,9 +100,10 @@ define([
this.panelHistory.$el.find('#history-list').css('padding-bottom', hasChanges ? '45px' : 0); this.panelHistory.$el.find('#history-list').css('padding-bottom', hasChanges ? '45px' : 0);
}, },
onDownloadUrl: function(url) { onDownloadUrl: function(url, fileType) {
if (this.isFromSelectRevision !== undefined) if (this.isFromSelectRevision !== undefined) {
Common.Gateway.requestRestore(this.isFromSelectRevision, url); Common.Gateway.requestRestore(this.isFromSelectRevision, url, fileType);
}
this.isFromSelectRevision = undefined; this.isFromSelectRevision = undefined;
}, },
@ -111,7 +112,7 @@ define([
var btn = $(e.target); var btn = $(e.target);
if (btn && btn.hasClass('revision-restore')) { if (btn && btn.hasClass('revision-restore')) {
if (record.get('isRevision')) if (record.get('isRevision'))
Common.Gateway.requestRestore(record.get('revision')); Common.Gateway.requestRestore(record.get('revision'), undefined, record.get('fileType'));
else { else {
this.isFromSelectRevision = record.get('revision'); this.isFromSelectRevision = record.get('revision');
var fileType = Asc.c_oAscFileType[(record.get('fileType') || '').toUpperCase()] || Asc.c_oAscFileType.DOCX; var fileType = Asc.c_oAscFileType[(record.get('fileType') || '').toUpperCase()] || Asc.c_oAscFileType.DOCX;
@ -216,6 +217,7 @@ define([
rev.set('docIdPrev', docIdPrev, {silent: true}); rev.set('docIdPrev', docIdPrev, {silent: true});
} }
rev.set('token', token, {silent: true}); rev.set('token', token, {silent: true});
opts.data.fileType && rev.set('fileType', opts.data.fileType, {silent: true});
} }
} }
var hist = new Asc.asc_CVersionHistory(); var hist = new Asc.asc_CVersionHistory();

View file

@ -1072,3 +1072,12 @@ Common.Utils.UserInfoParser = new(function() {
} }
} }
})(); })();
Common.Utils.getKeyByValue = function(obj, value) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop)) {
if(obj[prop] === value)
return prop;
}
}
};

View file

@ -266,8 +266,8 @@ DE.ApplicationController = new(function(){
} }
} }
function onDownloadUrl(url) { function onDownloadUrl(url, fileType) {
Common.Gateway.downloadAs(url); Common.Gateway.downloadAs(url, fileType);
} }
function onPrint() { function onPrint() {

View file

@ -398,7 +398,7 @@ define([
} }
}, },
onDownloadUrl: function(url) { onDownloadUrl: function(url, fileType) {
if (this.isFromFileDownloadAs) { if (this.isFromFileDownloadAs) {
var me = this, var me = this,
defFileName = this.getApplication().getController('Viewport').getView('Common.Views.Header').getDocumentCaption(); defFileName = this.getApplication().getController('Viewport').getView('Common.Views.Header').getDocumentCaption();
@ -411,7 +411,7 @@ define([
} }
if (me.mode.canRequestSaveAs) { if (me.mode.canRequestSaveAs) {
Common.Gateway.requestSaveAs(url, defFileName); Common.Gateway.requestSaveAs(url, defFileName, fileType);
} else { } else {
me._saveCopyDlg = new Common.Views.SaveAsDlg({ me._saveCopyDlg = new Common.Views.SaveAsDlg({
saveFolderUrl: me.mode.saveAsUrl, saveFolderUrl: me.mode.saveAsUrl,

View file

@ -2053,9 +2053,10 @@ define([
}); });
}, },
onDownloadUrl: function(url) { onDownloadUrl: function(url, fileType) {
if (this._state.isFromGatewayDownloadAs) if (this._state.isFromGatewayDownloadAs) {
Common.Gateway.downloadAs(url); Common.Gateway.downloadAs(url, fileType);
}
this._state.isFromGatewayDownloadAs = false; this._state.isFromGatewayDownloadAs = false;
}, },

View file

@ -570,7 +570,7 @@ define([
} }
}, },
onSaveMailMerge: function(url) { onSaveMailMerge: function(url, fileType) {
var loadMask = DE.getController('Main').loadMask; var loadMask = DE.getController('Main').loadMask;
loadMask && loadMask.hide(); loadMask && loadMask.hide();
@ -579,7 +579,7 @@ define([
if (this.cmbMergeTo.getValue() != Asc.c_oAscFileType.HTML) { if (this.cmbMergeTo.getValue() != Asc.c_oAscFileType.HTML) {
var defFileName = me.defFileName + ((this.cmbMergeTo.getValue() == Asc.c_oAscFileType.PDF) ? '.pdf' : '.docx'); var defFileName = me.defFileName + ((this.cmbMergeTo.getValue() == Asc.c_oAscFileType.PDF) ? '.pdf' : '.docx');
if (me.mode.canRequestSaveAs) { if (me.mode.canRequestSaveAs) {
Common.Gateway.requestSaveAs(url, defFileName); Common.Gateway.requestSaveAs(url, defFileName, fileType);
} else { } else {
me._mailMergeDlg = new Common.Views.SaveAsDlg({ me._mailMergeDlg = new Common.Views.SaveAsDlg({
saveFolderUrl: me.mode.mergeFolderUrl, saveFolderUrl: me.mode.mergeFolderUrl,

View file

@ -687,9 +687,9 @@ class MainController extends Component {
} }
} }
onDownloadUrl () { onDownloadUrl (url, fileType) {
if (this._state.isFromGatewayDownloadAs) { if (this._state.isFromGatewayDownloadAs) {
Common.Gateway.downloadAs(url); Common.Gateway.downloadAs(url, fileType);
} }
this._state.isFromGatewayDownloadAs = false; this._state.isFromGatewayDownloadAs = false;

View file

@ -225,8 +225,8 @@ PE.ApplicationController = new(function(){
} }
} }
function onDownloadUrl(url) { function onDownloadUrl(url, fileType) {
Common.Gateway.downloadAs(url); Common.Gateway.downloadAs(url, fileType);
} }
function onPrint() { function onPrint() {

View file

@ -296,7 +296,7 @@ define([
menu.hide(); menu.hide();
}, },
onDownloadUrl: function(url) { onDownloadUrl: function(url, fileType) {
if (this.isFromFileDownloadAs) { if (this.isFromFileDownloadAs) {
var me = this, var me = this,
defFileName = this.getApplication().getController('Viewport').getView('Common.Views.Header').getDocumentCaption(); defFileName = this.getApplication().getController('Viewport').getView('Common.Views.Header').getDocumentCaption();
@ -309,7 +309,7 @@ define([
} }
if (me.mode.canRequestSaveAs) { if (me.mode.canRequestSaveAs) {
Common.Gateway.requestSaveAs(url, defFileName); Common.Gateway.requestSaveAs(url, defFileName, fileType);
} else { } else {
me._saveCopyDlg = new Common.Views.SaveAsDlg({ me._saveCopyDlg = new Common.Views.SaveAsDlg({
saveFolderUrl: me.mode.saveAsUrl, saveFolderUrl: me.mode.saveAsUrl,

View file

@ -1703,9 +1703,10 @@ define([
}); });
}, },
onDownloadUrl: function(url) { onDownloadUrl: function(url, fileType) {
if (this._state.isFromGatewayDownloadAs) if (this._state.isFromGatewayDownloadAs) {
Common.Gateway.downloadAs(url); Common.Gateway.downloadAs(url, fileType);
}
this._state.isFromGatewayDownloadAs = false; this._state.isFromGatewayDownloadAs = false;
}, },

View file

@ -179,8 +179,8 @@ SSE.ApplicationController = new(function(){
setActiveWorkSheet(api.asc_getActiveWorksheetIndex()); setActiveWorkSheet(api.asc_getActiveWorksheetIndex());
} }
function onDownloadUrl(url) { function onDownloadUrl(url, fileType) {
Common.Gateway.downloadAs(url); Common.Gateway.downloadAs(url, fileType);
} }
function onPrint() { function onPrint() {

View file

@ -373,7 +373,7 @@ define([
} }
}, },
onDownloadUrl: function(url) { onDownloadUrl: function(url, fileType) {
if (this.isFromFileDownloadAs) { if (this.isFromFileDownloadAs) {
var me = this, var me = this,
defFileName = this.getApplication().getController('Viewport').getView('Common.Views.Header').getDocumentCaption(); defFileName = this.getApplication().getController('Viewport').getView('Common.Views.Header').getDocumentCaption();
@ -386,7 +386,7 @@ define([
} }
if (me.mode.canRequestSaveAs) { if (me.mode.canRequestSaveAs) {
Common.Gateway.requestSaveAs(url, defFileName); Common.Gateway.requestSaveAs(url, defFileName, fileType);
} else { } else {
me._saveCopyDlg = new Common.Views.SaveAsDlg({ me._saveCopyDlg = new Common.Views.SaveAsDlg({
saveFolderUrl: me.mode.saveAsUrl, saveFolderUrl: me.mode.saveAsUrl,

View file

@ -2010,9 +2010,10 @@ define([
}); });
}, },
onDownloadUrl: function(url) { onDownloadUrl: function(url, fileType) {
if (this._state.isFromGatewayDownloadAs) if (this._state.isFromGatewayDownloadAs) {
Common.Gateway.downloadAs(url); Common.Gateway.downloadAs(url, fileType);
}
this._state.isFromGatewayDownloadAs = false; this._state.isFromGatewayDownloadAs = false;
}, },

View file

@ -650,9 +650,9 @@ class MainController extends Component {
} }
} }
onDownloadUrl () { onDownloadUrl (url, fileType) {
if (this._state.isFromGatewayDownloadAs) { if (this._state.isFromGatewayDownloadAs) {
Common.Gateway.downloadAs(url); Common.Gateway.downloadAs(url, fileType);
} }
this._state.isFromGatewayDownloadAs = false; this._state.isFromGatewayDownloadAs = false;