From cb05587be1572b4ac005e261088c9313b7b91929 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 16 Dec 2016 14:33:38 +0300 Subject: [PATCH] [DE] [PE] Change chart type from the toolbar when chart is selected . --- .../main/app/controller/Toolbar.js | 61 +++++++++++++------ .../main/app/controller/Toolbar.js | 43 +++++++++---- 2 files changed, 75 insertions(+), 29 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Toolbar.js b/apps/documenteditor/main/app/controller/Toolbar.js index 8ed872111..2fdede3ba 100644 --- a/apps/documenteditor/main/app/controller/Toolbar.js +++ b/apps/documenteditor/main/app/controller/Toolbar.js @@ -563,6 +563,7 @@ define([ var pr, sh, i = -1, type, paragraph_locked = false, header_locked = false, + image_locked = false, can_add_table = false, can_add_image = false, enable_dropcap = undefined, @@ -590,6 +591,7 @@ define([ in_header = true; } else if (type === Asc.c_oAscTypeSelectElement.Image) { in_image = in_header = true; + image_locked = pr.get_Locked(); if (pr && pr.get_ChartProperties()) in_chart = true; } else if (type === Asc.c_oAscTypeSelectElement.Math) { @@ -670,16 +672,18 @@ define([ } need_disable = paragraph_locked || header_locked || !can_add_image || in_equation; - if (need_disable != toolbar.btnInsertChart.isDisabled()) { - toolbar.btnInsertChart.setDisabled(need_disable); + if (need_disable != toolbar.btnInsertImage.isDisabled()) { toolbar.btnInsertImage.setDisabled(need_disable); toolbar.btnInsertShape.setDisabled(need_disable); toolbar.btnInsertText.setDisabled(need_disable); } - need_disable = need_disable || in_image; - if (need_disable != toolbar.mnuInsertTextArt.isDisabled()) - toolbar.mnuInsertTextArt.setDisabled(need_disable); + if ((need_disable || in_image) != toolbar.mnuInsertTextArt.isDisabled()) + toolbar.mnuInsertTextArt.setDisabled(need_disable || in_image); + + need_disable = in_chart && image_locked || !in_chart && need_disable; + if (need_disable != toolbar.btnInsertChart.isDisabled()) + toolbar.btnInsertChart.setDisabled(need_disable); need_disable = paragraph_locked || header_locked || in_chart || !can_add_image&&!in_equation; if (need_disable !== toolbar.btnInsertEquation.isDisabled()) toolbar.btnInsertEquation.setDisabled(need_disable); @@ -1675,20 +1679,43 @@ define([ onSelectChart: function(picker, item, record) { var me = this, - type = record.get('type'); + type = record.get('type'), + chart = false; - if (!this.diagramEditor) - this.diagramEditor = this.getApplication().getController('Common.Controllers.ExternalDiagramEditor').getView('Common.Views.ExternalDiagramEditor'); - - if (this.diagramEditor && me.api) { - this.diagramEditor.setEditMode(false); - this.diagramEditor.show(); - - var chart = me.api.asc_getChartObject(type); - if (chart) { - this.diagramEditor.setChartData(new Asc.asc_CChartBinary(chart)); + var selectedElements = me.api.getSelectedElements(); + if (selectedElements && _.isArray(selectedElements)) { + for (var i = 0; i< selectedElements.length; i++) { + if (Asc.c_oAscTypeSelectElement.Image == selectedElements[i].get_ObjectType()) { + var elValue = selectedElements[i].get_ObjectValue().get_ChartProperties(); + if (elValue) { + chart = elValue; + break; + } + } + } + } + + if (chart) { + var props = new Asc.asc_CImgProperty(); + chart.changeType(type); + props.put_ChartProperties(chart); + this.api.ImgApply(props); + + Common.NotificationCenter.trigger('edit:complete', this.toolbar); + } else { + if (!this.diagramEditor) + this.diagramEditor = this.getApplication().getController('Common.Controllers.ExternalDiagramEditor').getView('Common.Views.ExternalDiagramEditor'); + + if (this.diagramEditor && me.api) { + this.diagramEditor.setEditMode(false); + this.diagramEditor.show(); + + chart = me.api.asc_getChartObject(type); + if (chart) { + this.diagramEditor.setChartData(new Asc.asc_CChartBinary(chart)); + } + me.toolbar.fireEvent('insertchart', me.toolbar); } - me.toolbar.fireEvent('insertchart', me.toolbar); } }, diff --git a/apps/presentationeditor/main/app/controller/Toolbar.js b/apps/presentationeditor/main/app/controller/Toolbar.js index 2bfe4873a..2707e9f24 100644 --- a/apps/presentationeditor/main/app/controller/Toolbar.js +++ b/apps/presentationeditor/main/app/controller/Toolbar.js @@ -1450,20 +1450,39 @@ define([ onSelectChart: function(picker, item, record) { var me = this, - type = record.get('type'); + type = record.get('type'), + chart = false; - if (!this.diagramEditor) - this.diagramEditor = this.getApplication().getController('Common.Controllers.ExternalDiagramEditor').getView('Common.Views.ExternalDiagramEditor'); - - if (this.diagramEditor && me.api) { - this.diagramEditor.setEditMode(false); - this.diagramEditor.show(); - - var chart = me.api.asc_getChartObject(type); - if (chart) { - this.diagramEditor.setChartData(new Asc.asc_CChartBinary(chart)); + var selectedElements = me.api.getSelectedElements(); + if (selectedElements && _.isArray(selectedElements)) { + for (var i = 0; i< selectedElements.length; i++) { + if (Asc.c_oAscTypeSelectElement.Chart == selectedElements[i].get_ObjectType()) { + chart = true; + break; + } + } + } + + if (chart) { + var props = new Asc.CAscChartProp(); + props.changeType(type); + this.api.ChartApply(props); + + Common.NotificationCenter.trigger('edit:complete', this.toolbar); + } else { + if (!this.diagramEditor) + this.diagramEditor = this.getApplication().getController('Common.Controllers.ExternalDiagramEditor').getView('Common.Views.ExternalDiagramEditor'); + + if (this.diagramEditor && me.api) { + this.diagramEditor.setEditMode(false); + this.diagramEditor.show(); + + chart = me.api.asc_getChartObject(type); + if (chart) { + this.diagramEditor.setChartData(new Asc.asc_CChartBinary(chart)); + } + me.toolbar.fireEvent('insertchart', me.toolbar); } - me.toolbar.fireEvent('insertchart', me.toolbar); } },