Skip to content

Commit

Permalink
Merge pull request #2913 from ONLYOFFICE/feature/Bug_67130
Browse files Browse the repository at this point in the history
[DE PE SSE mobile] For Bug 67130
  • Loading branch information
maxkadushkin authored Apr 4, 2024
2 parents d510780 + e278e16 commit 7bc29d2
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 16 deletions.
60 changes: 54 additions & 6 deletions apps/documenteditor/mobile/src/controller/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1094,24 +1094,72 @@ class MainController extends Component {
}
}

onDownloadAs () {
onDownloadAs(format) {
const appOptions = this.props.storeAppOptions;
if ( !appOptions.canDownload && !appOptions.canDownloadOrigin) {

if (!appOptions.canDownload && !appOptions.canDownloadOrigin) {
const { t } = this.props;
const _t = t('Main', {returnObjects:true});
Common.Gateway.reportError(Asc.c_oAscError.ID.AccessDeny, _t.errorAccessDeny);
return;
}

this._state.isFromGatewayDownloadAs = true;

let _format = (format && (typeof format == 'string')) ? Asc.c_oAscFileType[format.toUpperCase()] : null,
_defaultFormat = null,
textParams,
_supported = [
Asc.c_oAscFileType.TXT,
Asc.c_oAscFileType.RTF,
Asc.c_oAscFileType.ODT,
Asc.c_oAscFileType.DOCX,
Asc.c_oAscFileType.HTML,
Asc.c_oAscFileType.DOTX,
Asc.c_oAscFileType.OTT,
Asc.c_oAscFileType.FB2,
Asc.c_oAscFileType.EPUB,
Asc.c_oAscFileType.DOCM,
Asc.c_oAscFileType.JPG,
Asc.c_oAscFileType.PNG
];
const type = /^(?:(pdf|djvu|xps|oxps))$/.exec(this.document.fileType);

let options = new Asc.asc_CDownloadOptions(Asc.c_oAscFileType.DOCX, true);
options.asc_setIsSaveAs(true);
if (type && typeof type[1] === 'string') {
this.api.asc_DownloadOrigin(options);
if (type && typeof type[1] === 'string' && !appOptions.isForm) {
if (!(format && (typeof format == 'string')) || type[1] === format.toLowerCase()) {
const options = new Asc.asc_CDownloadOptions();
options.asc_setIsDownloadEvent(true);
options.asc_setIsSaveAs(true);
this.api.asc_DownloadOrigin(options);
return;
}

if (/^xps|oxps$/.test(this.document.fileType))
_supported = _supported.concat([Asc.c_oAscFileType.PDF, Asc.c_oAscFileType.PDFA]);
else if (/^djvu$/.test(this.document.fileType)) {
_supported = [Asc.c_oAscFileType.PDF];
}

textParams = new AscCommon.asc_CTextParams(Asc.c_oAscTextAssociation.PlainLine);
} else {
_supported = _supported.concat([Asc.c_oAscFileType.PDF, Asc.c_oAscFileType.PDFA]);
_defaultFormat = Asc.c_oAscFileType.DOCX;
}

if (appOptions.canFeatureForms && !/^djvu$/.test(this.document.fileType)) {
_supported = _supported.concat([Asc.c_oAscFileType.DOCXF]);
}
if (!_format || _supported.indexOf(_format) < 0)
_format = _defaultFormat;

const options = new Asc.asc_CDownloadOptions(_format, true);
options.asc_setIsSaveAs(true);

if(_format) {
textParams && options.asc_setTextParams(textParams);
this.api.asc_DownloadAs(options);
} else {
this.api.asc_DownloadOrigin(options);
}
}

Expand Down
40 changes: 36 additions & 4 deletions apps/presentationeditor/mobile/src/controller/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ class MainController extends Component {
storePresentationSettings.addSchemes(arr);
});

this.api.asc_registerCallback('asc_onDownloadUrl', this.onDownloadUrl.bind(this));

EditorUIController.initFocusObjects && EditorUIController.initFocusObjects(this.props.storeFocusObjects);

EditorUIController.initEditorStyles && EditorUIController.initEditorStyles(this.props.storeSlideSettings);
Expand Down Expand Up @@ -955,13 +957,43 @@ class MainController extends Component {
}
}

onDownloadAs () {
if ( !this.props.storeAppOptions.canDownload) {
Common.Gateway.reportError(Asc.c_oAscError.ID.AccessDeny, this.errorAccessDeny);
onDownloadUrl(url, fileType) {
if (this._state.isFromGatewayDownloadAs) {
Common.Gateway.downloadAs(url, fileType);
}

this._state.isFromGatewayDownloadAs = false;
}

onDownloadAs(format) {
const appOptions = this.props.storeAppOptions;

if (!appOptions.canDownload) {
const { t } = this.props;
const _t = t('Controller.Main', { returnObjects:true });
Common.Gateway.reportError(Asc.c_oAscError.ID.AccessDeny, _t.errorAccessDeny);
return;
}

this._state.isFromGatewayDownloadAs = true;
var options = new Asc.asc_CDownloadOptions(Asc.c_oAscFileType.PPTX, true);

let _format = (format && (typeof format == 'string')) ? Asc.c_oAscFileType[format.toUpperCase()] : null,
_supported = [
Asc.c_oAscFileType.PPTX,
Asc.c_oAscFileType.ODP,
Asc.c_oAscFileType.PDF,
Asc.c_oAscFileType.PDFA,
Asc.c_oAscFileType.POTX,
Asc.c_oAscFileType.OTP,
Asc.c_oAscFileType.PPTM,
Asc.c_oAscFileType.PNG,
Asc.c_oAscFileType.JPG
];

if (!_format || _supported.indexOf(_format) < 0)
_format = Asc.c_oAscFileType.PPTX;

const options = new Asc.asc_CDownloadOptions(_format, true);
options.asc_setIsSaveAs(true);
this.api.asc_DownloadAs(options);
}
Expand Down
44 changes: 38 additions & 6 deletions apps/spreadsheeteditor/mobile/src/controller/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ class MainController extends Component {
this.api.asc_registerCallback('asc_onDocumentName', this.onDocumentName.bind(this));
this.api.asc_registerCallback('asc_onEndAction', this._onLongActionEnd.bind(this));

Common.Notifications.on('download:cancel', this.onDownloadCancel.bind(this));

EditorUIController.initCellInfo && EditorUIController.initCellInfo(this.props);

EditorUIController.initEditorStyles && EditorUIController.initEditorStyles(this.props.storeCellSettings);
Expand Down Expand Up @@ -1141,17 +1143,47 @@ class MainController extends Component {
}
}

onDownloadAs () {
if ( this.props.storeAppOptions.canDownload) {
onDownloadCancel() {
this._state.isFromGatewayDownloadAs = false;
}

onDownloadAs(format) {
const appOptions = this.props.storeAppOptions;

if(!appOptions.canDownload) {
const { t } = this.props;
const _t = t('Controller.Main', {returnObjects:true});
const _t = t('Controller.Main', { returnObjects:true });
Common.Gateway.reportError(Asc.c_oAscError.ID.AccessDeny, _t.errorAccessDeny);
return;
}

this._state.isFromGatewayDownloadAs = true;
var options = new Asc.asc_CDownloadOptions(Asc.c_oAscFileType.XLSX, true);
options.asc_setIsSaveAs(true);
this.api.asc_DownloadAs(options);

let _format = (format && (typeof format == 'string')) ? Asc.c_oAscFileType[format.toUpperCase()] : null,
_supported = [
Asc.c_oAscFileType.XLSX,
Asc.c_oAscFileType.ODS,
Asc.c_oAscFileType.CSV,
Asc.c_oAscFileType.PDF,
Asc.c_oAscFileType.PDFA,
Asc.c_oAscFileType.XLTX,
Asc.c_oAscFileType.OTS,
Asc.c_oAscFileType.XLSM,
Asc.c_oAscFileType.XLSB,
Asc.c_oAscFileType.JPG,
Asc.c_oAscFileType.PNG
];

if (!_format || _supported.indexOf(_format) < 0)
_format = Asc.c_oAscFileType.XLSX;

if (_format == Asc.c_oAscFileType.PDF || _format == Asc.c_oAscFileType.PDFA) {
Common.Notifications.trigger('download:settings', this, _format, true);
} else {
const options = new Asc.asc_CDownloadOptions(_format, true);
options.asc_setIsSaveAs(true);
this.api.asc_DownloadAs(options);
}
}

onRequestClose () {
Expand Down

0 comments on commit 7bc29d2

Please sign in to comment.