From 351286c8d1c5fb1ca93d888dab8e1a2318c40289 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 11 Nov 2020 23:55:11 +0300 Subject: [PATCH 1/8] [SSE] Show data validation settings --- apps/common/main/lib/component/Window.js | 2 +- .../main/app/controller/DataTab.js | 52 ++++++- .../main/app/controller/Toolbar.js | 7 +- .../template/DataValidationDialog.template | 18 +++ .../main/app/template/Toolbar.template | 1 + .../main/app/view/DataTab.js | 20 ++- .../main/app/view/DataValidationDialog.js | 129 ++++++++++++++++++ 7 files changed, 221 insertions(+), 8 deletions(-) create mode 100644 apps/spreadsheeteditor/main/app/template/DataValidationDialog.template create mode 100644 apps/spreadsheeteditor/main/app/view/DataValidationDialog.js diff --git a/apps/common/main/lib/component/Window.js b/apps/common/main/lib/component/Window.js index d54e083fe..d2e132659 100644 --- a/apps/common/main/lib/component/Window.js +++ b/apps/common/main/lib/component/Window.js @@ -606,7 +606,7 @@ define([ if (b.value !== undefined) newBtns[b.value] = {text: b.caption, cls: 'custom' + ((b.primary || options.primary==b.value) ? ' primary' : '')}; } else { - newBtns[b] = {text: (b=='custom') ? options.customButtonText : arrBtns[b], cls: (options.primary==b) ? 'primary' : ''}; + newBtns[b] = {text: (b=='custom') ? options.customButtonText : arrBtns[b], cls: (options.primary==b || _.indexOf(options.primary, b)>-1) ? 'primary' : ''}; if (b=='custom') newBtns[b].cls += ' custom'; } diff --git a/apps/spreadsheeteditor/main/app/controller/DataTab.js b/apps/spreadsheeteditor/main/app/controller/DataTab.js index bac379324..3a81ea77a 100644 --- a/apps/spreadsheeteditor/main/app/controller/DataTab.js +++ b/apps/spreadsheeteditor/main/app/controller/DataTab.js @@ -44,6 +44,7 @@ define([ 'spreadsheeteditor/main/app/view/DataTab', 'spreadsheeteditor/main/app/view/SortDialog', 'spreadsheeteditor/main/app/view/RemoveDuplicatesDialog', + 'spreadsheeteditor/main/app/view/DataValidationDialog', 'common/main/lib/view/OptionsDialog' ], function () { 'use strict'; @@ -90,7 +91,8 @@ define([ 'data:hide': this.onHideClick, 'data:groupsettings': this.onGroupSettings, 'data:sortcustom': this.onCustomSort, - 'data:remduplicates': this.onRemoveDuplicates + 'data:remduplicates': this.onRemoveDuplicates, + 'data:datavalidation': this.onDataValidation }, 'Statusbar': { 'sheet:changed': this.onApiSheetChanged @@ -279,7 +281,6 @@ define([ width: 500, title: this.txtRemDuplicates, msg: this.txtExpandRemDuplicates, - buttons: [ {caption: this.txtExpand, primary: true, value: 'expand'}, {caption: this.txtRemSelected, primary: true, value: 'remove'}, 'cancel'], @@ -313,6 +314,48 @@ define([ } }, + onDataValidation: function() { + var me = this; + if (this.api) { + var res = this.api.asc_getDataValidationProps(); + if (typeof res !== 'object') { + var config = { + maxwidth: 500, + title: this.txtDataValidation, + msg: res===Asc.c_oAscError.ID.MoreOneTypeDataValidate ? this.txtExtendDataValidation : this.txtRemoveDataValidation, + buttons: res===Asc.c_oAscError.ID.MoreOneTypeDataValidate ? ['yes', 'no', 'cancel'] : ['ok', 'cancel'], + primary: res===Asc.c_oAscError.ID.MoreOneTypeDataValidate ? ['yes', 'no'] : 'ok', + callback: function(btn){ + if (btn == 'yes' || btn == 'no' || btn == 'ok') { + setTimeout(function(){ + var props = me.api.asc_getDataValidationProps(btn == 'yes'); + me.showDataValidation(props); + },1); + } + } + }; + Common.UI.alert(config); + } else + me.showDataValidation(res); + } + }, + + showDataValidation: function(props) { + var me = this; + if (props) { + (new SSE.Views.DataValidationDialog({ + title: this.txtDataValidation, + props: props, + api: me.api, + handler: function (result, settings) { + if (me && me.api && result == 'ok') { + me.api.asc_setDataValidation(settings); + } + } + })).show(); + } + }, + onWorksheetLocked: function(index,locked) { if (index == this.api.asc_getActiveWorksheetIndex()) { Common.Utils.lockControls(SSE.enumLock.sheetLock, locked, {array: this.view.btnsSortDown.concat(this.view.btnsSortUp, this.view.btnCustomSort, this.view.btnGroup, this.view.btnUngroup)}); @@ -332,7 +375,10 @@ define([ txtExpand: 'Expand', txtRemSelected: 'Remove in selected', textRows: 'Rows', - textColumns: 'Columns' + textColumns: 'Columns', + txtDataValidation: 'Data Validation', + txtExtendDataValidation: 'The selection contains some cells without Data Validation settings.
Do you want to extend Data Validation to these cells?', + txtRemoveDataValidation: 'The selection contains more than one type of validation.
Erase current settings and continue?' }, SSE.Controllers.DataTab || {})); }); \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index 371faa2e3..e28e93882 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -2410,7 +2410,7 @@ define([ } need_disable = this._state.controlsdisabled.filters || (val===null); toolbar.lockToolbar(SSE.enumLock.ruleFilter, need_disable, - { array: toolbar.btnsSetAutofilter.concat(toolbar.btnCustomSort, toolbar.btnTableTemplate, toolbar.btnInsertTable, toolbar.btnRemoveDuplicates) }); + { array: toolbar.btnsSetAutofilter.concat(toolbar.btnCustomSort, toolbar.btnTableTemplate, toolbar.btnInsertTable, toolbar.btnRemoveDuplicates, toolbar.btnDataValidation) }); toolbar.lockToolbar(SSE.enumLock.tableHasSlicer, filterInfo && filterInfo.asc_getIsSlicerAdded(), { array: toolbar.btnsSetAutofilter }); @@ -2446,12 +2446,12 @@ define([ this._state.inpivot = !!info.asc_getPivotTableInfo(); toolbar.lockToolbar(SSE.enumLock.editPivot, this._state.inpivot, { array: toolbar.btnsSetAutofilter.concat(toolbar.btnCustomSort, - toolbar.btnMerge, toolbar.btnInsertHyperlink, toolbar.btnInsertTable, toolbar.btnRemoveDuplicates)}); + toolbar.btnMerge, toolbar.btnInsertHyperlink, toolbar.btnInsertTable, toolbar.btnRemoveDuplicates, toolbar.btnDataValidation)}); toolbar.lockToolbar(SSE.enumLock.noSlicerSource, !(this._state.inpivot || formatTableInfo), { array: [toolbar.btnInsertSlicer]}); need_disable = !this.appConfig.canModifyFilter; toolbar.lockToolbar(SSE.enumLock.cantModifyFilter, need_disable, { array: toolbar.btnsSetAutofilter.concat(toolbar.btnsSortDown, toolbar.btnsSortUp, toolbar.btnCustomSort, toolbar.btnTableTemplate, - toolbar.btnClearStyle.menu.items[0], toolbar.btnClearStyle.menu.items[2], toolbar.btnInsertTable, toolbar.btnRemoveDuplicates)}); + toolbar.btnClearStyle.menu.items[0], toolbar.btnClearStyle.menu.items[2], toolbar.btnInsertTable, toolbar.btnRemoveDuplicates, toolbar.btnDataValidation)}); } @@ -3340,6 +3340,7 @@ define([ me.toolbar.btnsClearAutofilter = datatab.getButtons('clear-filter'); me.toolbar.btnCustomSort = datatab.getButtons('sort-custom'); me.toolbar.btnRemoveDuplicates = datatab.getButtons('rem-duplicates'); + me.toolbar.btnDataValidation = datatab.getButtons('data-validation'); var formulatab = me.getApplication().getController('FormulaDialog'); formulatab.setConfig({toolbar: me}); diff --git a/apps/spreadsheeteditor/main/app/template/DataValidationDialog.template b/apps/spreadsheeteditor/main/app/template/DataValidationDialog.template new file mode 100644 index 000000000..5cbbce369 --- /dev/null +++ b/apps/spreadsheeteditor/main/app/template/DataValidationDialog.template @@ -0,0 +1,18 @@ +
+
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
diff --git a/apps/spreadsheeteditor/main/app/template/Toolbar.template b/apps/spreadsheeteditor/main/app/template/Toolbar.template index b2324d5d0..49cca6662 100644 --- a/apps/spreadsheeteditor/main/app/template/Toolbar.template +++ b/apps/spreadsheeteditor/main/app/template/Toolbar.template @@ -211,6 +211,7 @@
+
diff --git a/apps/spreadsheeteditor/main/app/view/DataTab.js b/apps/spreadsheeteditor/main/app/view/DataTab.js index d9020b935..0e2f1599a 100644 --- a/apps/spreadsheeteditor/main/app/view/DataTab.js +++ b/apps/spreadsheeteditor/main/app/view/DataTab.js @@ -69,6 +69,9 @@ define([ me.btnRemoveDuplicates.on('click', function (b, e) { me.fireEvent('data:remduplicates'); }); + me.btnDataValidation.on('click', function (b, e) { + me.fireEvent('data:datavalidation'); + }); // isn't used for awhile // me.btnShow.on('click', function (b, e) { // me.fireEvent('data:show'); @@ -179,6 +182,16 @@ define([ }); this.lockedControls.push(this.btnRemoveDuplicates); + this.btnDataValidation = new Common.UI.Button({ + parentEl: $host.find('#slot-btn-data-validation'), + cls: 'btn-toolbar x-huge icon-top', + iconCls: 'toolbar__icon btn-data-validation', + caption: this.capBtnTextDataValidation, + disabled: true, + lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selSlicer, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.editPivot, _set.cantModifyFilter, _set.sheetLock] + }); + this.lockedControls.push(this.btnDataValidation); + this.btnCustomSort = new Common.UI.Button({ parentEl: $host.find('#slot-btn-custom-sort'), cls: 'btn-toolbar x-huge icon-top', @@ -240,6 +253,7 @@ define([ me.btnTextToColumns.updateHint(me.tipToColumns); me.btnRemoveDuplicates.updateHint(me.tipRemDuplicates); + me.btnDataValidation.updateHint(me.tipDataValidation); me.btnsSortDown.forEach( function(btn) { btn.updateHint(me.toolbar.txtSortAZ); @@ -277,6 +291,8 @@ define([ return this.btnsClearAutofilter; else if (type == 'rem-duplicates') return this.btnRemoveDuplicates; + else if (type == 'data-validation') + return this.btnDataValidation; else if (type===undefined) return this.lockedControls; return []; @@ -308,7 +324,9 @@ define([ capBtnTextCustomSort: 'Custom Sort', tipCustomSort: 'Custom sort', capBtnTextRemDuplicates: 'Remove Duplicates', - tipRemDuplicates: 'Remove duplicate rows from a sheet' + tipRemDuplicates: 'Remove duplicate rows from a sheet', + capBtnTextDataValidation: 'Data Validation', + tipDataValidation: 'Data validation' } }()), SSE.Views.DataTab || {})); }); diff --git a/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js b/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js new file mode 100644 index 000000000..891350ca2 --- /dev/null +++ b/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js @@ -0,0 +1,129 @@ +/* + * + * (c) Copyright Ascensio System SIA 2010-2020 + * + * 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-12 Ernesta Birznieka-Upisha + * 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 + * + */ + +/** + * DataValidationDialog.js + * + * Created by Julia Radzhabova on 11.11.2020 + * Copyright (c) 2020 Ascensio System SIA. All rights reserved. + * + */ + +define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.template', + 'common/main/lib/util/utils', + 'common/main/lib/component/InputField', + 'common/main/lib/component/ComboBox', + 'common/main/lib/component/CheckBox', + 'common/main/lib/view/AdvancedSettingsWindow' +], function (contentTemplate) { 'use strict'; + + SSE.Views.DataValidationDialog = Common.Views.AdvancedSettingsWindow.extend(_.extend({ + options: { + contentWidth: 284, + height: 350, + toggleGroup: 'data-validation-group', + storageName: 'sse-data-validation-category' + }, + + initialize : function(options) { + var me = this; + + _.extend(this.options, { + title: this.options.title, + items: [ + {panelId: 'id-data-validation-settings', panelCaption: this.strSettings}, + {panelId: 'id-data-validation-input', panelCaption: this.strInput}, + {panelId: 'id-data-validation-error', panelCaption: this.strError} + ], + contentTemplate: _.template(contentTemplate)({ + scope: this + }) + }, options); + + this.api = options.api; + this.handler = options.handler; + this.props = options.props; + + Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options); + }, + + render: function() { + Common.Views.AdvancedSettingsWindow.prototype.render.call(this); + var me = this; + + this.afterRender(); + }, + + afterRender: function() { + this._setDefaults(this.props); + if (this.storageName) { + var value = Common.localStorage.getItem(this.storageName); + this.setActiveCategory((value!==null) ? parseInt(value) : 0); + } + }, + + show: function() { + Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments); + }, + + _setDefaults: function (props) { + if (props) { + } + }, + + getSettings: function () { + var props = new Asc.CDataValidation(); + return props; + }, + + onDlgBtnClick: function(event) { + var me = this; + var state = (typeof(event) == 'object') ? event.currentTarget.attributes['result'].value : event; + if (state == 'ok') { + this.handler && this.handler.call(this, state, (state == 'ok') ? this.getSettings() : undefined); + } + + this.close(); + }, + + onPrimary: function() { + this.onDlgBtnClick('ok'); + return false; + }, + + strSettings: 'Settings', + strInput: 'Input Message', + strError: 'Error Alert' + + }, SSE.Views.DataValidationDialog || {})) +}); \ No newline at end of file From df3825ec800bd6f8c7d0f9f8947c176bbdfded12 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 12 Nov 2020 11:30:05 +0300 Subject: [PATCH 2/8] [SSE] Refactoring data validation --- apps/spreadsheeteditor/main/app/controller/DataTab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/spreadsheeteditor/main/app/controller/DataTab.js b/apps/spreadsheeteditor/main/app/controller/DataTab.js index 3a81ea77a..e3b6498f8 100644 --- a/apps/spreadsheeteditor/main/app/controller/DataTab.js +++ b/apps/spreadsheeteditor/main/app/controller/DataTab.js @@ -328,7 +328,7 @@ define([ callback: function(btn){ if (btn == 'yes' || btn == 'no' || btn == 'ok') { setTimeout(function(){ - var props = me.api.asc_getDataValidationProps(btn == 'yes'); + var props = me.api.asc_getDataValidationProps((btn=='ok') ? null : (btn == 'yes')); me.showDataValidation(props); },1); } From 0369ff1604cb328d5d63d3b80b4b2bffd719eca7 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 13 Nov 2020 15:06:45 +0300 Subject: [PATCH 3/8] [SSE] Add dialog for data validation --- apps/common/main/resources/less/window.less | 52 ++- .../template/DataValidationDialog.template | 96 ++++- .../main/app/view/DataValidationDialog.js | 395 +++++++++++++++++- 3 files changed, 515 insertions(+), 28 deletions(-) diff --git a/apps/common/main/resources/less/window.less b/apps/common/main/resources/less/window.less index 5a47e07ca..dca6ba2c7 100644 --- a/apps/common/main/resources/less/window.less +++ b/apps/common/main/resources/less/window.less @@ -138,34 +138,40 @@ z-index: @zindex-modal - 2; } - &.alert { - min-height: 90px; - min-width: 230px; + .icon { + &.warn { + width: 35px; + height: 32px; + background-position: @alerts-offset-x @alerts-offset-y - 105px; + } - .icon { - float: left; + &.error, &.info, &.confirm { width: 35px; height: 35px; - margin: 0 0 0 10px; - - &.warn { - height: 32px; - background-position: @alerts-offset-x @alerts-offset-y - 105px; - } - - &.error { - background-position: @alerts-offset-x @alerts-offset-y - 0; - } - - &.info { - background-position: @alerts-offset-x @alerts-offset-y - 35px; - } - - &.confirm { - background-position: @alerts-offset-x @alerts-offset-y - 70px; - } } + &.error { + background-position: @alerts-offset-x @alerts-offset-y - 0; + } + + &.info { + background-position: @alerts-offset-x @alerts-offset-y - 35px; + } + + &.confirm { + background-position: @alerts-offset-x @alerts-offset-y - 70px; + } + } + + &.alert { + .icon { + float: left; + margin: 0 0 0 10px; + } + + min-height: 90px; + min-width: 230px; + .body { .info-box { padding: 20px 20px 20px 10px; diff --git a/apps/spreadsheeteditor/main/app/template/DataValidationDialog.template b/apps/spreadsheeteditor/main/app/template/DataValidationDialog.template index 5cbbce369..8a5a9429f 100644 --- a/apps/spreadsheeteditor/main/app/template/DataValidationDialog.template +++ b/apps/spreadsheeteditor/main/app/template/DataValidationDialog.template @@ -1,18 +1,112 @@
- +
+ + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+
+ + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+
+ + + + + + + + + + + +
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+
+ +
+
diff --git a/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js b/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js index 891350ca2..d7fa4488e 100644 --- a/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js +++ b/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js @@ -44,12 +44,13 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ 'common/main/lib/component/InputField', 'common/main/lib/component/ComboBox', 'common/main/lib/component/CheckBox', + 'common/main/lib/component/TextareaField', 'common/main/lib/view/AdvancedSettingsWindow' ], function (contentTemplate) { 'use strict'; SSE.Views.DataValidationDialog = Common.Views.AdvancedSettingsWindow.extend(_.extend({ options: { - contentWidth: 284, + contentWidth: 320, height: 350, toggleGroup: 'data-validation-group', storageName: 'sse-data-validation-category' @@ -80,6 +81,192 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ render: function() { Common.Views.AdvancedSettingsWindow.prototype.render.call(this); var me = this; + var $window = this.getChild(); + + // settings + this.cmbAllow = new Common.UI.ComboBox({ + el: $window.find('#data-validation-cmb-allow'), + cls: 'input-group-nr', + editable: false, + data: [ + {value: Asc.EDataValidationType.None, displayValue: this.txtAny}, + {value: Asc.EDataValidationType.Whole, displayValue: this.txtWhole}, + {value: Asc.EDataValidationType.Decimal, displayValue: this.txtDecimal}, + {value: Asc.EDataValidationType.List, displayValue: this.txtList}, + {value: Asc.EDataValidationType.Date, displayValue: this.txtDate}, + {value: Asc.EDataValidationType.Time, displayValue: this.txtTime}, + {value: Asc.EDataValidationType.TextLength, displayValue: this.txtTextLength}, + {value: Asc.EDataValidationType.Custom, displayValue: this.txtOther} + ], + style: 'width: 100%;', + menuStyle : 'min-width: 100%;', + takeFocusOnClose: true + }); + this.cmbAllow.setValue(Asc.EDataValidationType.None); + this.cmbAllow.on('selected', _.bind(this.onAllowSelect, this)); + + this.cmbData = new Common.UI.ComboBox({ + el: $window.find('#data-validation-cmb-data'), + cls: 'input-group-nr', + editable: false, + data: [ + {value: Asc.EDataValidationOperator.Between, displayValue: this.txtBetween}, + {value: Asc.EDataValidationOperator.NotBetween, displayValue: this.txtNotBetween}, + {value: Asc.EDataValidationOperator.Equal, displayValue: this.txtEqual}, + {value: Asc.EDataValidationOperator.NotEqual, displayValue: this.txtNotEqual}, + {value: Asc.EDataValidationOperator.GreaterThan, displayValue: this.txtGreaterThan}, + {value: Asc.EDataValidationOperator.LessThan, displayValue: this.txtLessThan}, + {value: Asc.EDataValidationOperator.GreaterThanOrEqual, displayValue: this.txtGreaterThanOrEqual}, + {value: Asc.EDataValidationOperator.LessThanOrEqual, displayValue: this.txtLessThanOrEqual} + ], + style: 'width: 100%;', + menuStyle : 'min-width: 100%;', + takeFocusOnClose: true + }); + this.cmbData.setValue(Asc.EDataValidationOperator.Between); + this.cmbData.on('selected', _.bind(this.onDataSelect, this)); + + this.chIgnore = new Common.UI.CheckBox({ + el: $window.find('#data-validation-ch-ignore'), + labelText: this.textIgnore, + value: true + }); + // this.chIgnore.on('change', _.bind(this.onIgnoreChange, this)); + + this.lblRangeMin = $window.find('#data-validation-label-min'); + this.inputRangeMin = new Common.UI.InputFieldBtn({ + el: $window.find('#data-validation-txt-min'), + style: '100%', + textSelectData: 'Select data', + // validateOnChange: true, + validateOnBlur: false + }).on('changed:after', function(input, newValue, oldValue, e) { + if (newValue == oldValue) return; + }).on('button:click', _.bind(this.onSelectData, this)); + + this.lblRangeMax = $window.find('#data-validation-label-max'); + this.inputRangeMax = new Common.UI.InputFieldBtn({ + el: $window.find('#data-validation-txt-max'), + style: '100%', + textSelectData: 'Select data', + // validateOnChange: true, + validateOnBlur: false + }).on('changed:after', function(input, newValue, oldValue, e) { + if (newValue == oldValue) return; + }).on('button:click', _.bind(this.onSelectData, this)); + + this.chShowDropDown = new Common.UI.CheckBox({ + el: $window.find('#data-validation-ch-show-dropdown'), + labelText: this.textShowDropDown, + value: true + }); + // this.chShowDropDown.on('change', _.bind(this.onDropDownChange, this)); + + this.lblRangeSource = $window.find('#data-validation-label-source'); + this.inputRangeSource = new Common.UI.InputFieldBtn({ + el: $window.find('#data-validation-txt-source'), + style: '100%', + textSelectData: 'Select data', + // validateOnChange: true, + validateOnBlur: false + }).on('changed:after', function(input, newValue, oldValue, e) { + if (newValue == oldValue) return; + }).on('button:click', _.bind(this.onSelectData, this)); + + this.chApply = new Common.UI.CheckBox({ + el: $window.find('#data-validation-ch-apply'), + labelText: this.textApply + }); + // this.chApply.on('change', _.bind(this.onApplyChange, this)); + + // input message + this.chShowInput = new Common.UI.CheckBox({ + el: $window.find('#data-validation-ch-show-input'), + labelText: this.textShowInput, + value: true + }); + this.chShowInput.on('change', _.bind(this.onShowInputChange, this)); + + this.inputInputTitle = new Common.UI.InputField({ + el: $window.find('#data-validation-input-title'), + allowBlank : true, + validateOnBlur: false, + style : 'width: 100%;' + }).on('changed:after', function() { + me.isInputTitleChanged = true; + }); + + // this.textareaInput = $window.find('#data-validation-input-msg'); + // this.textareaInput.keydown(function (event) { + // if (event.keyCode == Common.UI.Keys.RETURN) { + // event.stopPropagation(); + // } + // me.isInputChanged = true; + // }); + + this.textareaInput = new Common.UI.TextareaField({ + el : $window.find('#data-validation-input-msg'), + style : 'width: 100%; height: 70px;', + value : '' + }); + this.textareaInput.on('changed:after', function() { + me.isInputChanged = true; + }); + + // error message + this.chShowError = new Common.UI.CheckBox({ + el: $window.find('#data-validation-ch-show-error'), + labelText: this.textShowError, + value: true + }); + this.chShowError.on('change', _.bind(this.onShowErrorChange, this)); + + this.cmbStyle = new Common.UI.ComboBox({ + el: $window.find('#data-validation-cmb-style'), + cls: 'input-group-nr', + editable: false, + data: [ + {value: 'error', displayValue: this.textStop}, + {value: 'warn', displayValue: this.textAlert}, + {value: 'info', displayValue: this.textMessage} + ], + style: 'width: 95px;', + menuStyle : 'min-width: 95px;', + takeFocusOnClose: true + }); + this.cmbStyle.setValue('error'); + this.cmbStyle.on('selected', _.bind(this.onStyleSelect, this)); + + this.inputErrorTitle = new Common.UI.InputField({ + el: $window.find('#data-validation-error-title'), + allowBlank : true, + validateOnBlur: false, + style : 'width: 100%;' + }).on('changed:after', function() { + me.isErrorTitleChanged = true; + }); + + // this.textareaError = $window.find('#data-validation-error-msg'); + // this.textareaError.keydown(function (event) { + // if (event.keyCode == Common.UI.Keys.RETURN) { + // event.stopPropagation(); + // } + // me.isErrorChanged = true; + // }); + + this.textareaError = new Common.UI.TextareaField({ + el : $window.find('#data-validation-error-msg'), + style : 'width: 100%; height: 70px;', + value : '' + }); + this.textareaError.on('changed:after', function() { + me.isErrorChanged = true; + }); + + this.minMaxTr = $window.find('#data-validation-txt-min').closest('tr'); + this.sourceTr = $window.find('#data-validation-txt-source').closest('tr'); + this.dropdownTr = $window.find('#data-validation-ch-show-dropdown').closest('tr'); + this.errorIcon = $window.find('#data-validation-img-style'); this.afterRender(); }, @@ -92,18 +279,117 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ } }, + getFocusedComponents: function() { + return [ + this.cmbAllow, this.cmbData, this.inputRangeSource, this.inputRangeMin, this.inputRangeMax, // 0 tab + this.inputInputTitle, this.textareaInput, // 1 tab + this.cmbStyle, this.inputErrorTitle, this.textareaError // 2 tab + ]; + }, + + onCategoryClick: function(btn, index) { + Common.Views.AdvancedSettingsWindow.prototype.onCategoryClick.call(this, btn, index); + + var me = this; + setTimeout(function(){ + switch (index) { + case 0: + me.cmbAllow.focus(); + break; + case 1: + me.inputInputTitle.focus(); + break; + case 2: + me.cmbStyle.focus(); + break; + } + }, 10); + }, + show: function() { Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments); }, + onSelectData: function(input) { + var me = this; + if (me.api) { + var handlerDlg = function(dlg, result) { + if (result == 'ok') { + input.setValue(dlg.getSettings()); + } + }; + + var win = new SSE.Views.CellRangeDialog({ + handler: handlerDlg + }).on('close', function() { + me.show(); + setTimeout(function(){ + me._noApply = true; + input.focus(); + me._noApply = false; + },1); + }); + + var xy = me.$window.offset(); + me.hide(); + win.show(xy.left + 160, xy.top + 125); + win.setSettings({ + api : me.api, + range : input.getValue(), + type : Asc.c_oAscSelectionDialogType.Chart, + validation: function() {return true;} + }); + } + }, + + onAllowSelect: function(combo, record) { + this.ShowHideElem(); + }, + + onDataSelect: function(combo, record) { + this.ShowHideElem(); + }, + + onStyleSelect: function(combo, record) { + this.errorIcon.removeClass("error warn info"); + this.errorIcon.addClass(record.value); + }, + + onShowInputChange: function(field, newValue, oldValue, eOpts) { + var checked = (field.getValue()=='checked'); + this.inputInputTitle.setDisabled(!checked); + this.textareaInput.setDisabled(!checked); + + if (this.api && !this._noApply) { + var properties = this.props; + // properties.asc_putStrikeout(field.getValue()=='checked'); + // properties.asc_putDStrikeout(this.chDoubleStrike.getValue()=='checked'); + // this.api.asc_setDrawImagePlaceParagraph('paragraphadv-font-img', properties); + } + }, + + onShowErrorChange: function(field, newValue, oldValue, eOpts) { + var checked = (field.getValue()=='checked'); + this.inputErrorTitle.setDisabled(!checked); + this.cmbStyle.setDisabled(!checked); + this.textareaError.setDisabled(!checked); + + if (this.api && !this._noApply) { + var properties = this.props; + // properties.asc_putStrikeout(field.getValue()=='checked'); + // properties.asc_putDStrikeout(this.chDoubleStrike.getValue()=='checked'); + // this.api.asc_setDrawImagePlaceParagraph('paragraphadv-font-img', properties); + } + }, + _setDefaults: function (props) { if (props) { } + this.ShowHideElem(); }, getSettings: function () { - var props = new Asc.CDataValidation(); - return props; + return this.props; }, onDlgBtnClick: function(event) { @@ -121,9 +407,110 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ return false; }, + ShowHideElem: function() { + var allow = this.cmbAllow.getValue(), + data = this.cmbData.getValue(); + var between = (data==Asc.EDataValidationOperator.Between || data==Asc.EDataValidationOperator.NotBetween); + var source = (allow==Asc.EDataValidationType.Custom || allow==Asc.EDataValidationType.List); + this.minMaxTr.toggleClass('hidden', allow==Asc.EDataValidationType.None || source || !between); + this.sourceTr.toggleClass('hidden', allow==Asc.EDataValidationType.None || !source && between ); + this.dropdownTr.toggleClass('hidden', allow!=Asc.EDataValidationType.List); + + this.chIgnore.setDisabled(allow===Asc.EDataValidationType.None); + this.cmbData.setDisabled(allow===Asc.EDataValidationType.None || allow===Asc.EDataValidationType.Custom || allow===Asc.EDataValidationType.List); + + var str = this.textSource; + if (allow==Asc.EDataValidationType.Custom) + str = this.textFormula; + else if (data==Asc.EDataValidationOperator.Equal || data==Asc.EDataValidationOperator.NotEqual) { // equals, not equals + if (allow==Asc.EDataValidationType.Date) + str = this.txtDate; + else if (allow==Asc.EDataValidationType.TextLength) + str = this.txtLength; + else if (allow==Asc.EDataValidationType.Time) + str = this.txtElTime; + else + str = this.textCompare; + } else if (data==Asc.EDataValidationOperator.GreaterThan || data==Asc.EDataValidationOperator.GreaterThanOrEqual) { // greater, greater or equals + if (allow==Asc.EDataValidationType.Date) + str = this.txtStartDate; + else if (allow==Asc.EDataValidationType.Time) + str = this.txtStartTime; + else + str = this.textMin; + } else if (data==Asc.EDataValidationOperator.LessThan || data==Asc.EDataValidationOperator.LessThanOrEqual) { // less, less or equals + if (allow==Asc.EDataValidationType.Date) + str = this.txtEndDate; + else if (allow==Asc.EDataValidationType.Time) + str = this.txtEndTime; + else + str = this.textMax; + } + this.lblRangeSource.text(str); + + var str1 = this.textMin, + str2 = this.textMax; + if (allow==Asc.EDataValidationType.Date) { + str1 = this.txtStartDate; + str2 = this.txtEndDate; + } else if (allow==Asc.EDataValidationType.Time) { + str1 = this.txtStartTime; + str2 = this.txtEndTime; + } + this.lblRangeMin.text(str1); + this.lblRangeMax.text(str2); + }, + strSettings: 'Settings', strInput: 'Input Message', - strError: 'Error Alert' + strError: 'Error Alert', + textAllow: 'Allow', + textData: 'Data', + textMin: 'Minimum', + textMax: 'Maximum', + textCompare: 'Compare to', + textSource: 'Source', + textStartDate: 'Start Date', + textEndDate: 'End Date', + textStartTime: 'Start Time', + textEndTime: 'End Time', + textFormula: 'Formula', + textIgnore: 'Ignore blank', + textApply: 'Apply these changes to all othes calls the same settings', + textShowDropDown: 'Show drop-down list in cell', + textCellSelected: 'When cell is selected, show this input message', + textTitle: 'Title', + textInput: 'Input Message', + textUserEnters: 'When user enters invalid data, show this error alert', + textStyle: 'Style', + textError: 'Error Message', + textShowInput: 'Show input message when cell is selected', + textShowError: 'Show error alert after invalid data is entered', + txtBetween: 'between', + txtNotBetween: 'not between', + txtEqual: 'equals', + txtNotEqual: 'does not equal', + txtLessThan: 'less than', + txtGreaterThan: 'greater than', + txtLessThanOrEqual: 'less than or equal to', + txtGreaterThanOrEqual: 'greater than or equal to', + txtAny: 'Any value', + txtWhole: 'Whole number', + txtDecimal: 'Decimal', + txtList: 'List', + txtDate: 'Date', + txtTime: 'Time', + txtTextLength: 'Text length', + txtLength: 'Length', + txtOther: 'Other', + txtElTime: 'Elapsed time', + txtStartDate: 'Start date', + txtStartTime: 'Start time', + txtEndDate: 'End date', + txtEndTime: 'End time', + textStop: 'Stop', + textAlert: 'Alert', + textMessage: 'Message' }, SSE.Views.DataValidationDialog || {})) }); \ No newline at end of file From abd5e91ed36da5d0c7236adeaebe7dc52b61f413 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 13 Nov 2020 21:47:43 +0300 Subject: [PATCH 4/8] [SSE] Set data validation settings --- .../main/app/view/DataValidationDialog.js | 125 ++++++++++++------ 1 file changed, 83 insertions(+), 42 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js b/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js index d7fa4488e..085d92e4b 100644 --- a/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js +++ b/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js @@ -74,6 +74,7 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ this.api = options.api; this.handler = options.handler; this.props = options.props; + this._noApply = true; Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options); }, @@ -131,7 +132,7 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ labelText: this.textIgnore, value: true }); - // this.chIgnore.on('change', _.bind(this.onIgnoreChange, this)); + this.chIgnore.on('change', _.bind(this.onIgnoreChange, this)); this.lblRangeMin = $window.find('#data-validation-label-min'); this.inputRangeMin = new Common.UI.InputFieldBtn({ @@ -140,9 +141,7 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ textSelectData: 'Select data', // validateOnChange: true, validateOnBlur: false - }).on('changed:after', function(input, newValue, oldValue, e) { - if (newValue == oldValue) return; - }).on('button:click', _.bind(this.onSelectData, this)); + }).on('changed:after', _.bind(this.onRangeChange, this, 1)).on('button:click', _.bind(this.onSelectData, this, 1)); this.lblRangeMax = $window.find('#data-validation-label-max'); this.inputRangeMax = new Common.UI.InputFieldBtn({ @@ -151,16 +150,14 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ textSelectData: 'Select data', // validateOnChange: true, validateOnBlur: false - }).on('changed:after', function(input, newValue, oldValue, e) { - if (newValue == oldValue) return; - }).on('button:click', _.bind(this.onSelectData, this)); + }).on('changed:after', _.bind(this.onRangeChange, this, 2)).on('button:click', _.bind(this.onSelectData, this, 2)); this.chShowDropDown = new Common.UI.CheckBox({ el: $window.find('#data-validation-ch-show-dropdown'), labelText: this.textShowDropDown, value: true }); - // this.chShowDropDown.on('change', _.bind(this.onDropDownChange, this)); + this.chShowDropDown.on('change', _.bind(this.onDropDownChange, this)); this.lblRangeSource = $window.find('#data-validation-label-source'); this.inputRangeSource = new Common.UI.InputFieldBtn({ @@ -169,9 +166,7 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ textSelectData: 'Select data', // validateOnChange: true, validateOnBlur: false - }).on('changed:after', function(input, newValue, oldValue, e) { - if (newValue == oldValue) return; - }).on('button:click', _.bind(this.onSelectData, this)); + }).on('changed:after', _.bind(this.onRangeChange, this, 3)).on('button:click', _.bind(this.onSelectData, this, 3)); this.chApply = new Common.UI.CheckBox({ el: $window.find('#data-validation-ch-apply'), @@ -196,14 +191,6 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ me.isInputTitleChanged = true; }); - // this.textareaInput = $window.find('#data-validation-input-msg'); - // this.textareaInput.keydown(function (event) { - // if (event.keyCode == Common.UI.Keys.RETURN) { - // event.stopPropagation(); - // } - // me.isInputChanged = true; - // }); - this.textareaInput = new Common.UI.TextareaField({ el : $window.find('#data-validation-input-msg'), style : 'width: 100%; height: 70px;', @@ -226,15 +213,15 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ cls: 'input-group-nr', editable: false, data: [ - {value: 'error', displayValue: this.textStop}, - {value: 'warn', displayValue: this.textAlert}, - {value: 'info', displayValue: this.textMessage} + {value: Asc.c_oAscEDataValidationErrorStyle.Stop, clsText: 'error', displayValue: this.textStop}, + {value: Asc.c_oAscEDataValidationErrorStyle.Warning, clsText: 'warn', displayValue: this.textAlert}, + {value: Asc.c_oAscEDataValidationErrorStyle.Information, clsText: 'info', displayValue: this.textMessage} ], style: 'width: 95px;', menuStyle : 'min-width: 95px;', takeFocusOnClose: true }); - this.cmbStyle.setValue('error'); + this.cmbStyle.setValue(Asc.c_oAscEDataValidationErrorStyle.Stop); this.cmbStyle.on('selected', _.bind(this.onStyleSelect, this)); this.inputErrorTitle = new Common.UI.InputField({ @@ -246,14 +233,6 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ me.isErrorTitleChanged = true; }); - // this.textareaError = $window.find('#data-validation-error-msg'); - // this.textareaError.keydown(function (event) { - // if (event.keyCode == Common.UI.Keys.RETURN) { - // event.stopPropagation(); - // } - // me.isErrorChanged = true; - // }); - this.textareaError = new Common.UI.TextareaField({ el : $window.find('#data-validation-error-msg'), style : 'width: 100%; height: 70px;', @@ -310,12 +289,14 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments); }, - onSelectData: function(input) { + onSelectData: function(type, input) { var me = this; if (me.api) { var handlerDlg = function(dlg, result) { if (result == 'ok') { - input.setValue(dlg.getSettings()); + var val = dlg.getSettings(); + input.setValue(val); + me.onRangeChange(type, input, val); } }; @@ -342,17 +323,49 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ } }, + onRangeChange: function(type, input, newValue, oldValue, e) { + if (newValue == oldValue) return; + if (!this._noApply) { + if (type==1 || type==3) + this.props.asc_setFormula1(newValue); + else if (type==2) + this.props.asc_setFormula2(newValue); + } + }, + onAllowSelect: function(combo, record) { this.ShowHideElem(); + if (!this._noApply) + this.props.asc_setType(record.value); + this.inputRangeMin.setValue(this.props.asc_getFormula1() || ''); + this.inputRangeSource.setValue(this.props.asc_getFormula1() || ''); + this.inputRangeMax.setValue(this.props.asc_getFormula2() || ''); }, onDataSelect: function(combo, record) { this.ShowHideElem(); + if (!this._noApply) + this.props.asc_setOperator(record.value); + this.inputRangeMin.setValue(this.props.asc_getFormula1() || ''); + this.inputRangeSource.setValue(this.props.asc_getFormula1() || ''); + this.inputRangeMax.setValue(this.props.asc_getFormula2() || ''); }, onStyleSelect: function(combo, record) { this.errorIcon.removeClass("error warn info"); - this.errorIcon.addClass(record.value); + this.errorIcon.addClass(record.clsText); + }, + + onIgnoreChange: function(field, newValue, oldValue, eOpts) { + if (!this._noApply) { + this.props.asc_setAllowBlank(field.getValue()!=='checked'); + } + }, + + onDropDownChange: function(field, newValue, oldValue, eOpts) { + if (!this._noApply) { + this.props.asc_setShowDropDown(field.getValue()=='checked'); + } }, onShowInputChange: function(field, newValue, oldValue, eOpts) { @@ -361,10 +374,7 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ this.textareaInput.setDisabled(!checked); if (this.api && !this._noApply) { - var properties = this.props; - // properties.asc_putStrikeout(field.getValue()=='checked'); - // properties.asc_putDStrikeout(this.chDoubleStrike.getValue()=='checked'); - // this.api.asc_setDrawImagePlaceParagraph('paragraphadv-font-img', properties); + this.props.asc_setShowInputMessage(field.getValue()=='checked'); } }, @@ -375,20 +385,51 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ this.textareaError.setDisabled(!checked); if (this.api && !this._noApply) { - var properties = this.props; - // properties.asc_putStrikeout(field.getValue()=='checked'); - // properties.asc_putDStrikeout(this.chDoubleStrike.getValue()=='checked'); - // this.api.asc_setDrawImagePlaceParagraph('paragraphadv-font-img', properties); + this.props.asc_setShowErrorMessage(field.getValue()=='checked'); } }, _setDefaults: function (props) { + this._noApply = true; if (props) { + var value = props.asc_getAllowBlank(); + this.chIgnore.setValue(!value, true); + value = props.asc_getShowDropDown(); + this.chShowDropDown.setValue(!!value, true); + value = props.asc_getType(); + this.cmbAllow.setValue(value!==null ? value : Asc.EDataValidationType.None, true); + value = props.asc_getOperator(); + this.cmbData.setValue(value!==null ? value : Asc.EDataValidationOperator.Between, true); + this.inputRangeMin.setValue(props.asc_getFormula1() || ''); + this.inputRangeSource.setValue(props.asc_getFormula1() || ''); + this.inputRangeMax.setValue(props.asc_getFormula2() || ''); + + // input + this.chShowInput.setValue(!!props.asc_getShowInputMessage()); + this.inputInputTitle.setValue(props.asc_getPromptTitle() || ''); + this.textareaInput.setValue(props.asc_getPrompt() || ''); + + // error + this.chShowError.setValue(!!props.asc_getShowErrorMessage()); + this.inputErrorTitle.setValue(props.asc_getErrorTitle() || ''); + this.textareaError.setValue(props.asc_getError() || ''); + value = props.asc_getErrorStyle(); + this.cmbStyle.setValue(value!==null ? value : Asc.EDataValidationErrorStyle.Stop); + } this.ShowHideElem(); + this._noApply = false; }, getSettings: function () { + if (this.isInputTitleChanged) + this.props.asc_setPromptTitle(this.inputInputTitle.getValue()); + if (this.isInputChanged) + this.props.asc_setPrompt(this.textareaInput.getValue()); + if (this.isErrorTitleChanged) + this.props.asc_setErrorTitle(this.inputErrorTitle.getValue()); + if (this.isErrorChanged) + this.props.asc_setError(this.textareaError.getValue()); return this.props; }, From 1d632aa2ad5ef2d22931bc35e589f6ca4a8bbf81 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 13 Nov 2020 22:55:21 +0300 Subject: [PATCH 5/8] [SSE] Refactoring data validation dialog --- .../main/app/template/DataValidationDialog.template | 10 +++++----- .../main/app/view/DataValidationDialog.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/template/DataValidationDialog.template b/apps/spreadsheeteditor/main/app/template/DataValidationDialog.template index 8a5a9429f..ef85cbaf5 100644 --- a/apps/spreadsheeteditor/main/app/template/DataValidationDialog.template +++ b/apps/spreadsheeteditor/main/app/template/DataValidationDialog.template @@ -1,6 +1,6 @@ -
-
- +
+
+
- - + diff --git a/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js b/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js index 085d92e4b..480e7f562 100644 --- a/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js +++ b/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js @@ -51,7 +51,7 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ SSE.Views.DataValidationDialog = Common.Views.AdvancedSettingsWindow.extend(_.extend({ options: { contentWidth: 320, - height: 350, + height: 330, toggleGroup: 'data-validation-group', storageName: 'sse-data-validation-category' }, From 7e70852223b010a32988ca80abdd58abbe105113 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 18 Nov 2020 19:15:05 +0300 Subject: [PATCH 6/8] [SSE] Data validation refactoring --- .../main/app/view/DataValidationDialog.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js b/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js index 480e7f562..9d3d1ac99 100644 --- a/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js +++ b/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js @@ -138,7 +138,7 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ this.inputRangeMin = new Common.UI.InputFieldBtn({ el: $window.find('#data-validation-txt-min'), style: '100%', - textSelectData: 'Select data', + btnHint: this.textSelectData, // validateOnChange: true, validateOnBlur: false }).on('changed:after', _.bind(this.onRangeChange, this, 1)).on('button:click', _.bind(this.onSelectData, this, 1)); @@ -147,7 +147,7 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ this.inputRangeMax = new Common.UI.InputFieldBtn({ el: $window.find('#data-validation-txt-max'), style: '100%', - textSelectData: 'Select data', + btnHint: this.textSelectData, // validateOnChange: true, validateOnBlur: false }).on('changed:after', _.bind(this.onRangeChange, this, 2)).on('button:click', _.bind(this.onSelectData, this, 2)); @@ -163,7 +163,7 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ this.inputRangeSource = new Common.UI.InputFieldBtn({ el: $window.find('#data-validation-txt-source'), style: '100%', - textSelectData: 'Select data', + btnHint: this.textSelectData, // validateOnChange: true, validateOnBlur: false }).on('changed:after', _.bind(this.onRangeChange, this, 3)).on('button:click', _.bind(this.onSelectData, this, 3)); @@ -551,7 +551,8 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ txtEndTime: 'End time', textStop: 'Stop', textAlert: 'Alert', - textMessage: 'Message' + textMessage: 'Message', + textSelectData: 'Select data' }, SSE.Views.DataValidationDialog || {})) }); \ No newline at end of file From 42ab9d6fe2f4605aee2be5ef0e0eddd96afc9c05 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 19 Nov 2020 00:08:31 +0300 Subject: [PATCH 7/8] [SSE] Check settings for data validation --- .../main/app/view/DataValidationDialog.js | 104 +++++++++++++++--- 1 file changed, 90 insertions(+), 14 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js b/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js index 9d3d1ac99..f3ac76208 100644 --- a/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js +++ b/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js @@ -186,6 +186,7 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ el: $window.find('#data-validation-input-title'), allowBlank : true, validateOnBlur: false, + maxLength: 32, style : 'width: 100%;' }).on('changed:after', function() { me.isInputTitleChanged = true; @@ -194,6 +195,7 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ this.textareaInput = new Common.UI.TextareaField({ el : $window.find('#data-validation-input-msg'), style : 'width: 100%; height: 70px;', + maxLength : 255, value : '' }); this.textareaInput.on('changed:after', function() { @@ -228,6 +230,7 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ el: $window.find('#data-validation-error-title'), allowBlank : true, validateOnBlur: false, + maxLength: 32, style : 'width: 100%;' }).on('changed:after', function() { me.isErrorTitleChanged = true; @@ -236,6 +239,7 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ this.textareaError = new Common.UI.TextareaField({ el : $window.find('#data-validation-error-msg'), style : 'width: 100%; height: 70px;', + maxLength : 255, value : '' }); this.textareaError.on('changed:after', function() { @@ -326,10 +330,15 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ onRangeChange: function(type, input, newValue, oldValue, e) { if (newValue == oldValue) return; if (!this._noApply) { - if (type==1 || type==3) - this.props.asc_setFormula1(newValue); - else if (type==2) - this.props.asc_setFormula2(newValue); + if (type==1 || type==3) { + if (!this.props.asc_getFormula1()) + this.props.asc_setFormula1(new AscCommonExcel.CDataFormula()); + this.props.asc_getFormula1().asc_setValue(newValue); + } else if (type==2) { + if (!this.props.asc_getFormula2()) + this.props.asc_setFormula2(new AscCommonExcel.CDataFormula()); + this.props.asc_getFormula2().asc_setValue(newValue); + } } }, @@ -337,18 +346,18 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ this.ShowHideElem(); if (!this._noApply) this.props.asc_setType(record.value); - this.inputRangeMin.setValue(this.props.asc_getFormula1() || ''); - this.inputRangeSource.setValue(this.props.asc_getFormula1() || ''); - this.inputRangeMax.setValue(this.props.asc_getFormula2() || ''); + this.inputRangeMin.setValue(this.props.asc_getFormula1() ? this.props.asc_getFormula1().asc_getValue() || '' : ''); + this.inputRangeSource.setValue(this.props.asc_getFormula1() ? this.props.asc_getFormula1().asc_getValue() || '' : ''); + this.inputRangeMax.setValue(this.props.asc_getFormula2() ? this.props.asc_getFormula2().asc_getValue() || '' : ''); }, onDataSelect: function(combo, record) { this.ShowHideElem(); if (!this._noApply) this.props.asc_setOperator(record.value); - this.inputRangeMin.setValue(this.props.asc_getFormula1() || ''); - this.inputRangeSource.setValue(this.props.asc_getFormula1() || ''); - this.inputRangeMax.setValue(this.props.asc_getFormula2() || ''); + this.inputRangeMin.setValue(this.props.asc_getFormula1() ? this.props.asc_getFormula1().asc_getValue() || '' : ''); + this.inputRangeSource.setValue(this.props.asc_getFormula1() ? this.props.asc_getFormula1().asc_getValue() || '' : ''); + this.inputRangeMax.setValue(this.props.asc_getFormula2() ? this.props.asc_getFormula2().asc_getValue() || '' : ''); }, onStyleSelect: function(combo, record) { @@ -400,9 +409,9 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ this.cmbAllow.setValue(value!==null ? value : Asc.EDataValidationType.None, true); value = props.asc_getOperator(); this.cmbData.setValue(value!==null ? value : Asc.EDataValidationOperator.Between, true); - this.inputRangeMin.setValue(props.asc_getFormula1() || ''); - this.inputRangeSource.setValue(props.asc_getFormula1() || ''); - this.inputRangeMax.setValue(props.asc_getFormula2() || ''); + this.inputRangeMin.setValue(props.asc_getFormula1() ? props.asc_getFormula1().asc_getValue() || '' : ''); + this.inputRangeSource.setValue(props.asc_getFormula1() ? props.asc_getFormula1().asc_getValue() || '' : ''); + this.inputRangeMax.setValue(props.asc_getFormula2() ? props.asc_getFormula2().asc_getValue() || '' : ''); // input this.chShowInput.setValue(!!props.asc_getShowInputMessage()); @@ -437,6 +446,7 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ var me = this; var state = (typeof(event) == 'object') ? event.currentTarget.attributes['result'].value : event; if (state == 'ok') { + if (!this.isRangeValid()) return; this.handler && this.handler.call(this, state, (state == 'ok') ? this.getSettings() : undefined); } @@ -502,6 +512,65 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ this.lblRangeMax.text(str2); }, + isRangeValid: function() { + var isvalid = Asc.c_oAscError.ID.No; + var type = this.cmbAllow.getValue(); + if (type!==Asc.EDataValidationType.None) { + var focusedInput, + lblField, + error, + minVisible = this.inputRangeMin.isVisible(); + isvalid = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.DataValidation, this.props.asc_getFormula1() ? this.props.asc_getFormula1().asc_getValue() : null, true, undefined, type); + if (isvalid !== Asc.c_oAscError.ID.No) { + focusedInput = minVisible ? this.inputRangeMin : this.inputRangeSource; + lblField = minVisible ? this.lblRangeMin : this.lblRangeSource; + } + if (isvalid === Asc.c_oAscError.ID.No) { + isvalid = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.DataValidation, this.props.asc_getFormula2() ? this.props.asc_getFormula2().asc_getValue() : null, true, undefined, type); + if (isvalid !== Asc.c_oAscError.ID.No) { + focusedInput = this.inputRangeMax; + lblField = this.lblRangeMax; + } + } + if (isvalid === Asc.c_oAscError.ID.No) { + isvalid = this.props.asc_checkValid(); + if (isvalid===null) + isvalid = Asc.c_oAscError.ID.DataValidateMustEnterValue; + else + isvalid = isvalid ? Asc.c_oAscError.ID.No : Asc.c_oAscError.ID.DataValidateMinGreaterMax; + (isvalid !== Asc.c_oAscError.ID.No) && (focusedInput = minVisible ? this.inputRangeMin : this.inputRangeSource); + } + + switch (isvalid) { + case Asc.c_oAscError.ID.DataValidateNotNumeric: + error = Common.Utils.String.format(this.errorNotNumeric, lblField.text()); + break; + case Asc.c_oAscError.ID.DataValidateNegativeTextLength: + error = Common.Utils.String.format(this.errorNegativeTextLength, this.cmbAllow.getDisplayValue(this.cmbAllow.getSelectedRecord())); + break; + case Asc.c_oAscError.ID.DataValidateMustEnterValue: + error = minVisible ? Common.Utils.String.format(this.errorMustEnterBothValues, this.lblRangeMin.text(), this.lblRangeMax.text()) : + Common.Utils.String.format(this.errorMustEnterValue, this.lblRangeSource.text()); + break; + case Asc.c_oAscError.ID.DataValidateMinGreaterMax: + error = Common.Utils.String.format(this.errorMinGreaterMax, this.lblRangeMin.text(), this.lblRangeMax.text()); + break; + case Asc.c_oAscError.ID.DataValidateInvalid: + error = Common.Utils.String.format((type==Asc.EDataValidationType.Time) ? this.errorInvalidTime : this.errorInvalidDate, lblField.text()); + break; + } + error && Common.UI.warning({ + msg: error, + maxwidth: 600, + callback: function(btn){ + focusedInput.focus(); + } + }); + } + + return (isvalid === Asc.c_oAscError.ID.No); + }, + strSettings: 'Settings', strInput: 'Input Message', strError: 'Error Alert', @@ -552,7 +621,14 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ textStop: 'Stop', textAlert: 'Alert', textMessage: 'Message', - textSelectData: 'Select data' + textSelectData: 'Select data', + errorMustEnterBothValues: 'You must enter a value in both field \"{0}\" and field \"{1}\".', + errorMustEnterValue: 'You must enter a value in field \"{0}\".', + errorInvalidDate: 'The date you entered for the field \"{0}\" is invalid.', + errorInvalidTime: 'The time you entered for the field \"{0}\" is invalid.', + errorNotNumeric: 'The field \"{0}\" must be a numeric value, numeric expression, or refer to a cell containing a numeric value.', + errorNegativeTextLength: 'Negative values cannot be used in conditions \"{0}\".', + errorMinGreaterMax: 'The \"{1}\" field must be greater than or equal to the \"{0}\" field.' }, SSE.Views.DataValidationDialog || {})) }); \ No newline at end of file From 4dd434ec1de200206cee616ded1c99fedbb60827 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 19 Nov 2020 11:58:45 +0300 Subject: [PATCH 8/8] Refactoring --- apps/spreadsheeteditor/main/app/view/DataValidationDialog.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js b/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js index f3ac76208..4f89aae63 100644 --- a/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js +++ b/apps/spreadsheeteditor/main/app/view/DataValidationDialog.js @@ -534,10 +534,6 @@ define([ 'text!spreadsheeteditor/main/app/template/DataValidationDialog.templ } if (isvalid === Asc.c_oAscError.ID.No) { isvalid = this.props.asc_checkValid(); - if (isvalid===null) - isvalid = Asc.c_oAscError.ID.DataValidateMustEnterValue; - else - isvalid = isvalid ? Asc.c_oAscError.ID.No : Asc.c_oAscError.ID.DataValidateMinGreaterMax; (isvalid !== Asc.c_oAscError.ID.No) && (focusedInput = minVisible ? this.inputRangeMin : this.inputRangeSource); }
@@ -37,8 +37,8 @@
+