Send file type in events onRequestRestore, onDownloadAs, onRequestSaveAs

This commit is contained in:
Julia Radzhabova 2021-07-30 01:01:33 +03:00
parent 7ddde2c3fa
commit 92bb409c5a
16 changed files with 77 additions and 37 deletions

View file

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

View file

@ -92,6 +92,14 @@
str = num.toString();
for (var i=str.length; i<digits; i++) strfill += fill;
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,11 @@ define([
this.panelHistory.$el.find('#history-list').css('padding-bottom', hasChanges ? '45px' : 0);
},
onDownloadUrl: function(url) {
if (this.isFromSelectRevision !== undefined)
Common.Gateway.requestRestore(this.isFromSelectRevision, url);
onDownloadUrl: function(url, fileType) {
if (this.isFromSelectRevision !== undefined) {
fileType = (Common.Utils.getKeyByValue(Asc.c_oAscFileType, fileType) || '').toLowerCase();
Common.Gateway.requestRestore(this.isFromSelectRevision, url, fileType);
}
this.isFromSelectRevision = undefined;
},
@ -111,7 +113,7 @@ define([
var btn = $(e.target);
if (btn && btn.hasClass('revision-restore')) {
if (record.get('isRevision'))
Common.Gateway.requestRestore(record.get('revision'));
Common.Gateway.requestRestore(record.get('revision'), undefined, record.get('fileType'));
else {
this.isFromSelectRevision = record.get('revision');
var fileType = Asc.c_oAscFileType[(record.get('fileType') || '').toUpperCase()] || Asc.c_oAscFileType.DOCX;
@ -205,6 +207,7 @@ define([
rev.set('docIdPrev', docIdPrev, {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();

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

@ -249,8 +249,9 @@ DE.ApplicationController = new(function(){
}
}
function onDownloadUrl(url) {
Common.Gateway.downloadAs(url);
function onDownloadUrl(url, fileType) {
fileType = (common.utils.getKeyByValue(Asc.c_oAscFileType, fileType) || '').toLowerCase();
Common.Gateway.downloadAs(url, fileType);
}
function onPrint() {

View file

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

View file

@ -2052,9 +2052,11 @@ define([
});
},
onDownloadUrl: function(url) {
if (this._state.isFromGatewayDownloadAs)
Common.Gateway.downloadAs(url);
onDownloadUrl: function(url, fileType) {
if (this._state.isFromGatewayDownloadAs) {
fileType = (Common.Utils.getKeyByValue(Asc.c_oAscFileType, fileType) || '').toLowerCase();
Common.Gateway.downloadAs(url, fileType);
}
this._state.isFromGatewayDownloadAs = false;
},

View file

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

View file

@ -687,9 +687,10 @@ class MainController extends Component {
}
}
onDownloadUrl () {
onDownloadUrl (url, fileType) {
if (this._state.isFromGatewayDownloadAs) {
Common.Gateway.downloadAs(url);
fileType = (Common.Utils.getKeyByValue(Asc.c_oAscFileType, fileType) || '').toLowerCase();
Common.Gateway.downloadAs(url, fileType);
}
this._state.isFromGatewayDownloadAs = false;

View file

@ -225,8 +225,9 @@ PE.ApplicationController = new(function(){
}
}
function onDownloadUrl(url) {
Common.Gateway.downloadAs(url);
function onDownloadUrl(url, fileType) {
fileType = (common.utils.getKeyByValue(Asc.c_oAscFileType, fileType) || '').toLowerCase();
Common.Gateway.downloadAs(url, fileType);
}
function onPrint() {

View file

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

View file

@ -1701,9 +1701,11 @@ define([
});
},
onDownloadUrl: function(url) {
if (this._state.isFromGatewayDownloadAs)
Common.Gateway.downloadAs(url);
onDownloadUrl: function(url, fileType) {
if (this._state.isFromGatewayDownloadAs) {
fileType = (Common.Utils.getKeyByValue(Asc.c_oAscFileType, fileType) || '').toLowerCase();
Common.Gateway.downloadAs(url, fileType);
}
this._state.isFromGatewayDownloadAs = false;
},

View file

@ -179,8 +179,9 @@ SSE.ApplicationController = new(function(){
setActiveWorkSheet(api.asc_getActiveWorksheetIndex());
}
function onDownloadUrl(url) {
Common.Gateway.downloadAs(url);
function onDownloadUrl(url, fileType) {
fileType = (common.utils.getKeyByValue(Asc.c_oAscFileType, fileType) || '').toLowerCase();
Common.Gateway.downloadAs(url, fileType);
}
function onPrint() {

View file

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

View file

@ -1993,9 +1993,11 @@ define([
});
},
onDownloadUrl: function(url) {
if (this._state.isFromGatewayDownloadAs)
Common.Gateway.downloadAs(url);
onDownloadUrl: function(url, fileType) {
if (this._state.isFromGatewayDownloadAs) {
fileType = (Common.Utils.getKeyByValue(Asc.c_oAscFileType, fileType) || '').toLowerCase();
Common.Gateway.downloadAs(url, fileType);
}
this._state.isFromGatewayDownloadAs = false;
},

View file

@ -636,9 +636,10 @@ class MainController extends Component {
}
}
onDownloadUrl () {
onDownloadUrl (url, fileType) {
if (this._state.isFromGatewayDownloadAs) {
Common.Gateway.downloadAs(url);
fileType = (Common.Utils.getKeyByValue(Asc.c_oAscFileType, fileType) || '').toLowerCase();
Common.Gateway.downloadAs(url, fileType);
}
this._state.isFromGatewayDownloadAs = false;