From a8482985e80bf620ac08947dcf12f4055cea0621 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 22 Aug 2018 11:13:37 +0300 Subject: [PATCH] [DE] Add 'Save Copy As' action to file menu. Bug 23603, Bug 32790 --- .../main/app/controller/LeftMenu.js | 76 ++++++++++++++++++- .../main/app/controller/Main.js | 1 + .../main/app/template/FileMenu.template | 2 + apps/documenteditor/main/app/view/FileMenu.js | 16 +++- .../main/app/view/FileMenuPanels.js | 61 +++++++++++++++ apps/documenteditor/main/locale/en.json | 2 + .../main/resources/less/filemenu.less | 2 +- 7 files changed, 156 insertions(+), 4 deletions(-) diff --git a/apps/documenteditor/main/app/controller/LeftMenu.js b/apps/documenteditor/main/app/controller/LeftMenu.js index 808680d5b..26eba22ed 100644 --- a/apps/documenteditor/main/app/controller/LeftMenu.js +++ b/apps/documenteditor/main/app/controller/LeftMenu.js @@ -44,7 +44,8 @@ define([ 'core', 'common/main/lib/util/Shortcuts', 'documenteditor/main/app/view/LeftMenu', - 'documenteditor/main/app/view/FileMenu' + 'documenteditor/main/app/view/FileMenu', + 'documenteditor/main/app/view/MailMergeSaveDlg' ], function () { 'use strict'; @@ -85,6 +86,7 @@ define([ 'menu:show': _.bind(this.menuFilesShowHide, this, 'show'), 'item:click': _.bind(this.clickMenuFileItem, this), 'saveas:format': _.bind(this.clickSaveAsFormat, this), + 'savecopy:format': _.bind(this.clickSaveCopyAsFormat, this), 'settings:apply': _.bind(this.applySettings, this), 'create:new': _.bind(this.onCreateNew, this), 'recent:open': _.bind(this.onOpenRecent, this) @@ -143,6 +145,7 @@ define([ this.api.asc_registerCallback('asc_onReplaceAll', _.bind(this.onApiTextReplaced, this)); this.api.asc_registerCallback('asc_onCoAuthoringDisconnect', _.bind(this.onApiServerDisconnect, this, true)); Common.NotificationCenter.on('api:disconnect', _.bind(this.onApiServerDisconnect, this)); + this.api.asc_registerCallback('asc_onDownloadUrl', _.bind(this.onDownloadUrl, this)); /** coauthoring begin **/ if (this.mode.canCoAuthoring) { if (this.mode.canChat) @@ -229,6 +232,10 @@ define([ if ( isopts ) close_menu = false; else this.clickSaveAsFormat(undefined); break; + case 'save-copy': + if ( isopts ) close_menu = false; + else this.clickSaveCopyAsFormat(undefined); + break; case 'print': this.api.asc_Print(Common.Utils.isChrome || Common.Utils.isSafari || Common.Utils.isOpera); break; case 'exit': Common.NotificationCenter.trigger('goback'); break; case 'edit': @@ -307,6 +314,70 @@ define([ this.api.asc_DownloadOrigin(); }, + clickSaveCopyAsFormat: function(menu, format, ext) { + if (menu) { + if (format == Asc.c_oAscFileType.TXT || format == Asc.c_oAscFileType.RTF) { + Common.UI.warning({ + closable: false, + title: this.notcriticalErrorTitle, + msg: (format == Asc.c_oAscFileType.TXT) ? this.warnDownloadAs : this.warnDownloadAsRTF, + buttons: ['ok', 'cancel'], + callback: _.bind(function(btn){ + if (btn == 'ok') { + this.isFromFileDownloadAs = ext; + this.api.asc_DownloadAs(format, true); + menu.hide(); + } + }, this) + }); + } else { + this.isFromFileDownloadAs = ext; + this.api.asc_DownloadAs(format, true); + menu.hide(); + } + } else { + this.isFromFileDownloadAs = true; + this.api.asc_DownloadOrigin(true); + } + }, + + onDownloadUrl: function(url) { + if (this.isFromFileDownloadAs) { + var me = this, + defFileName = this.getApplication().getController('Viewport').getView('Common.Views.Header').getDocumentCaption(); + !defFileName && (defFileName = me.txtUntitled); + + if (typeof this.isFromFileDownloadAs == 'string') { + var idx = defFileName.lastIndexOf('.'); + if (idx>0) + defFileName = defFileName.substring(0, idx) + this.isFromFileDownloadAs; + } + + me._saveCopyDlg = new DE.Views.MailMergeSaveDlg({ + mergeFolderUrl: me.mode.saveCopyFolderUrl, + mergedFileUrl: url, + defFileName: defFileName + }); + me._saveCopyDlg.on('mailmergeerror', function(obj, err){ + var config = { + closable: false, + title: this.notcriticalErrorTitle, + msg: err, + iconCls: 'warn', + buttons: ['ok'], + callback: function(btn){ + Common.NotificationCenter.trigger('edit:complete', me); + } + }; + Common.UI.alert(config); + }).on('close', function(obj){ + me._saveCopyDlg = undefined; + }); + me._saveCopyDlg.show(); + } + this.isFromFileDownloadAs = false; + }, + applySettings: function(menu) { var value; @@ -732,6 +803,7 @@ define([ notcriticalErrorTitle: 'Warning', leavePageText: 'All unsaved changes in this document will be lost.
Click \'Cancel\' then \'Save\' to save them. Click \'OK\' to discard all the unsaved changes.', warnDownloadAs : 'If you continue saving in this format all features except the text will be lost.
Are you sure you want to continue?', - warnDownloadAsRTF : 'If you continue saving in this format some of the formatting might be lost.
Are you sure you want to continue?' + warnDownloadAsRTF : 'If you continue saving in this format some of the formatting might be lost.
Are you sure you want to continue?', + txtUntitled: 'Untitled' }, DE.Controllers.LeftMenu || {})); }); \ No newline at end of file diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 5f4075f1f..0edc65ffa 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -305,6 +305,7 @@ define([ this.appOptions.sharingSettingsUrl = this.editorConfig.sharingSettingsUrl; this.appOptions.fileChoiceUrl = this.editorConfig.fileChoiceUrl; this.appOptions.mergeFolderUrl = this.editorConfig.mergeFolderUrl; + this.appOptions.saveCopyFolderUrl = this.editorConfig.saveCopyFolderUrl; this.appOptions.canAnalytics = false; this.appOptions.customization = this.editorConfig.customization; this.appOptions.canBackToFolder = (this.editorConfig.canBackToFolder!==false) && (typeof (this.editorConfig.customization) == 'object') diff --git a/apps/documenteditor/main/app/template/FileMenu.template b/apps/documenteditor/main/app/template/FileMenu.template index 8ec3a1927..35378e635 100644 --- a/apps/documenteditor/main/app/template/FileMenu.template +++ b/apps/documenteditor/main/app/template/FileMenu.template @@ -5,6 +5,7 @@
  • +
  • @@ -25,6 +26,7 @@
    +
    diff --git a/apps/documenteditor/main/app/view/FileMenu.js b/apps/documenteditor/main/app/view/FileMenu.js index ec5073524..dc0ddfb3f 100644 --- a/apps/documenteditor/main/app/view/FileMenu.js +++ b/apps/documenteditor/main/app/view/FileMenu.js @@ -105,6 +105,13 @@ define([ canFocused: false }); + this.miSaveCopyAs = new Common.UI.MenuItem({ + el : $('#fm-btn-save-copy',this.el), + action : 'save-copy', + caption : this.btnSaveCopyAsCaption, + canFocused: false + }); + this.miSaveAs = new Common.UI.MenuItem({ el : $('#fm-btn-save-desktop',this.el), action : 'save-desktop', @@ -179,6 +186,7 @@ define([ this.miSave, this.miEdit, this.miDownload, + this.miSaveCopyAs, this.miSaveAs, this.miPrint, this.miRename, @@ -251,6 +259,7 @@ define([ this.miNew.$el.find('+.devider')[this.mode.canCreateNew?'show':'hide'](); this.miDownload[((this.mode.canDownload || this.mode.canDownloadOrigin) && (!this.mode.isDesktopApp || !this.mode.isOffline))?'show':'hide'](); + this.miSaveCopyAs[((this.mode.canDownload || this.mode.canDownloadOrigin) && (!this.mode.isDesktopApp || !this.mode.isOffline)) && this.mode.saveCopyFolderUrl ?'show':'hide'](); this.miSaveAs[((this.mode.canDownload || this.mode.canDownloadOrigin) && this.mode.isDesktopApp && this.mode.isOffline)?'show':'hide'](); // this.hkSaveAs[this.mode.canDownload?'enable':'disable'](); @@ -295,6 +304,10 @@ define([ } else if (this.mode.canDownloadOrigin) $('a',this.miDownload.$el).text(this.textDownload); + if (this.mode.canDownload && this.mode.saveCopyFolderUrl) { + this.panels['save-copy'] = ((new DE.Views.FileMenuPanels.ViewSaveCopy({menu: this})).render()); + } + if (this.mode.canHelp) { this.panels['help'] = ((new DE.Views.FileMenuPanels.Help({menu: this})).render()); this.panels['help'].setLangConfig(this.mode.lang); @@ -385,6 +398,7 @@ define([ textDownload : 'Download', btnRenameCaption : 'Rename...', btnCloseMenuCaption : 'Close Menu', - btnProtectCaption: 'Protect' + btnProtectCaption: 'Protect', + btnSaveCopyAsCaption : 'Save Copy as...' }, DE.Views.FileMenu || {})); }); diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index 44dd732c1..8bfb0abda 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -107,6 +107,67 @@ define([ } }); + DE.Views.FileMenuPanels.ViewSaveCopy = Common.UI.BaseView.extend({ + el: '#panel-savecopy', + menu: undefined, + + formats: [[ + {name: 'DOCX', imgCls: 'docx', type: Asc.c_oAscFileType.DOCX, ext: '.docx'}, + {name: 'PDF', imgCls: 'pdf', type: Asc.c_oAscFileType.PDF, ext: '.pdf'}, + {name: 'PDFA', imgCls: 'pdfa', type: Asc.c_oAscFileType.PDFA, ext: '.pdf'}, + {name: 'TXT', imgCls: 'txt', type: Asc.c_oAscFileType.TXT, ext: '.txt'} + ],[ +// {name: 'DOC', imgCls: 'doc-format btn-doc', type: Asc.c_oAscFileType.DOC, ext: '.doc'}, + {name: 'ODT', imgCls: 'odt', type: Asc.c_oAscFileType.ODT, ext: '.odt'}, + {name: 'RTF', imgCls: 'rtf', type: Asc.c_oAscFileType.RTF, ext: '.rtf'}, + {name: 'HTML (Zipped)', imgCls: 'html', type: Asc.c_oAscFileType.HTML, ext: '.html'} +// {name: 'EPUB', imgCls: 'doc-format btn-epub', type: Asc.c_oAscFileType.EPUB, ext: '.epub'} + ]], + + + template: _.template([ + '', + '<% _.each(rows, function(row) { %>', + '', + '<% _.each(row, function(item) { %>', + '', + '<% }) %>', + '', + '<% }) %>', + '
    ', + '', + '
    ' + ].join('')), + + initialize: function(options) { + Common.UI.BaseView.prototype.initialize.call(this,arguments); + + this.menu = options.menu; + }, + + render: function() { + $(this.el).html(this.template({rows:this.formats})); + $('.btn-doc-format',this.el).on('click', _.bind(this.onFormatClick,this)); + + if (_.isUndefined(this.scroller)) { + this.scroller = new Common.UI.Scroller({ + el: $(this.el), + suppressScrollX: true + }); + } + + return this; + }, + + onFormatClick: function(e) { + var type = e.currentTarget.attributes['format'], + ext = e.currentTarget.attributes['format-ext']; + if (!_.isUndefined(type) && !_.isUndefined(ext) && this.menu) { + this.menu.fireEvent('savecopy:format', [this.menu, parseInt(type.value), ext.value]); + } + } + }); + DE.Views.FileMenuPanels.Settings = Common.UI.BaseView.extend(_.extend({ el: '#panel-settings', menu: undefined, diff --git a/apps/documenteditor/main/locale/en.json b/apps/documenteditor/main/locale/en.json index 39840748b..b0d237932 100644 --- a/apps/documenteditor/main/locale/en.json +++ b/apps/documenteditor/main/locale/en.json @@ -316,6 +316,7 @@ "DE.Controllers.LeftMenu.textReplaceSuccess": "The search has been done. Occurrences replaced: {0}", "DE.Controllers.LeftMenu.warnDownloadAs": "If you continue saving in this format all features except the text will be lost.
    Are you sure you want to continue?", "DE.Controllers.LeftMenu.warnDownloadAsRTF": "If you continue saving in this format some of the formatting might be lost.
    Are you sure you want to continue?", + "DE.Controllers.LeftMenu.txtUntitled": "Untitled", "DE.Controllers.Main.applyChangesTextText": "Loading the changes...", "DE.Controllers.Main.applyChangesTitleText": "Loading the Changes", "DE.Controllers.Main.convertationTimeoutText": "Conversion timeout exceeded.", @@ -1105,6 +1106,7 @@ "DE.Views.FileMenu.btnSettingsCaption": "Advanced Settings...", "DE.Views.FileMenu.btnToEditCaption": "Edit Document", "DE.Views.FileMenu.textDownload": "Download", + "DE.Views.FileMenu.btnSaveCopyAsCaption": "Save Copy as...", "DE.Views.FileMenuPanels.CreateNew.fromBlankText": "From Blank", "DE.Views.FileMenuPanels.CreateNew.fromTemplateText": "From Template", "DE.Views.FileMenuPanels.CreateNew.newDescriptionText": "Create a new blank text document which you will be able to style and format after it is created during the editing. Or choose one of the templates to start a document of a certain type or purpose where some styles have already been pre-applied.", diff --git a/apps/documenteditor/main/resources/less/filemenu.less b/apps/documenteditor/main/resources/less/filemenu.less index c800db23b..67712c42c 100644 --- a/apps/documenteditor/main/resources/less/filemenu.less +++ b/apps/documenteditor/main/resources/less/filemenu.less @@ -86,7 +86,7 @@ } } -#panel-saveas { +#panel-saveas, #panel-savecopy { table { margin-left: auto; margin-right: auto;