luci: Using dict for arguments of function

This commit is contained in:
remittor
2026-01-17 15:50:46 +03:00
parent d91f44c287
commit 10997a443f
2 changed files with 85 additions and 74 deletions

View File

@@ -157,7 +157,14 @@ return view.extend({
if (multiline == 2) { if (multiline == 2) {
desc += '<br/>' + _('Example') + ': <a target=_blank href=%s>%s</a>'.format(tools.nfqws_opt_url); desc += '<br/>' + _('Example') + ': <a target=_blank href=%s>%s</a>'.format(tools.nfqws_opt_url);
} }
btn.onclick = () => new tools.longstrEditDialog('config', param, param, desc, rows, multiline).show(); btn.onclick = () => new tools.longstrEditDialog({
cfgsec: 'config',
cfgparam: param,
title: param,
desc: desc,
rows: rows,
multiline: multiline,
}).show();
}; };
if (tools.appName == 'zapret2') { if (tools.appName == 'zapret2') {
@@ -313,13 +320,12 @@ return view.extend({
o.inputtitle = _('Edit'); o.inputtitle = _('Edit');
o.inputstyle = 'edit btn'; o.inputstyle = 'edit btn';
o.description = tools.autoHostListFN; o.description = tools.autoHostListFN;
o.onclick = () => new tools.fileEditDialog( o.onclick = () => new tools.fileEditDialog({
tools.autoHostListFN, file: tools.autoHostListFN,
_('Auto host list'), title: _('Auto host list'),
'', desc: '',
'', rows: 15,
15 }).show();
).show();
o = s.taboption(tabname, form.Flag, 'AUTOHOSTLIST_DEBUGLOG', _('DEBUGLOG')); o = s.taboption(tabname, form.Flag, 'AUTOHOSTLIST_DEBUGLOG', _('DEBUGLOG'));
o.rmempty = false; o.rmempty = false;
@@ -329,13 +335,12 @@ return view.extend({
o.inputtitle = _('Edit'); o.inputtitle = _('Edit');
o.inputstyle = 'edit btn'; o.inputstyle = 'edit btn';
o.description = tools.autoHostListDbgFN; o.description = tools.autoHostListDbgFN;
o.onclick = () => new tools.fileEditDialog( o.onclick = () => new tools.fileEditDialog({
tools.autoHostListDbgFN, file: tools.autoHostListDbgFN,
_('Auto host debug list'), title: _('Auto host debug list'),
'', desc: '',
'', rows: 15,
15 }).show();
).show();
/* HostList settings */ /* HostList settings */
@@ -346,37 +351,37 @@ return view.extend({
o.inputtitle = _('Edit'); o.inputtitle = _('Edit');
o.inputstyle = 'edit btn'; o.inputstyle = 'edit btn';
o.description = tools.hostsGoogleFN; o.description = tools.hostsGoogleFN;
o.onclick = () => new tools.fileEditDialog( o.onclick = () => new tools.fileEditDialog({
tools.hostsGoogleFN, file: tools.hostsGoogleFN,
_('Google hostname entries'), title: _('Google hostname entries'),
_('One hostname per line.<br />Examples:'), desc: _('One hostname per line.<br />Examples:'),
'<code>youtube.com<br />googlevideo.com</code>', aux: '<code>youtube.com<br />googlevideo.com</code>',
15 rows: 15,
).show(); }).show();
o = s.taboption(tabname, form.Button, '_user_entries_btn', _('User hostname entries <HOSTLIST>')); o = s.taboption(tabname, form.Button, '_user_entries_btn', _('User hostname entries <HOSTLIST>'));
o.inputtitle = _('Edit'); o.inputtitle = _('Edit');
o.inputstyle = 'edit btn'; o.inputstyle = 'edit btn';
o.description = tools.hostsUserFN; o.description = tools.hostsUserFN;
o.onclick = () => new tools.fileEditDialog( o.onclick = () => new tools.fileEditDialog({
tools.hostsUserFN, file: tools.hostsUserFN,
_('User entries'), title: _('User entries'),
_('One hostname per line.<br />Examples:'), desc: _('One hostname per line.<br />Examples:'),
'<code>domain.net<br />sub.domain.com<br />facebook.com</code>', aux: '<code>domain.net<br />sub.domain.com<br />facebook.com</code>',
15 rows: 15,
).show(); }).show();
o = s.taboption(tabname, form.Button, '_user_excluded_entries_btn', _('User excluded hostname entries')); o = s.taboption(tabname, form.Button, '_user_excluded_entries_btn', _('User excluded hostname entries'));
o.inputtitle = _('Edit'); o.inputtitle = _('Edit');
o.inputstyle = 'edit btn'; o.inputstyle = 'edit btn';
o.description = tools.hostsUserExcludeFN; o.description = tools.hostsUserExcludeFN;
o.onclick = () => new tools.fileEditDialog( o.onclick = () => new tools.fileEditDialog({
tools.hostsUserExcludeFN, file: tools.hostsUserExcludeFN,
_('User excluded entries'), title: _('User excluded entries'),
_('One hostname per line.<br />Examples:'), desc: _('One hostname per line.<br />Examples:'),
'<code>domain.net<br />sub.domain.com<br />gosuslugi.ru</code>', aux: '<code>domain.net<br />sub.domain.com<br />gosuslugi.ru</code>',
15 rows: 15,
).show(); }).show();
add_delim(s); add_delim(s);
@@ -384,37 +389,37 @@ return view.extend({
o.inputtitle = _('Edit'); o.inputtitle = _('Edit');
o.inputstyle = 'edit btn'; o.inputstyle = 'edit btn';
o.description = tools.iplstExcludeFN; o.description = tools.iplstExcludeFN;
o.onclick = () => new tools.fileEditDialog( o.onclick = () => new tools.fileEditDialog({
tools.iplstExcludeFN, file: tools.iplstExcludeFN,
_('Excluded IP filter'), title: _('Excluded IP filter'),
_('Patterns can be strings or regular expressions. Each pattern in a separate line<br />Examples:'), desc: _('Patterns can be strings or regular expressions. Each pattern in a separate line<br />Examples:'),
'<code>128.199.0.0/16<br />34.217.90.52<br />162.13.190.77</code>', aux: '<code>128.199.0.0/16<br />34.217.90.52<br />162.13.190.77</code>',
15 rows: 15,
).show(); }).show();
o = s.taboption(tabname, form.Button, '_user_ip_filter_btn', _('User IP entries')); o = s.taboption(tabname, form.Button, '_user_ip_filter_btn', _('User IP entries'));
o.inputtitle = _('Edit'); o.inputtitle = _('Edit');
o.inputstyle = 'edit btn'; o.inputstyle = 'edit btn';
o.description = tools.iplstUserFN; o.description = tools.iplstUserFN;
o.onclick = () => new tools.fileEditDialog( o.onclick = () => new tools.fileEditDialog({
tools.iplstUserFN, file: tools.iplstUserFN,
_('User IP filter'), title: _('User IP filter'),
_('Patterns can be strings or regular expressions. Each pattern in a separate line<br />Examples:'), desc: _('Patterns can be strings or regular expressions. Each pattern in a separate line<br />Examples:'),
'<code>128.199.0.0/16<br />34.217.90.52<br />162.13.190.77</code>', aux: '<code>128.199.0.0/16<br />34.217.90.52<br />162.13.190.77</code>',
15 rows: 15,
).show(); }).show();
o = s.taboption(tabname, form.Button, '_user_excluded_ip_filter_btn', _('User excluded IP entries')); o = s.taboption(tabname, form.Button, '_user_excluded_ip_filter_btn', _('User excluded IP entries'));
o.inputtitle = _('Edit'); o.inputtitle = _('Edit');
o.inputstyle = 'edit btn'; o.inputstyle = 'edit btn';
o.description = tools.iplstUserExcludeFN; o.description = tools.iplstUserExcludeFN;
o.onclick = () => new tools.fileEditDialog( o.onclick = () => new tools.fileEditDialog({
tools.iplstUserExcludeFN, file: tools.iplstUserExcludeFN,
_('User excluded IP filter'), title: _('User excluded IP filter'),
_('Patterns can be strings or regular expressions. Each pattern in a separate line<br />Examples:'), desc: _('Patterns can be strings or regular expressions. Each pattern in a separate line<br />Examples:'),
'<code>128.199.0.0/16<br />34.217.90.52<br />162.13.190.77</code>', aux: '<code>128.199.0.0/16<br />34.217.90.52<br />162.13.190.77</code>',
15 rows: 15,
).show(); }).show();
add_delim(s); add_delim(s);
@@ -425,7 +430,7 @@ return view.extend({
o.inputtitle = _('Edit'); o.inputtitle = _('Edit');
o.inputstyle = 'edit btn'; o.inputstyle = 'edit btn';
o.description = fn; o.description = fn;
o.onclick = () => new tools.fileEditDialog(fn, name, '', '', 15).show(); o.onclick = () => new tools.fileEditDialog({ file: fn, title: name, rows: 15}).show();
} }
/* custom.d files */ /* custom.d files */
@@ -467,7 +472,7 @@ return view.extend({
desc += '<a target=_blank href=' + url + '>' + filename + '</a>'; desc += '<a target=_blank href=' + url + '>' + filename + '</a>';
} }
} }
o.onclick = () => new tools.fileEditDialog(fn, name, desc, '', 15).show(); o.onclick = () => new tools.fileEditDialog({ file: fn, title: name, desc: desc, rows: 15}).show();
} }
let map_promise = m.render(); let map_promise = m.render();

View File

@@ -320,14 +320,17 @@ return baseclass.extend({
}, },
fileEditDialog: baseclass.extend({ fileEditDialog: baseclass.extend({
__init__: function(file, title, desc, aux = null, rows = 10, callback, file_exists = false) { __init__: function(opts = {})
this.file = file; {
this.title = title; Object.assign(this, {
this.desc = desc; file: '',
this.aux = aux; title: '',
this.rows = rows, desc: '',
this.callback = callback; aux: '',
this.file_exists = file_exists; rows: 10,
callback: null,
file_exists: false
}, opts);
}, },
load: function() { load: function() {
@@ -455,13 +458,16 @@ return baseclass.extend({
}), }),
longstrEditDialog: baseclass.extend({ longstrEditDialog: baseclass.extend({
__init__: function(cfgsec, cfgparam, title, desc, rows = 10, multiline = false) { __init__: function(opts = {})
this.cfgsec = cfgsec; {
this.cfgparam = cfgparam; Object.assign(this, {
this.title = title; cfgsec: '',
this.desc = desc; cfgparam: '',
this.rows = rows; title: '',
this.multiline = multiline; desc: '',
rows: 10,
multiline: false // may be 2
}, opts);
env_tools.load_env(this); env_tools.load_env(this);
}, },