protocols: replace luci/getTTYDevices calls with generic file/list ones
[project/luci.git] / protocols / luci-proto-ppp / htdocs / luci-static / resources / protocol / ppp.js
index 133b472d1a979965b103495f4705ed34a7c0eb77..57a7b6a0e115a0043cb45b3e2f50044db01ce817 100644 (file)
@@ -4,11 +4,18 @@
 'require form';
 'require network';
 
-var callTTYDevices = rpc.declare({
-       object: 'luci',
-       method: 'getTTYDevices',
-       params: [ 'with_cdc', 'with_tts' ],
-       expect: { result: [] }
+var callFileList = rpc.declare({
+       object: 'file',
+       method: 'list',
+       params: [ 'path' ],
+       expect: { entries: [] },
+       filter: function(list, params) {
+               var rv = [];
+               for (var i = 0; i < list.length; i++)
+                       if (list[i].name.match(/^tty[A-Z]/) || list[i].name.match(/^cdc-wdm/) || list[i].name.match(/^[0-9]+$/))
+                               rv.push(params.path + list[i].name);
+               return rv.sort();
+       }
 });
 
 network.registerPatternVirtual(/^ppp-.+$/);
@@ -66,11 +73,13 @@ return network.registerProtocol('ppp', {
                o = s.taboption('general', form.Value, 'device', _('Modem device'));
                o.rmempty = false;
                o.load = function(section_id) {
-                       return callTTYDevices(true, true).then(L.bind(function(devices) {
-                               if (Array.isArray(devices))
-                                       for (var i = 0; i < devices.length; i++)
-                                               this.value(devices[i]);
-
+                       return callFileList('/dev/').then(L.bind(function(devices) {
+                               for (var i = 0; i < devices.length; i++)
+                                       this.value(devices[i]);
+                               return callFileList('/dev/tts/');
+                       }, this)).then(L.bind(function(devices) {
+                               for (var i = 0; i < devices.length; i++)
+                                       this.value(devices[i]);
                                return form.Value.prototype.load.apply(this, [section_id]);
                        }, this));
                };