luci2: split into submodules
[project/luci2/ui.git] / luci2 / htdocs / luci2 / system.js
1 Class.extend({
2         getSystemInfo: L.rpc.declare({
3                 object: 'system',
4                 method: 'info',
5                 expect: { '': { } }
6         }),
7
8         getBoardInfo: L.rpc.declare({
9                 object: 'system',
10                 method: 'board',
11                 expect: { '': { } }
12         }),
13
14         getDiskInfo: L.rpc.declare({
15                 object: 'luci2.system',
16                 method: 'diskfree',
17                 expect: { '': { } }
18         }),
19
20         getInfo: function(cb)
21         {
22                 L.rpc.batch();
23
24                 this.getSystemInfo();
25                 this.getBoardInfo();
26                 this.getDiskInfo();
27
28                 return L.rpc.flush().then(function(info) {
29                         var rv = { };
30
31                         $.extend(rv, info[0]);
32                         $.extend(rv, info[1]);
33                         $.extend(rv, info[2]);
34
35                         return rv;
36                 });
37         },
38
39
40         initList: L.rpc.declare({
41                 object: 'luci2.system',
42                 method: 'init_list',
43                 expect: { initscripts: [ ] },
44                 filter: function(data) {
45                         data.sort(function(a, b) { return (a.start || 0) - (b.start || 0) });
46                         return data;
47                 }
48         }),
49
50         initEnabled: function(init, cb)
51         {
52                 return this.initList().then(function(list) {
53                         for (var i = 0; i < list.length; i++)
54                                 if (list[i].name == init)
55                                         return !!list[i].enabled;
56
57                         return false;
58                 });
59         },
60
61         initRun: L.rpc.declare({
62                 object: 'luci2.system',
63                 method: 'init_action',
64                 params: [ 'name', 'action' ],
65                 filter: function(data) {
66                         return (data == 0);
67                 }
68         }),
69
70         initStart:   function(init, cb) { return L.system.initRun(init, 'start',   cb) },
71         initStop:    function(init, cb) { return L.system.initRun(init, 'stop',    cb) },
72         initRestart: function(init, cb) { return L.system.initRun(init, 'restart', cb) },
73         initReload:  function(init, cb) { return L.system.initRun(init, 'reload',  cb) },
74         initEnable:  function(init, cb) { return L.system.initRun(init, 'enable',  cb) },
75         initDisable: function(init, cb) { return L.system.initRun(init, 'disable', cb) },
76
77
78         performReboot: L.rpc.declare({
79                 object: 'luci2.system',
80                 method: 'reboot'
81         })
82 });