luci2: adapt views to changed luci2 framework
[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 }, {
27 key: 'enabled',
28 format: function(v, n) {
29 return [
30 $('<div />')
31 .addClass('btn-group pull-right')
32 .append($('<button />')
33 .attr('disabled', !allow_write)
34 .attr('name', list[n].name)
35 .addClass('btn btn-sm')
36 .addClass(v ? 'btn-success' : 'btn-danger')
37 .text(v ? L.trc('Init script state', 'Enabled') : L.trc('Init script state', 'Disabled'))
38 .click(function() {
39 L.ui.loading(true);
40 if (v)
41 L.system.initDisable(this.getAttribute('name')).then(redraw);
42 else
43 L.system.initEnable(this.getAttribute('name')).then(redraw);
44 }))
45 .append($('<button />')
46 .addClass('btn btn-primary btn-sm dropdown-toggle')
47 .attr('data-toggle', 'dropdown')
48 .attr('disabled', !allow_write)
49 .text(L.tr('Action…')))
50 .append($('<ul />')
51 .addClass('dropdown-menu pull-right')
52 .append($('<li />')
53 .append($('<a />')
54 .attr('href', '#')
55 .text(L.tr('Reload'))
56 .click(function(ev) { L.system.initReload(v).then(redraw); ev.preventDefault(); })))
57 .append($('<li />')
58 .append($('<a />')
59 .attr('href', '#')
60 .text(L.tr('Restart'))
61 .click(function(ev) { L.system.initRestart(v).then(redraw); ev.preventDefault(); })))
62 .append($('<li />')
63 .append($('<a />')
64 .attr('href', '#')
65 .text(L.tr('Stop'))
66 .click(function(ev) { L.system.initStop(v).then(redraw); ev.preventDefault(); }))))
67 ];
68 }
69 } ]
70 });
71
72 initTable.rows(list);
73 initTable.insertInto('#init_table');
74
75 L.ui.loading(false);
76 }),
77 L.system.getRcLocal().then(function(data) {
78 $('textarea').val(data).attr('disabled', !allow_write);
79 $('input.cbi-button-save').attr('disabled', !allow_write).click(function() {
80 var data = ($('textarea').val() || '').replace(/\r/g, '').replace(/\n?$/, '\n');
81 L.ui.loading(true);
82 L.system.setRcLocal(data).then(function() {
83 $('textarea').val(data);
84 L.ui.loading(false);
85 });
86 });
87 })
88 );
89 }
90 });