diff --git a/apps/spreadsheeteditor/main/app/controller/Print.js b/apps/spreadsheeteditor/main/app/controller/Print.js index 3a6f827e5..c3d5b8b68 100644 --- a/apps/spreadsheeteditor/main/app/controller/Print.js +++ b/apps/spreadsheeteditor/main/app/controller/Print.js @@ -65,7 +65,8 @@ define([ 'PrintWithPreview': { 'show': _.bind(this.onShowMainSettingsPrint, this), 'render:after': _.bind(this.onAfterRender, this), - 'changerange': _.bind(this.onChangeRange, this, false) + 'changerange': _.bind(this.onChangeRange, this, false), + 'openheader': _.bind(this.onOpenHeaderSettings, this), }, 'PrintSettings': { 'changerange': _.bind(this.onChangeRange, this, true) @@ -115,7 +116,6 @@ define([ this.api = o; this.api.asc_registerCallback('asc_onSheetsChanged', _.bind(this.updateSheetsInfo, this)); this.api.asc_registerCallback('asc_onPrintPreviewSheetChanged', _.bind(this.onApiChangePreviewSheet, this)); - this.api.asc_registerCallback('asc_onUpdateDocumentProps', _.bind(this.updateDocumentProps, this)); }, updateSheetsInfo: function() { @@ -148,7 +148,11 @@ define([ }, comboSheetsChange: function(panel, combo, record) { - this.fillPageOptions(panel, this._changedProps[record.value] ? this._changedProps[record.value] : this.api.asc_getPageOptions(record.value, true), record.value); + var currentSheet = record.value; + this.fillPageOptions(panel, this._changedProps[currentSheet] ? this._changedProps[currentSheet] : this.api.asc_getPageOptions(currentSheet, true), currentSheet); + if (!this._changedProps[currentSheet]) { + this._changedProps[currentSheet] = this.getPageOptions(this.printSettings, currentSheet); + } }, fillPageOptions: function(panel, props, sheet) { @@ -248,12 +252,12 @@ define([ } }, - getPageOptions: function(panel) { - var props = new Asc.asc_CPageOptions(); + getPageOptions: function(panel, sheet) { + var props = this._changedProps[sheet] ? this._changedProps[sheet] : new Asc.asc_CPageOptions(); props.asc_setGridLines(panel.chPrintGrid.getValue()==='checked'); props.asc_setHeadings(panel.chPrintRows.getValue()==='checked'); - var opt = new Asc.asc_CPageSetup(); + var opt = this._changedProps[sheet] ? this._changedProps[sheet].asc_getPageSetup() : new Asc.asc_CPageSetup(); opt.asc_setOrientation(panel.cmbPaperOrientation.getValue() == '-' ? undefined : panel.cmbPaperOrientation.getValue()); var pagew = /^\d{3}\.?\d*/.exec(panel.cmbPaperSize.getValue()); @@ -275,15 +279,19 @@ define([ opt.asc_setFitToHeight(this.fitHeight); opt.asc_setScale(this.fitScale); } - props.asc_setPageSetup(opt); + if (!this._changedProps[sheet]) { + props.asc_setPageSetup(opt); + } - opt = new Asc.asc_CPageMargins(); + opt = this._changedProps[sheet] ? this._changedProps[sheet].asc_getPageMargins() : new Asc.asc_CPageMargins(); opt.asc_setLeft(panel.spnMarginLeft.getValue() == '-' ? undefined : Common.Utils.Metric.fnRecalcToMM(panel.spnMarginLeft.getNumberValue())); // because 1.91*10=19.0999999... opt.asc_setTop(panel.spnMarginTop.getValue() == '-' ? undefined : Common.Utils.Metric.fnRecalcToMM(panel.spnMarginTop.getNumberValue())); opt.asc_setRight(panel.spnMarginRight.getValue() == '-' ? undefined : Common.Utils.Metric.fnRecalcToMM(panel.spnMarginRight.getNumberValue())); opt.asc_setBottom(panel.spnMarginBottom.getValue() == '-' ? undefined : Common.Utils.Metric.fnRecalcToMM(panel.spnMarginBottom.getNumberValue())); - props.asc_setPageMargins(opt); + if (!this._changedProps[sheet]) { + props.asc_setPageMargins(opt); + } var check = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.PrintTitles, panel.txtRangeTop.getValue(), false) !== Asc.c_oAscError.ID.DataRangeError; props.asc_setPrintTitlesHeight(check ? panel.txtRangeTop.getValue() : panel.dataRangeTop); @@ -480,7 +488,8 @@ define([ me.fitScale = result.scale; me.setScaling(panel, me.fitWidth, me.fitHeight, me.fitScale); if (me._changedProps) { - me._changedProps[panel.cmbSheet.getValue()] = me.getPageOptions(panel); + var currentSheet = panel.cmbSheet.getValue(); + me._changedProps[currentSheet] = me.getPageOptions(panel, currentSheet); me.updatePreview(); } } @@ -498,7 +507,8 @@ define([ Common.NotificationCenter.trigger('edit:complete', this.toolbar); } else { if (this._changedProps) { - this._changedProps[panel.cmbSheet.getValue()] = this.getPageOptions(panel); + var currentSheet = panel.cmbSheet.getValue(); + this._changedProps[currentSheet] = this.getPageOptions(panel, currentSheet); this.updatePreview(); } } @@ -749,11 +759,9 @@ define([ this.printSettings.btnNextPage.setDisabled(curPage > pageCount - 2); }, - updateDocumentProps: function (index) { - if (this._isPreviewVisible) { - this._changedProps[index] = this.api.asc_getPageOptions(index); - this.updatePreview(); - } + onOpenHeaderSettings: function () { + var pageSetup = this._changedProps[this.printSettings.cmbSheet.getValue()].asc_getPageSetup(); + SSE.getController('Toolbar').onEditHeaderClick(pageSetup); }, warnCheckMargings: 'Margins are incorrect', diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index 29be2e544..d5b388be3 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -401,7 +401,7 @@ define([ toolbar.btnImgForward.on('click', this.onImgArrangeSelect.bind(this, 'forward')); toolbar.btnImgBackward.on('click', this.onImgArrangeSelect.bind(this, 'backward')); toolbar.btnsEditHeader.forEach(function(button) { - button.on('click', _.bind(me.onEditHeaderClick, me)); + button.on('click', _.bind(me.onEditHeaderClick, me, undefined)); }); toolbar.btnPrintTitles.on('click', _.bind(this.onPrintTitlesClick, this)); toolbar.chPrintGridlines.on('change', _.bind(this.onPrintGridlinesChange, this)); @@ -3964,7 +3964,7 @@ define([ this.toolbar.btnPrintArea.menu.items[2].setVisible(this.api.asc_CanAddPrintArea()); }, - onEditHeaderClick: function(btn) { + onEditHeaderClick: function(pageSetup, btn) { var me = this; if (_.isUndefined(me.fontStore)) { me.fontStore = new Common.Collections.Fonts(); @@ -3981,6 +3981,7 @@ define([ var win = new SSE.Views.HeaderFooterDialog({ api: me.api, fontStore: me.fontStore, + pageSetup: pageSetup, handler: function(dlg, result) { if (result === 'ok') { me.getApplication().getController('Print').updatePreview(); diff --git a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js index df69c1f5d..67626ca3f 100644 --- a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js +++ b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js @@ -2778,7 +2778,7 @@ define([ }, openHeaderSettings: function() { - SSE.getController('Toolbar').onEditHeaderClick(); + this.fireEvent('openheader', this); }, updateCountOfPages: function (count) { diff --git a/apps/spreadsheeteditor/main/app/view/HeaderFooterDialog.js b/apps/spreadsheeteditor/main/app/view/HeaderFooterDialog.js index 8fd8290e4..711839b95 100644 --- a/apps/spreadsheeteditor/main/app/view/HeaderFooterDialog.js +++ b/apps/spreadsheeteditor/main/app/view/HeaderFooterDialog.js @@ -63,6 +63,7 @@ define([ this.api = this.options.api; this.props = this.options.props; this.fontStore = this.options.fontStore; + this.pageSetup = this.options.pageSetup; this.isFooter = false; this.currentCanvas = null; this.headerControls = []; @@ -619,7 +620,7 @@ define([ Common.UI.Window.prototype.close.apply(this, arguments); if (this.HFObject) - this.HFObject.destroy(); + this.HFObject.destroy(false, this.pageSetup); }, afterRender: function () { @@ -631,7 +632,7 @@ define([ this.cmbFonts[1].fillFonts(this.fontStore); this.updateThemeColors(); - this.HFObject = new Asc.asc_CHeaderFooterEditor(['header-left-img', 'header-center-img', 'header-right-img', 'footer-left-img', 'footer-center-img', 'footer-right-img'], 205); + this.HFObject = new Asc.asc_CHeaderFooterEditor(['header-left-img', 'header-center-img', 'header-right-img', 'footer-left-img', 'footer-center-img', 'footer-right-img'], 205, undefined, this.pageSetup); this._setDefaults(this.props); this.editorCanvas = this.$window.find('#ce-canvas-menu'); var me = this; @@ -697,7 +698,7 @@ define([ _handleInput: function(state) { if (this.HFObject) { - var id = this.HFObject.destroy(state=='ok'); + var id = this.HFObject.destroy(state=='ok', this.pageSetup); if (id) { var me = this; this.showError(function() {