From 7d163cdcb0fddca3dec92d725f7e23d34dceed74 Mon Sep 17 00:00:00 2001 From: Julia Svinareva Date: Wed, 4 Sep 2019 10:53:56 +0300 Subject: [PATCH] [SSE] Add Custom Scaling into Print Settings --- .../main/app/controller/Print.js | 55 ++++++++++++++++--- .../main/app/view/PrintSettings.js | 9 ++- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/controller/Print.js b/apps/spreadsheeteditor/main/app/controller/Print.js index df38ffdea..a5fee5bba 100644 --- a/apps/spreadsheeteditor/main/app/controller/Print.js +++ b/apps/spreadsheeteditor/main/app/controller/Print.js @@ -142,11 +142,9 @@ define([ parseFloat(Common.Utils.Metric.fnRecalcFromMM(h).toFixed(2)) + Common.Utils.Metric.getCurrentMetricName() + ')'); var fitwidth = opt.asc_getFitToWidth(), - fitheight = opt.asc_getFitToHeight(); - if (!fitwidth && !fitheight) panel.cmbLayout.setValue(0); - else if (fitwidth && fitheight) panel.cmbLayout.setValue(1); - else if (fitwidth && !fitheight) panel.cmbLayout.setValue(2); - else panel.cmbLayout.setValue(3); + fitheight = opt.asc_getFitToHeight(), + fitscale = opt.asc_getScale(); + this.setScaling(panel, fitwidth, fitheight, fitscale); item = panel.cmbPaperOrientation.store.findWhere({value: opt.asc_getOrientation()}); if (item) panel.cmbPaperOrientation.setValue(item.get('value')); @@ -194,9 +192,14 @@ define([ opt.asc_setHeight(pageh? parseFloat(pageh[0]) : (this._originalPageSettings ? this._originalPageSettings.asc_getHeight() : undefined)); var value = panel.cmbLayout.getValue(); - opt.asc_setFitToWidth(value==1 || value==2); - opt.asc_setFitToHeight(value==1 || value==3); - + if (value !== 4) { + opt.asc_setFitToWidth((value==1 || value==2) ? 1 : 0); + opt.asc_setFitToHeight((value==1 || value==3) ? 1 : 0); + } else { + opt.asc_setFitToWidth(this.fitWidth); + opt.asc_setFitToHeight(this.fitHeight); + opt.asc_setScale(this.fitScale); + } props.asc_setPageSetup(opt); opt = new Asc.asc_CPageMargins(); @@ -340,6 +343,7 @@ define([ panel.cmbPaperSize.on('selected', _.bind(this.propertyChange, this, panel)); panel.cmbPaperOrientation.on('selected', _.bind(this.propertyChange, this, panel)); panel.cmbLayout.on('selected', _.bind(this.propertyChange, this, panel)); + panel.menuLayout && panel.menuLayout.on('item:click', _.bind(this.onCustomScale, this, panel)); panel.spnMarginTop.on('change', _.bind(this.propertyChange, this, panel)); panel.spnMarginBottom.on('change', _.bind(this.propertyChange, this, panel)); panel.spnMarginLeft.on('change', _.bind(this.propertyChange, this, panel)); @@ -358,6 +362,41 @@ define([ return this.adjPrintParams; }, + onCustomScale: function(panel) { + var me = this; + var win = new SSE.Views.ScaleDialog({ + api: me.api, + handler: function(dlg, result) { + if (dlg == 'ok') { + if (me.api && result) { + me.fitWidth = result.width; + me.fitHeight = result.height; + me.fitScale = result.scale; + me.setScaling(panel, me.fitWidth, me.fitHeight, me.fitScale); + me.propertyChange(panel); + } + } + Common.NotificationCenter.trigger('edit:complete'); + } + }); + win.show(); + Common.NotificationCenter.trigger('edit:complete', this.toolbar); + }, + + setScaling: function (panel, width, height, scale) { + var me = this; + if (!width && !height && scale === 100) panel.cmbLayout.setValue(0); + else if (width === 1 && height === 1) panel.cmbLayout.setValue(1); + else if (width === 1 && !height) panel.cmbLayout.setValue(2); + else if (!width && height === 1) panel.cmbLayout.setValue(3); + else { + if (!panel.cmbLayout.store.findWhere({value: 4})) { + panel.cmbLayout.store.add({value: 4, displayValue: me.txtCustom}); + } + panel.cmbLayout.setValue(4); + } + }, + warnCheckMargings: 'Margins are incorrect', strAllSheets: 'All Sheets', textWarning: 'Warning', diff --git a/apps/spreadsheeteditor/main/app/view/PrintSettings.js b/apps/spreadsheeteditor/main/app/view/PrintSettings.js index 59cabc3c6..cb7026bfc 100644 --- a/apps/spreadsheeteditor/main/app/view/PrintSettings.js +++ b/apps/spreadsheeteditor/main/app/view/PrintSettings.js @@ -216,6 +216,12 @@ define([ 'text!spreadsheeteditor/main/app/template/PrintSettings.template', { value: 3, displayValue: this.textFitRows } ] }); + this.menuLayout = new Common.UI.Menu({ + items: [ + { template: _.template('' + this.textCustom + '') } + ] + }); + this.menuLayout.render($('#printadv-dlg-combo-layout')); this.btnHide = new Common.UI.Button({ el: $('#printadv-dlg-btn-hide') @@ -322,7 +328,8 @@ define([ 'text!spreadsheeteditor/main/app/template/PrintSettings.template', strShow: 'Show', btnDownload: 'Save & Download', textRange: 'Range', - textIgnore: 'Ignore Print Area' + textIgnore: 'Ignore Print Area', + textCustom: 'Custom' }, SSE.Views.PrintSettings || {})); }); \ No newline at end of file