From c0fea1c230ebf21cf777843cd98d6b0fdcb674a1 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 21 Oct 2022 23:22:16 +0300 Subject: [PATCH 01/45] [DE] Add print preview panel --- apps/documenteditor/main/app.js | 2 + .../main/app/controller/Main.js | 4 + .../main/app/controller/Print.js | 436 ++++++++++++++++++ .../main/app/template/FileMenu.template | 3 +- apps/documenteditor/main/app/view/FileMenu.js | 16 +- .../main/app/view/FileMenuPanels.js | 335 ++++++++++++++ apps/documenteditor/main/app_dev.js | 2 + .../main/resources/less/filemenu.less | 109 ++++- 8 files changed, 900 insertions(+), 7 deletions(-) create mode 100644 apps/documenteditor/main/app/controller/Print.js diff --git a/apps/documenteditor/main/app.js b/apps/documenteditor/main/app.js index 190281919..289356861 100644 --- a/apps/documenteditor/main/app.js +++ b/apps/documenteditor/main/app.js @@ -157,6 +157,7 @@ require([ 'Main', 'ViewTab', 'Search', + 'Print', 'Common.Controllers.Fonts', 'Common.Controllers.History' /** coauthoring begin **/ @@ -191,6 +192,7 @@ require([ 'documenteditor/main/app/controller/Main', 'documenteditor/main/app/controller/ViewTab', 'documenteditor/main/app/controller/Search', + 'documenteditor/main/app/controller/Print', 'documenteditor/main/app/view/FileMenuPanels', 'documenteditor/main/app/view/ParagraphSettings', 'documenteditor/main/app/view/HeaderFooterSettings', diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 99971b70b..81a158e7e 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -1663,6 +1663,9 @@ define([ toolbarController.setMode(this.appOptions); documentHolder.setMode(this.appOptions); + var printController = app.getController('Print'); + printController && this.api && printController.setApi(this.api).setMode(this.appOptions); + this.api.asc_registerCallback('asc_onSendThemeColors', _.bind(this.onSendThemeColors, this)); this.api.asc_registerCallback('asc_onDownloadUrl', _.bind(this.onDownloadUrl, this)); this.api.asc_registerCallback('asc_onAuthParticipantsChanged', _.bind(this.onAuthParticipantsChanged, this)); @@ -2460,6 +2463,7 @@ define([ this.api.asc_SetDocumentUnits((value==Common.Utils.Metric.c_MetricUnits.inch) ? Asc.c_oAscDocumentUnits.Inch : ((value==Common.Utils.Metric.c_MetricUnits.pt) ? Asc.c_oAscDocumentUnits.Point : Asc.c_oAscDocumentUnits.Millimeter)); this.getApplication().getController('RightMenu').updateMetricUnit(); this.getApplication().getController('Toolbar').getView().updateMetricUnit(); + this.getApplication().getController('Print').getView('PrintWithPreview').updateMetricUnit(); }, onAdvancedOptions: function(type, advOptions, mode, formatOptions) { diff --git a/apps/documenteditor/main/app/controller/Print.js b/apps/documenteditor/main/app/controller/Print.js new file mode 100644 index 000000000..08cf44427 --- /dev/null +++ b/apps/documenteditor/main/app/controller/Print.js @@ -0,0 +1,436 @@ +/* + * + * (c) Copyright Ascensio System SIA 2010-2022 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * +*/ +define([ + 'core', + 'documenteditor/main/app/view/FileMenuPanels' +], function () { + 'use strict'; + + DE.Controllers.Print = Backbone.Controller.extend(_.extend({ + views: [ + 'PrintWithPreview' + ], + + initialize: function() { + var value = Common.localStorage.getItem("de-print-settings-range"); + value = (value!==null) ? parseInt(value) : Asc.c_oAscPrintType.ActiveSheets; + this._currentPrintType = value; + + this.adjPrintParams = new Asc.asc_CAdjustPrint(); + this.adjPrintParams.asc_setPrintType(value); + // fill page numbers, copies, collated from local storage + + this._state = {}; + + this._navigationPreview = { + pageCount: false, + currentPage: 0, + currentPreviewPage: 0 + }; + + this._isPreviewVisible = false; + + this.addListeners({ + 'PrintWithPreview': { + 'show': _.bind(this.onShowMainSettingsPrint, this), + 'render:after': _.bind(this.onAfterRender, this) + } + }); + }, + + onLaunch: function() { + this.printSettings = this.createView('PrintWithPreview'); + }, + + onAfterRender: function(view) { + var me = this; + this.printSettings.menu.on('menu:hide', _.bind(this.onHidePrintMenu, this)); + // this.printSettings.btnPrint.on('click', _.bind(me.onBtnPrint, me)); + // this.printSettings.btnPrintPdf.on('click', _.bind(me.onBtnPrintPdf, me)); + this.printSettings.btnPrevPage.on('click', _.bind(this.onChangePreviewPage, this, false)); + this.printSettings.btnNextPage.on('click', _.bind(this.onChangePreviewPage, this, true)); + this.printSettings.txtNumberPage.on({ + 'keypress:after': _.bind(this.onKeypressPageNumber, this), + 'keyup:after': _.bind(this.onKeyupPageNumber, this) + }); + this.printSettings.txtNumberPage.cmpEl.find('input').on('blur', _.bind(this.onBlurPageNumber, this)); + this.printSettings.cmbPaperSize.on('selected', _.bind(this.onPaperSizeSelect, this)); + this.printSettings.cmbPaperOrientation.on('selected', _.bind(this.onPaperOrientSelect, this)); + this.printSettings.cmbPaperMargins.on('selected', _.bind(this.onPaperMarginsSelect, this)); + this.printSettings.cmbRange.on('selected', _.bind(this.comboRangeChange, this)); + + Common.NotificationCenter.on('window:resize', _.bind(function () { + if (this._isPreviewVisible) { + this.api.asc_drawPrintPreview(this._navigationPreview.currentPreviewPage); + } + }, this)); + + var eventname = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel'; + this.printSettings.$previewBox.on(eventname, _.bind(this.onPreviewWheel, this)); + }, + + setMode: function (mode) { + this.mode = mode; + this.printSettings && this.printSettings.setMode(mode); + }, + + setApi: function(o) { + this.api = o; + this.api.asc_registerCallback('asc_onDocSize', _.bind(this.onApiPageSize, this)); + this.api.asc_registerCallback('asc_onPageOrient', _.bind(this.onApiPageOrient, this)); + this.api.asc_registerCallback('asc_onSectionProps', _.bind(this.onSectionProps, this)); + this.api.asc_registerCallback('asc_onCountPages', _.bind(this.onCountPages, this)); + this.api.asc_registerCallback('asc_onCurrentPage', _.bind(this.onCurrentPage, this)); + + return this; + }, + + onApiPageSize: function(w, h) { + this._state.pgsize = [w, h]; + if (this.printSettings.isVisible()) { + var width = this._state.pgorient ? w : h, + height = this._state.pgorient ? h : w; + var panel = this.printSettings; + var store = panel.cmbPaperSize.store, + item = null; + for (var i=0; i count - 1) { + this._navigationPreview.currentPreviewPage = Math.max(0, count - 1); + if (this.printSettings.isVisible()) { + this.api.asc_drawPrintPreview(this._navigationPreview.currentPreviewPage); + this.updateNavigationButtons(this._navigationPreview.currentPreviewPage, count); + } + } + }, + + onCurrentPage: function(number) { + this._navigationPreview.currentPreviewPage = number; + if (this.printSettings.isVisible()) { + this.api.asc_drawPrintPreview(this._navigationPreview.currentPreviewPage); + this.updateNavigationButtons(this._navigationPreview.currentPreviewPage, this._navigationPreview.pageCount); + } + }, + + onShowMainSettingsPrint: function() { + var me = this; + this.printSettings.$previewBox.removeClass('hidden'); + + this.onApiPageSize(this._state.pgsize[0], this._state.pgsize[1]); + this.onApiPageOrient(this._state.pgorient); + this.onSectionProps(this._state.sectionprops); + + this.fillPrintOptions(this.adjPrintParams); + + var opts = new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86); + opts.asc_setAdvancedOptions(this.adjPrintParams); + + this._navigationPreview.currentPreviewPage = this._navigationPreview.currentPage = this.api.getCurrentPage(); + this.api.asc_drawPrintPreview(this._navigationPreview.currentPreviewPage); + this.updateNavigationButtons(this._navigationPreview.currentPreviewPage, this._navigationPreview.pageCount); + }, + + onPaperSizeSelect: function(combo, record) { + this._state.pgsize = [0, 0]; + if (record.value !== -1) { + if (this.checkPageSize(record.size[0], record.size[1])) { + var section = this.api.asc_GetSectionProps(); + this.onApiPageSize(section.get_W(), section.get_H()); + return; + } else + this.api.change_DocSize(record.size[0], record.size[1]); + } else { + var win, props, + me = this; + win = new DE.Views.PageSizeDialog({ + checkPageSize: _.bind(this.checkPageSize, this), + handler: function(dlg, result) { + if (result == 'ok') { + props = dlg.getSettings(); + me.api.change_DocSize(props[0], props[1]); + Common.NotificationCenter.trigger('edit:complete'); + } + } + }); + win.show(); + win.setSettings(me.api.asc_GetSectionProps()); + } + + Common.NotificationCenter.trigger('edit:complete'); + }, + + onPaperMarginsSelect: function(combo, record) { + this._state.pgmargins = undefined; + if (record.value !== -1) { + if (this.checkPageSize(undefined, undefined, record.size[1], record.size[3], record.size[0], record.size[2])) { + this.onSectionProps(this.api.asc_GetSectionProps()); + return; + } else { + var props = new Asc.CDocumentSectionProps(); + props.put_TopMargin(record.size[0]); + props.put_LeftMargin(record.size[1]); + props.put_BottomMargin(record.size[2]); + props.put_RightMargin(record.size[3]); + this.api.asc_SetSectionProps(props); + } + } else { + var win, props, + me = this; + win = new DE.Views.PageMarginsDialog({ + api: me.api, + handler: function(dlg, result) { + if (result == 'ok') { + // props = dlg.getSettings(); + // var mnu = me.toolbar.btnPageMargins.menu.items[0]; + // mnu.setVisible(true); + // mnu.setChecked(true); + // mnu.options.value = mnu.value = [props.get_TopMargin(), props.get_LeftMargin(), props.get_BottomMargin(), props.get_RightMargin()]; + // $(mnu.el).html(mnu.template({id: Common.UI.getId(), caption : mnu.caption, options : mnu.options})); + Common.localStorage.setItem("de-pgmargins-top", props.get_TopMargin()); + Common.localStorage.setItem("de-pgmargins-left", props.get_LeftMargin()); + Common.localStorage.setItem("de-pgmargins-bottom", props.get_BottomMargin()); + Common.localStorage.setItem("de-pgmargins-right", props.get_RightMargin()); + + me.api.asc_SetSectionProps(props); + Common.NotificationCenter.trigger('edit:complete'); + } + } + }); + win.show(); + win.setSettings(me.api.asc_GetSectionProps()); + } + + Common.NotificationCenter.trigger('edit:complete'); + }, + + onPaperOrientSelect: function(combo, record) { + this._state.pgorient = undefined; + if (this.api && item.checked) { + this.api.change_PageOrient(record.value === Asc.c_oAscPageOrientation.PagePortrait); + } + + Common.NotificationCenter.trigger('edit:complete'); + }, + + checkPageSize: function(width, height, left, right, top, bottom) { + var section = this.api.asc_GetSectionProps(); + (width===undefined) && (width = parseFloat(section.get_W().toFixed(4))); + (height===undefined) && (height = parseFloat(section.get_H().toFixed(4))); + (left===undefined) && (left = parseFloat(section.get_LeftMargin().toFixed(4))); + (right===undefined) && (right = parseFloat(section.get_RightMargin().toFixed(4))); + (top===undefined) && (top = parseFloat(section.get_TopMargin().toFixed(4))); + (bottom===undefined) && (bottom = parseFloat(section.get_BottomMargin().toFixed(4))); + var gutterLeft = section.get_GutterAtTop() ? 0 : parseFloat(section.get_Gutter().toFixed(4)), + gutterTop = section.get_GutterAtTop() ? parseFloat(section.get_Gutter().toFixed(4)) : 0; + + var errmsg = null; + if (left + right + gutterLeft > width-12.7 ) + errmsg = this.txtMarginsW; + else if (top + bottom + gutterTop > height-2.6 ) + errmsg = this.txtMarginsH; + if (errmsg) { + Common.UI.warning({ + title: this.notcriticalErrorTitle, + msg : errmsg, + callback: function() { + Common.NotificationCenter.trigger('edit:complete'); + } + }); + return true; + } + }, + + getPrintParams: function() { + return this.adjPrintParams; + }, + + onHidePrintMenu: function () { + if (this._isPreviewVisible) { + this.api.asc_closePrintPreview(this._isPrint); + this._isPreviewVisible = false; + } + }, + + onChangePreviewPage: function (next) { + var index = this._navigationPreview.currentPreviewPage; + if (next) { + index++; + index = Math.min(index, this._navigationPreview.pageCount - 1); + } else { + index--; + index = Math.max(index, 0); + } + this.api.goToPage(index); + }, + + onKeypressPageNumber: function (input, e) { + if (e.keyCode === Common.UI.Keys.RETURN) { + var box = this.printSettings.$el.find('#print-number-page'), + edit = box.find('input[type=text]'), page = parseInt(edit.val()); + if (!page || page > this._navigationPreview.pageCount || page < 0) { + edit.select(); + this.printSettings.txtNumberPage.setValue(this._navigationPreview.currentPreviewPage + 1); + this.printSettings.txtNumberPage.checkValidate(); + return false; + } + + box.focus(); // for IE + + this.api.goToPage(page-1); + this.api.asc_enableKeyEvents(true); + return false; + } + }, + + onKeyupPageNumber: function (input, e) { + if (e.keyCode === Common.UI.Keys.ESC) { + var box = this.printSettings.$el.find('#print-number-page'); + box.focus(); // for IE + this.api.asc_enableKeyEvents(true); + return false; + } + }, + + onBlurPageNumber: function () { + if (this.printSettings.txtNumberPage.getValue() != this._navigationPreview.currentPreviewPage + 1) { + this.printSettings.txtNumberPage.setValue(this._navigationPreview.currentPreviewPage + 1); + this.printSettings.txtNumberPage.checkValidate(); + } + }, + + onPreviewWheel: function (e) { + if (e.ctrlKey) { + e.preventDefault(); + e.stopImmediatePropagation(); + } + var forward = (e.deltaY || (e.detail && -e.detail) || e.wheelDelta) < 0; + this.onChangePreviewPage(forward); + }, + + updateNavigationButtons: function (page, count) { + this._navigationPreview.currentPage = page; + this.printSettings.updateCurrentPage(page); + this._navigationPreview.pageCount = count; + this.printSettings.updateCountOfPages(count); + this.disableNavButtons(); + }, + + disableNavButtons: function (force) { + if (force) { + this.printSettings.btnPrevPage.setDisabled(true); + this.printSettings.btnNextPage.setDisabled(true); + return; + } + var curPage = this._navigationPreview.currentPage, + pageCount = this._navigationPreview.pageCount; + this.printSettings.btnPrevPage.setDisabled(curPage < 1); + this.printSettings.btnNextPage.setDisabled(curPage > pageCount - 2); + }, + + textWarning: 'Warning', + txtCustom: 'Custom' + }, DE.Controllers.Print || {})); +}); \ No newline at end of file diff --git a/apps/documenteditor/main/app/template/FileMenu.template b/apps/documenteditor/main/app/template/FileMenu.template index 3ad620221..8071eaded 100644 --- a/apps/documenteditor/main/app/template/FileMenu.template +++ b/apps/documenteditor/main/app/template/FileMenu.template @@ -7,7 +7,7 @@
  • -
  • +
  • @@ -34,4 +34,5 @@
    +
    \ No newline at end of file diff --git a/apps/documenteditor/main/app/view/FileMenu.js b/apps/documenteditor/main/app/view/FileMenu.js index 8bf3fdb57..87ae3fef5 100644 --- a/apps/documenteditor/main/app/view/FileMenu.js +++ b/apps/documenteditor/main/app/view/FileMenu.js @@ -158,9 +158,9 @@ define([ dataHintOffset: [2, 14] }); - this.miPrint = new Common.UI.MenuItem({ - el : $markup.elementById('#fm-btn-print'), - action : 'print', + this.miPrintWithPreview = new Common.UI.MenuItem({ + el : $markup.elementById('#fm-btn-print-with-preview'), + action : 'printpreview', caption : this.btnPrintCaption, canFocused: false, dataHint: 1, @@ -291,7 +291,7 @@ define([ this.miDownload, this.miSaveCopyAs, this.miSaveAs, - this.miPrint, + this.miPrintWithPreview, this.miRename, this.miProtect, this.miRecent, @@ -381,7 +381,7 @@ define([ this.miSaveAs[((this.mode.canDownload || this.mode.canDownloadOrigin) && this.mode.isDesktopApp && this.mode.isOffline)?'show':'hide'](); this.miSave[this.mode.isEdit && Common.UI.LayoutManager.isElementVisible('toolbar-file-save') ?'show':'hide'](); this.miEdit[!this.mode.isEdit && this.mode.canEdit && this.mode.canRequestEditRights ?'show':'hide'](); - this.miPrint[this.mode.canPrint?'show':'hide'](); + this.miPrintWithPreview[this.mode.canPrint?'show':'hide'](); this.miRename[(this.mode.canRename && !this.mode.isDesktopApp) ?'show':'hide'](); this.miProtect[this.mode.canProtect ?'show':'hide'](); separatorVisible = (this.mode.canDownload || this.mode.canDownloadOrigin || this.mode.isEdit && Common.UI.LayoutManager.isElementVisible('toolbar-file-save') || this.mode.canPrint || this.mode.canProtect || @@ -463,6 +463,12 @@ define([ this.panels['help'].setLangConfig(this.mode.lang); } + if (this.mode.canPrint) { + var printPanel = DE.getController('Print').getView('PrintWithPreview'); + printPanel.menu = this; + !this.panels['printpreview'] && (this.panels['printpreview'] = printPanel.render(this.$el.find('#panel-print'))); + } + if ( Common.Controllers.Desktop.isActive() ) { $('
  • ').insertAfter($('#fm-btn-recent', this.$el)); this.items.push( diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index 23e81759b..d9949a3db 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -2329,4 +2329,339 @@ define([ }, DE.Views.FileMenuPanels.ProtectDoc || {})); + DE.Views.PrintWithPreview = Common.UI.BaseView.extend(_.extend({ + el: '#panel-print', + menu: undefined, + + template: _.template([ + '
    ', + '
    ', + '', + '
    ', + '', + '
    ' + ].join('')), + + initialize: function(options) { + Common.UI.BaseView.prototype.initialize.call(this,arguments); + + this.menu = options.menu; + + this._initSettings = true; + }, + + render: function(node) { + var me = this; + + var $markup = $(this.template({scope: this})); + + this.cmbRange = new Common.UI.ComboBox({ + el: $markup.findById('#print-combo-range'), + menuStyle: 'min-width: 248px;max-height: 280px;', + editable: false, + takeFocusOnClose: true, + cls: 'input-group-nr', + data: [ + { value: Asc.c_oAscPrintType.EntireWorkbook, displayValue: this.txtAllPages }, + { value: Asc.c_oAscPrintType.ActiveSheets, displayValue: this.txtCurrentPage }, + { value: Asc.c_oAscPrintType.Selection, displayValue: this.txtSelection }, + { value: -1, displayValue: this.txtCustomPages } + ], + dataHint: '2', + dataHintDirection: 'bottom', + dataHintOffset: 'big' + }); + + this.txtPages = new Common.UI.InputField({ + el: $markup.findById('#print-txt-pages'), + allowBlank: true, + validateOnChange: true, + style: 'width: 150px;', + maskExp: /[0-9]/, + dataHint: '2', + dataHintDirection: 'left', + dataHintOffset: 'small' + }); + + this.cmbPaperSize = new Common.UI.ComboBox({ + el: $markup.findById('#print-combo-pages'), + menuStyle: 'max-height: 280px; min-width: 248px;', + editable: false, + takeFocusOnClose: true, + cls: 'input-group-nr', + data: [ + { value: 0, displayValue:'US Letter (21,59cm x 27,94cm)', caption: 'US Letter', size: [215.9, 279.4]}, + { value: 1, displayValue:'US Legal (21,59cm x 35,56cm)', caption: 'US Legal', size: [215.9, 355.6]}, + { value: 2, displayValue:'A4 (21cm x 29,7cm)', caption: 'A4', size: [210, 297]}, + { value: 3, displayValue:'A5 (14,8cm x 21cm)', caption: 'A5', size: [148, 210]}, + { value: 4, displayValue:'B5 (17,6cm x 25cm)', caption: 'B5', size: [176, 250]}, + { value: 5, displayValue:'Envelope #10 (10,48cm x 24,13cm)', caption: 'Envelope #10', size: [104.8, 241.3]}, + { value: 6, displayValue:'Envelope DL (11cm x 22cm)', caption: 'Envelope DL', size: [110, 220]}, + { value: 7, displayValue:'Tabloid (27,94cm x 43,18cm)', caption: 'Tabloid', size: [279.4, 431.8]}, + { value: 8, displayValue:'A3 (29,7cm x 42cm)', caption: 'A3', size: [297, 420]}, + { value: 9, displayValue:'Tabloid Oversize (30,48cm x 45,71cm)', caption: 'Tabloid Oversize', size: [304.8, 457.1]}, + { value: 10, displayValue:'ROC 16K (19,68cm x 27,3cm)', caption: 'ROC 16K', size: [196.8, 273]}, + { value: 11, displayValue:'Envelope Choukei 3 (11,99cm x 23,49cm)', caption: 'Envelope Choukei 3', size: [119.9, 234.9]}, + { value: 12, displayValue:'Super B/A3 (33,02cm x 48,25cm)', caption: 'Super B/A3', size: [330.2, 482.5]}, + { value: 13, displayValue:'A4 (84,1cm x 118,9cm)', caption: 'A0', size: [841, 1189]}, + { value: 14, displayValue:'A4 (59,4cm x 84,1cm)', caption: 'A1', size: [594, 841]}, + { value: 16, displayValue:'A4 (42cm x 59,4cm)', caption: 'A2', size: [420, 594]}, + { value: 17, displayValue:'A4 (10,5cm x 14,8cm)', caption: 'A6', size: [105, 148]}, + { value: -1, displayValue: this.txtCustom, caption: this.txtCustom, size: []} + ], + dataHint: '2', + dataHintDirection: 'bottom', + dataHintOffset: 'big' + }); + + this.cmbPaperOrientation = new Common.UI.ComboBox({ + el : $markup.findById('#print-combo-orient'), + menuStyle : 'min-width: 150px;', + editable : false, + takeFocusOnClose: true, + cls : 'input-group-nr', + data : [ + { value: Asc.c_oAscPageOrientation.PagePortrait, displayValue: this.txtPortrait }, + { value: Asc.c_oAscPageOrientation.PageLandscape, displayValue: this.txtLandscape } + ], + dataHint: '2', + dataHintDirection: 'bottom', + dataHintOffset: 'big' + }); + + this.cmbPaperMargins = new Common.UI.ComboBox({ + el: $markup.findById('#print-combo-margins'), + menuStyle: 'max-height: 280px; min-width: 248px;', + editable: false, + takeFocusOnClose: true, + cls: 'input-group-nr', + data: [ + { value: 0, displayValue: this.textMarginsNormal, size: [20, 30, 20, 15]}, + { value: 1, displayValue: this.textMarginsUsNormal, size: [25.4, 25.4, 25.4, 25.4]}, + { value: 2, displayValue: this.textMarginsNarrow, size: [12.7, 12.7, 12.7, 12.7]}, + { value: 3, displayValue: this.textMarginsModerate, size: [25.4, 19.1, 25.4, 19.1]}, + { value: 4, displayValue: this.textMarginsWide, size: [25.4, 50.8, 25.4, 50.8]}, + { value: -1, displayValue: this.txtCustom, size: null} + ], + itemsTemplate: _.template([ + '<% _.each(items, function(item) { %>', + '
  • ', + '
    <%= scope.getDisplayValue(item) %>
    ', + '<% if (item.size !== null) { %>
    ' + + '' + + '
    ' + + '' + + '
    ' + + '<% } %>', + '<% }); %>' + ].join('')), + dataHint: '2', + dataHintDirection: 'bottom', + dataHintOffset: 'big' + }); + + this.pnlSettings = $markup.find('.flex-settings').addBack().filter('.flex-settings'); + this.pnlTable = $(this.pnlSettings.find('table')[0]); + this.trApply = $markup.find('.fms-btn-apply'); + + this.btnPrint = new Common.UI.Button({ + el: $markup.findById('#print-btn-print') + }); + this.btnPrintPdf = new Common.UI.Button({ + el: $markup.findById('#print-btn-print-pdf') + }); + + this.btnPrevPage = new Common.UI.Button({ + parentEl: $markup.findById('#print-prev-page'), + cls: 'btn-prev-page', + iconCls: 'arrow', + dataHint: '2', + dataHintDirection: 'top' + }); + + this.btnNextPage = new Common.UI.Button({ + parentEl: $markup.findById('#print-next-page'), + cls: 'btn-next-page', + iconCls: 'arrow', + dataHint: '2', + dataHintDirection: 'top' + }); + + this.countOfPages = $markup.findById('#print-count-page'); + + this.txtNumberPage = new Common.UI.InputField({ + el: $markup.findById('#print-number-page'), + allowBlank: true, + validateOnChange: true, + style: 'width: 50px;', + maskExp: /[0-9]/, + validation: function(value) { + if (/(^[0-9]+$)/.test(value)) { + value = parseInt(value); + if (undefined !== value && value > 0 && value <= me.pageCount) + return true; + } + + return me.txtPageNumInvalid; + }, + dataHint: '2', + dataHintDirection: 'left', + dataHintOffset: 'small' + }); + + this.$el = $(node).html($markup); + this.$previewBox = $('#print-preview-box'); + + if (_.isUndefined(this.scroller)) { + this.scroller = new Common.UI.Scroller({ + el: this.pnlSettings, + suppressScrollX: true, + alwaysVisibleY: true + }); + } + + Common.NotificationCenter.on({ + 'window:resize': function() { + me.isVisible() && me.updateScroller(); + } + }); + + this.updateMetricUnit(); + + this.fireEvent('render:after', this); + + return this; + }, + + show: function() { + Common.UI.BaseView.prototype.show.call(this,arguments); + if (this._initSettings) { + this.updateMetricUnit(); + this._initSettings = false; + } + this.updateScroller(); + this.fireEvent('show', this); + }, + + updateScroller: function() { + if (this.scroller) { + Common.UI.Menu.Manager.hideAll(); + var scrolled = this.$el.height()< this.pnlTable.height(); + this.pnlSettings.css('overflow', scrolled ? 'hidden' : 'visible'); + this.scroller.update(); + } + }, + + setMode: function(mode) { + this.mode = mode; + }, + + setApi: function(api) { + + }, + + updateMetricUnit: function() { + var store = this.cmbPaperSize.store; + for (var i=0; i Date: Mon, 24 Oct 2022 14:16:34 +0300 Subject: [PATCH 02/45] [DE] Init preview div --- apps/documenteditor/main/app/controller/Print.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/documenteditor/main/app/controller/Print.js b/apps/documenteditor/main/app/controller/Print.js index 08cf44427..6c3b7df7a 100644 --- a/apps/documenteditor/main/app/controller/Print.js +++ b/apps/documenteditor/main/app/controller/Print.js @@ -227,6 +227,7 @@ define([ var opts = new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86); opts.asc_setAdvancedOptions(this.adjPrintParams); + this.api.asc_initPrintPreview('print-preview', opts); this._navigationPreview.currentPreviewPage = this._navigationPreview.currentPage = this.api.getCurrentPage(); this.api.asc_drawPrintPreview(this._navigationPreview.currentPreviewPage); From d8600b8a2ac680b7dd93c9a215161c0423dc58c9 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Mon, 24 Oct 2022 19:02:05 +0300 Subject: [PATCH 03/45] [DE] Refactoring print preview, hide preview for mac os --- .../main/app/controller/LeftMenu.js | 8 ++++++++ apps/documenteditor/main/app/controller/Main.js | 5 ++--- .../documenteditor/main/app/controller/Print.js | 17 +++++++++++++++-- .../main/app/controller/Toolbar.js | 4 +--- .../main/app/template/FileMenu.template | 1 + apps/documenteditor/main/app/view/FileMenu.js | 17 +++++++++++++++-- 6 files changed, 42 insertions(+), 10 deletions(-) diff --git a/apps/documenteditor/main/app/controller/LeftMenu.js b/apps/documenteditor/main/app/controller/LeftMenu.js index 41a64ae92..077d7b4a5 100644 --- a/apps/documenteditor/main/app/controller/LeftMenu.js +++ b/apps/documenteditor/main/app/controller/LeftMenu.js @@ -113,6 +113,7 @@ define([ if ( !this.leftMenu.panelHistory.isVisible() ) this.clickMenuFileItem(null, 'history'); }, this)); + Common.NotificationCenter.on('file:print', _.bind(this.clickToolbarPrint, this)); }, onLaunch: function() { @@ -549,6 +550,13 @@ define([ this.leftMenu.menuFile.hide(); }, + clickToolbarPrint: function () { + if (this.mode.canPreviewPrint) + this.leftMenu.showMenu('file:printpreview'); + else if (this.mode.canPrint) + this.clickMenuFileItem(null, 'print'); + }, + changeToolbarSaveState: function (state) { var btnSave = this.leftMenu.menuFile.getButton('save'); btnSave && btnSave.setDisabled(state); diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 81a158e7e..31b233d18 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -1494,6 +1494,7 @@ define([ } this.appOptions.canEditStyles = this.appOptions.canLicense && this.appOptions.canEdit; this.appOptions.canPrint = (this.permissions.print !== false); + this.appOptions.canPreviewPrint = this.appOptions.canPrint && !Common.Utils.isMac; this.appOptions.canRename = this.editorConfig.canRename; this.appOptions.buildVersion = params.asc_getBuildVersion(); this.appOptions.canForcesave = this.appOptions.isEdit && !this.appOptions.isOffline && (typeof (this.editorConfig.customization) == 'object' && !!this.editorConfig.customization.forcesave); @@ -2618,9 +2619,7 @@ define([ onPrint: function() { if (!this.appOptions.canPrint || Common.Utils.ModalWindow.isVisible()) return; - - if (this.api) - this.api.asc_Print(new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86)); // if isChrome or isOpera == true use asc_onPrintUrl event + Common.NotificationCenter.trigger('file:print'); Common.component.Analytics.trackEvent('Print'); }, diff --git a/apps/documenteditor/main/app/controller/Print.js b/apps/documenteditor/main/app/controller/Print.js index 6c3b7df7a..7bb6c26f4 100644 --- a/apps/documenteditor/main/app/controller/Print.js +++ b/apps/documenteditor/main/app/controller/Print.js @@ -75,8 +75,8 @@ define([ onAfterRender: function(view) { var me = this; this.printSettings.menu.on('menu:hide', _.bind(this.onHidePrintMenu, this)); - // this.printSettings.btnPrint.on('click', _.bind(me.onBtnPrint, me)); - // this.printSettings.btnPrintPdf.on('click', _.bind(me.onBtnPrintPdf, me)); + this.printSettings.btnPrint.on('click', _.bind(this.onBtnPrint, this, true)); + this.printSettings.btnPrintPdf.on('click', _.bind(this.onBtnPrint, this, false)); this.printSettings.btnPrevPage.on('click', _.bind(this.onChangePreviewPage, this, false)); this.printSettings.btnNextPage.on('click', _.bind(this.onChangePreviewPage, this, true)); this.printSettings.txtNumberPage.on({ @@ -431,6 +431,19 @@ define([ this.printSettings.btnNextPage.setDisabled(curPage > pageCount - 2); }, + onBtnPrint: function(print) { + if ( print ) { + var opts = new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86); + opts.asc_setAdvancedOptions(this.adjPrintParams); + this.api.asc_Print(opts); + } else { + var opts = new Asc.asc_CDownloadOptions(Asc.c_oAscFileType.PDF); + opts.asc_setAdvancedOptions(this.adjPrintParams); + this.api.asc_DownloadAs(opts); + } + this.printSettings.menu.hide(); + }, + textWarning: 'Warning', txtCustom: 'Custom' }, DE.Controllers.Print || {})); diff --git a/apps/documenteditor/main/app/controller/Toolbar.js b/apps/documenteditor/main/app/controller/Toolbar.js index 6812ef505..95ed26c66 100644 --- a/apps/documenteditor/main/app/controller/Toolbar.js +++ b/apps/documenteditor/main/app/controller/Toolbar.js @@ -1057,9 +1057,7 @@ define([ }, onPrint: function(e) { - if (this.api) - this.api.asc_Print(new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86)); // if isChrome or isOpera == true use asc_onPrintUrl event - + Common.NotificationCenter.trigger('file:print', this.toolbar); Common.NotificationCenter.trigger('edit:complete', this.toolbar); Common.component.Analytics.trackEvent('Print'); diff --git a/apps/documenteditor/main/app/template/FileMenu.template b/apps/documenteditor/main/app/template/FileMenu.template index 8071eaded..ba1e7d69d 100644 --- a/apps/documenteditor/main/app/template/FileMenu.template +++ b/apps/documenteditor/main/app/template/FileMenu.template @@ -7,6 +7,7 @@
  • +
  • diff --git a/apps/documenteditor/main/app/view/FileMenu.js b/apps/documenteditor/main/app/view/FileMenu.js index 87ae3fef5..7e5454e14 100644 --- a/apps/documenteditor/main/app/view/FileMenu.js +++ b/apps/documenteditor/main/app/view/FileMenu.js @@ -169,6 +169,17 @@ define([ dataHintTitle: 'P' }); + this.miPrint = new Common.UI.MenuItem({ + el : $markup.elementById('#fm-btn-print'), + action : 'print', + caption : this.btnPrintCaption, + canFocused: false, + dataHint: 1, + dataHintDirection: 'left-top', + dataHintOffset: [2, 14], + dataHintTitle: 'P' + }); + this.miRename = new Common.UI.MenuItem({ el : $markup.elementById('#fm-btn-rename'), action : 'rename', @@ -291,6 +302,7 @@ define([ this.miDownload, this.miSaveCopyAs, this.miSaveAs, + this.miPrint, this.miPrintWithPreview, this.miRename, this.miProtect, @@ -381,7 +393,8 @@ define([ this.miSaveAs[((this.mode.canDownload || this.mode.canDownloadOrigin) && this.mode.isDesktopApp && this.mode.isOffline)?'show':'hide'](); this.miSave[this.mode.isEdit && Common.UI.LayoutManager.isElementVisible('toolbar-file-save') ?'show':'hide'](); this.miEdit[!this.mode.isEdit && this.mode.canEdit && this.mode.canRequestEditRights ?'show':'hide'](); - this.miPrintWithPreview[this.mode.canPrint?'show':'hide'](); + this.miPrint[this.mode.canPrint && !this.mode.canPreviewPrint ?'show':'hide'](); + this.miPrintWithPreview[this.mode.canPreviewPrint?'show':'hide'](); this.miRename[(this.mode.canRename && !this.mode.isDesktopApp) ?'show':'hide'](); this.miProtect[this.mode.canProtect ?'show':'hide'](); separatorVisible = (this.mode.canDownload || this.mode.canDownloadOrigin || this.mode.isEdit && Common.UI.LayoutManager.isElementVisible('toolbar-file-save') || this.mode.canPrint || this.mode.canProtect || @@ -463,7 +476,7 @@ define([ this.panels['help'].setLangConfig(this.mode.lang); } - if (this.mode.canPrint) { + if (this.mode.canPreviewPrint) { var printPanel = DE.getController('Print').getView('PrintWithPreview'); printPanel.menu = this; !this.panels['printpreview'] && (this.panels['printpreview'] = printPanel.render(this.$el.find('#panel-print'))); From 0020e55ea088a200d8936cfcdce21539a3ca62fd Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 25 Oct 2022 21:40:16 +0300 Subject: [PATCH 04/45] [DE] Fix pages numbers for printing --- .../main/app/controller/Print.js | 69 ++++++++++++++++--- .../main/app/view/FileMenuPanels.js | 10 +-- 2 files changed, 66 insertions(+), 13 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Print.js b/apps/documenteditor/main/app/controller/Print.js index 7bb6c26f4..948ba6e08 100644 --- a/apps/documenteditor/main/app/controller/Print.js +++ b/apps/documenteditor/main/app/controller/Print.js @@ -44,11 +44,9 @@ define([ initialize: function() { var value = Common.localStorage.getItem("de-print-settings-range"); value = (value!==null) ? parseInt(value) : Asc.c_oAscPrintType.ActiveSheets; - this._currentPrintType = value; this.adjPrintParams = new Asc.asc_CAdjustPrint(); this.adjPrintParams.asc_setPrintType(value); - // fill page numbers, copies, collated from local storage this._state = {}; @@ -88,6 +86,43 @@ define([ this.printSettings.cmbPaperOrientation.on('selected', _.bind(this.onPaperOrientSelect, this)); this.printSettings.cmbPaperMargins.on('selected', _.bind(this.onPaperMarginsSelect, this)); this.printSettings.cmbRange.on('selected', _.bind(this.comboRangeChange, this)); + this.printSettings.txtPages.on('changing', _.bind(this.txtPagesChanging, this)); + this.printSettings.txtPages.validation = function(value) { + if (!_.isEmpty(value) && /[0-9,\-]/.test(value)) { + var res = [], + arr = value.split(','); + for (var i=0; i1) // more than 1 symbol '-' + return me.txtPrintRangeInvalid; + if (!str) {// one number + var num = parseInt(item)-1; + (num>=0) && res.push(num); + } else { // range + var pages = item.split('-'), + start = (pages[0] ? parseInt(pages[0])-1 : 0), + end = (pages[1] ? parseInt(pages[1])-1 : me._navigationPreview.pageCount-1); + if (start>end) { + var num = start; + start = end; + end = num; + } + for (var j=start; j<=end; j++) { + (j>=0) && res.push(j); + } + } + } + if (res.length>0) { + // me.adjPrintParams.asc_setPages(res); + return true; + } + } + + return me.txtPrintRangeInvalid; + }; Common.NotificationCenter.on('window:resize', _.bind(function () { if (this._isPreviewVisible) { @@ -97,6 +132,8 @@ define([ var eventname = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel'; this.printSettings.$previewBox.on(eventname, _.bind(this.onPreviewWheel, this)); + + this.fillPrintOptions(); }, setMode: function (mode) { @@ -184,14 +221,18 @@ define([ // fill page numbers, copies, collated var panel = this.printSettings; panel.cmbRange.setValue(this.adjPrintParams.asc_getPrintType()); - panel.txtPages.setValue(); // pages numbers + panel.txtPages.setValue(''); // pages numbers }, comboRangeChange: function(combo, record) { if (record.value === -1) { - // set page numbers - // this.printSettings.txtNumberPage.setValue(); + var me = this; + setTimeout(function(){ + me.printSettings.txtPages.focus(); + }, 50); + // this.adjPrintParams.asc_setPrintType(record.value) } else { + this.printSettings.txtPages.setValue(''); this.adjPrintParams.asc_setPrintType(record.value) } }, @@ -223,8 +264,6 @@ define([ this.onApiPageOrient(this._state.pgorient); this.onSectionProps(this._state.sectionprops); - this.fillPrintOptions(this.adjPrintParams); - var opts = new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86); opts.asc_setAdvancedOptions(this.adjPrintParams); this.api.asc_initPrintPreview('print-preview', opts); @@ -432,6 +471,12 @@ define([ }, onBtnPrint: function(print) { + if (this.printSettings.txtPages.checkValidate() !== true) { + this.printSettings.txtPages.focus(); + return; + } + + if ( print ) { var opts = new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86); opts.asc_setAdvancedOptions(this.adjPrintParams); @@ -444,7 +489,15 @@ define([ this.printSettings.menu.hide(); }, + txtPagesChanging: function (input, value) { + if (value.length<1) + this.printSettings.cmbRange.setValue(Asc.c_oAscPrintType.EntireWorkbook); + else if (this.printSettings.cmbRange.getValue()!==-1) + this.printSettings.cmbRange.setValue(-1); + }, + textWarning: 'Warning', - txtCustom: 'Custom' + txtCustom: 'Custom', + txtPrintRangeInvalid: 'Invalid print range' }, DE.Controllers.Print || {})); }); \ No newline at end of file diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index d9949a3db..8ec0aadaf 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -2343,8 +2343,9 @@ define([ '', '', '', - '', - '', + '', + '', + '
    <%= scope.txtPages %>
    ', '', '', '', @@ -2400,7 +2401,6 @@ define([ data: [ { value: Asc.c_oAscPrintType.EntireWorkbook, displayValue: this.txtAllPages }, { value: Asc.c_oAscPrintType.ActiveSheets, displayValue: this.txtCurrentPage }, - { value: Asc.c_oAscPrintType.Selection, displayValue: this.txtSelection }, { value: -1, displayValue: this.txtCustomPages } ], dataHint: '2', @@ -2412,8 +2412,8 @@ define([ el: $markup.findById('#print-txt-pages'), allowBlank: true, validateOnChange: true, - style: 'width: 150px;', - maskExp: /[0-9]/, + validateOnBlur: false, + maskExp: /[0-9,\-]/, dataHint: '2', dataHintDirection: 'left', dataHintOffset: 'small' From e0c8c84c725103054eb996dee32e39fb968a3ec2 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 25 Oct 2022 23:56:46 +0300 Subject: [PATCH 05/45] [DE] Refactoring custom margins --- .../main/app/controller/DocumentHolder.js | 6 +--- .../main/app/controller/Print.js | 31 ++++++++++++++----- .../main/app/controller/Toolbar.js | 6 +--- apps/documenteditor/main/app/view/Toolbar.js | 29 ++++++++++------- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/apps/documenteditor/main/app/controller/DocumentHolder.js b/apps/documenteditor/main/app/controller/DocumentHolder.js index 9aa1bd3f6..0189f139f 100644 --- a/apps/documenteditor/main/app/controller/DocumentHolder.js +++ b/apps/documenteditor/main/app/controller/DocumentHolder.js @@ -1249,15 +1249,11 @@ define([ handler: function(dlg, result) { if (result == 'ok') { var props = dlg.getSettings(); - var mnu = DE.getController('Toolbar').toolbar.btnPageMargins.menu.items[0]; - mnu.setVisible(true); - mnu.setChecked(true); - mnu.options.value = mnu.value = [props.get_TopMargin(), props.get_LeftMargin(), props.get_BottomMargin(), props.get_RightMargin()]; - $(mnu.el).html(mnu.template({id: Common.UI.getId(), caption : mnu.caption, options : mnu.options})); Common.localStorage.setItem("de-pgmargins-top", props.get_TopMargin()); Common.localStorage.setItem("de-pgmargins-left", props.get_LeftMargin()); Common.localStorage.setItem("de-pgmargins-bottom", props.get_BottomMargin()); Common.localStorage.setItem("de-pgmargins-right", props.get_RightMargin()); + Common.NotificationCenter.trigger('margins:update', props); me.api.asc_SetSectionProps(props); me.editComplete(); diff --git a/apps/documenteditor/main/app/controller/Print.js b/apps/documenteditor/main/app/controller/Print.js index 948ba6e08..bfbf7176c 100644 --- a/apps/documenteditor/main/app/controller/Print.js +++ b/apps/documenteditor/main/app/controller/Print.js @@ -129,6 +129,7 @@ define([ this.api.asc_drawPrintPreview(this._navigationPreview.currentPreviewPage); } }, this)); + Common.NotificationCenter.on('margins:update', _.bind(this.onUpdateLastCustomMargins, this)); var eventname = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel'; this.printSettings.$previewBox.on(eventname, _.bind(this.onPreviewWheel, this)); @@ -260,6 +261,7 @@ define([ var me = this; this.printSettings.$previewBox.removeClass('hidden'); + this.onUpdateLastCustomMargins(this._state.lastmargins); this.onApiPageSize(this._state.pgsize[0], this._state.pgsize[1]); this.onApiPageOrient(this._state.pgorient); this.onSectionProps(this._state.sectionprops); @@ -323,16 +325,12 @@ define([ api: me.api, handler: function(dlg, result) { if (result == 'ok') { - // props = dlg.getSettings(); - // var mnu = me.toolbar.btnPageMargins.menu.items[0]; - // mnu.setVisible(true); - // mnu.setChecked(true); - // mnu.options.value = mnu.value = [props.get_TopMargin(), props.get_LeftMargin(), props.get_BottomMargin(), props.get_RightMargin()]; - // $(mnu.el).html(mnu.template({id: Common.UI.getId(), caption : mnu.caption, options : mnu.options})); + props = dlg.getSettings(); Common.localStorage.setItem("de-pgmargins-top", props.get_TopMargin()); Common.localStorage.setItem("de-pgmargins-left", props.get_LeftMargin()); Common.localStorage.setItem("de-pgmargins-bottom", props.get_BottomMargin()); Common.localStorage.setItem("de-pgmargins-right", props.get_RightMargin()); + Common.NotificationCenter.trigger('margins:update', props); me.api.asc_SetSectionProps(props); Common.NotificationCenter.trigger('edit:complete'); @@ -346,6 +344,24 @@ define([ Common.NotificationCenter.trigger('edit:complete'); }, + onUpdateLastCustomMargins: function(props) { + this._state.lastmargins = props; + if (this.printSettings.isVisible()) { + var top = props ? props.get_TopMargin() : Common.localStorage.getItem("de-pgmargins-top"), + left = props ? props.get_LeftMargin() : Common.localStorage.getItem("de-pgmargins-left"), + bottom = props ? props.get_BottomMargin() : Common.localStorage.getItem("de-pgmargins-bottom"), + right = props ? props.get_RightMargin() : Common.localStorage.getItem("de-pgmargins-right"); + if ( top!==null && left!==null && bottom!==null && right!==null ) { + var rec = this.printSettings.cmbPaperMargins.store.at(0); + if (rec.get('value')===-2) + rec.set('size', [parseFloat(top), parseFloat(left), parseFloat(bottom), parseFloat(right)]); + else + this.printSettings.cmbPaperMargins.store.unshift({ value: -2, displayValue: this.textMarginsLast, size: [parseFloat(top), parseFloat(left), parseFloat(bottom), parseFloat(right)]}); + this.printSettings.cmbPaperMargins.onResetItems(); + } + } + }, + onPaperOrientSelect: function(combo, record) { this._state.pgorient = undefined; if (this.api && item.checked) { @@ -498,6 +514,7 @@ define([ textWarning: 'Warning', txtCustom: 'Custom', - txtPrintRangeInvalid: 'Invalid print range' + txtPrintRangeInvalid: 'Invalid print range', + textMarginsLast: 'Last Custom' }, DE.Controllers.Print || {})); }); \ No newline at end of file diff --git a/apps/documenteditor/main/app/controller/Toolbar.js b/apps/documenteditor/main/app/controller/Toolbar.js index 95ed26c66..3edfc217d 100644 --- a/apps/documenteditor/main/app/controller/Toolbar.js +++ b/apps/documenteditor/main/app/controller/Toolbar.js @@ -1746,15 +1746,11 @@ define([ handler: function(dlg, result) { if (result == 'ok') { props = dlg.getSettings(); - var mnu = me.toolbar.btnPageMargins.menu.items[0]; - mnu.setVisible(true); - mnu.setChecked(true); - mnu.options.value = mnu.value = [props.get_TopMargin(), props.get_LeftMargin(), props.get_BottomMargin(), props.get_RightMargin()]; - $(mnu.el).html(mnu.template({id: Common.UI.getId(), caption : mnu.caption, options : mnu.options})); Common.localStorage.setItem("de-pgmargins-top", props.get_TopMargin()); Common.localStorage.setItem("de-pgmargins-left", props.get_LeftMargin()); Common.localStorage.setItem("de-pgmargins-bottom", props.get_BottomMargin()); Common.localStorage.setItem("de-pgmargins-right", props.get_RightMargin()); + Common.NotificationCenter.trigger('margins:update', props); me.api.asc_SetSectionProps(props); Common.NotificationCenter.trigger('edit:complete', me.toolbar); diff --git a/apps/documenteditor/main/app/view/Toolbar.js b/apps/documenteditor/main/app/view/Toolbar.js index d495b0f92..7017370ce 100644 --- a/apps/documenteditor/main/app/view/Toolbar.js +++ b/apps/documenteditor/main/app/view/Toolbar.js @@ -1628,17 +1628,8 @@ define([ me.setTab('home'); - var top = Common.localStorage.getItem("de-pgmargins-top"), - left = Common.localStorage.getItem("de-pgmargins-left"), - bottom = Common.localStorage.getItem("de-pgmargins-bottom"), - right = Common.localStorage.getItem("de-pgmargins-right"); - if ( top!==null && left!==null && bottom!==null && right!==null ) { - var mnu = this.btnPageMargins.menu.items[0]; - mnu.options.value = mnu.value = [parseFloat(top), parseFloat(left), parseFloat(bottom), parseFloat(right)]; - mnu.setVisible(true); - $(mnu.el).html(mnu.template({id: Common.UI.getId(), caption : mnu.caption, options : mnu.options})); - } else - this.btnPageMargins.menu.items[0].setVisible(false); + me.onUpdateLastCustomMargins(); + Common.NotificationCenter.on('margins:update', _.bind(me.onUpdateLastCustomMargins, me)); } if ( me.isCompactView ) @@ -2643,6 +2634,22 @@ define([ this.api.asc_RemoveAllCustomStyles(); }, + onUpdateLastCustomMargins: function(props) { + if (!this.btnPageMargins) return; + + var top = props ? props.get_TopMargin() : Common.localStorage.getItem("de-pgmargins-top"), + left = props ? props.get_LeftMargin() : Common.localStorage.getItem("de-pgmargins-left"), + bottom = props ? props.get_BottomMargin() : Common.localStorage.getItem("de-pgmargins-bottom"), + right = props ? props.get_RightMargin() : Common.localStorage.getItem("de-pgmargins-right"); + if ( top!==null && left!==null && bottom!==null && right!==null ) { + var mnu = this.btnPageMargins.menu.items[0]; + mnu.options.value = mnu.value = [parseFloat(top), parseFloat(left), parseFloat(bottom), parseFloat(right)]; + mnu.setVisible(true); + $(mnu.el).html(mnu.template({id: Common.UI.getId(), caption : mnu.caption, options : mnu.options})); + } else + this.btnPageMargins.menu.items[0].setVisible(false); + }, + lockToolbar: function (causes, lock, opts) { Common.Utils.lockControls(causes, lock, opts, this.lockControls); }, From 3dffb8a7ba449f2aaf1aaafcaeae54c44a4591fe Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 26 Oct 2022 00:22:23 +0300 Subject: [PATCH 06/45] [DE] Fix print preview --- .../main/app/controller/Print.js | 23 +++++++++++-------- .../main/app/view/FileMenuPanels.js | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Print.js b/apps/documenteditor/main/app/controller/Print.js index bfbf7176c..e56279ebf 100644 --- a/apps/documenteditor/main/app/controller/Print.js +++ b/apps/documenteditor/main/app/controller/Print.js @@ -86,8 +86,8 @@ define([ this.printSettings.cmbPaperOrientation.on('selected', _.bind(this.onPaperOrientSelect, this)); this.printSettings.cmbPaperMargins.on('selected', _.bind(this.onPaperMarginsSelect, this)); this.printSettings.cmbRange.on('selected', _.bind(this.comboRangeChange, this)); - this.printSettings.txtPages.on('changing', _.bind(this.txtPagesChanging, this)); - this.printSettings.txtPages.validation = function(value) { + this.printSettings.inputPages.on('changing', _.bind(this.inputPagesChanging, this)); + this.printSettings.inputPages.validation = function(value) { if (!_.isEmpty(value) && /[0-9,\-]/.test(value)) { var res = [], arr = value.split(','); @@ -222,20 +222,21 @@ define([ // fill page numbers, copies, collated var panel = this.printSettings; panel.cmbRange.setValue(this.adjPrintParams.asc_getPrintType()); - panel.txtPages.setValue(''); // pages numbers + panel.inputPages.setValue(''); // pages numbers }, comboRangeChange: function(combo, record) { if (record.value === -1) { var me = this; setTimeout(function(){ - me.printSettings.txtPages.focus(); + me.printSettings.inputPages.focus(); }, 50); // this.adjPrintParams.asc_setPrintType(record.value) } else { - this.printSettings.txtPages.setValue(''); + this.printSettings.inputPages.setValue(''); this.adjPrintParams.asc_setPrintType(record.value) } + this.printSettings.inputPages.showError(); }, onCountPages: function(count) { @@ -364,7 +365,7 @@ define([ onPaperOrientSelect: function(combo, record) { this._state.pgorient = undefined; - if (this.api && item.checked) { + if (this.api) { this.api.change_PageOrient(record.value === Asc.c_oAscPageOrientation.PagePortrait); } @@ -487,8 +488,9 @@ define([ }, onBtnPrint: function(print) { - if (this.printSettings.txtPages.checkValidate() !== true) { - this.printSettings.txtPages.focus(); + if (this.printSettings.cmbRange.getValue()===-1 && this.printSettings.inputPages.checkValidate() !== true) { + this.printSettings.inputPages.focus(); + this.isInputFirstChange = true; return; } @@ -505,7 +507,10 @@ define([ this.printSettings.menu.hide(); }, - txtPagesChanging: function (input, value) { + inputPagesChanging: function (input, value) { + this.isInputFirstChange && this.printSettings.inputPages.showError(); + this.isInputFirstChange = false; + if (value.length<1) this.printSettings.cmbRange.setValue(Asc.c_oAscPrintType.EntireWorkbook); else if (this.printSettings.cmbRange.getValue()!==-1) diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index 8ec0aadaf..469243261 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -2408,7 +2408,7 @@ define([ dataHintOffset: 'big' }); - this.txtPages = new Common.UI.InputField({ + this.inputPages = new Common.UI.InputField({ el: $markup.findById('#print-txt-pages'), allowBlank: true, validateOnChange: true, From 591cf88d5ef83a63af7bf4f46e22ff262bc56162 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 26 Oct 2022 22:13:10 +0300 Subject: [PATCH 07/45] [DE] Disable page settings in print preview --- .../main/app/controller/Print.js | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Print.js b/apps/documenteditor/main/app/controller/Print.js index e56279ebf..31fb75b58 100644 --- a/apps/documenteditor/main/app/controller/Print.js +++ b/apps/documenteditor/main/app/controller/Print.js @@ -48,7 +48,9 @@ define([ this.adjPrintParams = new Asc.asc_CAdjustPrint(); this.adjPrintParams.asc_setPrintType(value); - this._state = {}; + this._state = { + lock_doc: false + }; this._navigationPreview = { pageCount: false, @@ -149,6 +151,8 @@ define([ this.api.asc_registerCallback('asc_onSectionProps', _.bind(this.onSectionProps, this)); this.api.asc_registerCallback('asc_onCountPages', _.bind(this.onCountPages, this)); this.api.asc_registerCallback('asc_onCurrentPage', _.bind(this.onCurrentPage, this)); + this.api.asc_registerCallback('asc_onLockDocumentProps', _.bind(this.onApiLockDocumentProps, this)); + this.api.asc_registerCallback('asc_onUnLockDocumentProps', _.bind(this.onApiUnLockDocumentProps, this)); return this; }, @@ -182,14 +186,16 @@ define([ }, onApiPageOrient: function(isportrait) { - this._state.pgorient = isportrait; + this._state.pgorient = !!isportrait; if (this.printSettings.isVisible()) { - var item = this.printSettings.cmbPaperOrientation.store.findWhere({value: isportrait ? Asc.c_oAscPageOrientation.PagePortrait : Asc.c_oAscPageOrientation.PageLandscape}); + var item = this.printSettings.cmbPaperOrientation.store.findWhere({value: this._state.pgorient ? Asc.c_oAscPageOrientation.PagePortrait : Asc.c_oAscPageOrientation.PageLandscape}); if (item) this.printSettings.cmbPaperOrientation.setValue(item.get('value')); } }, onSectionProps: function(props) { + if (!props) return; + this._state.sectionprops = props; if (this.printSettings.isVisible()) { var left = props.get_LeftMargin(), @@ -263,9 +269,9 @@ define([ this.printSettings.$previewBox.removeClass('hidden'); this.onUpdateLastCustomMargins(this._state.lastmargins); - this.onApiPageSize(this._state.pgsize[0], this._state.pgsize[1]); + this._state.pgsize && this.onApiPageSize(this._state.pgsize[0], this._state.pgsize[1]); this.onApiPageOrient(this._state.pgorient); - this.onSectionProps(this._state.sectionprops); + this._state.sectionprops && this.onSectionProps(this._state.sectionprops); var opts = new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86); opts.asc_setAdvancedOptions(this.adjPrintParams); @@ -274,6 +280,7 @@ define([ this._navigationPreview.currentPreviewPage = this._navigationPreview.currentPage = this.api.getCurrentPage(); this.api.asc_drawPrintPreview(this._navigationPreview.currentPreviewPage); this.updateNavigationButtons(this._navigationPreview.currentPreviewPage, this._navigationPreview.pageCount); + this.SetDisabled(); }, onPaperSizeSelect: function(combo, record) { @@ -517,6 +524,25 @@ define([ this.printSettings.cmbRange.setValue(-1); }, + onApiLockDocumentProps: function() { + this._state.lock_doc = true; + this.SetDisabled(); + }, + + onApiUnLockDocumentProps: function() { + this._state.lock_doc = false; + this.SetDisabled(); + }, + + SetDisabled: function() { + if (this.printSettings.isVisible()) { + var disable = !this.mode.isEdit || this._state.lock_doc; + this.printSettings.cmbPaperSize.setDisabled(disable); + this.printSettings.cmbPaperMargins.setDisabled(disable); + this.printSettings.cmbPaperOrientation.setDisabled(disable); + } + }, + textWarning: 'Warning', txtCustom: 'Custom', txtPrintRangeInvalid: 'Invalid print range', From d4aed51fdf98838039cc867baf3966b0152b4442 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 27 Oct 2022 15:29:06 +0300 Subject: [PATCH 08/45] [DE] Print preview refactoring --- apps/documenteditor/main/app/controller/Print.js | 7 ++++--- apps/documenteditor/main/app/view/FileMenuPanels.js | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Print.js b/apps/documenteditor/main/app/controller/Print.js index 31fb75b58..d92d4e893 100644 --- a/apps/documenteditor/main/app/controller/Print.js +++ b/apps/documenteditor/main/app/controller/Print.js @@ -281,6 +281,7 @@ define([ this.api.asc_drawPrintPreview(this._navigationPreview.currentPreviewPage); this.updateNavigationButtons(this._navigationPreview.currentPreviewPage, this._navigationPreview.pageCount); this.SetDisabled(); + this._isPreviewVisible = true; }, onPaperSizeSelect: function(combo, record) { @@ -413,7 +414,7 @@ define([ onHidePrintMenu: function () { if (this._isPreviewVisible) { - this.api.asc_closePrintPreview(this._isPrint); + this.api.asc_closePrintPreview && this.api.asc_closePrintPreview(this._isPrint); this._isPreviewVisible = false; } }, @@ -500,12 +501,13 @@ define([ this.isInputFirstChange = true; return; } - + this._isPrint = print; if ( print ) { var opts = new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86); opts.asc_setAdvancedOptions(this.adjPrintParams); this.api.asc_Print(opts); + this._isPrint = false; } else { var opts = new Asc.asc_CDownloadOptions(Asc.c_oAscFileType.PDF); opts.asc_setAdvancedOptions(this.adjPrintParams); @@ -543,7 +545,6 @@ define([ } }, - textWarning: 'Warning', txtCustom: 'Custom', txtPrintRangeInvalid: 'Invalid print range', textMarginsLast: 'Last Custom' diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index 469243261..881050d70 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -2654,7 +2654,6 @@ define([ txtPage: 'Page', txtOf: 'of {0}', txtPageNumInvalid: 'Page number invalid', - txtEmptyTable: 'There is nothing to print because the document is empty', txtPages: 'Pages', textMarginsLast: 'Last Custom', textMarginsNormal: 'Normal', From 42b75058c5d5c60f523106a6facac5429420ed9e Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 27 Oct 2022 15:40:52 +0300 Subject: [PATCH 09/45] [PE] Show print preview --- apps/presentationeditor/main/app.js | 2 + .../main/app/controller/LeftMenu.js | 10 +- .../main/app/controller/Main.js | 9 +- .../main/app/controller/Print.js | 342 ++++++++++++++++++ .../main/app/controller/Toolbar.js | 4 +- .../main/app/template/FileMenu.template | 2 + .../main/app/view/FileMenu.js | 21 +- .../main/app/view/FileMenuPanels.js | 216 +++++++++++ apps/presentationeditor/main/app_dev.js | 2 + .../main/resources/less/leftmenu.less | 122 +++++++ 10 files changed, 722 insertions(+), 8 deletions(-) create mode 100644 apps/presentationeditor/main/app/controller/Print.js diff --git a/apps/presentationeditor/main/app.js b/apps/presentationeditor/main/app.js index b34a9cd72..ef1a5665a 100644 --- a/apps/presentationeditor/main/app.js +++ b/apps/presentationeditor/main/app.js @@ -152,6 +152,7 @@ require([ 'Main', 'ViewTab', 'Search', + 'Print', 'Common.Controllers.Fonts', 'Common.Controllers.History' /** coauthoring begin **/ @@ -182,6 +183,7 @@ require([ 'presentationeditor/main/app/controller/Main', 'presentationeditor/main/app/controller/ViewTab', 'presentationeditor/main/app/controller/Search', + 'presentationeditor/main/app/controller/Print', 'presentationeditor/main/app/view/FileMenuPanels', 'presentationeditor/main/app/view/ParagraphSettings', 'presentationeditor/main/app/view/ImageSettings', diff --git a/apps/presentationeditor/main/app/controller/LeftMenu.js b/apps/presentationeditor/main/app/controller/LeftMenu.js index 3915b3fb0..58800f121 100644 --- a/apps/presentationeditor/main/app/controller/LeftMenu.js +++ b/apps/presentationeditor/main/app/controller/LeftMenu.js @@ -107,6 +107,7 @@ define([ if ( !this.leftMenu.panelHistory.isVisible() ) this.clickMenuFileItem(null, 'history'); }, this)); + Common.NotificationCenter.on('file:print', _.bind(this.clickToolbarPrint, this)); }, onLaunch: function() { @@ -764,7 +765,14 @@ define([ isCommentsVisible: function() { return this.leftMenu && this.leftMenu.panelComments && this.leftMenu.panelComments.isVisible(); }, - + + clickToolbarPrint: function () { + if (this.mode.canPreviewPrint) + this.leftMenu.showMenu('file:printpreview'); + else if (this.mode.canPrint) + this.clickMenuFileItem(null, 'print'); + }, + textNoTextFound : 'Text not found', newDocumentTitle : 'Unnamed document', requestEditRightsText : 'Requesting editing rights...', diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index f86a51cbe..a967c5918 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -1165,6 +1165,7 @@ define([ console.log("Obsolete: The 'chat' parameter of the 'customization' section is deprecated. Please use 'chat' parameter in the permissions instead."); } this.appOptions.canPrint = (this.permissions.print !== false); + this.appOptions.canPreviewPrint = this.appOptions.canPrint && !Common.Utils.isMac; this.appOptions.canRename = this.editorConfig.canRename; this.appOptions.canForcesave = this.appOptions.isEdit && !this.appOptions.isOffline && (typeof (this.editorConfig.customization) == 'object' && !!this.editorConfig.customization.forcesave); this.appOptions.forcesave = this.appOptions.canForcesave; @@ -1297,6 +1298,9 @@ define([ toolbarController.setMode(this.appOptions); documentHolder.setMode(this.appOptions); + var printController = app.getController('Print'); + printController && this.api && printController.setApi(this.api).setMode(this.appOptions); + this.api.asc_registerCallback('asc_onSendThemeColors', _.bind(this.onSendThemeColors, this)); this.api.asc_registerCallback('asc_onDownloadUrl', _.bind(this.onDownloadUrl, this)); this.api.asc_registerCallback('asc_onDocumentModifiedChanged', _.bind(this.onDocumentModifiedChanged, this)); @@ -1922,6 +1926,7 @@ define([ Common.Utils.InternalSettings.set("pe-settings-unit", value); this.api.asc_SetDocumentUnits((value==Common.Utils.Metric.c_MetricUnits.inch) ? Asc.c_oAscDocumentUnits.Inch : ((value==Common.Utils.Metric.c_MetricUnits.pt) ? Asc.c_oAscDocumentUnits.Point : Asc.c_oAscDocumentUnits.Millimeter)); this.getApplication().getController('RightMenu').updateMetricUnit(); + this.getApplication().getController('Print').getView('PrintWithPreview').updateMetricUnit(); }, updateThemeColors: function() { @@ -2175,9 +2180,7 @@ define([ onPrint: function() { if (!this.appOptions.canPrint || Common.Utils.ModalWindow.isVisible()) return; - - if (this.api) - this.api.asc_Print(new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86)); // if isChrome or isOpera == true use asc_onPrintUrl event + Common.NotificationCenter.trigger('file:print'); Common.component.Analytics.trackEvent('Print'); }, diff --git a/apps/presentationeditor/main/app/controller/Print.js b/apps/presentationeditor/main/app/controller/Print.js new file mode 100644 index 000000000..3f3938aa4 --- /dev/null +++ b/apps/presentationeditor/main/app/controller/Print.js @@ -0,0 +1,342 @@ +/* + * + * (c) Copyright Ascensio System SIA 2010-2022 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * +*/ +define([ + 'core', + 'presentationeditor/main/app/view/FileMenuPanels' +], function () { + 'use strict'; + + PE.Controllers.Print = Backbone.Controller.extend(_.extend({ + views: [ + 'PrintWithPreview' + ], + + initialize: function() { + var value = Common.localStorage.getItem("pe-print-settings-range"); + value = (value!==null) ? parseInt(value) : Asc.c_oAscPrintType.ActiveSheets; + + this.adjPrintParams = new Asc.asc_CAdjustPrint(); + this.adjPrintParams.asc_setPrintType(value); + + this._state = {}; + + this._navigationPreview = { + pageCount: false, + currentPage: 0, + currentPreviewPage: 0 + }; + + this._isPreviewVisible = false; + + this.addListeners({ + 'PrintWithPreview': { + 'show': _.bind(this.onShowMainSettingsPrint, this), + 'render:after': _.bind(this.onAfterRender, this) + } + }); + }, + + onLaunch: function() { + this.printSettings = this.createView('PrintWithPreview'); + }, + + onAfterRender: function(view) { + var me = this; + this.printSettings.menu.on('menu:hide', _.bind(this.onHidePrintMenu, this)); + this.printSettings.btnPrint.on('click', _.bind(this.onBtnPrint, this, true)); + this.printSettings.btnPrintPdf.on('click', _.bind(this.onBtnPrint, this, false)); + this.printSettings.btnPrevPage.on('click', _.bind(this.onChangePreviewPage, this, false)); + this.printSettings.btnNextPage.on('click', _.bind(this.onChangePreviewPage, this, true)); + this.printSettings.txtNumberPage.on({ + 'keypress:after': _.bind(this.onKeypressPageNumber, this), + 'keyup:after': _.bind(this.onKeyupPageNumber, this) + }); + this.printSettings.txtNumberPage.cmpEl.find('input').on('blur', _.bind(this.onBlurPageNumber, this)); + this.printSettings.cmbRange.on('selected', _.bind(this.comboRangeChange, this)); + this.printSettings.inputPages.on('changing', _.bind(this.inputPagesChanging, this)); + this.printSettings.inputPages.validation = function(value) { + if (!_.isEmpty(value) && /[0-9,\-]/.test(value)) { + var res = [], + arr = value.split(','); + for (var i=0; i1) // more than 1 symbol '-' + return me.txtPrintRangeInvalid; + if (!str) {// one number + var num = parseInt(item)-1; + (num>=0) && res.push(num); + } else { // range + var pages = item.split('-'), + start = (pages[0] ? parseInt(pages[0])-1 : 0), + end = (pages[1] ? parseInt(pages[1])-1 : me._navigationPreview.pageCount-1); + if (start>end) { + var num = start; + start = end; + end = num; + } + for (var j=start; j<=end; j++) { + (j>=0) && res.push(j); + } + } + } + if (res.length>0) { + // me.adjPrintParams.asc_setPages(res); + return true; + } + } + + return me.txtPrintRangeInvalid; + }; + + Common.NotificationCenter.on('window:resize', _.bind(function () { + if (this._isPreviewVisible) { + this.api.asc_drawPrintPreview(this._navigationPreview.currentPreviewPage); + } + }, this)); + + var eventname = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel'; + this.printSettings.$previewBox.on(eventname, _.bind(this.onPreviewWheel, this)); + + this.fillPrintOptions(); + }, + + setMode: function (mode) { + this.mode = mode; + this.printSettings && this.printSettings.setMode(mode); + }, + + setApi: function(o) { + this.api = o; + this.api.asc_registerCallback('asc_onCountPages', _.bind(this.onCountPages, this)); + this.api.asc_registerCallback('asc_onCurrentPage', _.bind(this.onCurrentPage, this)); + + return this; + }, + + fillPrintOptions: function(props) { + // fill page numbers, copies, collated + var panel = this.printSettings; + panel.cmbRange.setValue(this.adjPrintParams.asc_getPrintType()); + panel.inputPages.setValue(''); // pages numbers + }, + + comboRangeChange: function(combo, record) { + if (record.value === -1) { + var me = this; + setTimeout(function(){ + me.printSettings.inputPages.focus(); + }, 50); + // this.adjPrintParams.asc_setPrintType(record.value) + } else { + this.printSettings.inputPages.setValue(''); + this.adjPrintParams.asc_setPrintType(record.value) + } + this.printSettings.inputPages.showError(); + }, + + onCountPages: function(count) { + this._navigationPreview.pageCount = count; + + if (this.printSettings.isVisible()) { + this.printSettings.$previewBox.toggleClass('hidden', !this._navigationPreview.pageCount); + this.printSettings.$previewEmpty.toggleClass('hidden', !!this._navigationPreview.pageCount); + } + if (!!this._navigationPreview.pageCount) { + if (this._navigationPreview.currentPreviewPage > count - 1) + this._navigationPreview.currentPreviewPage = Math.max(0, count - 1); + if (this.printSettings.isVisible()) { + this.api.asc_drawPrintPreview(this._navigationPreview.currentPreviewPage); + this.updateNavigationButtons(this._navigationPreview.currentPreviewPage, count); + } + } + }, + + onCurrentPage: function(number) { + this._navigationPreview.currentPreviewPage = number; + if (this.printSettings.isVisible()) { + this.api.asc_drawPrintPreview(this._navigationPreview.currentPreviewPage); + this.updateNavigationButtons(this._navigationPreview.currentPreviewPage, this._navigationPreview.pageCount); + } + }, + + onShowMainSettingsPrint: function() { + var me = this; + this.printSettings.$previewBox.removeClass('hidden'); + + var opts = new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86); + opts.asc_setAdvancedOptions(this.adjPrintParams); + this.api.asc_initPrintPreview('print-preview', opts); + + this.printSettings.$previewBox.toggleClass('hidden', !this._navigationPreview.pageCount); + this.printSettings.$previewEmpty.toggleClass('hidden', !!this._navigationPreview.pageCount); + if (!!this._navigationPreview.pageCount) { + this._navigationPreview.currentPreviewPage = this._navigationPreview.currentPage = this.api.getCurrentPage(); + this.api.asc_drawPrintPreview(this._navigationPreview.currentPreviewPage); + this.updateNavigationButtons(this._navigationPreview.currentPreviewPage, this._navigationPreview.pageCount); + this.SetDisabled(); + } + this._isPreviewVisible = true; + }, + + getPrintParams: function() { + return this.adjPrintParams; + }, + + onHidePrintMenu: function () { + if (this._isPreviewVisible) { + this.api.asc_closePrintPreview && this.api.asc_closePrintPreview(this._isPrint); + this._isPreviewVisible = false; + } + }, + + onChangePreviewPage: function (next) { + var index = this._navigationPreview.currentPreviewPage; + if (next) { + index++; + index = Math.min(index, this._navigationPreview.pageCount - 1); + } else { + index--; + index = Math.max(index, 0); + } + this.api.goToPage(index); + }, + + onKeypressPageNumber: function (input, e) { + if (e.keyCode === Common.UI.Keys.RETURN) { + var box = this.printSettings.$el.find('#print-number-page'), + edit = box.find('input[type=text]'), page = parseInt(edit.val()); + if (!page || page > this._navigationPreview.pageCount || page < 0) { + edit.select(); + this.printSettings.txtNumberPage.setValue(this._navigationPreview.currentPreviewPage + 1); + this.printSettings.txtNumberPage.checkValidate(); + return false; + } + + box.focus(); // for IE + + this.api.goToPage(page-1); + this.api.asc_enableKeyEvents(true); + return false; + } + }, + + onKeyupPageNumber: function (input, e) { + if (e.keyCode === Common.UI.Keys.ESC) { + var box = this.printSettings.$el.find('#print-number-page'); + box.focus(); // for IE + this.api.asc_enableKeyEvents(true); + return false; + } + }, + + onBlurPageNumber: function () { + if (this.printSettings.txtNumberPage.getValue() != this._navigationPreview.currentPreviewPage + 1) { + this.printSettings.txtNumberPage.setValue(this._navigationPreview.currentPreviewPage + 1); + this.printSettings.txtNumberPage.checkValidate(); + } + }, + + onPreviewWheel: function (e) { + if (e.ctrlKey) { + e.preventDefault(); + e.stopImmediatePropagation(); + } + var forward = (e.deltaY || (e.detail && -e.detail) || e.wheelDelta) < 0; + this.onChangePreviewPage(forward); + }, + + updateNavigationButtons: function (page, count) { + this._navigationPreview.currentPage = page; + this.printSettings.updateCurrentPage(page); + this._navigationPreview.pageCount = count; + this.printSettings.updateCountOfPages(count); + this.disableNavButtons(); + }, + + disableNavButtons: function (force) { + if (force) { + this.printSettings.btnPrevPage.setDisabled(true); + this.printSettings.btnNextPage.setDisabled(true); + return; + } + var curPage = this._navigationPreview.currentPage, + pageCount = this._navigationPreview.pageCount; + this.printSettings.btnPrevPage.setDisabled(curPage < 1); + this.printSettings.btnNextPage.setDisabled(curPage > pageCount - 2); + }, + + onBtnPrint: function(print) { + if (this.printSettings.cmbRange.getValue()===-1 && this.printSettings.inputPages.checkValidate() !== true) { + this.printSettings.inputPages.focus(); + this.isInputFirstChange = true; + return; + } + if (this._navigationPreview.pageCount<1) + return; + + this._isPrint = print; + if ( print ) { + var opts = new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86); + opts.asc_setAdvancedOptions(this.adjPrintParams); + this.api.asc_Print(opts); + this._isPrint = false; + } else { + var opts = new Asc.asc_CDownloadOptions(Asc.c_oAscFileType.PDF); + opts.asc_setAdvancedOptions(this.adjPrintParams); + this.api.asc_DownloadAs(opts); + } + this.printSettings.menu.hide(); + }, + + inputPagesChanging: function (input, value) { + this.isInputFirstChange && this.printSettings.inputPages.showError(); + this.isInputFirstChange = false; + + if (value.length<1) + this.printSettings.cmbRange.setValue(Asc.c_oAscPrintType.EntireWorkbook); + else if (this.printSettings.cmbRange.getValue()!==-1) + this.printSettings.cmbRange.setValue(-1); + }, + + SetDisabled: function() { + if (this.printSettings.isVisible()) { + var disable = !this.mode.isEdit; + } + }, + + txtPrintRangeInvalid: 'Invalid print range' + }, PE.Controllers.Print || {})); +}); \ No newline at end of file diff --git a/apps/presentationeditor/main/app/controller/Toolbar.js b/apps/presentationeditor/main/app/controller/Toolbar.js index 917fb1299..121084f53 100644 --- a/apps/presentationeditor/main/app/controller/Toolbar.js +++ b/apps/presentationeditor/main/app/controller/Toolbar.js @@ -1061,9 +1061,7 @@ define([ }, onPrint: function(e) { - if (this.api) - this.api.asc_Print(new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86)); // if isChrome or isOpera == true use asc_onPrintUrl event - + Common.NotificationCenter.trigger('file:print', this.toolbar); Common.NotificationCenter.trigger('edit:complete', this.toolbar); Common.component.Analytics.trackEvent('Print'); diff --git a/apps/presentationeditor/main/app/template/FileMenu.template b/apps/presentationeditor/main/app/template/FileMenu.template index 3ad620221..ba1e7d69d 100644 --- a/apps/presentationeditor/main/app/template/FileMenu.template +++ b/apps/presentationeditor/main/app/template/FileMenu.template @@ -8,6 +8,7 @@
  • +
  • @@ -34,4 +35,5 @@
    +
    \ No newline at end of file diff --git a/apps/presentationeditor/main/app/view/FileMenu.js b/apps/presentationeditor/main/app/view/FileMenu.js index eda4f9afa..089618d55 100644 --- a/apps/presentationeditor/main/app/view/FileMenu.js +++ b/apps/presentationeditor/main/app/view/FileMenu.js @@ -171,6 +171,17 @@ define([ dataHintTitle: 'P' }); + this.miPrintWithPreview = new Common.UI.MenuItem({ + el : $markup.elementById('#fm-btn-print-with-preview'), + action : 'printpreview', + caption : this.btnPrintCaption, + canFocused: false, + dataHint: 1, + dataHintDirection: 'left-top', + dataHintOffset: [2, 14], + dataHintTitle: 'P' + }); + this.miRename = new Common.UI.MenuItem({ el : $markup.elementById('#fm-btn-rename'), action : 'rename', @@ -292,6 +303,7 @@ define([ this.miSaveCopyAs, this.miSaveAs, this.miPrint, + this.miPrintWithPreview, this.miRename, this.miProtect, this.miRecent, @@ -381,7 +393,8 @@ define([ this.miSaveAs[(this.mode.canDownload && this.mode.isDesktopApp && this.mode.isOffline)?'show':'hide'](); this.miSave[this.mode.isEdit && Common.UI.LayoutManager.isElementVisible('toolbar-file-save') ?'show':'hide'](); this.miEdit[!this.mode.isEdit && this.mode.canEdit && this.mode.canRequestEditRights ?'show':'hide'](); - this.miPrint[this.mode.canPrint?'show':'hide'](); + this.miPrint[this.mode.canPrint && !this.mode.canPreviewPrint ?'show':'hide'](); + this.miPrintWithPreview[this.mode.canPreviewPrint?'show':'hide'](); this.miRename[(this.mode.canRename && !this.mode.isDesktopApp) ?'show':'hide'](); this.miProtect[this.mode.canProtect ?'show':'hide'](); separatorVisible = (this.mode.canDownload || this.mode.isEdit && Common.UI.LayoutManager.isElementVisible('toolbar-file-save') || this.mode.canPrint || this.mode.canProtect || @@ -462,6 +475,12 @@ define([ this.panels['help'].setLangConfig(this.mode.lang); } + if (this.mode.canPreviewPrint) { + var printPanel = PE.getController('Print').getView('PrintWithPreview'); + printPanel.menu = this; + !this.panels['printpreview'] && (this.panels['printpreview'] = printPanel.render(this.$el.find('#panel-print'))); + } + if ( Common.Controllers.Desktop.isActive() ) { $('
  • ').insertAfter($('#fm-btn-recent', this.$el)); this.items.push( diff --git a/apps/presentationeditor/main/app/view/FileMenuPanels.js b/apps/presentationeditor/main/app/view/FileMenuPanels.js index 662166101..f02b56ff3 100644 --- a/apps/presentationeditor/main/app/view/FileMenuPanels.js +++ b/apps/presentationeditor/main/app/view/FileMenuPanels.js @@ -1821,4 +1821,220 @@ define([ }, PE.Views.FileMenuPanels.ProtectDoc || {})); + PE.Views.PrintWithPreview = Common.UI.BaseView.extend(_.extend({ + el: '#panel-print', + menu: undefined, + + template: _.template([ + '
    ', + '
    ', + '', + '
    ', + '', + '', + '
    ' + ].join('')), + + initialize: function(options) { + Common.UI.BaseView.prototype.initialize.call(this,arguments); + + this.menu = options.menu; + }, + + render: function(node) { + var me = this; + + var $markup = $(this.template({scope: this})); + + this.cmbRange = new Common.UI.ComboBox({ + el: $markup.findById('#print-combo-range'), + menuStyle: 'min-width: 248px;max-height: 280px;', + editable: false, + takeFocusOnClose: true, + cls: 'input-group-nr', + data: [ + { value: Asc.c_oAscPrintType.EntireWorkbook, displayValue: this.txtAllPages }, + { value: Asc.c_oAscPrintType.ActiveSheets, displayValue: this.txtCurrentPage }, + { value: -1, displayValue: this.txtCustomPages } + ], + dataHint: '2', + dataHintDirection: 'bottom', + dataHintOffset: 'big' + }); + + this.inputPages = new Common.UI.InputField({ + el: $markup.findById('#print-txt-pages'), + allowBlank: true, + validateOnChange: true, + validateOnBlur: false, + maskExp: /[0-9,\-]/, + dataHint: '2', + dataHintDirection: 'left', + dataHintOffset: 'small' + }); + + this.pnlSettings = $markup.find('.flex-settings').addBack().filter('.flex-settings'); + this.pnlTable = $(this.pnlSettings.find('table')[0]); + this.trApply = $markup.find('.fms-btn-apply'); + + this.btnPrint = new Common.UI.Button({ + el: $markup.findById('#print-btn-print') + }); + this.btnPrintPdf = new Common.UI.Button({ + el: $markup.findById('#print-btn-print-pdf') + }); + + this.btnPrevPage = new Common.UI.Button({ + parentEl: $markup.findById('#print-prev-page'), + cls: 'btn-prev-page', + iconCls: 'arrow', + dataHint: '2', + dataHintDirection: 'top' + }); + + this.btnNextPage = new Common.UI.Button({ + parentEl: $markup.findById('#print-next-page'), + cls: 'btn-next-page', + iconCls: 'arrow', + dataHint: '2', + dataHintDirection: 'top' + }); + + this.countOfPages = $markup.findById('#print-count-page'); + + this.txtNumberPage = new Common.UI.InputField({ + el: $markup.findById('#print-number-page'), + allowBlank: true, + validateOnChange: true, + style: 'width: 50px;', + maskExp: /[0-9]/, + validation: function(value) { + if (/(^[0-9]+$)/.test(value)) { + value = parseInt(value); + if (undefined !== value && value > 0 && value <= me.pageCount) + return true; + } + + return me.txtPageNumInvalid; + }, + dataHint: '2', + dataHintDirection: 'left', + dataHintOffset: 'small' + }); + + this.$el = $(node).html($markup); + this.$previewBox = $('#print-preview-box'); + this.$previewEmpty = $('#print-preview-empty'); + + if (_.isUndefined(this.scroller)) { + this.scroller = new Common.UI.Scroller({ + el: this.pnlSettings, + suppressScrollX: true, + alwaysVisibleY: true + }); + } + + Common.NotificationCenter.on({ + 'window:resize': function() { + me.isVisible() && me.updateScroller(); + } + }); + + this.fireEvent('render:after', this); + + return this; + }, + + show: function() { + Common.UI.BaseView.prototype.show.call(this,arguments); + this.updateScroller(); + this.fireEvent('show', this); + }, + + updateScroller: function() { + if (this.scroller) { + Common.UI.Menu.Manager.hideAll(); + var scrolled = this.$el.height()< this.pnlTable.height(); + this.pnlSettings.css('overflow', scrolled ? 'hidden' : 'visible'); + this.scroller.update(); + } + }, + + setMode: function(mode) { + this.mode = mode; + }, + + setApi: function(api) { + + }, + + isVisible: function() { + return (this.$el || $(this.el)).is(":visible"); + }, + + setRange: function(value) { + this.cmbRange.setValue(value); + }, + + getRange: function() { + return this.cmbRange.getValue(); + }, + + updateCountOfPages: function (count) { + this.countOfPages.text( + Common.Utils.String.format(this.txtOf, count) + ); + this.pageCount = count; + }, + + updateCurrentPage: function (index) { + this.txtNumberPage.setValue(index + 1); + }, + + txtPrint: 'Print', + txtPrintPdf: 'Print to PDF', + txtPrintRange: 'Print range', + txtCurrentPage: 'Current slide', + txtAllPages: 'All slides', + txtCustomPages: 'Custom print', + txtPage: 'Slide', + txtOf: 'of {0}', + txtPageNumInvalid: 'Slide number invalid', + txtEmptyTable: 'There is nothing to print because the presentation is empty', + txtPages: 'Slides' + + }, PE.Views.PrintWithPreview || {})); }); diff --git a/apps/presentationeditor/main/app_dev.js b/apps/presentationeditor/main/app_dev.js index 8d7c9c55e..f22a6e1f0 100644 --- a/apps/presentationeditor/main/app_dev.js +++ b/apps/presentationeditor/main/app_dev.js @@ -143,6 +143,7 @@ require([ 'Main', 'ViewTab', 'Search', + 'Print', 'Common.Controllers.Fonts', 'Common.Controllers.History' /** coauthoring begin **/ @@ -173,6 +174,7 @@ require([ 'presentationeditor/main/app/controller/Main', 'presentationeditor/main/app/controller/ViewTab', 'presentationeditor/main/app/controller/Search', + 'presentationeditor/main/app/controller/Print', 'presentationeditor/main/app/view/FileMenuPanels', 'presentationeditor/main/app/view/ParagraphSettings', 'presentationeditor/main/app/view/ImageSettings', diff --git a/apps/presentationeditor/main/resources/less/leftmenu.less b/apps/presentationeditor/main/resources/less/leftmenu.less index e852e3cc8..0bfa96c29 100644 --- a/apps/presentationeditor/main/resources/less/leftmenu.less +++ b/apps/presentationeditor/main/resources/less/leftmenu.less @@ -519,6 +519,128 @@ } } } + + #panel-print { + padding: 0; + #print-preview-empty { + padding: 14px; + color: @text-tertiary-ie; + color: @text-tertiary; + + position: absolute; + left: 280px; + top: 0; + right: 0; + bottom: 0; + display: flex; + justify-content: center; + align-items: center; + + div { + text-align: center; + } + } + #id-print-settings { + position: absolute; + width:280px; + top: 0; + bottom: 0; + } + .print-settings { + width: 100%; + height: 100%; + overflow: hidden; + display: flex; + flex-direction: column; + border-right: @scaled-one-px-value-ie solid @border-toolbar-ie; + border-right: @scaled-one-px-value solid @border-toolbar; + label.header { + font-weight: 700; + } + .footer { + .btn.primary { + margin-right: 8px; + } + } + .settings-container { + width: 100%; + height: 100%; + overflow: hidden; + padding: 12px 16px; + .padding-small { + padding-bottom: 8px; + } + .padding-large { + padding-bottom: 16px; + } + + #print-apply-all { + margin-top: 5px; + } + .link { + margin-top: 9px; + } + .footer { + margin-top: 24px; + } + } + } + #print-navigation { + height: 50px; + padding-left: 20px; + padding-top: 10px; + display: flex; + .btn-prev-page, .btn-next-page { + background-color: transparent; + padding: 0; + height: 20px; + width: 20px; + i.arrow { + display: inline-block; + width: 10px; + height: 10px; + + border: solid @scaled-one-px-value-ie @icon-normal-ie; + border: solid @scaled-one-px-value @icon-normal; + border-bottom: none; + border-right: none; + } + &.disabled { + opacity: @component-disabled-opacity; + } + + &:hover:not(:disabled):not(.disabled) { + background-color: @highlight-button-hover-ie; + background-color: @highlight-button-hover; + } + } + .btn-prev-page { + i { + transform: rotate(-45deg) translate(-1px, 3px); + } + } + .btn-next-page { + i { + transform: rotate(135deg) translate(4px, 0px); + } + } + .page-number { + display: flex; + align-items: center; + height: 20px; + margin-left: 10px; + label { + .font-weight-bold(); + } + #print-count-page, #print-number-page { + margin-left: 4px; + } + } + } + #print-preview { + height: calc(100% - 50px); + } + } } } From 1ac0d04f2e78d1fa1a9a1b348e0088e2812c1e0d Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 1 Nov 2022 16:13:30 +0300 Subject: [PATCH 10/45] Fix Bug 59592 --- .../main/app/view/DocumentHolder.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/documenteditor/main/app/view/DocumentHolder.js b/apps/documenteditor/main/app/view/DocumentHolder.js index 0f77874c4..6c2ff48c5 100644 --- a/apps/documenteditor/main/app/view/DocumentHolder.js +++ b/apps/documenteditor/main/app/view/DocumentHolder.js @@ -732,9 +732,9 @@ define([ me.menuImgPrint.setDisabled(!cancopy); var lockreview = Common.Utils.InternalSettings.get("de-accept-reject-lock"); - me.menuImgAccept.setVisible(!lockreview); - me.menuImgReject.setVisible(!lockreview); - menuImgReviewSeparator.setVisible(!lockreview); + me.menuImgAccept.setVisible(me.mode.canReview && !me.mode.isReviewOnly && !lockreview); + me.menuImgReject.setVisible(me.mode.canReview && !me.mode.isReviewOnly && !lockreview); + menuImgReviewSeparator.setVisible(me.mode.canReview && !me.mode.isReviewOnly && !lockreview); var signGuid = (value.imgProps && value.imgProps.value && me.mode.isSignatureSupport) ? value.imgProps.value.asc_getSignatureId() : undefined, isInSign = !!signGuid; @@ -1302,9 +1302,9 @@ define([ me.menuTablePrint.setDisabled(!cancopy); var lockreview = Common.Utils.InternalSettings.get("de-accept-reject-lock"); - me.menuTableAccept.setVisible(!lockreview); - me.menuTableReject.setVisible(!lockreview); - menuTableReviewSeparator.setVisible(!lockreview); + me.menuTableAccept.setVisible(me.mode.canReview && !me.mode.isReviewOnly && !lockreview); + me.menuTableReject.setVisible(me.mode.canReview && !me.mode.isReviewOnly && !lockreview); + menuTableReviewSeparator.setVisible(me.mode.canReview && !me.mode.isReviewOnly && !lockreview); // bullets & numbering var listId = me.api.asc_GetCurrentNumberingId(), @@ -1914,9 +1914,9 @@ define([ me.menuParaPrint.setDisabled(!cancopy); var lockreview = Common.Utils.InternalSettings.get("de-accept-reject-lock"); - me.menuParaAccept.setVisible(!lockreview); - me.menuParaReject.setVisible(!lockreview); - menuParaReviewSeparator.setVisible(!lockreview); + me.menuParaAccept.setVisible(me.mode.canReview && !me.mode.isReviewOnly && !lockreview); + me.menuParaReject.setVisible(me.mode.canReview && !me.mode.isReviewOnly && !lockreview); + menuParaReviewSeparator.setVisible(me.mode.canReview && !me.mode.isReviewOnly && !lockreview); // spellCheck var spell = (value.spellProps!==undefined && value.spellProps.value.get_Checked()===false); From c0493d45aba91f4c22d75ccfb767d9b0fbeba010 Mon Sep 17 00:00:00 2001 From: JuliaSvinareva Date: Mon, 24 Oct 2022 20:52:46 +0300 Subject: [PATCH 11/45] [SSE] Fix bug 59466 --- apps/spreadsheeteditor/main/app/controller/Print.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/spreadsheeteditor/main/app/controller/Print.js b/apps/spreadsheeteditor/main/app/controller/Print.js index d2a21bd82..5b5fa13b9 100644 --- a/apps/spreadsheeteditor/main/app/controller/Print.js +++ b/apps/spreadsheeteditor/main/app/controller/Print.js @@ -424,6 +424,7 @@ define([ this.printSettings.applySettings(); if (print) { + var view = SSE.getController('Toolbar').getView('Toolbar'); var printType = this.printSettings.getRange(); this.adjPrintParams.asc_setPrintType(printType); this.adjPrintParams.asc_setPageOptionsMap(this._changedProps); From a715c720ca85bb85481faade323c39c4867b645d Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Mon, 14 Nov 2022 18:00:11 +0300 Subject: [PATCH 12/45] Refactoring locks --- apps/common/main/lib/controller/Desktop.js | 2 +- apps/common/main/lib/util/utils.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/common/main/lib/controller/Desktop.js b/apps/common/main/lib/controller/Desktop.js index 76f4b67b2..356764bd4 100644 --- a/apps/common/main/lib/controller/Desktop.js +++ b/apps/common/main/lib/controller/Desktop.js @@ -234,7 +234,7 @@ define([ Common.NotificationCenter.on('document:ready', function () { if ( config.isEdit ) { var maincontroller = webapp.getController('Main'); - if (maincontroller.api.asc_isReadOnly && maincontroller.api.asc_isReadOnly()) { + if (maincontroller.api.asc_getLocalRestrictions && Asc.c_oAscLocalRestrictionType.None !== maincontroller.api.asc_getLocalRestrictions()) { maincontroller.warningDocumentIsLocked(); } } diff --git a/apps/common/main/lib/util/utils.js b/apps/common/main/lib/util/utils.js index b1d58e132..25b41ebf8 100644 --- a/apps/common/main/lib/util/utils.js +++ b/apps/common/main/lib/util/utils.js @@ -979,7 +979,7 @@ Common.Utils.warningDocumentIsLocked = function (opts) { callback: function(btn){ if (btn == 'edit') { if ( opts.disablefunc ) opts.disablefunc(false); - app.getController('Main').api.asc_setIsReadOnly(false); + app.getController('Main').api.asc_setLocalRestrictions(Asc.c_oAscLocalRestrictionType.None); } } }); From 24830cb70bf983f78d0a873f02c854574592a95c Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 15 Nov 2022 16:45:28 +0300 Subject: [PATCH 13/45] [DE] Send print settings to sdk. Enable print preview only for desktop. --- .../main/app/controller/Main.js | 2 +- .../main/app/controller/Print.js | 33 +++++++++---------- .../main/app/view/FileMenuPanels.js | 5 +-- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 31b233d18..813a2089f 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -1494,7 +1494,7 @@ define([ } this.appOptions.canEditStyles = this.appOptions.canLicense && this.appOptions.canEdit; this.appOptions.canPrint = (this.permissions.print !== false); - this.appOptions.canPreviewPrint = this.appOptions.canPrint && !Common.Utils.isMac; + this.appOptions.canPreviewPrint = this.appOptions.canPrint && !Common.Utils.isMac && this.appOptions.isDesktopApp; this.appOptions.canRename = this.editorConfig.canRename; this.appOptions.buildVersion = params.asc_getBuildVersion(); this.appOptions.canForcesave = this.appOptions.isEdit && !this.appOptions.isOffline && (typeof (this.editorConfig.customization) == 'object' && !!this.editorConfig.customization.forcesave); diff --git a/apps/documenteditor/main/app/controller/Print.js b/apps/documenteditor/main/app/controller/Print.js index d92d4e893..8ae19b397 100644 --- a/apps/documenteditor/main/app/controller/Print.js +++ b/apps/documenteditor/main/app/controller/Print.js @@ -42,14 +42,10 @@ define([ ], initialize: function() { - var value = Common.localStorage.getItem("de-print-settings-range"); - value = (value!==null) ? parseInt(value) : Asc.c_oAscPrintType.ActiveSheets; - this.adjPrintParams = new Asc.asc_CAdjustPrint(); - this.adjPrintParams.asc_setPrintType(value); - this._state = { - lock_doc: false + lock_doc: false, + firstPrintPage: 0 }; this._navigationPreview = { @@ -119,6 +115,7 @@ define([ } if (res.length>0) { // me.adjPrintParams.asc_setPages(res); + me._state.firstPrintPage = res[0]; return true; } } @@ -135,8 +132,6 @@ define([ var eventname = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel'; this.printSettings.$previewBox.on(eventname, _.bind(this.onPreviewWheel, this)); - - this.fillPrintOptions(); }, setMode: function (mode) { @@ -224,23 +219,14 @@ define([ } }, - fillPrintOptions: function(props) { - // fill page numbers, copies, collated - var panel = this.printSettings; - panel.cmbRange.setValue(this.adjPrintParams.asc_getPrintType()); - panel.inputPages.setValue(''); // pages numbers - }, - comboRangeChange: function(combo, record) { if (record.value === -1) { var me = this; setTimeout(function(){ me.printSettings.inputPages.focus(); }, 50); - // this.adjPrintParams.asc_setPrintType(record.value) } else { this.printSettings.inputPages.setValue(''); - this.adjPrintParams.asc_setPrintType(record.value) } this.printSettings.inputPages.showError(); }, @@ -501,8 +487,19 @@ define([ this.isInputFirstChange = true; return; } + if (this.printSettings.cmbRange.getValue()==='all') + this._state.firstPrintPage = 0; + else if (this.printSettings.cmbRange.getValue()==='current') + this._state.firstPrintPage = this._navigationPreview.currentPage; + this._isPrint = print; + this.adjPrintParams.asc_setNativeOptions({ + pages: this.printSettings.cmbRange.getValue()===-1 ? this.printSettings.inputPages.getValue() : this.printSettings.cmbRange.getValue(), + paperSize: this._state.pgsize, //this.api.asc_getPageSize(this._state.firstPrintPage), + paperOrientation: this._state.pgorient ? 'portrait' : 'landscape' // this.api.asc_getPageOrient(this._state.firstPrintPage) ? 'portrait' : 'landscape' + }); + if ( print ) { var opts = new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86); opts.asc_setAdvancedOptions(this.adjPrintParams); @@ -521,7 +518,7 @@ define([ this.isInputFirstChange = false; if (value.length<1) - this.printSettings.cmbRange.setValue(Asc.c_oAscPrintType.EntireWorkbook); + this.printSettings.cmbRange.setValue('all'); else if (this.printSettings.cmbRange.getValue()!==-1) this.printSettings.cmbRange.setValue(-1); }, diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index 881050d70..1365fa8f9 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -2399,14 +2399,15 @@ define([ takeFocusOnClose: true, cls: 'input-group-nr', data: [ - { value: Asc.c_oAscPrintType.EntireWorkbook, displayValue: this.txtAllPages }, - { value: Asc.c_oAscPrintType.ActiveSheets, displayValue: this.txtCurrentPage }, + { value: 'all', displayValue: this.txtAllPages }, + { value: 'current', displayValue: this.txtCurrentPage }, { value: -1, displayValue: this.txtCustomPages } ], dataHint: '2', dataHintDirection: 'bottom', dataHintOffset: 'big' }); + this.cmbRange.setValue('all'); this.inputPages = new Common.UI.InputField({ el: $markup.findById('#print-txt-pages'), From 53298b4aab26772c20eed8f73fab39c4c95ec95d Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 15 Nov 2022 17:47:41 +0300 Subject: [PATCH 14/45] [DE] Fix translation --- .../main/app/controller/Print.js | 4 +-- .../main/app/view/FileMenuPanels.js | 16 +++++----- apps/documenteditor/main/locale/en.json | 30 +++++++++++++++++++ 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Print.js b/apps/documenteditor/main/app/controller/Print.js index 8ae19b397..d6acb6ee5 100644 --- a/apps/documenteditor/main/app/controller/Print.js +++ b/apps/documenteditor/main/app/controller/Print.js @@ -114,7 +114,6 @@ define([ } } if (res.length>0) { - // me.adjPrintParams.asc_setPages(res); me._state.firstPrintPage = res[0]; return true; } @@ -492,14 +491,13 @@ define([ else if (this.printSettings.cmbRange.getValue()==='current') this._state.firstPrintPage = this._navigationPreview.currentPage; - this._isPrint = print; - this.adjPrintParams.asc_setNativeOptions({ pages: this.printSettings.cmbRange.getValue()===-1 ? this.printSettings.inputPages.getValue() : this.printSettings.cmbRange.getValue(), paperSize: this._state.pgsize, //this.api.asc_getPageSize(this._state.firstPrintPage), paperOrientation: this._state.pgorient ? 'portrait' : 'landscape' // this.api.asc_getPageOrient(this._state.firstPrintPage) ? 'portrait' : 'landscape' }); + this._isPrint = print; if ( print ) { var opts = new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86); opts.asc_setAdvancedOptions(this.adjPrintParams); diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index 1365fa8f9..92fc8b1ed 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -2485,10 +2485,10 @@ define([ '
  • ', '
    <%= scope.getDisplayValue(item) %>
    ', '<% if (item.size !== null) { %>
    ' + - '' + - '
    ' + - '' + - '
    ' + + '' + + '
    ' + + '' + + '
    ' + '<% } %>', '<% }); %>' ].join('')), @@ -2648,10 +2648,10 @@ define([ txtLandscape: 'Landscape', txtCustom: 'Custom', txtMargins: 'Margins', - txtTop: 'Top:', - txtBottom: 'Bottom:', - txtLeft: 'Left:', - txtRight: 'Right:', + txtTop: 'Top', + txtBottom: 'Bottom', + txtLeft: 'Left', + txtRight: 'Right', txtPage: 'Page', txtOf: 'of {0}', txtPageNumInvalid: 'Page number invalid', diff --git a/apps/documenteditor/main/locale/en.json b/apps/documenteditor/main/locale/en.json index 303e6e092..e27028544 100644 --- a/apps/documenteditor/main/locale/en.json +++ b/apps/documenteditor/main/locale/en.json @@ -951,6 +951,9 @@ "DE.Controllers.Statusbar.textTrackChanges": "The document is opened with the Track Changes mode enabled", "DE.Controllers.Statusbar.tipReview": "Track changes", "DE.Controllers.Statusbar.zoomText": "Zoom {0}%", + "DE.Controllers.Print.txtCustom": "Custom", + "DE.Controllers.Print.txtPrintRangeInvalid": "Invalid print range", + "DE.Controllers.Print.textMarginsLast": "Last Custom", "DE.Controllers.Toolbar.confirmAddFontName": "The font you are going to save is not available on the current device.
    The text style will be displayed using one of the system fonts, the saved font will be used when it is available.
    Do you want to continue?", "DE.Controllers.Toolbar.dataUrl": "Paste a data URL", "DE.Controllers.Toolbar.notcriticalErrorTitle": "Warning", @@ -2384,6 +2387,33 @@ "DE.Views.ParagraphSettingsAdvanced.tipTop": "Set top border only", "DE.Views.ParagraphSettingsAdvanced.txtAutoText": "Auto", "DE.Views.ParagraphSettingsAdvanced.txtNoBorders": "No borders", + "DE.Views.PrintWithPreview.txtPrint": "Print", + "DE.Views.PrintWithPreview.txtPrintPdf": "Print to PDF", + "DE.Views.PrintWithPreview.txtPrintRange": "Print range", + "DE.Views.PrintWithPreview.txtCurrentPage": "Current page", + "DE.Views.PrintWithPreview.txtAllPages": "All pages", + "DE.Views.PrintWithPreview.txtSelection": "Selection", + "DE.Views.PrintWithPreview.txtCustomPages": "Custom print", + "DE.Views.PrintWithPreview.txtPageSize": "Page size", + "DE.Views.PrintWithPreview.txtPageOrientation": "Page orientation", + "DE.Views.PrintWithPreview.txtPortrait": "Portrait", + "DE.Views.PrintWithPreview.txtLandscape": "Landscape", + "DE.Views.PrintWithPreview.txtCustom": "Custom", + "DE.Views.PrintWithPreview.txtMargins": "Margins", + "DE.Views.PrintWithPreview.txtTop": "Top", + "DE.Views.PrintWithPreview.txtBottom": "Bottom", + "DE.Views.PrintWithPreview.txtLeft": "Left", + "DE.Views.PrintWithPreview.txtRight": "Right", + "DE.Views.PrintWithPreview.txtPage": "Page", + "DE.Views.PrintWithPreview.txtOf": "of {0}", + "DE.Views.PrintWithPreview.txtPageNumInvalid": "Page number invalid", + "DE.Views.PrintWithPreview.txtPages": "Pages", + "DE.Views.PrintWithPreview.textMarginsLast": "Last Custom", + "DE.Views.PrintWithPreview.textMarginsNormal": "Normal", + "DE.Views.PrintWithPreview.textMarginsUsNormal": "US Normal", + "DE.Views.PrintWithPreview.textMarginsNarrow": "Narrow", + "DE.Views.PrintWithPreview.textMarginsModerate": "Moderate", + "DE.Views.PrintWithPreview.textMarginsWide": "Wide", "DE.Views.RightMenu.txtChartSettings": "Chart settings", "DE.Views.RightMenu.txtFormSettings": "Form Settings", "DE.Views.RightMenu.txtHeaderFooterSettings": "Header and footer settings", From c4536c080706d74847fb0014b0180e9daa18b6b7 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 15 Nov 2022 17:54:09 +0300 Subject: [PATCH 15/45] [PE] Add paper size. Send print settings to sdk. Enable print preview only for desktop. --- .../main/app/controller/Main.js | 2 +- .../main/app/controller/Print.js | 24 ++----- .../main/app/view/FileMenuPanels.js | 65 ++++++++++++++++++- apps/presentationeditor/main/locale/en.json | 13 ++++ 4 files changed, 83 insertions(+), 21 deletions(-) diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index a967c5918..595901701 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -1165,7 +1165,7 @@ define([ console.log("Obsolete: The 'chat' parameter of the 'customization' section is deprecated. Please use 'chat' parameter in the permissions instead."); } this.appOptions.canPrint = (this.permissions.print !== false); - this.appOptions.canPreviewPrint = this.appOptions.canPrint && !Common.Utils.isMac; + this.appOptions.canPreviewPrint = this.appOptions.canPrint && !Common.Utils.isMac && this.appOptions.isDesktopApp; this.appOptions.canRename = this.editorConfig.canRename; this.appOptions.canForcesave = this.appOptions.isEdit && !this.appOptions.isOffline && (typeof (this.editorConfig.customization) == 'object' && !!this.editorConfig.customization.forcesave); this.appOptions.forcesave = this.appOptions.canForcesave; diff --git a/apps/presentationeditor/main/app/controller/Print.js b/apps/presentationeditor/main/app/controller/Print.js index 3f3938aa4..fb2e54e80 100644 --- a/apps/presentationeditor/main/app/controller/Print.js +++ b/apps/presentationeditor/main/app/controller/Print.js @@ -42,11 +42,7 @@ define([ ], initialize: function() { - var value = Common.localStorage.getItem("pe-print-settings-range"); - value = (value!==null) ? parseInt(value) : Asc.c_oAscPrintType.ActiveSheets; - this.adjPrintParams = new Asc.asc_CAdjustPrint(); - this.adjPrintParams.asc_setPrintType(value); this._state = {}; @@ -113,7 +109,6 @@ define([ } } if (res.length>0) { - // me.adjPrintParams.asc_setPages(res); return true; } } @@ -129,8 +124,6 @@ define([ var eventname = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel'; this.printSettings.$previewBox.on(eventname, _.bind(this.onPreviewWheel, this)); - - this.fillPrintOptions(); }, setMode: function (mode) { @@ -146,23 +139,14 @@ define([ return this; }, - fillPrintOptions: function(props) { - // fill page numbers, copies, collated - var panel = this.printSettings; - panel.cmbRange.setValue(this.adjPrintParams.asc_getPrintType()); - panel.inputPages.setValue(''); // pages numbers - }, - comboRangeChange: function(combo, record) { if (record.value === -1) { var me = this; setTimeout(function(){ me.printSettings.inputPages.focus(); }, 50); - // this.adjPrintParams.asc_setPrintType(record.value) } else { this.printSettings.inputPages.setValue(''); - this.adjPrintParams.asc_setPrintType(record.value) } this.printSettings.inputPages.showError(); }, @@ -307,6 +291,12 @@ define([ if (this._navigationPreview.pageCount<1) return; + var rec = this.printSettings.cmbPaperSize.getSelectedRecord(); + this.adjPrintParams.asc_setNativeOptions({ + pages: this.printSettings.cmbRange.getValue()===-1 ? this.printSettings.inputPages.getValue() : this.printSettings.cmbRange.getValue(), + paperSize: rec ? rec.size : null + }); + this._isPrint = print; if ( print ) { var opts = new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86); @@ -326,7 +316,7 @@ define([ this.isInputFirstChange = false; if (value.length<1) - this.printSettings.cmbRange.setValue(Asc.c_oAscPrintType.EntireWorkbook); + this.printSettings.cmbRange.setValue('all'); else if (this.printSettings.cmbRange.getValue()!==-1) this.printSettings.cmbRange.setValue(-1); }, diff --git a/apps/presentationeditor/main/app/view/FileMenuPanels.js b/apps/presentationeditor/main/app/view/FileMenuPanels.js index f02b56ff3..9e727858e 100644 --- a/apps/presentationeditor/main/app/view/FileMenuPanels.js +++ b/apps/presentationeditor/main/app/view/FileMenuPanels.js @@ -1839,6 +1839,8 @@ define([ '<%= scope.txtPages %>', '', '', + '', + '', '', '