luci-mod-network: extended interfaces.js for check if new interface is createable 3713/head
authorHelge Mader <ma@dev.tdt.de>
Tue, 25 Feb 2020 08:56:58 +0000 (09:56 +0100)
committerHelge Mader <ma@dev.tdt.de>
Tue, 3 Mar 2020 15:12:10 +0000 (16:12 +0100)
Signed-off-by: Helge Mader <ma@dev.tdt.de>
modules/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js

index 80acd7c77d9250d8b8ca1a2eefd69afb32bb7099..5cc452c9f3f16eccb0d5b0429af90cfc20ca4dfd 100644 (file)
@@ -760,24 +760,35 @@ return L.view.extend({
                                                        'class': 'cbi-button cbi-button-positive important',
                                                        'click': ui.createHandlerFn(this, function(ev) {
                                                                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 == '')
                                                                        return;
 
-                                                               return m.save(function() {
-                                                                       var section_id = uci.add('network', 'interface', nameval);
+                                                               return protoclass.isCreateable(nameval).then(function(checkval) {
+                                                                       if (checkval != null) {
+                                                                               ui.addNotification(null,
+                                                                                               E('p', _('New interface for "%s" can not be created: %s').format(protoclass.getI18n(), checkval)));
+                                                                               ui.hideModal();
+                                                                               return;
+                                                                       }
 
-                                                                       uci.set('network', section_id, 'proto', protoval);
+                                                                       return m.save(function() {
+                                                                               var section_id = uci.add('network', 'interface', nameval);
 
-                                                                       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));
+                                                                               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'))
                                        ])