treewide: remove rendundant proto handler options
[project/luci.git] / protocols / luci-proto-ncm / htdocs / luci-static / resources / protocol / ncm.js
1 'use strict';
2 'require rpc';
3 'require form';
4 'require network';
5
6 var callFileList = rpc.declare({
7 object: 'file',
8 method: 'list',
9 params: [ 'path' ],
10 expect: { entries: [] },
11 filter: function(list, params) {
12 var rv = [];
13 for (var i = 0; i < list.length; i++)
14 if (list[i].name.match(/^ttyUSB/) || list[i].name.match(/^cdc-wdm/))
15 rv.push(params.path + list[i].name);
16 return rv.sort();
17 }
18 });
19
20 network.registerPatternVirtual(/^ncm-.+$/);
21 network.registerErrorCode('CONFIGURE_FAILED', _('Configuration failed'));
22 network.registerErrorCode('DISCONNECT_FAILED', _('Disconnection attempt failed'));
23 network.registerErrorCode('FINALIZE_FAILED', _('Finalizing failed'));
24 network.registerErrorCode('GETINFO_FAILED', _('Modem information query failed'));
25 network.registerErrorCode('INITIALIZE_FAILED', _('Initialization failure'));
26 network.registerErrorCode('SETMODE_FAILED', _('Setting operation mode failed'));
27 network.registerErrorCode('UNSUPPORTED_MODEM', _('Unsupported modem'));
28
29 return network.registerProtocol('ncm', {
30 getI18n: function() {
31 return _('NCM');
32 },
33
34 getIfname: function() {
35 return this._ubus('l3_device') || 'wan';
36 },
37
38 getOpkgPackage: function() {
39 return 'comgt-ncm';
40 },
41
42 isFloating: function() {
43 return true;
44 },
45
46 isVirtual: function() {
47 return true;
48 },
49
50 getDevices: function() {
51 return null;
52 },
53
54 containsDevice: function(ifname) {
55 return (network.getIfnameOf(ifname) == this.getIfname());
56 },
57
58 renderFormOptions: function(s) {
59 var o;
60
61 o = s.taboption('general', form.Value, 'device', _('Modem device'));
62 o.rmempty = false;
63 o.load = function(section_id) {
64 return callFileList('/dev/').then(L.bind(function(devices) {
65 for (var i = 0; i < devices.length; i++)
66 this.value(devices[i]);
67 return form.Value.prototype.load.apply(this, [section_id]);
68 }, this));
69 };
70
71 o = s.taboption('general', form.Value, 'service', _('Service Type'));
72 o.value('', _('Modem default'));
73 o.value('preferlte', _('Prefer LTE'));
74 o.value('preferumts', _('Prefer UMTS'));
75 o.value('lte', 'LTE');
76 o.value('umts', 'UMTS/GPRS');
77 o.value('gsm', _('GPRS only'));
78 o.value('auto', _('auto'));
79
80 o = s.taboption('general', form.ListValue, 'pdptype', _('IP Protocol'));
81 o.default = 'IP';
82 o.value('IP', _('IPv4'));
83 o.value('IPV4V6', _('IPv4+IPv6'));
84 o.value('IPV6', _('IPv6'));
85
86 s.taboption('general', form.Value, 'apn', _('APN'));
87 s.taboption('general', form.Value, 'pincode', _('PIN'));
88 s.taboption('general', form.Value, 'username', _('PAP/CHAP username'));
89
90 o = s.taboption('general', form.Value, 'password', _('PAP/CHAP password'));
91 o.password = true;
92
93 o = s.taboption('general', form.Value, 'dialnumber', _('Dial number'));
94 o.placeholder = '*99***1#';
95
96 if (L.hasSystemFeature('ipv6')) {
97 o = s.taboption('advanced', form.ListValue, 'ipv6', _('Obtain IPv6-Address'));
98 o.value('auto', _('Automatic'));
99 o.value('0', _('Disabled'));
100 o.value('1', _('Manual'));
101 o.default = 'auto';
102 }
103
104 o = s.taboption('advanced', form.Value, 'delay', _('Modem init timeout'), _('Maximum amount of seconds to wait for the modem to become ready'));
105 o.placeholder = '10';
106 o.datatype = 'min(1)';
107 }
108 });