7491b712369952471b6001b608675f07d22d633e
[project/luci.git] /
1 'use strict';
2 'require baseclass';
3 'require rpc';
4 'require uci';
5 'require form';
6
7 var callUSB = rpc.declare({
8 object: 'luci',
9 method: 'getUSBDevices',
10 expect: { 'ports': [] }
11 });
12
13 return baseclass.extend({
14 trigger: _('USB (kernel: usbport)'),
15 description: _('This LED trigger can be used for signalling to the user a presence of USB device in a given port.'),
16 kernel: true,
17 addFormOptions(s){
18 var o;
19
20 o = s.option(form.MultiValue, 'port', _('USB Ports'));
21 o.depends('trigger', 'usbport');
22 o.rmempty = true;
23 o.modalonly = true;
24 o.load = function(s) {
25 return Promise.all([
26 callUSB()
27 ]).then(L.bind(function(usbport){
28 for (var i = 0; i < usbport[0].length; i++)
29 o.value(usbport[0][i].port, _('Port %s').format(usbport[0][i].port));
30 },this));
31 };
32 o.cfgvalue = function(section_id) {
33 var ports = [],
34 value = uci.get('system', section_id, 'port');
35
36 if (!Array.isArray(value))
37 value = String(value || '').split(/\s+/);
38
39 for (var i = 0; i < value.length; i++)
40 if (value[i].match(/^(\d+)-(\d+)$/))
41 ports.push('usb%d-port%d'.format(Regexp.$1, Regexp.$2));
42 else
43 ports.push(value[i]);
44
45 return ports;
46 };
47 }
48 });