From 0020e55ea088a200d8936cfcdce21539a3ca62fd Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 25 Oct 2022 21:40:16 +0300 Subject: [PATCH] [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 7bb6c26f4f..948ba6e083 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 d9949a3db1..8ec0aadaf5 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'