luci-base: widgets.js: CBIZoneSelect: improve initial rendering
Ref: https://github.com/openwrt/luci/issues/2889 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
d1841af2f0
commit
e6ff0f39bb
1 changed files with 18 additions and 13 deletions
|
@ -30,8 +30,22 @@ var CBIZoneSelect = form.ListValue.extend({
|
||||||
|
|
||||||
renderWidget: function(section_id, option_index, cfgvalue) {
|
renderWidget: function(section_id, option_index, cfgvalue) {
|
||||||
var values = L.toArray((cfgvalue != null) ? cfgvalue : this.default),
|
var values = L.toArray((cfgvalue != null) ? cfgvalue : this.default),
|
||||||
|
isOutputOnly = false,
|
||||||
choices = {};
|
choices = {};
|
||||||
|
|
||||||
|
if (this.option == 'dest') {
|
||||||
|
for (var i = 0; i < this.section.children.length; i++) {
|
||||||
|
var opt = this.section.children[i];
|
||||||
|
if (opt.option == 'src') {
|
||||||
|
var val = opt.cfgvalue(section_id) || opt.default;
|
||||||
|
isOutputOnly = (val == null || val == '');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.title = isOutputOnly ? _('Output zone') : _('Destination zone');
|
||||||
|
}
|
||||||
|
|
||||||
if (this.allowlocal) {
|
if (this.allowlocal) {
|
||||||
choices[''] = E('span', {
|
choices[''] = E('span', {
|
||||||
'class': 'zonebadge',
|
'class': 'zonebadge',
|
||||||
|
@ -55,7 +69,7 @@ var CBIZoneSelect = form.ListValue.extend({
|
||||||
'style': 'background-color:' + firewall.getColorForName(null)
|
'style': 'background-color:' + firewall.getColorForName(null)
|
||||||
}, [
|
}, [
|
||||||
E('strong', _('Any zone')),
|
E('strong', _('Any zone')),
|
||||||
(this.allowany && this.allowlocal && this.option != 'src') ? ' (%s)'.format(_('forward')) : ''
|
(this.allowany && this.allowlocal && !isOutputOnly) ? ' (%s)'.format(_('forward')) : ''
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,19 +186,10 @@ var CBIZoneSelect = form.ListValue.extend({
|
||||||
|
|
||||||
}, this));
|
}, this));
|
||||||
}
|
}
|
||||||
else if (this.option == 'dest') {
|
else if (isOutputOnly) {
|
||||||
for (var i = 0; i < this.section.children.length; i++) {
|
|
||||||
var opt = this.section.children[i];
|
|
||||||
if (opt.option == 'src') {
|
|
||||||
if (!opt.cfgvalue(section_id) && !opt.default) {
|
|
||||||
var emptyval = elem.querySelector('[data-value=""]');
|
var emptyval = elem.querySelector('[data-value=""]');
|
||||||
|
|
||||||
if (emptyval != null)
|
|
||||||
emptyval.parentNode.removeChild(emptyval);
|
emptyval.parentNode.removeChild(emptyval);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return elem;
|
return elem;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue