2020-11-11 20:55:11 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (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',
|
2020-11-13 12:06:45 +00:00
|
|
|
'common/main/lib/component/TextareaField',
|
2020-11-11 20:55:11 +00:00
|
|
|
'common/main/lib/view/AdvancedSettingsWindow'
|
|
|
|
], function (contentTemplate) { 'use strict';
|
|
|
|
|
|
|
|
SSE.Views.DataValidationDialog = Common.Views.AdvancedSettingsWindow.extend(_.extend({
|
|
|
|
options: {
|
2020-11-13 12:06:45 +00:00
|
|
|
contentWidth: 320,
|
2020-11-13 19:55:21 +00:00
|
|
|
height: 330,
|
2020-11-11 20:55:11 +00:00
|
|
|
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;
|
2020-11-13 18:47:43 +00:00
|
|
|
this._noApply = true;
|
2020-11-11 20:55:11 +00:00
|
|
|
|
|
|
|
Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
Common.Views.AdvancedSettingsWindow.prototype.render.call(this);
|
|
|
|
var me = this;
|
2020-11-13 12:06:45 +00:00
|
|
|
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: [
|
2020-12-08 12:38:50 +00:00
|
|
|
{value: Asc.c_oAscEDataValidationType.None, displayValue: this.txtAny},
|
|
|
|
{value: Asc.c_oAscEDataValidationType.Whole, displayValue: this.txtWhole},
|
|
|
|
{value: Asc.c_oAscEDataValidationType.Decimal, displayValue: this.txtDecimal},
|
|
|
|
{value: Asc.c_oAscEDataValidationType.List, displayValue: this.txtList},
|
|
|
|
{value: Asc.c_oAscEDataValidationType.Date, displayValue: this.txtDate},
|
|
|
|
{value: Asc.c_oAscEDataValidationType.Time, displayValue: this.txtTime},
|
|
|
|
{value: Asc.c_oAscEDataValidationType.TextLength, displayValue: this.txtTextLength},
|
|
|
|
{value: Asc.c_oAscEDataValidationType.Custom, displayValue: this.txtOther}
|
2020-11-13 12:06:45 +00:00
|
|
|
],
|
|
|
|
style: 'width: 100%;',
|
|
|
|
menuStyle : 'min-width: 100%;',
|
|
|
|
takeFocusOnClose: true
|
|
|
|
});
|
2020-12-08 12:38:50 +00:00
|
|
|
this.cmbAllow.setValue(Asc.c_oAscEDataValidationType.None);
|
2020-11-13 12:06:45 +00:00
|
|
|
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
|
|
|
|
});
|
2020-11-13 18:47:43 +00:00
|
|
|
this.chIgnore.on('change', _.bind(this.onIgnoreChange, this));
|
2020-11-13 12:06:45 +00:00
|
|
|
|
|
|
|
this.lblRangeMin = $window.find('#data-validation-label-min');
|
|
|
|
this.inputRangeMin = new Common.UI.InputFieldBtn({
|
|
|
|
el: $window.find('#data-validation-txt-min'),
|
|
|
|
style: '100%',
|
2020-11-18 16:15:05 +00:00
|
|
|
btnHint: this.textSelectData,
|
2020-11-13 12:06:45 +00:00
|
|
|
// validateOnChange: true,
|
|
|
|
validateOnBlur: false
|
2020-11-13 18:47:43 +00:00
|
|
|
}).on('changed:after', _.bind(this.onRangeChange, this, 1)).on('button:click', _.bind(this.onSelectData, this, 1));
|
2020-11-13 12:06:45 +00:00
|
|
|
|
|
|
|
this.lblRangeMax = $window.find('#data-validation-label-max');
|
|
|
|
this.inputRangeMax = new Common.UI.InputFieldBtn({
|
|
|
|
el: $window.find('#data-validation-txt-max'),
|
|
|
|
style: '100%',
|
2020-11-18 16:15:05 +00:00
|
|
|
btnHint: this.textSelectData,
|
2020-11-13 12:06:45 +00:00
|
|
|
// validateOnChange: true,
|
|
|
|
validateOnBlur: false
|
2020-11-13 18:47:43 +00:00
|
|
|
}).on('changed:after', _.bind(this.onRangeChange, this, 2)).on('button:click', _.bind(this.onSelectData, this, 2));
|
2020-11-13 12:06:45 +00:00
|
|
|
|
|
|
|
this.chShowDropDown = new Common.UI.CheckBox({
|
|
|
|
el: $window.find('#data-validation-ch-show-dropdown'),
|
|
|
|
labelText: this.textShowDropDown,
|
|
|
|
value: true
|
|
|
|
});
|
2020-11-13 18:47:43 +00:00
|
|
|
this.chShowDropDown.on('change', _.bind(this.onDropDownChange, this));
|
2020-11-13 12:06:45 +00:00
|
|
|
|
|
|
|
this.lblRangeSource = $window.find('#data-validation-label-source');
|
|
|
|
this.inputRangeSource = new Common.UI.InputFieldBtn({
|
|
|
|
el: $window.find('#data-validation-txt-source'),
|
|
|
|
style: '100%',
|
2020-11-18 16:15:05 +00:00
|
|
|
btnHint: this.textSelectData,
|
2020-11-13 12:06:45 +00:00
|
|
|
// validateOnChange: true,
|
|
|
|
validateOnBlur: false
|
2020-11-13 18:47:43 +00:00
|
|
|
}).on('changed:after', _.bind(this.onRangeChange, this, 3)).on('button:click', _.bind(this.onSelectData, this, 3));
|
2020-11-13 12:06:45 +00:00
|
|
|
|
|
|
|
this.chApply = new Common.UI.CheckBox({
|
|
|
|
el: $window.find('#data-validation-ch-apply'),
|
2020-12-23 10:41:18 +00:00
|
|
|
labelText: this.textApply,
|
|
|
|
disabled: true
|
2020-11-13 12:06:45 +00:00
|
|
|
});
|
2020-12-23 10:41:18 +00:00
|
|
|
this.chApply.on('change', _.bind(this.onApplyChange, this));
|
2020-11-13 12:06:45 +00:00
|
|
|
|
|
|
|
// 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,
|
2020-11-18 21:08:31 +00:00
|
|
|
maxLength: 32,
|
2020-11-13 12:06:45 +00:00
|
|
|
style : 'width: 100%;'
|
|
|
|
}).on('changed:after', function() {
|
|
|
|
me.isInputTitleChanged = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.textareaInput = new Common.UI.TextareaField({
|
|
|
|
el : $window.find('#data-validation-input-msg'),
|
|
|
|
style : 'width: 100%; height: 70px;',
|
2020-11-18 21:08:31 +00:00
|
|
|
maxLength : 255,
|
2020-11-13 12:06:45 +00:00
|
|
|
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: [
|
2020-11-13 18:47:43 +00:00
|
|
|
{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}
|
2020-11-13 12:06:45 +00:00
|
|
|
],
|
2021-02-05 14:09:10 +00:00
|
|
|
style: 'width: 110px;',
|
|
|
|
menuStyle : 'min-width: 110px;',
|
2020-11-13 12:06:45 +00:00
|
|
|
takeFocusOnClose: true
|
|
|
|
});
|
2020-11-13 18:47:43 +00:00
|
|
|
this.cmbStyle.setValue(Asc.c_oAscEDataValidationErrorStyle.Stop);
|
2020-11-13 12:06:45 +00:00
|
|
|
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,
|
2020-11-18 21:08:31 +00:00
|
|
|
maxLength: 32,
|
2021-02-05 14:09:10 +00:00
|
|
|
style : 'width: 140px;'
|
2020-11-13 12:06:45 +00:00
|
|
|
}).on('changed:after', function() {
|
|
|
|
me.isErrorTitleChanged = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.textareaError = new Common.UI.TextareaField({
|
|
|
|
el : $window.find('#data-validation-error-msg'),
|
|
|
|
style : 'width: 100%; height: 70px;',
|
2020-11-18 21:08:31 +00:00
|
|
|
maxLength : 255,
|
2020-11-13 12:06:45 +00:00
|
|
|
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');
|
2020-11-11 20:55:11 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-11-13 12:06:45 +00:00
|
|
|
getFocusedComponents: function() {
|
|
|
|
return [
|
2021-04-13 22:12:59 +00:00
|
|
|
this.cmbAllow, this.cmbData, this.chIgnore, this.chShowDropDown, this.inputRangeSource, this.inputRangeMin, this.inputRangeMax, this.chApply, // 0 tab
|
|
|
|
this.chShowInput, this.inputInputTitle, this.textareaInput, // 1 tab
|
|
|
|
this.chShowError, this.cmbStyle, this.inputErrorTitle, this.textareaError // 2 tab
|
2020-11-13 12:06:45 +00:00
|
|
|
];
|
|
|
|
},
|
|
|
|
|
|
|
|
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:
|
2021-04-13 22:12:59 +00:00
|
|
|
if (!me.inputInputTitle.isDisabled())
|
|
|
|
me.inputInputTitle.focus();
|
|
|
|
else
|
|
|
|
me.chShowInput.focus();
|
2020-11-13 12:06:45 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2021-04-13 22:12:59 +00:00
|
|
|
if (!me.cmbStyle.isDisabled())
|
|
|
|
me.cmbStyle.focus();
|
|
|
|
else
|
|
|
|
me.chShowError.focus();
|
2020-11-13 12:06:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}, 10);
|
|
|
|
},
|
|
|
|
|
2020-11-11 20:55:11 +00:00
|
|
|
show: function() {
|
|
|
|
Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
2020-11-13 18:47:43 +00:00
|
|
|
onSelectData: function(type, input) {
|
2020-11-13 12:06:45 +00:00
|
|
|
var me = this;
|
|
|
|
if (me.api) {
|
|
|
|
var handlerDlg = function(dlg, result) {
|
|
|
|
if (result == 'ok') {
|
2020-11-13 18:47:43 +00:00
|
|
|
var val = dlg.getSettings();
|
|
|
|
input.setValue(val);
|
|
|
|
me.onRangeChange(type, input, val);
|
2020-11-13 12:06:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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(),
|
2020-12-10 15:17:38 +00:00
|
|
|
type : Asc.c_oAscSelectionDialogType.DataValidation,
|
2020-11-13 12:06:45 +00:00
|
|
|
validation: function() {return true;}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-11-13 18:47:43 +00:00
|
|
|
onRangeChange: function(type, input, newValue, oldValue, e) {
|
|
|
|
if (newValue == oldValue) return;
|
|
|
|
if (!this._noApply) {
|
2020-11-18 21:08:31 +00:00
|
|
|
if (type==1 || type==3) {
|
|
|
|
if (!this.props.asc_getFormula1())
|
2020-12-15 09:52:51 +00:00
|
|
|
this.props.asc_setFormula1(new Asc.CDataFormula());
|
2020-11-18 21:08:31 +00:00
|
|
|
this.props.asc_getFormula1().asc_setValue(newValue);
|
|
|
|
} else if (type==2) {
|
|
|
|
if (!this.props.asc_getFormula2())
|
2020-12-15 09:52:51 +00:00
|
|
|
this.props.asc_setFormula2(new Asc.CDataFormula());
|
2020-11-18 21:08:31 +00:00
|
|
|
this.props.asc_getFormula2().asc_setValue(newValue);
|
|
|
|
}
|
2020-11-13 18:47:43 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-11-13 12:06:45 +00:00
|
|
|
onAllowSelect: function(combo, record) {
|
|
|
|
this.ShowHideElem();
|
2020-11-13 18:47:43 +00:00
|
|
|
if (!this._noApply)
|
|
|
|
this.props.asc_setType(record.value);
|
2020-11-18 21:08:31 +00:00
|
|
|
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() || '' : '');
|
2020-11-13 12:06:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onDataSelect: function(combo, record) {
|
|
|
|
this.ShowHideElem();
|
2020-11-13 18:47:43 +00:00
|
|
|
if (!this._noApply)
|
|
|
|
this.props.asc_setOperator(record.value);
|
2020-11-18 21:08:31 +00:00
|
|
|
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() || '' : '');
|
2020-11-13 12:06:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onStyleSelect: function(combo, record) {
|
|
|
|
this.errorIcon.removeClass("error warn info");
|
2020-11-13 18:47:43 +00:00
|
|
|
this.errorIcon.addClass(record.clsText);
|
2020-12-15 09:19:50 +00:00
|
|
|
if (!this._noApply)
|
|
|
|
this.props.asc_setErrorStyle(record.value);
|
2020-11-13 18:47:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onIgnoreChange: function(field, newValue, oldValue, eOpts) {
|
|
|
|
if (!this._noApply) {
|
2021-01-18 09:25:31 +00:00
|
|
|
this.props.asc_setAllowBlank(field.getValue()=='checked');
|
2020-11-13 18:47:43 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onDropDownChange: function(field, newValue, oldValue, eOpts) {
|
|
|
|
if (!this._noApply) {
|
2020-12-09 09:03:21 +00:00
|
|
|
this.props.asc_setShowDropDown(field.getValue()!=='checked');
|
2020-11-13 18:47:43 +00:00
|
|
|
}
|
2020-11-13 12:06:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onShowInputChange: function(field, newValue, oldValue, eOpts) {
|
|
|
|
var checked = (field.getValue()=='checked');
|
|
|
|
this.inputInputTitle.setDisabled(!checked);
|
|
|
|
this.textareaInput.setDisabled(!checked);
|
|
|
|
|
|
|
|
if (this.api && !this._noApply) {
|
2020-11-13 18:47:43 +00:00
|
|
|
this.props.asc_setShowInputMessage(field.getValue()=='checked');
|
2020-11-13 12:06:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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) {
|
2020-11-13 18:47:43 +00:00
|
|
|
this.props.asc_setShowErrorMessage(field.getValue()=='checked');
|
2020-11-13 12:06:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-12-23 10:41:18 +00:00
|
|
|
onApplyChange: function(field, newValue, oldValue, eOpts) {
|
|
|
|
if (this.api && !this._noApply) {
|
|
|
|
this.api.asc_setDataValidation(this.getSettings(), field.getValue()=='checked');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-11-11 20:55:11 +00:00
|
|
|
_setDefaults: function (props) {
|
2020-11-13 18:47:43 +00:00
|
|
|
this._noApply = true;
|
2020-11-11 20:55:11 +00:00
|
|
|
if (props) {
|
2020-11-13 18:47:43 +00:00
|
|
|
var value = props.asc_getAllowBlank();
|
2021-01-18 09:25:31 +00:00
|
|
|
this.chIgnore.setValue(value, true);
|
2020-11-13 18:47:43 +00:00
|
|
|
value = props.asc_getShowDropDown();
|
2020-12-09 09:03:21 +00:00
|
|
|
this.chShowDropDown.setValue(!value, true);
|
2020-11-13 18:47:43 +00:00
|
|
|
value = props.asc_getType();
|
2020-12-08 12:38:50 +00:00
|
|
|
this.cmbAllow.setValue(value!==null ? value : Asc.c_oAscEDataValidationType.None, true);
|
2020-12-23 10:41:18 +00:00
|
|
|
this.chApply.setDisabled(value===Asc.c_oAscEDataValidationType.None);
|
2020-11-13 18:47:43 +00:00
|
|
|
value = props.asc_getOperator();
|
|
|
|
this.cmbData.setValue(value!==null ? value : Asc.EDataValidationOperator.Between, true);
|
2020-11-18 21:08:31 +00:00
|
|
|
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() || '' : '');
|
2020-11-13 18:47:43 +00:00
|
|
|
|
|
|
|
// 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);
|
2020-12-15 09:19:50 +00:00
|
|
|
var rec = this.cmbStyle.getSelectedRecord();
|
|
|
|
if (rec) {
|
|
|
|
this.errorIcon.removeClass("error warn info");
|
|
|
|
this.errorIcon.addClass(rec.clsText);
|
|
|
|
}
|
2020-11-11 20:55:11 +00:00
|
|
|
}
|
2020-11-13 12:06:45 +00:00
|
|
|
this.ShowHideElem();
|
2020-11-13 18:47:43 +00:00
|
|
|
this._noApply = false;
|
2020-11-11 20:55:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getSettings: function () {
|
2020-11-13 18:47:43 +00:00
|
|
|
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());
|
2020-11-13 12:06:45 +00:00
|
|
|
return this.props;
|
2020-11-11 20:55:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onDlgBtnClick: function(event) {
|
|
|
|
var me = this;
|
|
|
|
var state = (typeof(event) == 'object') ? event.currentTarget.attributes['result'].value : event;
|
|
|
|
if (state == 'ok') {
|
2020-12-11 18:47:58 +00:00
|
|
|
this.isRangeValid(function() {
|
|
|
|
me.handler && me.handler.call(me, state, (state == 'ok') ? me.getSettings() : undefined);
|
|
|
|
me.close();
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
this.close();
|
2020-11-11 20:55:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onPrimary: function() {
|
|
|
|
this.onDlgBtnClick('ok');
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2020-11-13 12:06:45 +00:00
|
|
|
ShowHideElem: function() {
|
|
|
|
var allow = this.cmbAllow.getValue(),
|
|
|
|
data = this.cmbData.getValue();
|
|
|
|
var between = (data==Asc.EDataValidationOperator.Between || data==Asc.EDataValidationOperator.NotBetween);
|
2020-12-08 12:38:50 +00:00
|
|
|
var source = (allow==Asc.c_oAscEDataValidationType.Custom || allow==Asc.c_oAscEDataValidationType.List);
|
|
|
|
this.minMaxTr.toggleClass('hidden', allow==Asc.c_oAscEDataValidationType.None || source || !between);
|
2021-02-16 08:41:46 +00:00
|
|
|
this._isMinMaxVisible = !(allow==Asc.c_oAscEDataValidationType.None || source || !between);
|
2020-12-08 12:38:50 +00:00
|
|
|
this.sourceTr.toggleClass('hidden', allow==Asc.c_oAscEDataValidationType.None || !source && between );
|
|
|
|
this.dropdownTr.toggleClass('hidden', allow!=Asc.c_oAscEDataValidationType.List);
|
2020-11-13 12:06:45 +00:00
|
|
|
|
2020-12-08 12:38:50 +00:00
|
|
|
this.chIgnore.setDisabled(allow===Asc.c_oAscEDataValidationType.None);
|
|
|
|
this.cmbData.setDisabled(allow===Asc.c_oAscEDataValidationType.None || allow===Asc.c_oAscEDataValidationType.Custom || allow===Asc.c_oAscEDataValidationType.List);
|
2020-11-13 12:06:45 +00:00
|
|
|
|
|
|
|
var str = this.textSource;
|
2020-12-26 08:56:01 +00:00
|
|
|
if (allow==Asc.c_oAscEDataValidationType.List)
|
|
|
|
str = this.textSource;
|
|
|
|
else if (allow==Asc.c_oAscEDataValidationType.Custom)
|
2020-11-13 12:06:45 +00:00
|
|
|
str = this.textFormula;
|
|
|
|
else if (data==Asc.EDataValidationOperator.Equal || data==Asc.EDataValidationOperator.NotEqual) { // equals, not equals
|
2020-12-08 12:38:50 +00:00
|
|
|
if (allow==Asc.c_oAscEDataValidationType.Date)
|
2020-11-13 12:06:45 +00:00
|
|
|
str = this.txtDate;
|
2020-12-08 12:38:50 +00:00
|
|
|
else if (allow==Asc.c_oAscEDataValidationType.TextLength)
|
2020-11-13 12:06:45 +00:00
|
|
|
str = this.txtLength;
|
2020-12-08 12:38:50 +00:00
|
|
|
else if (allow==Asc.c_oAscEDataValidationType.Time)
|
2020-11-13 12:06:45 +00:00
|
|
|
str = this.txtElTime;
|
|
|
|
else
|
|
|
|
str = this.textCompare;
|
|
|
|
} else if (data==Asc.EDataValidationOperator.GreaterThan || data==Asc.EDataValidationOperator.GreaterThanOrEqual) { // greater, greater or equals
|
2020-12-08 12:38:50 +00:00
|
|
|
if (allow==Asc.c_oAscEDataValidationType.Date)
|
2020-11-13 12:06:45 +00:00
|
|
|
str = this.txtStartDate;
|
2020-12-08 12:38:50 +00:00
|
|
|
else if (allow==Asc.c_oAscEDataValidationType.Time)
|
2020-11-13 12:06:45 +00:00
|
|
|
str = this.txtStartTime;
|
|
|
|
else
|
|
|
|
str = this.textMin;
|
|
|
|
} else if (data==Asc.EDataValidationOperator.LessThan || data==Asc.EDataValidationOperator.LessThanOrEqual) { // less, less or equals
|
2020-12-08 12:38:50 +00:00
|
|
|
if (allow==Asc.c_oAscEDataValidationType.Date)
|
2020-11-13 12:06:45 +00:00
|
|
|
str = this.txtEndDate;
|
2020-12-08 12:38:50 +00:00
|
|
|
else if (allow==Asc.c_oAscEDataValidationType.Time)
|
2020-11-13 12:06:45 +00:00
|
|
|
str = this.txtEndTime;
|
|
|
|
else
|
|
|
|
str = this.textMax;
|
|
|
|
}
|
|
|
|
this.lblRangeSource.text(str);
|
|
|
|
|
|
|
|
var str1 = this.textMin,
|
|
|
|
str2 = this.textMax;
|
2020-12-08 12:38:50 +00:00
|
|
|
if (allow==Asc.c_oAscEDataValidationType.Date) {
|
2020-11-13 12:06:45 +00:00
|
|
|
str1 = this.txtStartDate;
|
|
|
|
str2 = this.txtEndDate;
|
2020-12-08 12:38:50 +00:00
|
|
|
} else if (allow==Asc.c_oAscEDataValidationType.Time) {
|
2020-11-13 12:06:45 +00:00
|
|
|
str1 = this.txtStartTime;
|
|
|
|
str2 = this.txtEndTime;
|
|
|
|
}
|
|
|
|
this.lblRangeMin.text(str1);
|
|
|
|
this.lblRangeMax.text(str2);
|
|
|
|
},
|
|
|
|
|
2020-12-11 18:47:58 +00:00
|
|
|
isRangeValid: function(callback) {
|
|
|
|
var me = this;
|
2020-11-18 21:08:31 +00:00
|
|
|
var isvalid = Asc.c_oAscError.ID.No;
|
|
|
|
var type = this.cmbAllow.getValue();
|
2020-12-08 12:38:50 +00:00
|
|
|
if (type!==Asc.c_oAscEDataValidationType.None) {
|
2020-11-18 21:08:31 +00:00
|
|
|
var focusedInput,
|
|
|
|
lblField,
|
|
|
|
error,
|
2021-02-16 08:41:46 +00:00
|
|
|
minVisible = this._isMinMaxVisible;
|
2020-12-11 18:47:58 +00:00
|
|
|
var callback2 = function(isvalid) {
|
|
|
|
if (isvalid === Asc.c_oAscError.ID.No) {
|
|
|
|
isvalid = me.props.asc_checkValid();
|
|
|
|
(isvalid !== Asc.c_oAscError.ID.No) && (focusedInput = minVisible ? me.inputRangeMin : me.inputRangeSource);
|
|
|
|
}
|
|
|
|
switch (isvalid) {
|
|
|
|
case Asc.c_oAscError.ID.DataValidateNotNumeric:
|
|
|
|
error = Common.Utils.String.format(me.errorNotNumeric, lblField.text());
|
|
|
|
break;
|
|
|
|
case Asc.c_oAscError.ID.DataValidateNegativeTextLength:
|
|
|
|
error = Common.Utils.String.format(me.errorNegativeTextLength, me.cmbAllow.getDisplayValue(me.cmbAllow.getSelectedRecord()));
|
|
|
|
break;
|
|
|
|
case Asc.c_oAscError.ID.DataValidateMustEnterValue:
|
|
|
|
error = minVisible ? Common.Utils.String.format(me.errorMustEnterBothValues, me.lblRangeMin.text(), me.lblRangeMax.text()) :
|
|
|
|
Common.Utils.String.format(me.errorMustEnterValue, me.lblRangeSource.text());
|
|
|
|
break;
|
|
|
|
case Asc.c_oAscError.ID.DataValidateMinGreaterMax:
|
|
|
|
error = Common.Utils.String.format(me.errorMinGreaterMax, me.lblRangeMin.text(), me.lblRangeMax.text());
|
|
|
|
break;
|
|
|
|
case Asc.c_oAscError.ID.DataValidateInvalid:
|
|
|
|
error = Common.Utils.String.format((type==Asc.c_oAscEDataValidationType.Time) ? me.errorInvalidTime : ((type==Asc.c_oAscEDataValidationType.Date) ? me.errorInvalidDate : me.errorInvalid), lblField.text());
|
|
|
|
break;
|
|
|
|
case Asc.c_oAscError.ID.NamedRangeNotFound:
|
|
|
|
error = me.errorNamedRange;
|
|
|
|
break;
|
|
|
|
case Asc.c_oAscError.ID.DataValidateInvalidList:
|
|
|
|
error = me.errorInvalidList;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
error && Common.UI.warning({
|
|
|
|
msg: error,
|
|
|
|
maxwidth: 600,
|
|
|
|
callback: function(btn){
|
|
|
|
focusedInput.focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
(isvalid === Asc.c_oAscError.ID.No) && callback.call(me);
|
|
|
|
};
|
|
|
|
var callback1 = function(isvalid) {
|
2021-02-16 08:41:46 +00:00
|
|
|
if (me._isMinMaxVisible && isvalid === Asc.c_oAscError.ID.No) {
|
2020-12-11 18:47:58 +00:00
|
|
|
isvalid = me.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.DataValidation, me.props.asc_getFormula2() ? me.props.asc_getFormula2().asc_getValue() : null, true, undefined, type);
|
|
|
|
if (isvalid !== Asc.c_oAscError.ID.No) {
|
|
|
|
focusedInput = me.inputRangeMax;
|
|
|
|
lblField = me.lblRangeMax;
|
|
|
|
}
|
|
|
|
if (isvalid===Asc.c_oAscError.ID.FormulaEvaluateError) {
|
|
|
|
Common.UI.warning({
|
|
|
|
msg: me.errorFormula,
|
|
|
|
maxwidth: 600,
|
|
|
|
buttons: ['yes', 'no'],
|
|
|
|
primary: 'yes',
|
|
|
|
callback: function(btn){
|
|
|
|
if (btn=='yes') {
|
|
|
|
callback2(Asc.c_oAscError.ID.No);
|
|
|
|
} else
|
|
|
|
focusedInput.focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
callback2(isvalid);
|
|
|
|
} else
|
|
|
|
callback2(isvalid);
|
|
|
|
};
|
2020-11-18 21:08:31 +00:00
|
|
|
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) {
|
2020-12-11 18:47:58 +00:00
|
|
|
focusedInput = minVisible ? me.inputRangeMin : me.inputRangeSource;
|
|
|
|
lblField = minVisible ? me.lblRangeMin : me.lblRangeSource;
|
2020-11-18 21:08:31 +00:00
|
|
|
}
|
2020-12-11 18:47:58 +00:00
|
|
|
if (isvalid===Asc.c_oAscError.ID.FormulaEvaluateError) {
|
|
|
|
Common.UI.warning({
|
|
|
|
msg: this.errorFormula,
|
|
|
|
maxwidth: 600,
|
|
|
|
buttons: ['yes', 'no'],
|
|
|
|
primary: 'yes',
|
|
|
|
callback: function(btn){
|
|
|
|
if (btn=='yes') {
|
|
|
|
callback1(Asc.c_oAscError.ID.No);
|
|
|
|
} else
|
|
|
|
focusedInput.focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
callback1(isvalid);
|
|
|
|
} else
|
|
|
|
callback.call(me);
|
2020-11-18 21:08:31 +00:00
|
|
|
},
|
|
|
|
|
2020-11-11 20:55:11 +00:00
|
|
|
strSettings: 'Settings',
|
|
|
|
strInput: 'Input Message',
|
2020-11-13 12:06:45 +00:00
|
|
|
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',
|
2020-12-23 10:39:55 +00:00
|
|
|
textApply: 'Apply these changes to all other cells with the same settings',
|
2020-11-13 12:06:45 +00:00
|
|
|
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',
|
2020-11-18 16:15:05 +00:00
|
|
|
textMessage: 'Message',
|
2020-11-18 21:08:31 +00:00
|
|
|
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.',
|
2020-12-08 12:57:17 +00:00
|
|
|
errorInvalid: 'The value you entered for the field \"{0}\" is invalid.',
|
2020-11-18 21:08:31 +00:00
|
|
|
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}\".',
|
2020-12-11 18:47:58 +00:00
|
|
|
errorMinGreaterMax: 'The \"{1}\" field must be greater than or equal to the \"{0}\" field.',
|
|
|
|
errorFormula: 'The value currently evaluates to an error. Do you want to continue?',
|
|
|
|
errorNamedRange: 'A named range you specified cannot be found.',
|
|
|
|
errorInvalidList: 'The list source must be a delimited list, or a reference to single row or column.'
|
2020-11-11 20:55:11 +00:00
|
|
|
|
|
|
|
}, SSE.Views.DataValidationDialog || {}))
|
|
|
|
});
|