[SSE] Goal seek: add handlers, fix validation

This commit is contained in:
JuliaSvinareva
2023-10-11 18:25:37 +03:00
parent 7bfa477dba
commit 21102bf1d8
3 changed files with 64 additions and 33 deletions

View File

@ -85,7 +85,7 @@ define([
this.api.asc_registerCallback('asc_onSelectionChanged', _.bind(this.onSelectionChanged, this));
this.api.asc_registerCallback('asc_onWorksheetLocked', _.bind(this.onWorksheetLocked, this));
this.api.asc_registerCallback('asc_onChangeProtectWorkbook',_.bind(this.onChangeProtectWorkbook, this));
//this.api.asc_registerCallback('asc_onChangingCellSelection',_.bind(this.onUpdateChangingCellSelection, this));
this.api.asc_registerCallback('asc_onGoalSeekUpdate', _.bind(this.onUpdateChangingCellSelection, this));
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this));
Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this));
Common.NotificationCenter.on('protect:wslock', _.bind(this.onChangeProtectSheet, this));
@ -542,8 +542,7 @@ define([
api: me.api,
handler: function(result, settings) {
if (result == 'ok' && settings) {
me.api.asc_FormulaGoalSeek(settings.formulaCell, settings.expectedValue, settings.changingCell);
//me.onUpdateChangingCellSelection(0, 1, 0); // only for test
me.api.asc_StartGoalSeek(settings.formulaCell, settings.expectedValue, settings.changingCell);
}
Common.NotificationCenter.trigger('edit:complete');
}
@ -555,24 +554,19 @@ define([
if (!this.ChangingCellSelectionDlg) {
this.ChangingCellSelectionDlg = new SSE.Views.ChangingCellSelectionDlg({
api: me.api,
handler: function (result, settings) {
if (result == 'ok' && settings) {
// save changes
} else {
// cancel changes
}
handler: function (result) {
me.api.asc_CloseGoalClose(result == 'ok');
me.ChangingCellSelectionDlg = undefined;
Common.NotificationCenter.trigger('edit:complete');
}
});
this.ChangingCellSelectionDlg.on('close', function() {
me.api.asc_CloseGoalClose(false);
me.ChangingCellSelectionDlg = undefined;
});
this.ChangingCellSelectionDlg.show();
this.ChangingCellSelectionDlg.setSettings({targetValue: targetValue, currentValue: currentValue, iteration: iteration, formulaCell: 'E3'});
} else {
this.ChangingCellSelectionDlg.updateSettings({targetValue: targetValue, currentValue: currentValue, iteration: iteration});
}
this.ChangingCellSelectionDlg.setSettings({targetValue: targetValue, currentValue: currentValue, iteration: iteration, formulaCell: 'E3'});
},
onUpdateExternalReference: function(arr, callback) {

View File

@ -94,10 +94,7 @@ define([
this.props = options.props;
this._state = {
isPause: false,
iteration: undefined,
currentValue: undefined,
targetValue: undefined
isPause: false
}
this.options.handler = function(result, value) {
@ -106,7 +103,7 @@ define([
return;
};
//this.api.asc_registerCallback('asc_onChangingCellSelection',_.bind(this.onStopSelection, this));
this.api.asc_registerCallback('asc_onGoalSeekStop',_.bind(this.onStopSelection, this));
Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options);
},
@ -158,30 +155,23 @@ define([
var me = this;
},
updateSettings: function (props) {
this._state.targetValue = props.targetValue;
this._state.currentValue = props.currentValue;
this._state.iteration = props.iteration;
this.$targetValue.text(this._state.targetValue);
this.$currentValue.text(this._state.currentValue);
},
setSettings: function (props) {
if (props) {
this.updateSettings(props);
this.$formulaSolutionLabel.text(Common.Utils.String.format(this.textFoundSolution, props.formulaCell));
this.$targetValue.text(props.targetValue);
this.$currentValue.text(props.currentValue);
this.$formulaSolutionLabel.text(Common.Utils.String.format(this.textFoundSolution, props.formulaCell, props.iteration));
}
},
onBtnPause: function () {
this.btnPause.setCaption(this._state.isPause ? this.textContinue : this.textPause);
this.btnStep.setDisabled(this._state.isPause); // always? or only !last iteration?
// call api method
this._state.isPause = !this._state.isPause;
this.btnPause.setCaption(this._state.isPause ? this.textContinue : this.textPause);
this.btnStep.setDisabled(!this._state.isPause);
this._state.isPause ? this.api.asc_PauseGoalSeek() : this.api.asc_ContinueGoalSeek();
},
onBtnStep: function () {
// call api method
this.api.asc_StepGoalSeek();
},
onStopSelection: function () {
@ -201,7 +191,7 @@ define([
},
textTitle: 'Changing Cell Selection',
textFoundSolution: 'The search for the target using cell {0} has found a solution.',
textFoundSolution: 'The search for the target using cell {0} has found a solution. Iteration №{1}.',
textTargetValue: 'Target value:',
textCurrenttValue: 'Current value:',
textStep: 'Step',

View File

@ -197,7 +197,54 @@ define([
},
isRangeValid: function() {
return true;
var isvalid = true,
txtError = '',
value;
if (_.isEmpty(this.txtFormulaCell.getValue())) {
isvalid = false;
txtError = this.txtEmpty;
} else {
value = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.GoalSeek_Cell, this.txtFormulaCell.getValue(), true);
if (value != Asc.c_oAscError.ID.No) {
txtError = isvalid == Asc.c_oAscError.ID.DataRangeError ? this.textMissingRange :
(isvalid == Asc.c_oAscError.ID.MustSingleCell ? this.textSingleCell : this.textInvalidFormula);
isvalid = false;
}
}
if (!isvalid) {
this.txtFormulaCell.showError([txtError]);
this.txtFormulaCell.cmpEl.find('input').focus();
return isvalid;
}
if (_.isEmpty(this.txtExpectVal.getValue())) {
isvalid = false;
txtError = this.txtEmpty;
}
if (!isvalid) {
this.txtExpectVal.showError([txtError]);
this.txtExpectVal.cmpEl.find('input').focus();
return isvalid;
}
if (_.isEmpty(this.txtChangeCell.getValue())) {
isvalid = false;
txtError = this.txtEmpty;
} else {
value = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.GoalSeek_ChangingCell, this.txtChangeCell.getValue(), true);
if (value != Asc.c_oAscError.ID.No) {
txtError = isvalid == Asc.c_oAscError.ID.DataRangeError ? this.textMissingRange : this.textSingleCell;
isvalid = false;
}
}
if (!isvalid) {
this.txtChangeCell.showError([txtError]);
this.txtChangeCell.cmpEl.find('input').focus();
return isvalid;
}
return isvalid;
},
onSelectData: function(type) {