[SSE] Chart styles refactoring

This commit is contained in:
Julia Radzhabova 2022-02-16 22:28:39 +03:00
parent 9e75d89bb2
commit 337741f8b0

View file

@ -127,6 +127,7 @@ define([
this.api = api; this.api = api;
if (this.api) { if (this.api) {
this.api.asc_registerCallback('asc_onUpdateChartStyles', _.bind(this._onUpdateChartStyles, this)); this.api.asc_registerCallback('asc_onUpdateChartStyles', _.bind(this._onUpdateChartStyles, this));
this.api.asc_registerCallback('asc_onAddChartStylesPreview', _.bind(this.onAddChartStylesPreview, this));
} }
return this; return this;
}, },
@ -162,7 +163,7 @@ define([
if (this._state.ChartType !== type) { if (this._state.ChartType !== type) {
this.ShowCombinedProps(type); this.ShowCombinedProps(type);
!(type===null || type==Asc.c_oAscChartTypeSettings.comboBarLine || type==Asc.c_oAscChartTypeSettings.comboBarLineSecondary || !(type===null || type==Asc.c_oAscChartTypeSettings.comboBarLine || type==Asc.c_oAscChartTypeSettings.comboBarLineSecondary ||
type==Asc.c_oAscChartTypeSettings.comboAreaBar || type==Asc.c_oAscChartTypeSettings.comboCustom) && this.updateChartStyles(this.api.asc_getChartPreviews(type)); type==Asc.c_oAscChartTypeSettings.comboAreaBar || type==Asc.c_oAscChartTypeSettings.comboCustom) && this.updateChartStyles(this.api.asc_getChartPreviews(type, undefined, true));
this._state.ChartType = type; this._state.ChartType = type;
} }
@ -176,23 +177,9 @@ define([
} else { } else {
value = this.chartProps.getStyle(); value = this.chartProps.getStyle();
if (this._state.ChartStyle!==value || this._isChartStylesChanged) { if (this._state.ChartStyle!==value || this._isChartStylesChanged) {
this.cmbChartStyle.suspendEvents();
var rec = this.cmbChartStyle.menuPicker.store.findWhere({data: value});
if (rec)
this.cmbChartStyle.menuPicker.selectRecord(rec);
else {
this.cmbChartStyle.fieldPicker.deselectAll();
this.cmbChartStyle.menuPicker.deselectAll();
}
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), false);
}
this._state.ChartStyle=value; this._state.ChartStyle=value;
var arr = this.selectCurrentChartStyle();
this._isChartStylesChanged && this.api.asc_generateChartPreviews(this._state.ChartType, arr);
} }
} }
this._isChartStylesChanged = false; this._isChartStylesChanged = false;
@ -982,11 +969,52 @@ define([
Common.NotificationCenter.trigger('edit:complete', this); Common.NotificationCenter.trigger('edit:complete', this);
}, },
selectCurrentChartStyle: function() {
if (!this.cmbChartStyle) return;
this.cmbChartStyle.suspendEvents();
var rec = this.cmbChartStyle.menuPicker.store.findWhere({data: this._state.ChartStyle});
this.cmbChartStyle.menuPicker.selectRecord(rec);
this.cmbChartStyle.resumeEvents();
if (this._isChartStylesChanged) {
var currentRecords;
if (rec)
currentRecords = this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec(), true);
else
currentRecords = this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.store.at(0), true);
if (currentRecords && currentRecords.length>0) {
var arr = [];
_.each(currentRecords, function(style, index){
arr.push(style.get('data'));
});
return arr;
}
}
},
onAddChartStylesPreview: function(styles){
var me = this;
if (styles && styles.length>0){
var stylesStore = this.cmbChartStyle.menuPicker.store;
if (stylesStore) {
_.each(styles, function(item, index){
var rec = stylesStore.findWhere({
data: item.asc_getName()
});
rec && rec.set('imageUrl', item.asc_getImage());
});
}
}
},
_onUpdateChartStyles: function() { _onUpdateChartStyles: function() {
if (this.api && this._state.ChartType!==null && this._state.ChartType>-1 && if (this.api && this._state.ChartType!==null && this._state.ChartType>-1 &&
!(this._state.ChartType==Asc.c_oAscChartTypeSettings.comboBarLine || this._state.ChartType==Asc.c_oAscChartTypeSettings.comboBarLineSecondary || !(this._state.ChartType==Asc.c_oAscChartTypeSettings.comboBarLine || this._state.ChartType==Asc.c_oAscChartTypeSettings.comboBarLineSecondary ||
this._state.ChartType==Asc.c_oAscChartTypeSettings.comboAreaBar || this._state.ChartType==Asc.c_oAscChartTypeSettings.comboCustom)) this._state.ChartType==Asc.c_oAscChartTypeSettings.comboAreaBar || this._state.ChartType==Asc.c_oAscChartTypeSettings.comboCustom)) {
this.updateChartStyles(this.api.asc_getChartPreviews(this._state.ChartType)); this.updateChartStyles(this.api.asc_getChartPreviews(this._state.ChartType, undefined, true));
this.api.asc_generateChartPreviews(this._state.ChartType, this.selectCurrentChartStyle());
}
}, },
updateChartStyles: function(styles) { updateChartStyles: function(styles) {
@ -1020,24 +1048,15 @@ define([
if (styles && styles.length>0){ if (styles && styles.length>0){
var stylesStore = this.cmbChartStyle.menuPicker.store; var stylesStore = this.cmbChartStyle.menuPicker.store;
if (stylesStore) { if (stylesStore) {
var count = stylesStore.length; var stylearray = [];
if (count>0 && count==styles.length) { _.each(styles, function(item, index){
var data = stylesStore.models; stylearray.push({
_.each(styles, function(style, index){ imageUrl: item.asc_getImage(),
data[index].set('imageUrl', style.asc_getImage()); data : item.asc_getName(),
tip : me.textStyle + ' ' + item.asc_getName()
}); });
} else { });
var stylearray = [], stylesStore.reset(stylearray, {silent: false});
selectedIdx = -1;
_.each(styles, function(item, index){
stylearray.push({
imageUrl: item.asc_getImage(),
data : item.asc_getName(),
tip : me.textStyle + ' ' + item.asc_getName()
});
});
stylesStore.reset(stylearray, {silent: false});
}
} }
} else { } else {
this.cmbChartStyle.menuPicker.store.reset(); this.cmbChartStyle.menuPicker.store.reset();