luci-app-olsr: handle empty result for non-status tables
[oweals/luci.git] / modules / luci-mod-network / htdocs / luci-static / resources / view / network / hosts.js
1 'use strict';
2 'require rpc';
3 'require form';
4
5 return L.view.extend({
6         callHostHints: rpc.declare({
7                 object: 'luci',
8                 method: 'host_hints'
9         }),
10
11         load: function() {
12                 return this.callHostHints();
13         },
14
15         render: function(hosts) {
16                 var m, s, o;
17
18                 m = new form.Map('dhcp', _('Hostnames'));
19
20                 s = m.section(form.GridSection, 'domain', _('Host entries'));
21                 s.addremove = true;
22                 s.anonymous = true;
23                 s.sortable  = true;
24
25                 o = s.option(form.Value, 'name', _('Hostname'));
26                 o.datatype = 'hostname';
27                 o.rmempty = true;
28
29                 o = s.option(form.Value, 'ip', _('IP address'));
30                 o.datatype = 'ipaddr';
31                 o.rmempty = true;
32                 L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
33                         o.value(hosts[mac].ipv4, '%s (%s)'.format(
34                                 hosts[mac].ipv4,
35                                 hosts[mac].name || mac
36                         ));
37                 });
38
39                 return m.render();
40         }
41 });