luci-mod-network: dhcp.js: improve behavior with default configuration
[project/luci.git] / modules / luci-mod-network / htdocs / luci-static / resources / view / network / dhcp.js
index c723a4505432bafc657e102d41ad73636c621db6..cb8f4af4ffed689f34ed5ac88c84a2798b664d30 100644 (file)
@@ -318,7 +318,39 @@ return view.extend({
                s = m.section(form.TypedSection, 'dnsmasq');
                s.anonymous = false;
                s.addremove = true;
+               s.addbtntitle = _('Add server instance', 'Dnsmasq instance');
 
+               s.renderContents = function(/* ... */) {
+                       var renderTask = form.TypedSection.prototype.renderContents.apply(this, arguments),
+                           sections = this.cfgsections();
+
+                       return Promise.resolve(renderTask).then(function(nodes) {
+                               if (sections.length < 2) {
+                                       nodes.querySelector('#cbi-dhcp-dnsmasq > h3').remove();
+                                       nodes.querySelector('#cbi-dhcp-dnsmasq > .cbi-section-remove').remove();
+                               }
+                               else {
+                                       nodes.querySelectorAll('#cbi-dhcp-dnsmasq > .cbi-section-remove').forEach(function(div, i) {
+                                               var section = uci.get('dhcp', sections[i]),
+                                                   hline = div.nextElementSibling,
+                                                   btn = div.firstElementChild;
+
+                                               if (!section || section['.anonymous']) {
+                                                       hline.innerText = i ? _('Unnamed instance #%d', 'Dnsmasq instance').format(i+1) : _('Default instance', 'Dnsmasq instance');
+                                                       btn.innerText = i ? _('Remove instance #%d', 'Dnsmasq instance').format(i+1) : _('Remove default instance', 'Dnsmasq instance');
+                                               }
+                                               else {
+                                                       hline.innerText = _('Instance "%q"', 'Dnsmasq instance').format(section['.name']);
+                                                       btn.innerText = _('Remove instance "%q"', 'Dnsmasq instance').format(section['.name']);
+                                               }
+                                       });
+                               }
+
+                               nodes.querySelector('#cbi-dhcp-dnsmasq > .cbi-section-create input').placeholder = _('New instance nameā€¦', 'Dnsmasq instance');
+
+                               return nodes;
+                       });
+               };
 
 
                s.tab('general', _('General'));