/* * * (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 * */ /** * ChartSettings.js * * Created by Julia Radzhabova on 2/07/14 * Copyright (c) 2018 Ascensio System SIA. All rights reserved. * */ define([ 'text!documenteditor/main/app/template/ChartSettings.template', 'jquery', 'underscore', 'backbone', 'common/main/lib/component/Button', 'common/main/lib/component/ComboDataView', 'documenteditor/main/app/view/ImageSettingsAdvanced' ], function (menuTemplate, $, _, Backbone) { 'use strict'; DE.Views.ChartSettings = Backbone.View.extend(_.extend({ el: '#id-chart-settings', // Compile our stats template template: _.template(menuTemplate), // Delegated events for creating new items, and clearing completed ones. events: { }, options: { alias: 'ChartSettings' }, initialize: function () { this._initSettings = true; this._state = { WrappingStyle: Asc.c_oAscWrapStyle2.Inline, CanBeFlow: true, Width: 0, Height: 0, FromGroup: false, ChartStyle: 1, ChartType: -1, SeveralCharts: false, DisabledControls: false }; this.lockedControls = []; this._locked = false; this._noApply = false; this._originalProps = null; this.render(); }, render: function () { var el = this.$el || $(this.el); el.html(this.template({ scope: this })); this.labelWidth = el.find('#chart-label-width'); this.labelHeight = el.find('#chart-label-height'); }, setApi: function(api) { this.api = api; if (this.api) { this.api.asc_registerCallback('asc_onImgWrapStyleChanged', _.bind(this._ChartWrapStyleChanged, this)); this.api.asc_registerCallback('asc_onUpdateChartStyles', _.bind(this._onUpdateChartStyles, this)); } return this; }, ChangeSettings: function(props) { if (this._initSettings) this.createDelayedElements(); this.disableControls(this._locked); if (props && props.get_ChartProperties()){ this._originalProps = new Asc.asc_CImgProperty(props); this._noApply = true; var value = props.get_WrappingStyle(); if (this._state.WrappingStyle!==value) { this.cmbWrapType.suspendEvents(); var rec = this.cmbWrapType.menuPicker.store.findWhere({ data: value }); this.cmbWrapType.menuPicker.selectRecord(rec); this.cmbWrapType.resumeEvents(); this._state.WrappingStyle=value; } this.chartProps = props.get_ChartProperties(); value = props.get_SeveralCharts() || this._locked; if (this._state.SeveralCharts!==value) { this.btnEditData.setDisabled(value); this._state.SeveralCharts=value; } value = props.get_SeveralChartTypes(); if (this._state.SeveralCharts && value) { this.btnChartType.setIconCls(''); this._state.ChartType = null; } else { var type = this.chartProps.getType(); if (this._state.ChartType !== type) { var record = this.mnuChartTypePicker.store.findWhere({type: type}); this.mnuChartTypePicker.selectRecord(record, true); if (record) { this.btnChartType.setIconCls('item-chartlist ' + record.get('iconCls')); } else this.btnChartType.setIconCls(''); this.updateChartStyles(this.api.asc_getChartPreviews(type)); this._state.ChartType = type; } } value = props.get_SeveralChartStyles(); if (this._state.SeveralCharts && value) { this.cmbChartStyle.fieldPicker.deselectAll(); this.cmbChartStyle.menuPicker.deselectAll(); this._state.ChartStyle = null; } else { value = this.chartProps.getStyle(); if (this._state.ChartStyle!==value || this._isChartStylesChanged) { this.cmbChartStyle.suspendEvents(); var rec = this.cmbChartStyle.menuPicker.store.findWhere({data: value}); this.cmbChartStyle.menuPicker.selectRecord(rec); this.cmbChartStyle.resumeEvents(); if (this._isChartStylesChanged) { if (rec) this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec(),true); else this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.store.at(0), true); } this._state.ChartStyle=value; } } this._isChartStylesChanged = false; this._noApply = false; value = props.get_CanBeFlow() && !this._locked; var fromgroup = props.get_FromGroup() || this._locked; if (this._state.CanBeFlow!==value || this._state.FromGroup!==fromgroup) { this.cmbWrapType.setDisabled(!value || fromgroup); this._state.CanBeFlow=value; this._state.FromGroup=fromgroup; } value = props.get_Width(); if ( Math.abs(this._state.Width-value)>0.001 ) { this.labelWidth[0].innerHTML = this.textWidth + ': ' + Common.Utils.Metric.fnRecalcFromMM(value).toFixed(1) + ' ' + Common.Utils.Metric.getCurrentMetricName(); this._state.Width = value; } value = props.get_Height(); if ( Math.abs(this._state.Height-value)>0.001 ) { this.labelHeight[0].innerHTML = this.textHeight + ': ' + Common.Utils.Metric.fnRecalcFromMM(value).toFixed(1) + ' ' + Common.Utils.Metric.getCurrentMetricName(); this._state.Height = value; } } }, updateMetricUnit: function() { var value = Common.Utils.Metric.fnRecalcFromMM(this._state.Width); this.labelWidth[0].innerHTML = this.textWidth + ': ' + value.toFixed(1) + ' ' + Common.Utils.Metric.getCurrentMetricName(); value = Common.Utils.Metric.fnRecalcFromMM(this._state.Height); this.labelHeight[0].innerHTML = this.textHeight + ': ' + value.toFixed(1) + ' ' + Common.Utils.Metric.getCurrentMetricName(); }, createDelayedControls: function() { var me = this, viewData = [ { offsetx: 0, data: Asc.c_oAscWrapStyle2.Inline, tip: this.txtInline, selected: true }, { offsetx: 50, data: Asc.c_oAscWrapStyle2.Square, tip: this.txtSquare }, { offsetx: 100, data: Asc.c_oAscWrapStyle2.Tight, tip: this.txtTight }, { offsetx: 150, data: Asc.c_oAscWrapStyle2.Through, tip: this.txtThrough }, { offsetx: 200, data: Asc.c_oAscWrapStyle2.TopAndBottom, tip: this.txtTopAndBottom }, { offsetx: 250, data: Asc.c_oAscWrapStyle2.InFront, tip: this.txtInFront }, { offsetx: 300, data: Asc.c_oAscWrapStyle2.Behind, tip: this.txtBehind } ]; this.cmbWrapType = new Common.UI.ComboDataView({ itemWidth: 50, itemHeight: 50, menuMaxHeight: 300, enableKeyEvents: true, store: new Common.UI.DataViewStore(viewData), cls: 'combo-chart-style' }); this.cmbWrapType.menuPicker.itemTemplate = this.cmbWrapType.fieldPicker.itemTemplate = _.template([ '