add validationtextarea control, use it for filter match editor

This commit is contained in:
Andrew Dolgov 2020-02-28 13:53:45 +03:00
parent 2fefb4fd87
commit f24ece85a6
5 changed files with 43 additions and 27 deletions

View File

@ -964,19 +964,18 @@ class Pref_Filters extends Handler_Protected {
print "<section>";
print "<input dojoType=\"dijit.form.ValidationTextBox\"
required=\"true\" id=\"filterDlg_regExp\"
onchange='Filters.filterDlgCheckRegExp(this)'
onblur='Filters.filterDlgCheckRegExp(this)'
onfocus='Filters.filterDlgCheckRegExp(this)'
style=\"font-size : 16px; width : 500px\"
name=\"reg_exp\" value=\"$reg_exp\"/>";
print "<textarea dojoType='fox.form.ValidationTextArea'
required='true' id='filterDlg_regExp'
ValidRegExp='true'
rows='4'
style='font-size : 14px; width : 490px; word-break: break-all'
name='reg_exp'>$reg_exp</textarea>";
print "<div dojoType='dijit.Tooltip' id='filterDlg_regExp_tip' connectId='filterDlg_regExp' position='below'></div>";
print "<fieldset>";
print "<label class='checkbox'><input id=\"filterDlg_inverse\" dojoType=\"dijit.form.CheckBox\"
name=\"inverse\" $inverse_checked/> ".
print "<label class='checkbox'><input id='filterDlg_inverse' dojoType='dijit.form.CheckBox'
name='inverse' $inverse_checked/> ".
__("Inverse regular expression matching")."</label>";
print "</fieldset>";

View File

@ -1343,6 +1343,7 @@ class RSSUtils {
foreach ($filter["rules"] as $rule) {
$match = false;
$reg_exp = str_replace('/', '\/', $rule["reg_exp"]);
$reg_exp = str_replace("\n", "", $reg_exp); // reg_exp may be formatted with CRs now because of textarea, we need to strip those
$rule_inverse = $rule["inverse"];
if (!$reg_exp)

View File

@ -2,24 +2,6 @@
/* global __, ngettext */
define(["dojo/_base/declare"], function (declare) {
Filters = {
filterDlgCheckRegExp: function(sender) {
const tooltip = dijit.byId("filterDlg_regExp_tip").domNode;
try {
sender.domNode.removeClassName("invalid");
sender.domNode.removeClassName("valid");
new RegExp("/" + sender.value + "/");
sender.domNode.addClassName("valid");
tooltip.innerText = __("Regular expression, without outer delimiters (i.e. slashes)");
} catch (e) {
sender.domNode.addClassName("invalid");
tooltip.innerText = e.message;
}
},
filterDlgCheckAction: function(sender) {
const action = sender.value;

View File

@ -0,0 +1,33 @@
// https://stackoverflow.com/questions/19317258/how-to-use-dijit-textarea-validation-dojo-1-9
define(["dojo/_base/declare", "dojo/_base/lang", "dijit/form/SimpleTextarea", "dijit/form/ValidationTextBox"],
function(declare, lang, SimpleTextarea, ValidationTextBox) {
return declare('fox.form.ValidationTextArea', [SimpleTextarea, ValidationTextBox], {
constructor: function(params){
this.constraints = {};
this.baseClass += ' dijitValidationTextArea';
},
templateString: "<textarea ${!nameAttrSetting} data-dojo-attach-point='focusNode,containerNode,textbox' autocomplete='off'></textarea>",
validator: function(value, constraints) {
//console.log(this, value, constraints);
if (this.required && this._isEmpty(value))
return false;
if (this.validregexp) {
try {
new RegExp("/" + value + "/");
} catch (e) {
return false;
}
}
return value.match(new RegExp(this._computeRegexp(constraints)));
/*return (new RegExp("^(?:" + this._computeRegexp(constraints) + ")"+(this.required?"":"?")+"$",["m"])).test(value) &&
(!this.required || !this._isEmpty(value)) &&
(this._isEmpty(value) || this.parse(value, constraints) !== undefined); // Boolean*/
}
})
});

View File

@ -55,6 +55,7 @@ require(["dojo/_base/kernel",
"fox/PrefFilterTree",
"fox/PrefLabelTree",
"fox/Toolbar",
"fox/form/ValidationTextArea",
"fox/form/Select",
"fox/form/ComboButton",
"fox/form/DropDownButton"], function (dojo, declare, ready, parser, AppBase) {