luci-mod-network: extended interfaces.js for check if new interface is createable

Signed-off-by: Helge Mader <ma@dev.tdt.de>
This commit is contained in:
Helge Mader 2020-02-25 09:56:58 +01:00
parent 95804e5eaf
commit c949d116b0

View file

@ -760,24 +760,35 @@ return L.view.extend({
'class': 'cbi-button cbi-button-positive important', 'class': 'cbi-button cbi-button-positive important',
'click': ui.createHandlerFn(this, function(ev) { 'click': ui.createHandlerFn(this, function(ev) {
var nameval = name.isValid('_new_') ? name.formvalue('_new_') : null, var nameval = name.isValid('_new_') ? name.formvalue('_new_') : null,
protoval = proto.isValid('_new_') ? proto.formvalue('_new_') : null; protoval = proto.isValid('_new_') ? proto.formvalue('_new_') : null,
protoclass = protoval ? network.getProtocol(protoval) : null;
if (nameval == null || protoval == null || nameval == '' || protoval == '') if (nameval == null || protoval == null || nameval == '' || protoval == '')
return; return;
return m.save(function() { return protoclass.isCreateable(nameval).then(function(checkval) {
var section_id = uci.add('network', 'interface', nameval); if (checkval != null) {
ui.addNotification(null,
uci.set('network', section_id, 'proto', protoval); E('p', _('New interface for "%s" can not be created: %s').format(protoclass.getI18n(), checkval)));
ui.hideModal();
if (ifname_single.isActive('_new_')) { return;
uci.set('network', section_id, 'ifname', ifname_single.formvalue('_new_'));
} }
else if (ifname_multi.isActive('_new_')) {
uci.set('network', section_id, 'type', 'bridge'); return m.save(function() {
uci.set('network', section_id, 'ifname', L.toArray(ifname_multi.formvalue('_new_')).join(' ')); var section_id = uci.add('network', 'interface', nameval);
}
}).then(L.bind(m.children[0].renderMoreOptionsModal, m.children[0], nameval)); uci.set('network', section_id, 'proto', protoval);
if (ifname_single.isActive('_new_')) {
uci.set('network', section_id, 'ifname', ifname_single.formvalue('_new_'));
}
else if (ifname_multi.isActive('_new_')) {
uci.set('network', section_id, 'type', 'bridge');
uci.set('network', section_id, 'ifname', L.toArray(ifname_multi.formvalue('_new_')).join(' '));
}
}).then(L.bind(m.children[0].renderMoreOptionsModal, m.children[0], nameval));
});
}) })
}, _('Create interface')) }, _('Create interface'))
]) ])