diff --git a/apps/spreadsheeteditor/main/app/controller/DataTab.js b/apps/spreadsheeteditor/main/app/controller/DataTab.js index dcd313ecbb..399a1770bc 100644 --- a/apps/spreadsheeteditor/main/app/controller/DataTab.js +++ b/apps/spreadsheeteditor/main/app/controller/DataTab.js @@ -86,7 +86,6 @@ define([ 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_onChangingCellSelection',_.bind(this.onStopChangingCellSelection, 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)); @@ -543,8 +542,8 @@ 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_FormulaGoalSeek(settings.formulaCell, settings.expectedValue, settings.changingCell); + //me.onUpdateChangingCellSelection(0, 1, 0); // only for test } Common.NotificationCenter.trigger('edit:complete'); } @@ -562,17 +561,18 @@ define([ } else { // cancel changes } - this.ChangingCellSelectionDlg = undefined; + me.ChangingCellSelectionDlg = undefined; Common.NotificationCenter.trigger('edit:complete'); } }); + this.ChangingCellSelectionDlg.on('close', function() { + 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'}); - }, - - onStopChangingCellSelection: function () { - }, onUpdateExternalReference: function(arr, callback) { diff --git a/apps/spreadsheeteditor/main/app/view/ChangingCellSelectionDlg.js b/apps/spreadsheeteditor/main/app/view/ChangingCellSelectionDlg.js index ea9e557836..078b827ca5 100644 --- a/apps/spreadsheeteditor/main/app/view/ChangingCellSelectionDlg.js +++ b/apps/spreadsheeteditor/main/app/view/ChangingCellSelectionDlg.js @@ -93,15 +93,21 @@ define([ this.api = options.api; this.props = options.props; + this._state = { + isPause: false, + iteration: undefined, + currentValue: undefined, + targetValue: undefined + } + this.options.handler = function(result, value) { - if ( result != 'ok' || this.isRangeValid() ) { - if (options.handler) - options.handler.call(this, result, value); - return; - } - return true; + if (options.handler) + options.handler.call(this, result, value); + return; }; + //this.api.asc_registerCallback('asc_onChangingCellSelection',_.bind(this.onStopSelection, this)); + Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options); }, @@ -116,16 +122,20 @@ define([ this.btnStep = new Common.UI.Button({ parentEl: $('#changing-cell-stop'), caption: this.textStep, - cls: 'normal dlg-btn' + cls: 'normal dlg-btn', + disabled: true }); + this.btnStep.on('click', _.bind(this.onBtnStep, this)); this.btnPause = new Common.UI.Button({ parentEl: $('#changing-cell-pause'), caption: this.textPause, - disabled: true, cls: 'normal dlg-btn' }); - //this.btnPause.setCaption(status ? this.textPause : this.textContinue); + this.btnPause.on('click', _.bind(this.onBtnPause, this)); + + this.btnOk = this.getChild().find('.primary'); + this.setDisabledOkButton(true); this.afterRender(); }, @@ -148,17 +158,48 @@ 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.targetValue = props.targetValue; - this.currentValue = props.currentValue; - this.iteration = props.iteration; - this.$targetValue.text(this.targetValue); - this.$currentValue.text(this.currentValue); + this.updateSettings(props); this.$formulaSolutionLabel.text(Common.Utils.String.format(this.textFoundSolution, props.formulaCell)); } }, + 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; + }, + + onBtnStep: function () { + // call api method + }, + + onStopSelection: function () { + this.btnPause.setDisabled(true); + this.btnStep.setDisabled(true); + this.setDisabledOkButton(false); + }, + + setDisabledOkButton: function (disabled) { + if (disabled !== this.btnOk.hasClass('disabled')) { + var decorateBtn = function(button) { + button.toggleClass('disabled', disabled); + (disabled) ? button.attr({disabled: disabled}) : button.removeAttr('disabled'); + }; + decorateBtn(this.btnOk); + } + }, + textTitle: 'Changing Cell Selection', textFoundSolution: 'The search for the target using cell {0} has found a solution.', textTargetValue: 'Target value:', diff --git a/apps/spreadsheeteditor/main/app/view/GoalSeekDlg.js b/apps/spreadsheeteditor/main/app/view/GoalSeekDlg.js index c3471c7aca..046ca8835f 100644 --- a/apps/spreadsheeteditor/main/app/view/GoalSeekDlg.js +++ b/apps/spreadsheeteditor/main/app/view/GoalSeekDlg.js @@ -168,13 +168,27 @@ define([ var me = this; this.txtFormulaCell.validation = function(value) { var isvalid = me.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.GoalSeek_Cell, value, true); - return (isvalid==Asc.c_oAscError.ID.MustContainFormula) ? me.textInvalidFormula : true; + if (isvalid == Asc.c_oAscError.ID.DataRangeError) { + return me.textMissingRange; + } else if (isvalid == Asc.c_oAscError.ID.MustSingleCell) { + return me.textSingleCell; + } else if (isvalid==Asc.c_oAscError.ID.MustContainFormula) { + return me.textInvalidFormula; + } else { + return true; + } }; this.txtFormulaCell.setValue(this.api.asc_getActiveRangeStr(Asc.referenceType.A)); this.txtFormulaCell.checkValidate(); this.txtChangeCell.validation = function(value) { var isvalid = me.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.GoalSeek_ChangingCell, value, true); - return (isvalid==Asc.c_oAscError.ID.DataRangeError) ? me.textInvalidRange : true; + if (isvalid == Asc.c_oAscError.ID.DataRangeError) { + return me.textMissingRange; + } else if (isvalid == Asc.c_oAscError.ID.MustSingleCell) { + return me.textSingleCell; + } else { + return true; + } }; }, @@ -225,7 +239,8 @@ define([ textChangingCell: 'By changing cell', txtEmpty: 'This field is required', textSelectData: 'Select data', - textInvalidRange: 'Invalid cells range', + textMissingRange: 'The formula is missing a range', + textSingleCell: 'Reference must be to a single cell', textInvalidFormula: 'The cell must contain a formula' }, SSE.Views.GoalSeekDlg || {})) }); \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/resources/less/advanced-settings.less b/apps/spreadsheeteditor/main/resources/less/advanced-settings.less index e55b743a5b..1bec4f1893 100644 --- a/apps/spreadsheeteditor/main/resources/less/advanced-settings.less +++ b/apps/spreadsheeteditor/main/resources/less/advanced-settings.less @@ -602,10 +602,8 @@ display: flex; justify-content: start; .cell-1 { - min-width: 120px; - } - .cell-2 { - width: 100%; + min-width: 114px; + .margin-right(6px); } } }