protocols: replace luci/getTTYDevices calls with generic file/list ones
[oweals/luci.git] / protocols / luci-proto-qmi / htdocs / luci-static / resources / protocol / qmi.js
index 79b1fd3b22938ccbfa9cae3af47490e364b59816..eeda91f6e61d7c6b2aea147affba84359d8fb53e 100644 (file)
@@ -3,11 +3,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(/^cdc-wdm/))
+                               rv.push(params.path + list[i].name);
+               return rv.sort();
+       }
 });
 
 network.registerPatternVirtual(/^qmi-.+$/);
@@ -50,12 +57,9 @@ return network.registerProtocol('qmi', {
                o = s.taboption('general', form.Value, 'device', _('Modem device'));
                o.rmempty = false;
                o.load = function(section_id) {
-                       return callTTYDevices(true, false).then(L.bind(function(devices) {
-                               if (Array.isArray(devices))
-                                       for (var i = 0; i < devices.length; i++)
-                                               if (/cdc-wdm/.test(devices[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 form.Value.prototype.load.apply(this, [section_id]);
                        }, this));
                };