/* * * (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 * */ /** * TableSettingsAdvanced.js * * Created by Julia Radzhabova on 2/27/14 * Copyright (c) 2018 Ascensio System SIA. All rights reserved. * */ define([ 'text!documenteditor/main/app/template/TableSettingsAdvanced.template', 'common/main/lib/view/AdvancedSettingsWindow', 'common/main/lib/component/ComboBox', 'common/main/lib/component/MetricSpinner', 'common/main/lib/component/CheckBox', 'common/main/lib/component/RadioBox', 'common/main/lib/component/ThemeColorPalette', 'common/main/lib/component/ColorButton', 'common/main/lib/component/ListView', 'common/main/lib/component/TableStyler' ], function (contentTemplate) { 'use strict'; DE.Views.TableSettingsAdvanced = Common.Views.AdvancedSettingsWindow.extend(_.extend({ options: { contentWidth: 340, height: 436, toggleGroup: 'table-adv-settings-group', storageName: 'de-table-settings-adv-category' }, initialize : function(options) { _.extend(this.options, { title: this.textTitle, items: [ {panelId: 'id-adv-table-width', panelCaption: this.textTable}, {panelId: 'id-adv-table-cell-props', panelCaption: this.textCellProps}, {panelId: 'id-adv-table-borders', panelCaption: this.textBordersBackgroung}, {panelId: 'id-adv-table-position', panelCaption: this.textTablePosition}, {panelId: 'id-adv-table-wrap', panelCaption: this.textWrap}, {panelId: 'id-adv-table-alttext', panelCaption: this.textAlt} ], contentTemplate: _.template(contentTemplate)({ scope: this }) }, options); Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options); this.spinners = []; this._changedProps = null; this._cellBackground = null; this._state = { HAlignType: Asc.c_oAscXAlign.Left, HAlignFrom: Asc.c_oAscHAnchor.Margin, HPositionFrom: Asc.c_oAscHAnchor.Margin, VAlignType: Asc.c_oAscYAlign.Top, VAlignFrom: Asc.c_oAscVAnchor.Margin, VPositionFrom: Asc.c_oAscVAnchor.Margin, spnXChanged: false, spnYChanged: false, fromWrapInline: false, verticalPropChanged: false, horizontalPropChanged: false, alignChanged: false }; this._allTable = false; this.TableMargins = { Left : 0.19, Right : 0.19, Top : 0, Bottom : 0 }; this.CellMargins = { Left : 0.19, Right : 0.19, Top : null, Bottom : null, Flag : 0 // 0(checked) - как в таблице, 1(indeterminate) - разные значения, не определено, 2 (unchecked) - собственные }; this.TableBorders = {}; this.CellBorders = {}; this.ChangedTableBorders = undefined; // undefined - не менялись, null - применялись пресеты, отправлять TableBorders, object - менялись отдельные границы, отправлять ChangedTableBorders this.ChangedCellBorders = undefined; // undefined - не менялись, null - применялись пресеты, отправлять CellBorders, object - менялись отдельные границы, отправлять ChangedCellBorders this.BorderSize = {ptValue: 0, pxValue: 0}; this.TableColor = {Value: 1, Color: 'transparent'}; // value=1 - цвет определен - прозрачный или другой this.CellColor = {Value: 1, Color: 'transparent'}; // value=1 - цвет определен - прозрачный или другой, value=0 - цвет не определен, рисуем прозрачным this.IndeterminateColor = '#C8C8C8'; this.IndeterminateSize = 4.5; this.tableStylerRows = this.options.tableStylerRows; this.tableStylerColumns = this.options.tableStylerColumns; this.borderProps = this.options.borderProps; this.pageWidth = 210; this._originalProps = new Asc.CTableProp(this.options.tableProps); }, render: function() { Common.Views.AdvancedSettingsWindow.prototype.render.call(this); var me = this; this._marginsChange = function(field, newValue, oldValue, eOpts, source, property){ if (source=='table') this.TableMargins[property] = field.getNumberValue(); else this.CellMargins[property] = field.getNumberValue(); }; this.chWidth = new Common.UI.CheckBox({ el: $('#tableadv-checkbox-width'), value: true, labelText: '' }); this.chWidth.on('change', _.bind(function(field, newValue, oldValue, eOpts){ var value = (newValue=='checked'); this.nfWidth.setDisabled(!value); this.cmbUnit.setDisabled(!value); if (this._changedProps) { if (value && this.nfWidth.getNumberValue()>0) this._changedProps.put_Width(this.cmbUnit.getValue() ? -field.getNumberValue() : Common.Utils.Metric.fnRecalcToMM(this.nfWidth.getNumberValue())); else this._changedProps.put_Width(null); } }, this)); this.nfWidth = new Common.UI.MetricSpinner({ el: $('#tableadv-number-width'), step: .1, width: 115, defaultUnit : "cm", value: '10 cm', maxValue: 55.88, minValue: 0 }); this.nfWidth.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (this._changedProps) this._changedProps.put_Width(this.cmbUnit.getValue() ? -field.getNumberValue() : Common.Utils.Metric.fnRecalcToMM(field.getNumberValue())); }, this)); var currmetric = Common.Utils.Metric.getCurrentMetric(); this.cmbUnit = new Common.UI.ComboBox({ el : $('#tableadv-cmb-unit'), style : 'width: 115px;', menuStyle : 'min-width: 115px;', editable : false, cls : 'input-group-nr', data : [ { value: 0, displayValue: (currmetric == Common.Utils.Metric.c_MetricUnits.pt) ? this.txtPt : ((currmetric == Common.Utils.Metric.c_MetricUnits.inch) ? this.txtInch : this.txtCm) }, { value: 1, displayValue: this.txtPercent } ] }); this.cmbUnit.on('selected', _.bind(function(combo, record) { if (this._changedProps) { var maxwidth = Common.Utils.Metric.fnRecalcFromMM(558); this.nfWidth.setDefaultUnit(record.value ? '%' : Common.Utils.Metric.getCurrentMetricName()); this.nfWidth.setMaxValue(record.value ? parseFloat((100 * maxwidth/this.pageWidth).toFixed(2)) : maxwidth); this.nfWidth.setStep((record.value || Common.Utils.Metric.getCurrentMetric()==Common.Utils.Metric.c_MetricUnits.pt) ? 1 : 0.1); this.nfWidth.setValue((record.value) ? 100*this.nfWidth.getNumberValue()/this.pageWidth : this.pageWidth*this.nfWidth.getNumberValue()/100); this._changedProps.put_Width(record.value ? -this.nfWidth.getNumberValue() : Common.Utils.Metric.fnRecalcToMM(this.nfWidth.getNumberValue())); } }, this)); this.chAllowSpacing = new Common.UI.CheckBox({ el: $('#tableadv-checkbox-spacing'), value: true, labelText: '' }); this.chAllowSpacing.on('change', _.bind(function(field, newValue, oldValue, eOpts){ var value = (newValue=='checked'); if (this._changedProps) { this.nfSpacing.setDisabled(!value); this.ShowHideSpacing(value); if (this._changedProps) { if (value && this.nfSpacing.getNumberValue()>0) this._changedProps.put_Spacing(Common.Utils.Metric.fnRecalcToMM(this.nfSpacing.getNumberValue())); else this._changedProps.put_Spacing(null); } } }, this)); this.nfSpacing = new Common.UI.MetricSpinner({ el: $('#tableadv-number-spacing'), step: .1, width: 115, defaultUnit : "cm", value: '0.5 cm', maxValue: 2.14, minValue: 0 }); this.nfSpacing.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (this._changedProps) this._changedProps.put_Spacing(Common.Utils.Metric.fnRecalcToMM(field.getNumberValue())); }, this)); this.spinners.push(this.nfSpacing); this.chAutofit = new Common.UI.CheckBox({ el: $('#tableadv-checkbox-autofit'), value: true, labelText: this.textAutofit }); this.chAutofit.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (this._changedProps) { this._changedProps.put_TableLayout((field.getValue()=='checked') ? Asc.c_oAscTableLayout.AutoFit : Asc.c_oAscTableLayout. Fixed); } }, this)); // Margins this.spnTableMarginTop = new Common.UI.MetricSpinner({ el: $('#tableadv-number-margin-table-top'), step: .1, width: 85, defaultUnit : "cm", value: '0 cm', maxValue: 55.87, minValue: 0 }); this.spnTableMarginTop.on('change', _.bind(function(field, newValue, oldValue, eOpts){ this._marginsChange( field, newValue, oldValue, eOpts, 'table', 'Top'); if (this._changedProps) { if (this._changedProps.get_DefaultMargins()===undefined) this._changedProps.put_DefaultMargins(new Asc.asc_CPaddings()); this._changedProps.get_DefaultMargins().put_Top((this.TableMargins.Top!==null) ? Common.Utils.Metric.fnRecalcToMM(this.TableMargins.Top) : null); this.TableMargins.isChanged = true; } }, this)); this.spinners.push(this.spnTableMarginTop); this.spnTableMarginBottom = new Common.UI.MetricSpinner({ el: $('#tableadv-number-margin-table-bottom'), step: .1, width: 85, defaultUnit : "cm", value: '0 cm', maxValue: 55.87, minValue: 0 }); this.spnTableMarginBottom.on('change', _.bind(function(field, newValue, oldValue, eOpts){ this._marginsChange( field, newValue, oldValue, eOpts, 'table', 'Bottom'); if (this._changedProps) { if (this._changedProps.get_DefaultMargins()===undefined) this._changedProps.put_DefaultMargins(new Asc.asc_CPaddings()); this._changedProps.get_DefaultMargins().put_Bottom((this.TableMargins.Bottom!==null) ? Common.Utils.Metric.fnRecalcToMM(this.TableMargins.Bottom) : null); this.TableMargins.isChanged = true; } }, this)); this.spinners.push(this.spnTableMarginBottom); this.spnTableMarginLeft = new Common.UI.MetricSpinner({ el: $('#tableadv-number-margin-table-left'), step: .1, width: 85, defaultUnit : "cm", value: '0.19 cm', maxValue: 9.34, minValue: 0 }); this.spnTableMarginLeft.on('change', _.bind(function(field, newValue, oldValue, eOpts){ this._marginsChange( field, newValue, oldValue, eOpts, 'table', 'Left'); if (this._changedProps) { if (this._changedProps.get_DefaultMargins()===undefined) this._changedProps.put_DefaultMargins(new Asc.asc_CPaddings()); this._changedProps.get_DefaultMargins().put_Left((this.TableMargins.Left!==null) ? Common.Utils.Metric.fnRecalcToMM(this.TableMargins.Left) : null); this.TableMargins.isChanged = true; } }, this)); this.spinners.push(this.spnTableMarginLeft); this.spnTableMarginRight = new Common.UI.MetricSpinner({ el: $('#tableadv-number-margin-table-right'), step: .1, width: 85, defaultUnit : "cm", value: '0.19 cm', maxValue: 9.34, minValue: 0 }); this.spnTableMarginRight.on('change', _.bind(function(field, newValue, oldValue, eOpts){ this._marginsChange( field, newValue, oldValue, eOpts, 'table', 'Right'); if (this._changedProps) { if (this._changedProps.get_DefaultMargins()===undefined) this._changedProps.put_DefaultMargins(new Asc.asc_CPaddings()); this._changedProps.get_DefaultMargins().put_Right((this.TableMargins.Right!==null) ? Common.Utils.Metric.fnRecalcToMM(this.TableMargins.Right) : null); this.TableMargins.isChanged = true; } }, this)); this.spinners.push(this.spnTableMarginRight); // Cell Margins var setCellFlag = function() { if (me.CellMargins.Flag=='indeterminate') me._changedProps.get_CellMargins().put_Flag(1); else if (me.CellMargins.Flag=='checked') me._changedProps.get_CellMargins().put_Flag(0); else me._changedProps.get_CellMargins().put_Flag(2); }; this.chCellMargins = new Common.UI.CheckBox({ el: $('#tableadv-checkbox-margins'), value: true, labelText: this.textCheckMargins }); this.chCellMargins.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if ( oldValue=='checked' && this._originalProps && this._originalProps.get_CellMargins().get_Flag()==1 ) { // позволяем выставлять значение indeterminate только если исходные значения не совпадали field.setValue('indeterminate', true); } this.fillMargins.call( this, field.getValue()); this.CellMargins.Flag = field.getValue(); if (this._changedProps) { if (this._changedProps.get_CellMargins()===undefined) this._changedProps.put_CellMargins(new Asc.CMargins()); this._changedProps.get_CellMargins().put_Left( ( this.CellMargins.Left!== null) ? Common.Utils.Metric.fnRecalcToMM(this.CellMargins.Left) : null); this._changedProps.get_CellMargins().put_Top((this.CellMargins.Top!==null) ? Common.Utils.Metric.fnRecalcToMM(this.CellMargins.Top) : null); this._changedProps.get_CellMargins().put_Bottom((this.CellMargins.Bottom!==null) ? Common.Utils.Metric.fnRecalcToMM(this.CellMargins.Bottom) : null); this._changedProps.get_CellMargins().put_Right((this.CellMargins.Right!==null) ? Common.Utils.Metric.fnRecalcToMM(this.CellMargins.Right) : null); setCellFlag(); } }, this)); this.spnMarginTop = new Common.UI.MetricSpinner({ el: $('#tableadv-number-margin-top'), step: .1, width: 85, defaultUnit : "cm", value: '0 cm', maxValue: 55.87, minValue: 0 }); this.spnMarginTop.on('change', _.bind(function(field, newValue, oldValue, eOpts){ this._marginsChange( field, newValue, oldValue, eOpts, 'cell', 'Top'); if (this._changedProps) { if (this._changedProps.get_CellMargins()===undefined) this._changedProps.put_CellMargins(new Asc.CMargins()); this._changedProps.get_CellMargins().put_Top((this.CellMargins.Top!==null) ? Common.Utils.Metric.fnRecalcToMM(this.CellMargins.Top) : null); setCellFlag(); } }, this)); this.spinners.push(this.spnMarginTop); this.spnMarginBottom = new Common.UI.MetricSpinner({ el: $('#tableadv-number-margin-bottom'), step: .1, width: 85, defaultUnit : "cm", value: '0 cm', maxValue: 55.87, minValue: 0 }); this.spnMarginBottom.on('change', _.bind(function(field, newValue, oldValue, eOpts){ this._marginsChange( field, newValue, oldValue, eOpts, 'cell', 'Bottom'); if (this._changedProps) { if (this._changedProps.get_CellMargins()===undefined) this._changedProps.put_CellMargins(new Asc.CMargins()); this._changedProps.get_CellMargins().put_Bottom((this.CellMargins.Bottom!==null) ? Common.Utils.Metric.fnRecalcToMM(this.CellMargins.Bottom) : null); setCellFlag(); } }, this)); this.spinners.push(this.spnMarginBottom); this.spnMarginLeft = new Common.UI.MetricSpinner({ el: $('#tableadv-number-margin-left'), step: .1, width: 85, defaultUnit : "cm", value: '0.19 cm', maxValue: 9.34, minValue: 0 }); this.spnMarginLeft.on('change', _.bind(function(field, newValue, oldValue, eOpts){ this._marginsChange( field, newValue, oldValue, eOpts, 'cell', 'Left'); if (this._changedProps) { if (this._changedProps.get_CellMargins()===undefined) this._changedProps.put_CellMargins(new Asc.CMargins()); this._changedProps.get_CellMargins().put_Left((this.CellMargins.Left!==null) ? Common.Utils.Metric.fnRecalcToMM(this.CellMargins.Left) : null); setCellFlag(); } }, this)); this.spinners.push(this.spnMarginLeft); this.spnMarginRight = new Common.UI.MetricSpinner({ el: $('#tableadv-number-margin-right'), step: .1, width: 85, defaultUnit : "cm", value: '0.19 cm', maxValue: 9.34, minValue: 0 }); this.spnMarginRight.on('change', _.bind(function(field, newValue, oldValue, eOpts){ this._marginsChange( field, newValue, oldValue, eOpts, 'cell', 'Right'); if (this._changedProps) { if (this._changedProps.get_CellMargins()===undefined) this._changedProps.put_CellMargins(new Asc.CMargins()); this._changedProps.get_CellMargins().put_Right((this.CellMargins.Right!==null) ? Common.Utils.Metric.fnRecalcToMM(this.CellMargins.Right) : null); setCellFlag(); } }, this)); this.spinners.push(this.spnMarginRight); // Cell Size this.chPrefWidth = new Common.UI.CheckBox({ el: $('#tableadv-checkbox-prefwidth'), value: false, labelText: '' }); this.chPrefWidth.on('change', _.bind(function(field, newValue, oldValue, eOpts){ var value = (newValue=='checked'); this.nfPrefWidth.setDisabled(!value); this.cmbPrefWidthUnit.setDisabled(!value); if (this._changedProps) { if (value && this.nfPrefWidth.getNumberValue()>0) this._changedProps.put_CellsWidth(this.cmbPrefWidthUnit.getValue() ? -field.getNumberValue() : Common.Utils.Metric.fnRecalcToMM(this.nfPrefWidth.getNumberValue())); else this._changedProps.put_CellsWidth(null); } }, this)); this.nfPrefWidth = new Common.UI.MetricSpinner({ el: $('#tableadv-number-prefwidth'), step: .1, width: 115, defaultUnit : "cm", value: '10 cm', maxValue: 55.88, minValue: 0 }); this.nfPrefWidth.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (this._changedProps) this._changedProps.put_CellsWidth(this.cmbPrefWidthUnit.getValue() ? -field.getNumberValue() : Common.Utils.Metric.fnRecalcToMM(field.getNumberValue())); }, this)); this.cmbPrefWidthUnit = new Common.UI.ComboBox({ el : $('#tableadv-combo-prefwidth-unit'), style : 'width: 115px;', menuStyle : 'min-width: 115px;', editable : false, cls : 'input-group-nr', data : [ { value: 0, displayValue: (currmetric == Common.Utils.Metric.c_MetricUnits.pt) ? this.txtPt : ((currmetric == Common.Utils.Metric.c_MetricUnits.inch) ? this.txtInch : this.txtCm) }, { value: 1, displayValue: this.txtPercent } ] }); this.cmbPrefWidthUnit.on('selected', _.bind(function(combo, record) { if (this._changedProps) { var defUnit = (record.value) ? '%' : Common.Utils.Metric.getCurrentMetricName(); if (this.nfPrefWidth.getUnitValue() !== defUnit) { var maxwidth = Common.Utils.Metric.fnRecalcFromMM(558); this.nfPrefWidth.setDefaultUnit(defUnit); this.nfPrefWidth.setMaxValue(record.value ? parseFloat((100 * maxwidth/this.pageWidth).toFixed(2)) : maxwidth); this.nfPrefWidth.setStep((record.value || Common.Utils.Metric.getCurrentMetric()==Common.Utils.Metric.c_MetricUnits.pt) ? 1 : 0.1); this.nfPrefWidth.setValue((record.value) ? 100*this.nfPrefWidth.getNumberValue()/this.pageWidth : this.pageWidth*this.nfPrefWidth.getNumberValue()/100); this._changedProps.put_CellsWidth(record.value ? -this.nfPrefWidth.getNumberValue() : Common.Utils.Metric.fnRecalcToMM(this.nfPrefWidth.getNumberValue())); } } }, this)); this.chWrapText = new Common.UI.CheckBox({ el: $('#tableadv-checkbox-wrap'), value: false, labelText: this.textWrapText }); this.chWrapText.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (this._changedProps) { this._changedProps.put_CellsNoWrap((field.getValue()!='checked')); } }, this)); // Wrapping this.btnWrapNone = new Common.UI.Button({ cls: 'btn-options huge', iconCls: 'icon-right-panel btn-wrap-none', posId: c_tableWrap.TABLE_WRAP_NONE, hint: this.textWrapNoneTooltip, enableToggle: true, allowDepress: false, toggleGroup : 'advtablewrapGroup' }); this.btnWrapNone.render( $('#tableadv-button-wrap-none')) ; this.btnWrapNone.on('click', _.bind(this.onBtnInlineWrapClick, this)); this.btnWrapParallel = new Common.UI.Button({ cls: 'btn-options huge', iconCls: 'icon-right-panel btn-wrap-parallel', posId: c_tableWrap.TABLE_WRAP_PARALLEL, hint: this.textWrapParallelTooltip, enableToggle: true, allowDepress: false, toggleGroup : 'advtablewrapGroup' }); this.btnWrapParallel.render( $('#tableadv-button-wrap-parallel')) ; this.btnWrapParallel.on('click', _.bind(this.onBtnFlowWrapClick, this)); this.btnAlignLeft = new Common.UI.Button({ cls: 'btn-options huge', iconCls: 'icon-right-panel btn-table-align-left', posId: c_tableAlign.TABLE_ALIGN_LEFT, hint: this.textLeftTooltip, enableToggle: true, allowDepress: false, toggleGroup : 'advtablealignGroup' }); this.btnAlignLeft.render( $('#tableadv-button-align-left')) ; this.btnAlignLeft.on('click', _.bind(function(btn){ if (this._changedProps && btn.pressed) { this._changedProps.put_TableAlignment(btn.options.posId); this._changedProps.put_TableIndent(Common.Utils.Metric.fnRecalcToMM(this.spnIndentLeft.getNumberValue())); this.spnIndentLeft.setDisabled(!btn.pressed); this._state.alignChanged = true; } }, this)); this.btnAlignCenter = new Common.UI.Button({ cls: 'btn-options huge', iconCls: 'icon-right-panel btn-table-align-center', posId: c_tableAlign.TABLE_ALIGN_CENTER, hint: this.textCenterTooltip, enableToggle: true, allowDepress: false, toggleGroup : 'advtablealignGroup' }); this.btnAlignCenter.render( $('#tableadv-button-align-center')) ; this.btnAlignCenter.on('click', _.bind(function(btn){ if (this._changedProps && btn.pressed) { this._changedProps.put_TableAlignment(btn.options.posId); this._changedProps.put_TableIndent(0); this.spnIndentLeft.setDisabled(btn.pressed); this._state.alignChanged = true; } }, this)); this.btnAlignRight = new Common.UI.Button({ cls: 'btn-options huge', iconCls: 'icon-right-panel btn-table-align-right', posId: c_tableAlign.TABLE_ALIGN_RIGHT, hint: this.textRightTooltip, enableToggle: true, allowDepress: false, toggleGroup : 'advtablealignGroup' }); this.btnAlignRight.render( $('#tableadv-button-align-right')) ; this.btnAlignRight.on('click', _.bind(function(btn){ if (this._changedProps && btn.pressed) { this._changedProps.put_TableAlignment(btn.options.posId); this._changedProps.put_TableIndent(0); this.spnIndentLeft.setDisabled(btn.pressed); this._state.alignChanged = true; } }, this)); this.spnIndentLeft = new Common.UI.MetricSpinner({ el: $('#tableadv-number-indent'), step: .1, width: 85, defaultUnit : "cm", defaultValue : 0, value: '0 cm', maxValue: 38.09, minValue: -38.09 }); this.spnIndentLeft.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (this._changedProps) { this._changedProps.put_TableIndent(Common.Utils.Metric.fnRecalcToMM(field.getNumberValue())); } }, this)); this.spinners.push(this.spnIndentLeft); this.spnDistanceTop = new Common.UI.MetricSpinner({ el: $('#tableadv-number-distance-top'), step: .1, width: 85, defaultUnit : "cm", value: '1 cm', maxValue: 55.87, minValue: 0 }); this.spnDistanceTop.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (this._changedProps) { if (this._changedProps.get_TablePaddings()===undefined) this._changedProps.put_TablePaddings(new Asc.asc_CPaddings()); this._changedProps.get_TablePaddings().put_Top(Common.Utils.Metric.fnRecalcToMM(field.getNumberValue())); } }, this)); this.spinners.push(this.spnDistanceTop); this.spnDistanceBottom = new Common.UI.MetricSpinner({ el: $('#tableadv-number-distance-bottom'), step: .1, width: 85, defaultUnit : "cm", value: '1 cm', maxValue: 55.87, minValue: 0 }); this.spnDistanceBottom.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (this._changedProps) { if (this._changedProps.get_TablePaddings()===undefined) this._changedProps.put_TablePaddings(new Asc.asc_CPaddings()); this._changedProps.get_TablePaddings().put_Bottom(Common.Utils.Metric.fnRecalcToMM(field.getNumberValue())); } }, this)); this.spinners.push(this.spnDistanceBottom); this.spnDistanceLeft = new Common.UI.MetricSpinner({ el: $('#tableadv-number-distance-left'), step: .1, width: 85, defaultUnit : "cm", value: '1 cm', maxValue: 9.34, minValue: 0 }); this.spnDistanceLeft.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (this._changedProps) { if (this._changedProps.get_TablePaddings()===undefined) this._changedProps.put_TablePaddings(new Asc.asc_CPaddings()); this._changedProps.get_TablePaddings().put_Left(Common.Utils.Metric.fnRecalcToMM(field.getNumberValue())); } }, this)); this.spinners.push(this.spnDistanceLeft); this.spnDistanceRight = new Common.UI.MetricSpinner({ el: $('#tableadv-number-distance-right'), step: .1, width: 85, defaultUnit : "cm", value: '0.19 cm', maxValue: 9.34, minValue: 0 }); this.spnDistanceRight.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (this._changedProps) { if (this._changedProps.get_TablePaddings()===undefined) this._changedProps.put_TablePaddings(new Asc.asc_CPaddings()); this._changedProps.get_TablePaddings().put_Right(Common.Utils.Metric.fnRecalcToMM(field.getNumberValue())); } }, this)); this.spinners.push(this.spnDistanceRight); // Position this.spnX = new Common.UI.MetricSpinner({ el: $('#tableadv-spin-x'), step: .1, width: 115, disabled: true, defaultUnit : "cm", defaultValue : 0, value: '1 cm', maxValue: 55.87, minValue: -55.87 }); this.spnX.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (this._changedProps) { if (this._changedProps.get_PositionH()===null || this._changedProps.get_PositionH()===undefined) this._changedProps.put_PositionH(new Asc.CTablePositionH()); this._changedProps.get_PositionH().put_UseAlign(false); this._changedProps.get_PositionH().put_RelativeFrom(this._state.HPositionFrom); this._changedProps.get_PositionH().put_Value(Common.Utils.Metric.fnRecalcToMM(field.getNumberValue())); this._state.spnXChanged = true; } }, this)); this.spinners.push(this.spnX); this.spnY = new Common.UI.MetricSpinner({ el: $('#tableadv-spin-y'), step: .1, width: 115, disabled: true, defaultUnit : "cm", defaultValue : 0, value: '1 cm', maxValue: 55.87, minValue: -55.87 }); this.spnY.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (this._changedProps) { if (this._changedProps.get_PositionV()===null || this._changedProps.get_PositionV()===undefined) this._changedProps.put_PositionV(new Asc.CTablePositionV()); this._changedProps.get_PositionV().put_UseAlign(false); this._changedProps.get_PositionV().put_RelativeFrom(this._state.VPositionFrom); this._changedProps.get_PositionV().put_Value(Common.Utils.Metric.fnRecalcToMM(field.getNumberValue())); this._state.spnYChanged = true; } }, this)); this.spinners.push(this.spnY); // Horizontal this._arrHAlign = [ {displayValue: this.textLeft, value: Asc.c_oAscXAlign.Left}, {displayValue: this.textCenter, value: Asc.c_oAscXAlign.Center}, {displayValue: this.textRight, value: Asc.c_oAscXAlign.Right} ]; this.cmbHAlign = new Common.UI.ComboBox({ el: $('#tableadv-combo-halign'), cls: 'input-group-nr', menuStyle: 'min-width: 115px;', editable: false, data: this._arrHAlign }); this.cmbHAlign.setValue(this._state.HAlignType); this.cmbHAlign.on('selected', _.bind(this.onHAlignSelect, this)); this._arrHRelative = [ {displayValue: this.textMargin, value: Asc.c_oAscHAnchor.Margin}, {displayValue: this.textPage, value: Asc.c_oAscHAnchor.Page}, {displayValue: this.textAnchorText, value: Asc.c_oAscHAnchor.Text} ]; this.cmbHRelative = new Common.UI.ComboBox({ el: $('#tableadv-combo-hrelative'), cls: 'input-group-nr', menuStyle: 'min-width: 115px;', editable: false, data: this._arrHRelative }); this.cmbHRelative.setValue(this._state.HAlignFrom); this.cmbHRelative.on('selected', _.bind(this.onHRelativeSelect, this)); this.cmbHPosition = new Common.UI.ComboBox({ el: $('#tableadv-combo-hposition'), cls: 'input-group-nr', menuStyle: 'min-width: 115px;', editable: false, data: this._arrHRelative }); this.cmbHPosition.setDisabled(true); this.cmbHPosition.setValue(this._state.HPositionFrom); this.cmbHPosition.on('selected', _.bind(this.onHPositionSelect, this)); // Vertical this._arrVAlign = [ {displayValue: this.textTop, value: Asc.c_oAscYAlign.Top}, {displayValue: this.textCenter, value: Asc.c_oAscYAlign.Center}, {displayValue: this.textBottom, value: Asc.c_oAscYAlign.Bottom} ]; this.cmbVAlign = new Common.UI.ComboBox({ el: $('#tableadv-combo-valign'), cls: 'input-group-nr', menuStyle: 'min-width: 115px;', editable: false, data: this._arrVAlign }); this.cmbVAlign.setValue(this._state.VAlignType); this.cmbVAlign.on('selected', _.bind(this.onVAlignSelect, this)); this._arrVRelative = [ {displayValue: this.textMargin, value: Asc.c_oAscVAnchor.Margin}, {displayValue: this.textPage, value: Asc.c_oAscVAnchor.Page}, {displayValue: this.textAnchorText, value: Asc.c_oAscVAnchor.Text} ]; this.cmbVRelative = new Common.UI.ComboBox({ el: $('#tableadv-combo-vrelative'), cls: 'input-group-nr', menuStyle: 'min-width: 115px;', editable: false, data: this._arrVRelative }); this.cmbVRelative.setValue(this._state.VAlignFrom); this.cmbVRelative.on('selected', _.bind(this.onVRelativeSelect, this)); this.cmbVPosition = new Common.UI.ComboBox({ el: $('#tableadv-combo-vposition'), cls: 'input-group-nr', menuStyle: 'min-width: 115px;', editable: false, data: this._arrVRelative }); this.cmbVPosition.setDisabled(true); this.cmbVPosition.setValue(this._state.VPositionFrom); this.cmbVPosition.on('selected', _.bind(this.onVPositionSelect, this)); this.radioHAlign = new Common.UI.RadioBox({ el: $('#tableadv-radio-halign'), name: 'asc-radio-horizontal', checked: true }); this.radioHAlign.on('change', _.bind(this.onRadioHAlignChange, this)); this.radioHPosition = new Common.UI.RadioBox({ el: $('#tableadv-radio-hposition'), name: 'asc-radio-horizontal' }); this.radioHPosition.on('change', _.bind(this.onRadioHPositionChange, this)); this.radioVAlign = new Common.UI.RadioBox({ el: $('#tableadv-radio-valign'), name: 'asc-radio-vertical', checked: true }); this.radioVAlign.on('change', _.bind(this.onRadioVAlignChange, this)); this.radioVPosition = new Common.UI.RadioBox({ el: $('#tableadv-radio-vposition'), name: 'asc-radio-vertical' }); this.radioVPosition.on('change', _.bind(this.onRadioVPositionChange, this)); this.chMove = new Common.UI.CheckBox({ el: $('#tableadv-checkbox-move'), labelText: this.textMove }); this.chMove.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (this._changedProps) { var value = this._arrVRelative[(field.getValue()=='checked') ? 2 : 1].value; if (this.cmbVRelative.isDisabled()) { this.cmbVPosition.setValue(value); var rec = this.cmbVPosition.getSelectedRecord(); if (rec) this.onVPositionSelect(this.cmbVPosition, rec); } else { this.cmbVRelative.setValue(value); var rec = this.cmbVRelative.getSelectedRecord(); if (rec) this.onVRelativeSelect(this.cmbVRelative, rec); } } }, this)); this.chOverlap = new Common.UI.CheckBox({ el: $('#tableadv-checkbox-overlap'), labelText: this.textOverlap }); this.chOverlap.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (this._changedProps) { this._changedProps.put_AllowOverlap(field.getValue()=='checked'); } }, this)); // Borders this.cmbBorderSize = new Common.UI.ComboBorderSize({ el: $('#tableadv-combo-border-size'), style: "width: 93px;" }); var rec = this.cmbBorderSize.store.at(1); this.BorderSize = {ptValue: rec.get('value'), pxValue: rec.get('pxValue')}; this.cmbBorderSize.setValue(this.BorderSize.ptValue); this.cmbBorderSize.on('selected', _.bind(this.onBorderSizeSelect, this)); this.btnBorderColor = new Common.UI.ColorButton({ style: "width:45px;", menu : new Common.UI.Menu({ items: [ { template: _.template('
') }, { template: _.template('' + me.textNewColor + '') } ] }) }); this.btnBorderColor.on('render:after', function(btn) { me.colorsBorder = new Common.UI.ThemeColorPalette({ el: $('#tableadv-border-color-menu') }); me.colorsBorder.on('select', _.bind(me.onColorsBorderSelect, me)); }); this.btnBorderColor.render( $('#tableadv-border-color-btn')); this.btnBorderColor.setColor('000000'); $('#tableadv-border-color-new').on('click', _.bind(this.addNewColor, this, this.colorsBorder, this.btnBorderColor)); this.btnBackColor = new Common.UI.ColorButton({ style: "width:45px;", menu : new Common.UI.Menu({ items: [ { template: _.template('') }, { template: _.template('' + me.textNewColor + '') } ] }) }); this.btnBackColor.on('render:after', function(btn) { me.colorsBack = new Common.UI.ThemeColorPalette({ el: $('#tableadv-back-color-menu'), transparent: true }); me.colorsBack.on('select', _.bind(me.onColorsBackSelect, me)); }); this.btnBackColor.render( $('#tableadv-button-back-color')); $('#tableadv-back-color-new').on('click', _.bind(this.addNewColor, this, this.colorsBack, this.btnBackColor)); this.btnTableBackColor = new Common.UI.ColorButton({ style: "width:45px;", menu : new Common.UI.Menu({ items: [ { template: _.template('') }, { template: _.template('' + me.textNewColor + '') } ] }) }); this.btnTableBackColor.on('render:after', function(btn) { me.colorsTableBack = new Common.UI.ThemeColorPalette({ el: $('#tableadv-table-back-color-menu'), transparent: true }); me.colorsTableBack.on('select', _.bind(me.onColorsTableBackSelect, me)); }); this.btnTableBackColor.render( $('#tableadv-button-table-back-color')); $('#tableadv-table-back-color-new').on('click', _.bind(this.addNewColor, this, this.colorsTableBack, this.btnTableBackColor)); this.tableBordersImageSpacing = new Common.UI.TableStyler({ el: $('#id-detablestyler-spacing'), width: 200, height: 200, rows: this.tableStylerRows, columns: this.tableStylerColumns, spacingMode: true }); this.tableBordersImage = new Common.UI.TableStyler({ el: $('#id-detablestyler'), width: 200, height: 200, rows: this.tableStylerRows, columns: this.tableStylerColumns, spacingMode: false }); var _arrBorderPresets = [ ['cm', 'btn-borders-large btn-adv-position-inner', 'tableadv-button-border-inner', this.tipInner], ['lrtb', 'btn-borders-large btn-adv-position-outer', 'tableadv-button-border-outer', this.tipOuter], ['lrtbcm', 'btn-borders-large btn-adv-position-all', 'tableadv-button-border-all', this.tipAll], ['', 'btn-borders-large btn-adv-position-none', 'tableadv-button-border-none', this.tipNone] ]; this._btnsBorderPosition = []; _.each(_arrBorderPresets, function(item, index, list){ var _btn = new Common.UI.Button({ style: 'margin-left: 5px; margin-bottom: 4px;', cls: 'btn-options large', iconCls: item[1], strId :item[0], hint: item[3] }); _btn.render( $('#'+item[2])) ; _btn.on('click', _.bind(this._ApplyBorderPreset, this)); this._btnsBorderPosition.push( _btn ); }, this); var _arrTableBorderPresets = [ ['cm', '', 'btn-borders-large btn-adv-position-inner-none', 'tableadv-button-border-inner-none', this.tipCellInner], ['lrtb', '', 'btn-borders-large btn-adv-position-outer-none', 'tableadv-button-border-outer-none', this.tipCellOuter], ['lrtbcm', '', 'btn-borders-large btn-adv-position-all-none', 'tableadv-button-border-all-none', this.tipCellAll], ['', '', 'btn-borders-large btn-adv-position-none-none', 'tableadv-button-border-none-none', this.tipNone], ['lrtbcm', 'lrtb', 'btn-borders-large btn-adv-position-all-table', 'tableadv-button-border-all-table', this.tipTableOuterCellAll], ['', 'lrtb', 'btn-borders-large btn-adv-position-none-table', 'tableadv-button-border-none-table', this.tipOuter], ['cm', 'lrtb', 'btn-borders-large btn-adv-position-inner-table', 'tableadv-button-border-inner-table', this.tipTableOuterCellInner], ['lrtb', 'lrtb', 'btn-borders-large btn-adv-position-outer-table', 'tableadv-button-border-outer-table', this.tipTableOuterCellOuter] ]; this._btnsTableBorderPosition = []; _.each(_arrTableBorderPresets, function(item, index, list){ var _btn = new Common.UI.Button({ style: 'margin-left: 5px; margin-bottom: 4px;', cls: 'btn-options large', iconCls: item[2], strCellId :item[0], strTableId :item[1], hint: item[4] }); _btn.render( $('#'+item[3])) ; _btn.on('click', _.bind(this._ApplyBorderPreset, this)); this._btnsTableBorderPosition.push( _btn ); }, this); // Alt Text this.inputAltTitle = new Common.UI.InputField({ el : $('#table-advanced-alt-title'), allowBlank : true, validateOnBlur: false, style : 'width: 100%;' }).on('changed:after', function() { me.isAltTitleChanged = true; }); this.textareaAltDescription = this.$window.find('textarea'); this.textareaAltDescription.keydown(function (event) { if (event.keyCode == Common.UI.Keys.RETURN) { event.stopPropagation(); } me.isAltDescChanged = true; }); this.AlignContainer = $('#tableadv-panel-align'); this.DistanceContainer = $('#tableadv-panel-distance'); this.BordersContainer = $('#tableadv-panel-borders'); this.BordersSpacingContainer = $('#tableadv-panel-borders-spacing'); this.CellBackContainer = $('#tableadv-panel-cell-back'); this.TableBackContainer = $('#tableadv-panel-table-back'); this.btnsCategory[1].on('click', _.bind(this.onCellCategoryClick, this)); this.afterRender(); }, afterRender: function() { this.updateMetricUnit(); this.updateThemeColors(); this._setDefaults(this._originalProps); if (this.borderProps !== undefined) { this.btnBorderColor.setColor(this.borderProps.borderColor); var colorstr = (typeof(this.borderProps.borderColor) == 'object') ? this.borderProps.borderColor.color : this.borderProps.borderColor; this.tableBordersImageSpacing.setVirtualBorderColor(colorstr); this.tableBordersImage.setVirtualBorderColor(colorstr); this.cmbBorderSize.setValue(this.borderProps.borderSize.ptValue); var rec = this.cmbBorderSize.getSelectedRecord(); if (rec) this.onBorderSizeSelect(this.cmbBorderSize, rec); this.colorsBorder.select(this.borderProps.borderColor, true); } for (var i=0; i