From 47621b7ce10bae8c1fcd53b94e002925790f82c4 Mon Sep 17 00:00:00 2001
From: Julia Radzhabova <julia.radzhabova@onlyoffice.com>
Date: Fri, 9 Oct 2020 14:20:31 +0300
Subject: [PATCH] Fix Bug 46841

---
 .../main/app/controller/Toolbar.js            |  1 +
 .../main/app/view/ChartSettingsDlg.js         | 78 ++++++++++---------
 2 files changed, 44 insertions(+), 35 deletions(-)

diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js
index cabb7d14d..1fb2d6645 100644
--- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js
+++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js
@@ -951,6 +951,7 @@ define([
                             {
                                 chartSettings: props,
                                 imageSettings: imageSettings,
+                                isDiagramMode: me.toolbar.mode.isEditDiagram,
                                 isChart: true,
                                 api: me.api,
                                 handler: function(result, value) {
diff --git a/apps/spreadsheeteditor/main/app/view/ChartSettingsDlg.js b/apps/spreadsheeteditor/main/app/view/ChartSettingsDlg.js
index bed94f307..c996b5db7 100644
--- a/apps/spreadsheeteditor/main/app/view/ChartSettingsDlg.js
+++ b/apps/spreadsheeteditor/main/app/view/ChartSettingsDlg.js
@@ -96,6 +96,7 @@ define([    'text!spreadsheeteditor/main/app/template/ChartSettingsDlg.template'
             this.imageSettings = this.options.imageSettings;
             this.sparklineStyles = this.options.sparklineStyles;
             this.isChart       = this.options.isChart;
+            this.isDiagramMode = !!this.options.isDiagramMode;
             this.vertAxisProps = null;
             this.horAxisProps = null;
             this.currentAxisProps = null;
@@ -114,29 +115,31 @@ define([    'text!spreadsheeteditor/main/app/template/ChartSettingsDlg.template'
 
             // Layout
 
-            // this.btnChartType = new Common.UI.Button({
-            //     cls         : 'btn-large-dataview',
-            //     iconCls     : 'svgicon chart-bar-normal',
-            //     menu        : new Common.UI.Menu({
-            //         style: 'width: 364px; padding-top: 12px;',
-            //         additionalAlign: this.menuAddAlign,
-            //         items: [
-            //             { template: _.template('<div id="id-chart-dlg-menu-type" class="menu-insertchart"  style="margin: 5px 5px 5px 10px;"></div>') }
-            //         ]
-            //     })
-            // });
-            // this.btnChartType.on('render:after', function(btn) {
-            //     me.mnuChartTypePicker = new Common.UI.DataView({
-            //         el: $('#id-chart-dlg-menu-type'),
-            //         parentMenu: btn.menu,
-            //         restoreHeight: 421,
-            //         groups: new Common.UI.DataViewGroupStore(Common.define.chartData.getChartGroupData()),
-            //         store: new Common.UI.DataViewStore(Common.define.chartData.getChartData()),
-            //         itemTemplate: _.template('<div id="<%= id %>" class="item-chartlist"><svg width="40" height="40" class=\"icon\"><use xlink:href=\"#chart-<%= iconCls %>\"></use></svg></div>')
-            //     });
-            // });
-            // this.btnChartType.render($('#chart-dlg-button-type'));
-            // this.mnuChartTypePicker.on('item:click', _.bind(this.onSelectType, this, this.btnChartType));
+            if (this.isDiagramMode) {
+                this.btnChartType = new Common.UI.Button({
+                    cls         : 'btn-large-dataview',
+                    iconCls     : 'svgicon chart-bar-normal',
+                    menu        : new Common.UI.Menu({
+                        style: 'width: 364px; padding-top: 12px;',
+                        additionalAlign: this.menuAddAlign,
+                        items: [
+                            { template: _.template('<div id="id-chart-dlg-menu-type" class="menu-insertchart"  style="margin: 5px 5px 5px 10px;"></div>') }
+                        ]
+                    })
+                });
+                this.btnChartType.on('render:after', function(btn) {
+                    me.mnuChartTypePicker = new Common.UI.DataView({
+                        el: $('#id-chart-dlg-menu-type'),
+                        parentMenu: btn.menu,
+                        restoreHeight: 421,
+                        groups: new Common.UI.DataViewGroupStore(Common.define.chartData.getChartGroupData()),
+                        store: new Common.UI.DataViewStore(Common.define.chartData.getChartData()),
+                        itemTemplate: _.template('<div id="<%= id %>" class="item-chartlist"><svg width="40" height="40" class=\"icon\"><use xlink:href=\"#chart-<%= iconCls %>\"></use></svg></div>')
+                    });
+                });
+                this.btnChartType.render($('#chart-dlg-button-type'));
+                this.mnuChartTypePicker.on('item:click', _.bind(this.onSelectType, this, this.btnChartType));
+            }
 
             // this.cmbDataDirect = new Common.UI.ComboBox({
             //     el          : $('#chart-dlg-combo-range'),
@@ -979,7 +982,7 @@ define([    'text!spreadsheeteditor/main/app/template/ChartSettingsDlg.template'
 
             this.setTitle((this.isChart) ? this.textTitle : this.textTitleSparkline);
 
-            this.btnsCategory[0].setVisible(false); // hide type for charts
+            this.btnsCategory[0].setVisible(this.isDiagramMode); // hide type for charts
             if (this.isChart) {
                 this.btnsCategory[4].setVisible(false);
                 this.btnsCategory[5].setVisible(false);
@@ -1284,12 +1287,14 @@ define([    'text!spreadsheeteditor/main/app/template/ChartSettingsDlg.template'
 
                     // Layout
 
-                    // var record = this.mnuChartTypePicker.store.findWhere({type: this._state.ChartType});
-                    // this.mnuChartTypePicker.selectRecord(record, true);
-                    // if (record) {
-                    //     this.btnChartType.setIconCls('svgicon ' + 'chart-' + record.get('iconCls'));
-                    // } else
-                    //     this.btnChartType.setIconCls('svgicon');
+                    if (this.isDiagramMode) {
+                        var record = this.mnuChartTypePicker.store.findWhere({type: this._state.ChartType});
+                        this.mnuChartTypePicker.selectRecord(record, true);
+                        if (record) {
+                            this.btnChartType.setIconCls('svgicon ' + 'chart-' + record.get('iconCls'));
+                        } else
+                            this.btnChartType.setIconCls('svgicon');
+                    }
 
                     this._noApply = false;
 
@@ -1418,9 +1423,11 @@ define([    'text!spreadsheeteditor/main/app/template/ChartSettingsDlg.template'
             var value;
 
             if (this.isChart) {
-                // var rec = this.mnuChartTypePicker.getSelectedRec(),
-                //     type = (rec) ? rec.get('type') : this.currentChartType;
                 var type = this.currentChartType;
+                if (this.isDiagramMode) {
+                    var rec = this.mnuChartTypePicker.getSelectedRec();
+                    rec && (type = rec.get('type'));
+                }
 
                 this.chartSettings.putType(type);
 
@@ -1489,10 +1496,11 @@ define([    'text!spreadsheeteditor/main/app/template/ChartSettingsDlg.template'
                 var isvalid,
                     range = this.chartSettings.getRange();
                 if (!_.isEmpty(range)) {
-                    // var rec = this.mnuChartTypePicker.getSelectedRec(),
-                    //     type = (rec) ? rec.get('type') : this.currentChartType;
                     var type = this.currentChartType;
-
+                    if (this.isDiagramMode) {
+                        var rec = this.mnuChartTypePicker.getSelectedRec();
+                        rec && (type = rec.get('type'));
+                    }
                     isvalid = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.Chart, range, true, !this.chartSettings.getInColumns(), type);
                     if (isvalid == Asc.c_oAscError.ID.No)
                         return true;