/* * * (c) Copyright Ascensio System SIA 2010-2019 * * 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', 'spreadsheeteditor/main/app/view/FileMenuPanels', 'spreadsheeteditor/main/app/view/PrintSettings' ], function () { 'use strict'; SSE.Controllers.Print = Backbone.Controller.extend(_.extend({ views: [ 'MainSettingsPrint' ], initialize: function() { var value = Common.localStorage.getItem("sse-print-settings-range"); value = (value!==null) ? parseInt(value) : Asc.c_oAscPrintType.ActiveSheets; this.adjPrintParams = new Asc.asc_CAdjustPrint(); this.adjPrintParams.asc_setPrintType(value); this._changedProps = null; this._originalPageSettings = null; this.addListeners({ 'MainSettingsPrint': { 'show': _.bind(this.onShowMainSettingsPrint, this), 'render:after': _.bind(this.onAfterRender, this) }, 'PrintSettings': { 'changerange': _.bind(this.onChangeRange,this) } }); Common.NotificationCenter.on('print', _.bind(this.openPrintSettings, this, 'print')); Common.NotificationCenter.on('download:settings', _.bind(this.openPrintSettings, this, 'download')); }, onLaunch: function() { this.printSettings = this.createView('MainSettingsPrint'); }, onAfterRender: function(view) { this.printSettings.cmbSheet.on('selected', _.bind(this.comboSheetsChange, this, this.printSettings)); this.printSettings.btnOk.on('click', _.bind(this.querySavePrintSettings, this)); this.registerControlEvents(this.printSettings); }, setApi: function(o) { this.api = o; this.api.asc_registerCallback('asc_onSheetsChanged', _.bind(this.updateSheetsInfo, this)); }, updateSheetsInfo: function() { if (this.printSettings.isVisible()) { this.updateSettings(this.printSettings); } else { this.isFillSheets = false; } }, updateSettings: function(panel) { var wc = this.api.asc_getWorksheetsCount(), i = -1; var items = []; while (++i < wc) { if (!this.api.asc_isWorksheetHidden(i)) { items.push({ displayValue:this.api.asc_getWorksheetName(i), value: i }); } } panel.cmbSheet.store.reset(items); var item = panel.cmbSheet.store.findWhere({value: panel.cmbSheet.getValue()}) || panel.cmbSheet.store.findWhere({value: this.api.asc_getActiveWorksheetIndex()}); if (item) { panel.cmbSheet.setValue(item.get('value')); } }, comboSheetsChange: function(panel, combo, record) { this.fillPageOptions(panel, this._changedProps[record.value] ? this._changedProps[record.value] : this.api.asc_getPageOptions(record.value)); }, fillPageOptions: function(panel, props) { var opt = props.asc_getPageSetup(); this._originalPageSettings = opt; var item = panel.cmbPaperOrientation.store.findWhere({value: opt.asc_getOrientation()}); if (item) panel.cmbPaperOrientation.setValue(item.get('value')); var w = opt.asc_getWidth(); var h = opt.asc_getHeight(); var store = panel.cmbPaperSize.store; item = null; for (var i=0; i pagewidth) result = 'left'; else if (mr > pagewidth-ml) result = 'right'; else if (mt > pageheight) result = 'top'; else if (mb > pageheight-mt) result = 'bottom'; if (result) { Common.UI.warning({ title: this.textWarning, msg: this.warnCheckMargings, callback: function(btn,text) { switch(result) { case 'left': panel.spnMarginLeft.$el.focus(); return; case 'right': panel.spnMarginRight.$el.focus(); return; case 'top': panel.spnMarginTop.$el.focus(); return; case 'bottom': panel.spnMarginBottom.$el.focus(); return; } } }); return false; } return true; }, registerControlEvents: function(panel) { 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, 'scale')); 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)); panel.spnMarginRight.on('change', _.bind(this.propertyChange, this, panel)); panel.chPrintGrid.on('change', _.bind(this.propertyChange, this, panel)); panel.chPrintRows.on('change', _.bind(this.propertyChange, this, panel)); }, propertyChange: function(panel, scale, combo, record) { if (scale === 'scale' && record.value === 4) { var me = this, props = (me._changedProps.length > 0 && me._changedProps[panel.cmbSheet.getValue()]) ? me._changedProps[panel.cmbSheet.getValue()] : me.api.asc_getPageOptions(panel.cmbSheet.getValue()); var win = new SSE.Views.ScaleDialog({ api: me.api, props: props, 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); if (me._changedProps) { me._changedProps[panel.cmbSheet.getValue()] = me.getPageOptions(panel); } } } else { var opt = props.asc_getPageSetup(), fitwidth = opt.asc_getFitToWidth(), fitheight = opt.asc_getFitToHeight(), fitscale = opt.asc_getScale(); me.setScaling(panel, fitwidth, fitheight, fitscale); } Common.NotificationCenter.trigger('edit:complete'); } }); win.show(); Common.NotificationCenter.trigger('edit:complete', this.toolbar); } else { if (this._changedProps) { this._changedProps[panel.cmbSheet.getValue()] = this.getPageOptions(panel); } } }, getPrintParams: function() { return this.adjPrintParams; }, setScaling: function (panel, width, height, scale) { if (!width && !height && scale === 100) panel.cmbLayout.setValue(0, true); else if (width === 1 && height === 1) panel.cmbLayout.setValue(1, true); else if (width === 1 && !height) panel.cmbLayout.setValue(2, true); else if (!width && height === 1) panel.cmbLayout.setValue(3, true); else panel.cmbLayout.setValue(4, true); }, warnCheckMargings: 'Margins are incorrect', strAllSheets: 'All Sheets', textWarning: 'Warning', txtCustom: 'Custom' }, SSE.Controllers.Print || {})); });