luci2: make LuCI2.cbi.AbstractSection and LuCI2.cbi.AbstractValue public
[project/luci2/ui.git] / luci2 / htdocs / luci2 / view / system.startup.js
1 L.ui.view.extend({
2     title: L.tr('Startup'),
3     execute: function() {
4         var self = this;
5         var redraw = function() { return self.execute(); };
6         var allow_write = self.options.acls.startup;
7
8         return $.when(
9             L.system.initList().then(function(list) {
10                 /* filter init scripts with no start prio */
11                 for (var i = 0; i < list.length; i++)
12                 {
13                     if (typeof(list[i].start) != 'undefined')
14                         continue;
15
16                     list.splice(i--, 1);
17                 }
18
19                 var initTable = new L.ui.table({
20                     columns: [ {
21                         caption: L.tr('Start priority'),
22                         key:     'start'
23                     }, {
24                         caption: L.tr('Initscript'),
25                         key:     'name',
26                         width:   '90%'
27                     }, {
28                         caption: L.trc('Init script table heading', 'Enable'),
29                         key:     'enabled',
30                         format: function(v, n) {
31                             return $('<button />')
32                                 .attr('disabled', !allow_write)
33                                 .attr('name', list[n].name)
34                                 .addClass('cbi-button')
35                                 .addClass(v ? 'cbi-button-apply' : 'cbi-button-reset')
36                                 .text(v ? L.trc('Init script state', 'Enabled') : L.trc('Init script state', 'Disabled'))
37                                 .click(function() {
38                                     L.ui.loading(true);
39                                     if (v)
40                                         L.system.initDisable(this.getAttribute('name')).then(redraw);
41                                     else
42                                         L.system.initEnable(this.getAttribute('name')).then(redraw);
43                                 });
44                         }
45                     }, {
46                         caption: L.trc('Init script table heading', 'Restart'),
47                         key:     'enabled',
48                         format: function(v, n) {
49                             return $('<button />')
50                                 .attr('disabled', !allow_write)
51                                 .attr('name', list[n].name)
52                                 .addClass('cbi-button')
53                                 .addClass('cbi-button-reload')
54                                 .text(L.trc('Init script action', 'Restart'))
55                                 .click(function() {
56                                     L.ui.loading(true);
57                                     L.system.initRestart(this.getAttribute('name')).then(redraw)
58                                 });
59                         }
60                     }, {
61                         caption: L.trc('Init script table heading', 'Stop'),
62                         key:     'enabled',
63                         format: function(v, n) {
64                             return $('<button />')
65                                 .attr('disabled', !allow_write)
66                                 .attr('name', list[n].name)
67                                 .addClass('cbi-button')
68                                 .addClass('cbi-button-remove')
69                                 .text(L.trc('Init script action', 'Stop'))
70                                 .click(function() {
71                                     L.ui.loading(true);
72                                     L.system.initStop(this.getAttribute('name')).then(redraw)
73                                 });
74                         }
75                     } ]
76                 });
77
78                 initTable.rows(list);
79                 initTable.insertInto('#init_table');
80
81                 L.ui.loading(false);
82             }),
83             L.system.getRcLocal().then(function(data) {
84                 $('#maps').accordion({ heightStyle: 'content' });
85
86                 $('textarea').val(data).attr('disabled', !allow_write);
87                 $('input.cbi-button-save').attr('disabled', !allow_write).click(function() {
88                     var data = ($('textarea').val() || '').replace(/\r/g, '').replace(/\n?$/, '\n');
89                     L.ui.loading(true);
90                     L.system.setRcLocal(data).then(function() {
91                         $('textarea').val(data);
92                         L.ui.loading(false);
93                     });
94                 });
95             })
96         );
97     }
98 });