diff --git a/apps/spreadsheeteditor/main/app/view/ConstraintDialog.js b/apps/spreadsheeteditor/main/app/view/ConstraintDialog.js new file mode 100644 index 0000000000..baa0379a6b --- /dev/null +++ b/apps/spreadsheeteditor/main/app/view/ConstraintDialog.js @@ -0,0 +1,219 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2025 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ + +/** + * ConstraintDialog.js + * + * Created on 09.10.2025 + * + */ + +define([], function () { 'use strict'; + SSE.Views.ConstraintDialog = Common.UI.Window.extend(_.extend({ + initialize : function(options) { + var t = this, + _options = {}; + + _.extend(_options, { + title: options.isEdit ? this.txtTitleChange : this.txtTitle, + cls: 'modal-dlg', + width: 350, + height: 'auto', + buttons: ['ok', { value: 'add', caption: this.txtAdd }, 'cancel'] + }, options); + + this.handler = options.handler; + this.constraintOperator = options.constraintOperator; + + this.template = [ + '
', + '', + '', + '', + '', + '', + '', + '
', + '', + '
', + '
', + '', + '
', + '
', + '', + '
', + '
', + '
' + ].join(''); + + _options.tpl = _.template(this.template)(_options); + Common.UI.Window.prototype.initialize.call(this, _options); + }, + + render: function () { + Common.UI.Window.prototype.render.call(this); + + this.txtCellRef = new Common.UI.InputFieldBtn({ + el : this.$window.find('#id-dlg-constraint-ref'), + name : 'range', + style : 'width: 100%;', + btnHint : this.textSelectData, + allowBlank : true + // validateOnChange: true + }); + this.txtCellRef.on('button:click', _.bind(this.onSelectCellRef, this)); + this.txtCellRef.on('changed:after', _.bind(this.onCellRefChanged, this)); + + this.txtConstraint = new Common.UI.InputFieldBtn({ + el : this.$window.find('#id-dlg-constraint-constr'), + name : 'range', + style : 'width: 100%;', + btnHint : this.textSelectData, + allowBlank : true + // validateOnChange: true + }); + this.txtConstraint.on('button:click', _.bind(this.onSelectConstraint, this)); + this.txtConstraint.on('changed:after', _.bind(this.onConstraintChanged, this)); + + this.cmbOperator = new Common.UI.ComboBox({ + el: this.$window.find('#id-dlg-constraint-operator'), + style: 'width: 100px;', + menuStyle: 'min-width: 100%;', + editable: false, + cls: 'input-group-nr', + data: [ + {value: AscCommonExcel.c_oAscOperator['<='], displayValue: this.constraintOperator[AscCommonExcel.c_oAscOperator['<=']]}, + {value: AscCommonExcel.c_oAscOperator['='], displayValue: this.constraintOperator[AscCommonExcel.c_oAscOperator['=']]}, + {value: AscCommonExcel.c_oAscOperator['>='], displayValue: this.constraintOperator[AscCommonExcel.c_oAscOperator['>=']]} + ], + takeFocusOnClose: true + }); + this.cmbOperator.setValue(AscCommonExcel.c_oAscOperator['<=']); + this.cmbOperator.on('selected', _.bind(this.onOperator , this)); + + this.$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); + }, + + getFocusedComponents: function() { + return [this.txtCellRef, this.cmbOperator, this.txtConstraint].concat(this.getFooterButtons()); + }, + + getDefaultFocusableComponent: function () { + return this.txtCellRef; + }, + + onBtnClick: function(event) { + this._handleInput(event.currentTarget.attributes['result'].value); + }, + + onPrimary: function() { + this._handleInput('ok'); + return false; + }, + + _handleInput: function(state) { + if (this.options.handler) { + if (state == 'ok') { + if (this.isRangeValid() !== true) + return; + } + this.options.handler.call(this, this, state); + } + + this.close(); + }, + + setSettings: function(settings) { + if (settings) { + this.txtCellRef.setValue(settings.cellRef || ''); + this.txtConstraint.setValue(settings.constraint || ''); + + var item = this.cmbOperator.store.findWhere({value: settings.operator}); + if (item) + this.cmbOperator.setValue(settings.operator); + else if (this.constraintOperator[settings.operator] !== undefined) { + this.cmbOperator.setData([ + {value: AscCommonExcel.c_oAscOperator['<='], displayValue: this.constraintOperator[AscCommonExcel.c_oAscOperator['<=']]}, + {value: AscCommonExcel.c_oAscOperator['='], displayValue: this.constraintOperator[AscCommonExcel.c_oAscOperator['=']]}, + {value: AscCommonExcel.c_oAscOperator['>='], displayValue: this.constraintOperator[AscCommonExcel.c_oAscOperator['>=']]}, + {value: settings.operator, displayValue: this.constraintOperator[settings.operator]} + ]); + this.cmbOperator.setValue(settings.operator); + } + } + }, + + getSettings: function () { + return {cellRef: this.txtCellRef.getValue(), operator: this.cmbOperator.getValue(), constraint: this.txtConstraint.getValue()}; + }, + + isRangeValid: function() { + var isvalid = true, + txtError = '', + value; + if (_.isEmpty(this.txtCellRef.getValue())) { + isvalid = false; + txtError = this.txtEmpty; + } else { + value = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.Chart, this.txtCellRef.getValue(), true); + if (value != Asc.c_oAscError.ID.No) { + txtError = ''; // check errors + isvalid = false; + } + } + if (!isvalid) { + this.txtCellRef.showError([txtError]); + this.txtCellRef.focus(); + return isvalid; + } + + if (_.isEmpty(this.txtConstraint.getValue())) { + isvalid = false; + txtError = this.txtEmpty; + } else { + value = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.Chart, this.txtConstraint.getValue(), true); + if (value != Asc.c_oAscError.ID.No) { + txtError = ''; // check errors + isvalid = false; + } + } + if (!isvalid) { + this.txtConstraint.showError([txtError]); + this.txtConstraint.focus(); + return isvalid; + } + + return isvalid; + }, + + }, SSE.Views.ConstraintDialog || {})); +}); \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/app/view/SolverDlg.js b/apps/spreadsheeteditor/main/app/view/SolverDlg.js index 8c593140ac..7e4337fd3c 100644 --- a/apps/spreadsheeteditor/main/app/view/SolverDlg.js +++ b/apps/spreadsheeteditor/main/app/view/SolverDlg.js @@ -478,26 +478,25 @@ define([ onAddConstrains: function() { var me = this, index = this.constrainsList.store.length; - // var handlerDlg = function(dlg, result) { - // if (result == 'ok') { - // me.props.addConstraint(index, dlg.getSettings()); //{cellRef: '', operator:AscCommonExcel.c_oAscOperator, constraint:''} - // this.updateConstrainsList(index); - // this.updateButtons(); - // } - // }; - // var win = new SSE.Views.ConstraintDialog({ - // handler: handlerDlg - // }).on('close', function() { - // me.show(); - // }); - // - // var xy = Common.Utils.getOffset(me.$window); - // me.hide(); - // win.show(me.$window, xy); - // win.setSettings({ - // api : me.api, - // props: {cellRef: '', operator: AscCommonExcel.c_oAscOperator['<='], constraint: ''} - // }); + var handlerDlg = function(dlg, result) { + if (result == 'ok') { + me.props.addConstraint(index, dlg.getSettings()); //{cellRef: '', operator:AscCommonExcel.c_oAscOperator, constraint:''} + this.updateConstrainsList(index); + this.updateButtons(); + } + }; + var win = new SSE.Views.ConstraintDialog({ + handler: handlerDlg, + isEdit: false, + constraintOperator: me._constraintOperator + }).on('close', function() { + me.show(); + }); + + var xy = Common.Utils.getOffset(me.$window); + me.hide(); + win.show(me.$window, xy); + win.setSettings({cellRef: '', operator: AscCommonExcel.c_oAscOperator['<='], constraint: ''}); }, onDeleteConstrains: function() { diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index 176bc706e1..df8139bc39 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -2394,6 +2394,11 @@ "SSE.Views.ChartWizardDialog.textTitleChange": "Change chart type", "SSE.Views.ChartWizardDialog.textType": "Type", "SSE.Views.ChartWizardDialog.txtSeriesDesc": "Choose the chart type and axis for your data series", + "SSE.Views.ConstraintDialog.txtCellRef": "Cell reference", + "SSE.Views.ConstraintDialog.txtConstraint": "Constraint", + "SSE.Views.ConstraintDialog.txtTitle": "Add constraint", + "SSE.Views.ConstraintDialog.txtTitleChange": "Change constraint", + "SSE.Views.ConstraintDialog.txtAdd": "Add", "SSE.Views.CreatePivotDialog.textDataRange": "Source data range", "SSE.Views.CreatePivotDialog.textDestination": "Choose where to place the table", "SSE.Views.CreatePivotDialog.textExist": "Existing sheet",