luci2: make LuCI2.cbi.AbstractSection and LuCI2.cbi.AbstractValue public
[project/luci2/ui.git] / luci2 / htdocs / luci2 / luci2.js
index a074b44..e401c7c 100644 (file)
@@ -1429,7 +1429,7 @@ function LuCI2()
                startHeartbeat: function()
                {
                        this._hearbeatInterval = window.setInterval(function() {
                startHeartbeat: function()
                {
                        this._hearbeatInterval = window.setInterval(function() {
-                               _luci2.session.isAlive(function(alive) {
+                               _luci2.session.isAlive().then(function(alive) {
                                        if (!alive)
                                        {
                                                _luci2.session.stopHeartbeat();
                                        if (!alive)
                                        {
                                                _luci2.session.stopHeartbeat();
@@ -1443,7 +1443,10 @@ function LuCI2()
                stopHeartbeat: function()
                {
                        if (typeof(this._hearbeatInterval) != 'undefined')
                stopHeartbeat: function()
                {
                        if (typeof(this._hearbeatInterval) != 'undefined')
+                       {
                                window.clearInterval(this._hearbeatInterval);
                                window.clearInterval(this._hearbeatInterval);
+                               delete this._hearbeatInterval;
+                       }
                }
        };
 
                }
        };
 
@@ -1759,6 +1762,7 @@ function LuCI2()
                                _luci2.session.isAlive().then(function(access) {
                                        if (access)
                                        {
                                _luci2.session.isAlive().then(function(access) {
                                        if (access)
                                        {
+                                               _luci2.session.startHeartbeat();
                                                _luci2._login_deferred.resolve();
                                        }
                                        else
                                                _luci2._login_deferred.resolve();
                                        }
                                        else
@@ -1853,6 +1857,13 @@ function LuCI2()
                        return _luci2._login_deferred;
                },
 
                        return _luci2._login_deferred;
                },
 
+               cryptPassword: _luci2.rpc.declare({
+                       object: 'luci2.ui',
+                       method: 'crypt',
+                       params: [ 'data' ],
+                       expect: { crypt: '' }
+               }),
+
 
                _acl_merge_scope: function(acl_scope, scope)
                {
 
                _acl_merge_scope: function(acl_scope, scope)
                {
@@ -2973,7 +2984,7 @@ function LuCI2()
        };
 
 
        };
 
 
-       var AbstractValue = AbstractWidget.extend({
+       this.cbi.AbstractValue = AbstractWidget.extend({
                init: function(name, options)
                {
                        this.name = name;
                init: function(name, options)
                {
                        this.name = name;
@@ -3239,11 +3250,11 @@ function LuCI2()
                                {
                                        if (typeof(d[i]) == 'string')
                                                dep[d[i]] = true;
                                {
                                        if (typeof(d[i]) == 'string')
                                                dep[d[i]] = true;
-                                       else if (d[i] instanceof AbstractValue)
+                                       else if (d[i] instanceof _luci2.cbi.AbstractValue)
                                                dep[d[i].name] = true;
                                }
                        }
                                                dep[d[i].name] = true;
                                }
                        }
-                       else if (d instanceof AbstractValue)
+                       else if (d instanceof _luci2.cbi.AbstractValue)
                        {
                                dep = { };
                                dep[d.name] = (typeof(v) == 'undefined') ? true : v;
                        {
                                dep = { };
                                dep[d.name] = (typeof(v) == 'undefined') ? true : v;
@@ -3351,7 +3362,7 @@ function LuCI2()
                }
        });
 
                }
        });
 
-       this.cbi.CheckboxValue = AbstractValue.extend({
+       this.cbi.CheckboxValue = this.cbi.AbstractValue.extend({
                widget: function(sid)
                {
                        var o = this.options;
                widget: function(sid)
                {
                        var o = this.options;
@@ -3416,7 +3427,7 @@ function LuCI2()
                }
        });
 
                }
        });
 
-       this.cbi.InputValue = AbstractValue.extend({
+       this.cbi.InputValue = this.cbi.AbstractValue.extend({
                widget: function(sid)
                {
                        var i = $('<input />')
                widget: function(sid)
                {
                        var i = $('<input />')
@@ -3429,7 +3440,7 @@ function LuCI2()
                }
        });
 
                }
        });
 
-       this.cbi.PasswordValue = AbstractValue.extend({
+       this.cbi.PasswordValue = this.cbi.AbstractValue.extend({
                widget: function(sid)
                {
                        var i = $('<input />')
                widget: function(sid)
                {
                        var i = $('<input />')
@@ -3458,7 +3469,7 @@ function LuCI2()
                }
        });
 
                }
        });
 
-       this.cbi.ListValue = AbstractValue.extend({
+       this.cbi.ListValue = this.cbi.AbstractValue.extend({
                widget: function(sid)
                {
                        var s = $('<select />');
                widget: function(sid)
                {
                        var s = $('<select />');
@@ -3553,7 +3564,7 @@ function LuCI2()
                }
        });
 
                }
        });
 
-       this.cbi.ComboBox = AbstractValue.extend({
+       this.cbi.ComboBox = this.cbi.AbstractValue.extend({
                _change: function(ev)
                {
                        var s = ev.target;
                _change: function(ev)
                {
                        var s = ev.target;
@@ -3922,7 +3933,7 @@ function LuCI2()
                }
        });
 
                }
        });
 
-       this.cbi.DummyValue = AbstractValue.extend({
+       this.cbi.DummyValue = this.cbi.AbstractValue.extend({
                widget: function(sid)
                {
                        return $('<div />')
                widget: function(sid)
                {
                        return $('<div />')
@@ -3937,7 +3948,7 @@ function LuCI2()
                }
        });
 
                }
        });
 
-       this.cbi.NetworkList = AbstractValue.extend({
+       this.cbi.NetworkList = this.cbi.AbstractValue.extend({
                load: function(sid)
                {
                        var self = this;
                load: function(sid)
                {
                        var self = this;
@@ -3945,7 +3956,7 @@ function LuCI2()
                        if (!self.interfaces)
                        {
                                self.interfaces = [ ];
                        if (!self.interfaces)
                        {
                                self.interfaces = [ ];
-                               return _luci2.network.getNetworkStatus(function(ifaces) {
+                               return _luci2.network.getNetworkStatus().then(function(ifaces) {
                                        self.interfaces = ifaces;
                                        self = null;
                                });
                                        self.interfaces = ifaces;
                                        self = null;
                                });
@@ -3974,7 +3985,7 @@ function LuCI2()
                                type = 'wifi';
                                desc = _luci2.tr('Wireless Network');
                        }
                                type = 'wifi';
                                desc = _luci2.tr('Wireless Network');
                        }
-                       else if (dev.name.indexOf('.') > 0)
+                       else if (dev.device.indexOf('.') > 0)
                        {
                                type = 'vlan';
                                desc = _luci2.tr('VLAN interface');
                        {
                                type = 'vlan';
                                desc = _luci2.tr('VLAN interface');
@@ -3982,7 +3993,7 @@ function LuCI2()
 
                        return $('<img />')
                                .attr('src', _luci2.globals.resource + '/icons/' + type + (dev.up ? '' : '_disabled') + '.png')
 
                        return $('<img />')
                                .attr('src', _luci2.globals.resource + '/icons/' + type + (dev.up ? '' : '_disabled') + '.png')
-                               .attr('title', '%s (%s)'.format(desc, dev.name));
+                               .attr('title', '%s (%s)'.format(desc, dev.device));
                },
 
                widget: function(sid)
                },
 
                widget: function(sid)
@@ -4009,11 +4020,11 @@ function LuCI2()
                                        var iface = this.interfaces[i];
                                        var badge = $('<span />')
                                                .addClass('ifacebadge')
                                        var iface = this.interfaces[i];
                                        var badge = $('<span />')
                                                .addClass('ifacebadge')
-                                               .text('%s: '.format(iface.name));
+                                               .text('%s: '.format(iface['interface']));
 
 
-                                       if (iface.subdevices)
-                                               for (var j = 0; j < iface.subdevices.length; j++)
-                                                       badge.append(this._device_icon(iface.subdevices[j]));
+                                       if (iface.device && iface.device.subdevices)
+                                               for (var j = 0; j < iface.device.subdevices.length; j++)
+                                                       badge.append(this._device_icon(iface.device.subdevices[j]));
                                        else if (iface.device)
                                                badge.append(this._device_icon(iface.device));
                                        else
                                        else if (iface.device)
                                                badge.append(this._device_icon(iface.device));
                                        else
@@ -4024,8 +4035,8 @@ function LuCI2()
                                                        .append($('<input />')
                                                                .attr('name', itype + id)
                                                                .attr('type', itype)
                                                        .append($('<input />')
                                                                .attr('name', itype + id)
                                                                .attr('type', itype)
-                                                               .attr('value', iface.name)
-                                                               .prop('checked', !!check[iface.name])
+                                                               .attr('value', iface['interface'])
+                                                               .prop('checked', !!check[iface['interface']])
                                                                .addClass('cbi-input-' + itype))
                                                        .append(badge))
                                                .appendTo(ul);
                                                                .addClass('cbi-input-' + itype))
                                                        .append(badge))
                                                .appendTo(ul);
@@ -4100,7 +4111,7 @@ function LuCI2()
        });
 
 
        });
 
 
-       var AbstractSection = AbstractWidget.extend({
+       this.cbi.AbstractSection = AbstractWidget.extend({
                id: function()
                {
                        var s = [ arguments[0], this.map.uci_package, this.uci_type ];
                id: function()
                {
                        var s = [ arguments[0], this.map.uci_package, this.uci_type ];
@@ -4150,7 +4161,7 @@ function LuCI2()
 
                        var w = widget ? new widget(name, options) : null;
 
 
                        var w = widget ? new widget(name, options) : null;
 
-                       if (!(w instanceof AbstractValue))
+                       if (!(w instanceof _luci2.cbi.AbstractValue))
                                throw 'Widget must be an instance of AbstractValue';
 
                        w.section = this;
                                throw 'Widget must be an instance of AbstractValue';
 
                        w.section = this;
@@ -4246,7 +4257,7 @@ function LuCI2()
                }
        });
 
                }
        });
 
-       this.cbi.TypedSection = AbstractSection.extend({
+       this.cbi.TypedSection = this.cbi.AbstractSection.extend({
                init: function(uci_type, options)
                {
                        this.uci_type = uci_type;
                init: function(uci_type, options)
                {
                        this.uci_type = uci_type;
@@ -4377,9 +4388,9 @@ function LuCI2()
                                        for (var i = 0; i < this.options.teasers.length; i++)
                                        {
                                                var f = this.options.teasers[i];
                                        for (var i = 0; i < this.options.teasers.length; i++)
                                        {
                                                var f = this.options.teasers[i];
-                                               if (f instanceof AbstractValue)
+                                               if (f instanceof _luci2.cbi.AbstractValue)
                                                        tf.push(f);
                                                        tf.push(f);
-                                               else if (typeof(f) == 'string' && this.fields[f] instanceof AbstractValue)
+                                               else if (typeof(f) == 'string' && this.fields[f] instanceof _luci2.cbi.AbstractValue)
                                                        tf.push(this.fields[f]);
                                        }
                                }
                                                        tf.push(this.fields[f]);
                                        }
                                }
@@ -5050,7 +5061,7 @@ function LuCI2()
                {
                        var w = widget ? new widget(uci_type, options) : null;
 
                {
                        var w = widget ? new widget(uci_type, options) : null;
 
-                       if (!(w instanceof AbstractSection))
+                       if (!(w instanceof _luci2.cbi.AbstractSection))
                                throw 'Widget must be an instance of AbstractSection';
 
                        w.map = this;
                                throw 'Widget must be an instance of AbstractSection';
 
                        w.map = this;
@@ -5296,11 +5307,11 @@ function LuCI2()
                                                        for (var k in this.uci.creates[c][s])
                                                        {
                                                                if (k == '.type')
                                                        for (var k in this.uci.creates[c][s])
                                                        {
                                                                if (k == '.type')
-                                                                       r.type = this.uci.creates[i][k];
+                                                                       r.type = this.uci.creates[c][s][k];
                                                                else if (k == '.create')
                                                                else if (k == '.create')
-                                                                       r.name = this.uci.creates[i][k];
+                                                                       r.name = this.uci.creates[c][s][k];
                                                                else if (k.charAt(0) != '.')
                                                                else if (k.charAt(0) != '.')
-                                                                       r.values[k] = this.uci.creates[i][k];
+                                                                       r.values[k] = this.uci.creates[c][s][k];
                                                        }
 
                                                        _luci2.uci.add(r.config, r.type, r.name, r.values);
                                                        }
 
                                                        _luci2.uci.add(r.config, r.type, r.name, r.values);