From 05ce65f5ee269b9dd0ccd093bc0d40360f1389f1 Mon Sep 17 00:00:00 2001 From: Maxim Kadushkin Date: Fri, 21 Jul 2017 17:55:27 +0300 Subject: [PATCH] implemented 'Download As' for 'preview' mode --- .../main/app/controller/Toolbar.js | 28 +++++++++++++++++-- .../main/app/controller/Toolbar.js | 20 +++++++++++-- .../main/app/controller/Toolbar.js | 21 ++++++++++++-- 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Toolbar.js b/apps/documenteditor/main/app/controller/Toolbar.js index e4064fe1f..7d75a3952 100644 --- a/apps/documenteditor/main/app/controller/Toolbar.js +++ b/apps/documenteditor/main/app/controller/Toolbar.js @@ -116,9 +116,31 @@ define([ 'Common.Views.Header': { 'print': this.onPrint.bind(this), 'downloadas': function (opts) { - // this.api.asc_DownloadOrigin(); - console.log('download original'); - }.bind(this), + var _main = this.getApplication().getController('Main'); + var _file_type = _main.document.fileType, + _format; + if ( !!_file_type ) { + if ( /^pdf|xps|djvu/i.test(_file_type) ) { + this.api.asc_DownloadOrigin(); + return; + } else { + _format = Asc.c_oAscFileType[ _file_type.toUpperCase() ]; + } + } + + var _supported = [ + Asc.c_oAscFileType.TXT, + Asc.c_oAscFileType.RTF, + Asc.c_oAscFileType.ODT, + Asc.c_oAscFileType.DOCX, + Asc.c_oAscFileType.HTML + ]; + + if ( !_format || _supported.indexOf(_format) < 0 ) + _format = Asc.c_oAscFileType.PDF; + + _main.api.asc_DownloadAs(_format); + }, 'go:editor': function() { Common.Gateway.requestEditRights(); } diff --git a/apps/presentationeditor/main/app/controller/Toolbar.js b/apps/presentationeditor/main/app/controller/Toolbar.js index 930fc3f24..4fa491458 100644 --- a/apps/presentationeditor/main/app/controller/Toolbar.js +++ b/apps/presentationeditor/main/app/controller/Toolbar.js @@ -127,9 +127,23 @@ define([ 'Common.Views.Header': { 'print': this.onPrint.bind(this), 'downloadas': function (opts) { - // this.api.asc_DownloadOrigin(); - console.log('download original'); - }.bind(this), + var _main = this.getApplication().getController('Main'); + var _file_type = _main.document.fileType, + _format; + if ( !!_file_type ) { + _format = Asc.c_oAscFileType[ _file_type.toUpperCase() ]; + } + + var _supported = [ + Asc.c_oAscFileType.PPTX, + Asc.c_oAscFileType.ODP + ]; + + if ( !_format || _supported.indexOf(_format) < 0 ) + _format = Asc.c_oAscFileType.PDF; + + _main.api.asc_DownloadAs(_format); + }, 'go:editor': function() { Common.Gateway.requestEditRights(); } diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index bc8591d53..e9082ccd3 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -81,9 +81,24 @@ define([ 'Common.Views.Header': { 'print': this.onPrint.bind(this), 'downloadas': function (opts) { - // this.api.asc_DownloadOrigin(); - console.log('download original'); - }.bind(this), + var _main = this.getApplication().getController('Main'); + var _file_type = _main.appOptions.spreadsheet.fileType, + _format; + if ( !!_file_type ) { + _format = Asc.c_oAscFileType[ _file_type.toUpperCase() ]; + } + + var _supported = [ + Asc.c_oAscFileType.XLSX, + Asc.c_oAscFileType.ODS, + Asc.c_oAscFileType.CSV + ]; + + if ( !_format || _supported.indexOf(_format) < 0 ) + _format = Asc.c_oAscFileType.PDF; + + _main.api.asc_DownloadAs(_format); + }, 'go:editor': function() { Common.Gateway.requestEditRights(); }