1268256686bb5710ae6be9fd1afbc57001f9cb07
[project/luci.git] / docs / jsapi / luci.js.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Source: luci.js</title>
6
7
8 <script src="scripts/prettify/prettify.js"></script>
9 <script src="scripts/prettify/lang-css.js"></script>
10 <script src="scripts/jquery.min.js"></script>
11 <!--[if lt IE 9]>
12 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
13 <![endif]-->
14 <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
15 <link type="text/css" rel="stylesheet" href="styles/bootstrap.min.css">
16 <link type="text/css" rel="stylesheet" href="styles/jaguar.css">
17
18
19 <script>
20 var config = {"monospaceLinks":true,"cleverLinks":true,"default":{"outputSourceFiles":true}};
21 </script>
22
23
24
25 </head>
26 <body>
27 <div id="wrap" class="clearfix">
28
29 <div class="navigation">
30 <h3 class="applicationName"><a href="index.html"></a></h3>
31
32 <div class="search">
33 <input id="search" type="text" class="form-control input-sm" placeholder="Search Documentations">
34 </div>
35 <ul class="list">
36
37 <li class="item" data-name="LuCI">
38 <span class="title">
39 <a href="LuCI.html">LuCI</a>
40
41 </span>
42 <ul class="members itemMembers">
43
44 <span class="subtitle">Members</span>
45
46 <li data-name="LuCI#env"><a href="LuCI.html#env">env</a></li>
47
48 </ul>
49 <ul class="typedefs itemMembers">
50
51 <span class="subtitle">Typedefs</span>
52
53 <li data-name="LuCI.requestCallbackFn"><a href="LuCI.html#.requestCallbackFn">requestCallbackFn</a></li>
54
55 </ul>
56 <ul class="typedefs itemMembers">
57
58 </ul>
59 <ul class="methods itemMembers">
60
61 <span class="subtitle">Methods</span>
62
63 <li data-name="LuCI#bind"><a href="LuCI.html#bind">bind</a></li>
64
65 <li data-name="LuCI#error"><a href="LuCI.html#error">error</a></li>
66
67 <li data-name="LuCI#get"><a href="LuCI.html#get">get</a></li>
68
69 <li data-name="LuCI#halt"><a href="LuCI.html#halt">halt</a></li>
70
71 <li data-name="LuCI#hasSystemFeature"><a href="LuCI.html#hasSystemFeature">hasSystemFeature</a></li>
72
73 <li data-name="LuCI#isObject"><a href="LuCI.html#isObject">isObject</a></li>
74
75 <li data-name="LuCI#location"><a href="LuCI.html#location">location</a></li>
76
77 <li data-name="LuCI#path"><a href="LuCI.html#path">path</a></li>
78
79 <li data-name="LuCI#poll"><a href="LuCI.html#poll">poll</a></li>
80
81 <li data-name="LuCI#post"><a href="LuCI.html#post">post</a></li>
82
83 <li data-name="LuCI#raise"><a href="LuCI.html#raise">raise</a></li>
84
85 <li data-name="LuCI#require"><a href="LuCI.html#require">require</a></li>
86
87 <li data-name="LuCI#resolveDefault"><a href="LuCI.html#resolveDefault">resolveDefault</a></li>
88
89 <li data-name="LuCI#resource"><a href="LuCI.html#resource">resource</a></li>
90
91 <li data-name="LuCI#run"><a href="LuCI.html#run">run</a></li>
92
93 <li data-name="LuCI#sortedKeys"><a href="LuCI.html#sortedKeys">sortedKeys</a></li>
94
95 <li data-name="LuCI#stop"><a href="LuCI.html#stop">stop</a></li>
96
97 <li data-name="LuCI#toArray"><a href="LuCI.html#toArray">toArray</a></li>
98
99 <li data-name="LuCI#url"><a href="LuCI.html#url">url</a></li>
100
101 </ul>
102 <ul class="events itemMembers">
103
104 </ul>
105 </li>
106
107 <li class="item" data-name="LuCI.Class">
108 <span class="title">
109 <a href="LuCI.Class.html">LuCI.Class</a>
110
111 </span>
112 <ul class="members itemMembers">
113
114 </ul>
115 <ul class="typedefs itemMembers">
116
117 </ul>
118 <ul class="typedefs itemMembers">
119
120 </ul>
121 <ul class="methods itemMembers">
122
123 <span class="subtitle">Methods</span>
124
125 <li data-name="LuCI.Class.extend"><a href="LuCI.Class.html#.extend">extend</a></li>
126
127 <li data-name="LuCI.Class.instantiate"><a href="LuCI.Class.html#.instantiate">instantiate</a></li>
128
129 <li data-name="LuCI.Class.isSubclass"><a href="LuCI.Class.html#.isSubclass">isSubclass</a></li>
130
131 <li data-name="LuCI.Class.singleton"><a href="LuCI.Class.html#.singleton">singleton</a></li>
132
133 <li data-name="LuCI.Class#super"><a href="LuCI.Class.html#super">super</a></li>
134
135 <li data-name="LuCI.Class#varargs"><a href="LuCI.Class.html#varargs">varargs</a></li>
136
137 </ul>
138 <ul class="events itemMembers">
139
140 </ul>
141 </li>
142
143 <li class="item" data-name="LuCI.dom">
144 <span class="title">
145 <a href="LuCI.dom.html">LuCI.dom</a>
146
147 </span>
148 <ul class="members itemMembers">
149
150 </ul>
151 <ul class="typedefs itemMembers">
152
153 <span class="subtitle">Typedefs</span>
154
155 <li data-name="LuCI.dom~ignoreCallbackFn"><a href="LuCI.dom.html#~ignoreCallbackFn">ignoreCallbackFn</a></li>
156
157 </ul>
158 <ul class="typedefs itemMembers">
159
160 </ul>
161 <ul class="methods itemMembers">
162
163 <span class="subtitle">Methods</span>
164
165 <li data-name="LuCI.dom#append"><a href="LuCI.dom.html#append">append</a></li>
166
167 <li data-name="LuCI.dom#attr"><a href="LuCI.dom.html#attr">attr</a></li>
168
169 <li data-name="LuCI.dom#bindClassInstance"><a href="LuCI.dom.html#bindClassInstance">bindClassInstance</a></li>
170
171 <li data-name="LuCI.dom#callClassMethod"><a href="LuCI.dom.html#callClassMethod">callClassMethod</a></li>
172
173 <li data-name="LuCI.dom#content"><a href="LuCI.dom.html#content">content</a></li>
174
175 <li data-name="LuCI.dom#create"><a href="LuCI.dom.html#create">create</a></li>
176
177 <li data-name="LuCI.dom#data"><a href="LuCI.dom.html#data">data</a></li>
178
179 <li data-name="LuCI.dom#elem"><a href="LuCI.dom.html#elem">elem</a></li>
180
181 <li data-name="LuCI.dom#findClassInstance"><a href="LuCI.dom.html#findClassInstance">findClassInstance</a></li>
182
183 <li data-name="LuCI.dom#isEmpty"><a href="LuCI.dom.html#isEmpty">isEmpty</a></li>
184
185 <li data-name="LuCI.dom#matches"><a href="LuCI.dom.html#matches">matches</a></li>
186
187 <li data-name="LuCI.dom#parent"><a href="LuCI.dom.html#parent">parent</a></li>
188
189 <li data-name="LuCI.dom#parse"><a href="LuCI.dom.html#parse">parse</a></li>
190
191 </ul>
192 <ul class="events itemMembers">
193
194 </ul>
195 </li>
196
197 <li class="item" data-name="LuCI.fs">
198 <span class="title">
199 <a href="LuCI.fs.html">LuCI.fs</a>
200
201 </span>
202 <ul class="members itemMembers">
203
204 </ul>
205 <ul class="typedefs itemMembers">
206
207 <span class="subtitle">Typedefs</span>
208
209 <li data-name="LuCI.fs.FileExecResult"><a href="LuCI.fs.html#.FileExecResult">FileExecResult</a></li>
210
211 <li data-name="LuCI.fs.FileStatEntry"><a href="LuCI.fs.html#.FileStatEntry">FileStatEntry</a></li>
212
213 </ul>
214 <ul class="typedefs itemMembers">
215
216 </ul>
217 <ul class="methods itemMembers">
218
219 <span class="subtitle">Methods</span>
220
221 <li data-name="LuCI.fs#exec"><a href="LuCI.fs.html#exec">exec</a></li>
222
223 <li data-name="LuCI.fs#lines"><a href="LuCI.fs.html#lines">lines</a></li>
224
225 <li data-name="LuCI.fs#list"><a href="LuCI.fs.html#list">list</a></li>
226
227 <li data-name="LuCI.fs#read"><a href="LuCI.fs.html#read">read</a></li>
228
229 <li data-name="LuCI.fs#remove"><a href="LuCI.fs.html#remove">remove</a></li>
230
231 <li data-name="LuCI.fs#stat"><a href="LuCI.fs.html#stat">stat</a></li>
232
233 <li data-name="LuCI.fs#trimmed"><a href="LuCI.fs.html#trimmed">trimmed</a></li>
234
235 <li data-name="LuCI.fs#write"><a href="LuCI.fs.html#write">write</a></li>
236
237 </ul>
238 <ul class="events itemMembers">
239
240 </ul>
241 </li>
242
243 <li class="item" data-name="LuCI.Headers">
244 <span class="title">
245 <a href="LuCI.Headers.html">LuCI.Headers</a>
246
247 </span>
248 <ul class="members itemMembers">
249
250 </ul>
251 <ul class="typedefs itemMembers">
252
253 </ul>
254 <ul class="typedefs itemMembers">
255
256 </ul>
257 <ul class="methods itemMembers">
258
259 <span class="subtitle">Methods</span>
260
261 <li data-name="LuCI.Headers#get"><a href="LuCI.Headers.html#get">get</a></li>
262
263 <li data-name="LuCI.Headers#has"><a href="LuCI.Headers.html#has">has</a></li>
264
265 </ul>
266 <ul class="events itemMembers">
267
268 </ul>
269 </li>
270
271 <li class="item" data-name="LuCI.Network">
272 <span class="title">
273 <a href="LuCI.Network.html">LuCI.Network</a>
274
275 </span>
276 <ul class="members itemMembers">
277
278 </ul>
279 <ul class="typedefs itemMembers">
280
281 <span class="subtitle">Typedefs</span>
282
283 <li data-name="LuCI.Network.SwitchTopology"><a href="LuCI.Network.html#.SwitchTopology">SwitchTopology</a></li>
284
285 <li data-name="LuCI.Network.WifiEncryption"><a href="LuCI.Network.html#.WifiEncryption">WifiEncryption</a></li>
286
287 <li data-name="LuCI.Network.WifiPeerEntry"><a href="LuCI.Network.html#.WifiPeerEntry">WifiPeerEntry</a></li>
288
289 <li data-name="LuCI.Network.WifiRateEntry"><a href="LuCI.Network.html#.WifiRateEntry">WifiRateEntry</a></li>
290
291 <li data-name="LuCI.Network.WifiScanResult"><a href="LuCI.Network.html#.WifiScanResult">WifiScanResult</a></li>
292
293 </ul>
294 <ul class="typedefs itemMembers">
295
296 </ul>
297 <ul class="methods itemMembers">
298
299 <span class="subtitle">Methods</span>
300
301 <li data-name="LuCI.Network#addNetwork"><a href="LuCI.Network.html#addNetwork">addNetwork</a></li>
302
303 <li data-name="LuCI.Network#addWifiNetwork"><a href="LuCI.Network.html#addWifiNetwork">addWifiNetwork</a></li>
304
305 <li data-name="LuCI.Network#deleteNetwork"><a href="LuCI.Network.html#deleteNetwork">deleteNetwork</a></li>
306
307 <li data-name="LuCI.Network#deleteWifiNetwork"><a href="LuCI.Network.html#deleteWifiNetwork">deleteWifiNetwork</a></li>
308
309 <li data-name="LuCI.Network#flushCache"><a href="LuCI.Network.html#flushCache">flushCache</a></li>
310
311 <li data-name="LuCI.Network#formatWifiEncryption"><a href="LuCI.Network.html#formatWifiEncryption">formatWifiEncryption</a></li>
312
313 <li data-name="LuCI.Network#getDevice"><a href="LuCI.Network.html#getDevice">getDevice</a></li>
314
315 <li data-name="LuCI.Network#getDevices"><a href="LuCI.Network.html#getDevices">getDevices</a></li>
316
317 <li data-name="LuCI.Network#getDSLModemType"><a href="LuCI.Network.html#getDSLModemType">getDSLModemType</a></li>
318
319 <li data-name="LuCI.Network#getHostHints"><a href="LuCI.Network.html#getHostHints">getHostHints</a></li>
320
321 <li data-name="LuCI.Network#getIfnameOf"><a href="LuCI.Network.html#getIfnameOf">getIfnameOf</a></li>
322
323 <li data-name="LuCI.Network#getNetwork"><a href="LuCI.Network.html#getNetwork">getNetwork</a></li>
324
325 <li data-name="LuCI.Network#getNetworks"><a href="LuCI.Network.html#getNetworks">getNetworks</a></li>
326
327 <li data-name="LuCI.Network#getProtocol"><a href="LuCI.Network.html#getProtocol">getProtocol</a></li>
328
329 <li data-name="LuCI.Network#getProtocols"><a href="LuCI.Network.html#getProtocols">getProtocols</a></li>
330
331 <li data-name="LuCI.Network#getSwitchTopologies"><a href="LuCI.Network.html#getSwitchTopologies">getSwitchTopologies</a></li>
332
333 <li data-name="LuCI.Network#getWAN6Networks"><a href="LuCI.Network.html#getWAN6Networks">getWAN6Networks</a></li>
334
335 <li data-name="LuCI.Network#getWANNetworks"><a href="LuCI.Network.html#getWANNetworks">getWANNetworks</a></li>
336
337 <li data-name="LuCI.Network#getWifiDevice"><a href="LuCI.Network.html#getWifiDevice">getWifiDevice</a></li>
338
339 <li data-name="LuCI.Network#getWifiDevices"><a href="LuCI.Network.html#getWifiDevices">getWifiDevices</a></li>
340
341 <li data-name="LuCI.Network#getWifiNetwork"><a href="LuCI.Network.html#getWifiNetwork">getWifiNetwork</a></li>
342
343 <li data-name="LuCI.Network#getWifiNetworks"><a href="LuCI.Network.html#getWifiNetworks">getWifiNetworks</a></li>
344
345 <li data-name="LuCI.Network#isIgnoredDevice"><a href="LuCI.Network.html#isIgnoredDevice">isIgnoredDevice</a></li>
346
347 <li data-name="LuCI.Network#maskToPrefix"><a href="LuCI.Network.html#maskToPrefix">maskToPrefix</a></li>
348
349 <li data-name="LuCI.Network#prefixToMask"><a href="LuCI.Network.html#prefixToMask">prefixToMask</a></li>
350
351 <li data-name="LuCI.Network#registerErrorCode"><a href="LuCI.Network.html#registerErrorCode">registerErrorCode</a></li>
352
353 <li data-name="LuCI.Network#registerPatternVirtual"><a href="LuCI.Network.html#registerPatternVirtual">registerPatternVirtual</a></li>
354
355 <li data-name="LuCI.Network#registerProtocol"><a href="LuCI.Network.html#registerProtocol">registerProtocol</a></li>
356
357 <li data-name="LuCI.Network#renameNetwork"><a href="LuCI.Network.html#renameNetwork">renameNetwork</a></li>
358
359 </ul>
360 <ul class="events itemMembers">
361
362 </ul>
363 </li>
364
365 <li class="item" data-name="LuCI.Network.Device">
366 <span class="title">
367 <a href="LuCI.Network.Device.html">LuCI.Network.Device</a>
368
369 </span>
370 <ul class="members itemMembers">
371
372 </ul>
373 <ul class="typedefs itemMembers">
374
375 </ul>
376 <ul class="typedefs itemMembers">
377
378 </ul>
379 <ul class="methods itemMembers">
380
381 <span class="subtitle">Methods</span>
382
383 <li data-name="LuCI.Network.Device#getBridgeID"><a href="LuCI.Network.Device.html#getBridgeID">getBridgeID</a></li>
384
385 <li data-name="LuCI.Network.Device#getBridgeSTP"><a href="LuCI.Network.Device.html#getBridgeSTP">getBridgeSTP</a></li>
386
387 <li data-name="LuCI.Network.Device#getI18n"><a href="LuCI.Network.Device.html#getI18n">getI18n</a></li>
388
389 <li data-name="LuCI.Network.Device#getIP6Addrs"><a href="LuCI.Network.Device.html#getIP6Addrs">getIP6Addrs</a></li>
390
391 <li data-name="LuCI.Network.Device#getIPAddrs"><a href="LuCI.Network.Device.html#getIPAddrs">getIPAddrs</a></li>
392
393 <li data-name="LuCI.Network.Device#getMAC"><a href="LuCI.Network.Device.html#getMAC">getMAC</a></li>
394
395 <li data-name="LuCI.Network.Device#getMTU"><a href="LuCI.Network.Device.html#getMTU">getMTU</a></li>
396
397 <li data-name="LuCI.Network.Device#getName"><a href="LuCI.Network.Device.html#getName">getName</a></li>
398
399 <li data-name="LuCI.Network.Device#getNetwork"><a href="LuCI.Network.Device.html#getNetwork">getNetwork</a></li>
400
401 <li data-name="LuCI.Network.Device#getNetworks"><a href="LuCI.Network.Device.html#getNetworks">getNetworks</a></li>
402
403 <li data-name="LuCI.Network.Device#getPorts"><a href="LuCI.Network.Device.html#getPorts">getPorts</a></li>
404
405 <li data-name="LuCI.Network.Device#getRXBytes"><a href="LuCI.Network.Device.html#getRXBytes">getRXBytes</a></li>
406
407 <li data-name="LuCI.Network.Device#getRXPackets"><a href="LuCI.Network.Device.html#getRXPackets">getRXPackets</a></li>
408
409 <li data-name="LuCI.Network.Device#getShortName"><a href="LuCI.Network.Device.html#getShortName">getShortName</a></li>
410
411 <li data-name="LuCI.Network.Device#getTXBytes"><a href="LuCI.Network.Device.html#getTXBytes">getTXBytes</a></li>
412
413 <li data-name="LuCI.Network.Device#getTXPackets"><a href="LuCI.Network.Device.html#getTXPackets">getTXPackets</a></li>
414
415 <li data-name="LuCI.Network.Device#getType"><a href="LuCI.Network.Device.html#getType">getType</a></li>
416
417 <li data-name="LuCI.Network.Device#getTypeI18n"><a href="LuCI.Network.Device.html#getTypeI18n">getTypeI18n</a></li>
418
419 <li data-name="LuCI.Network.Device#getWifiNetwork"><a href="LuCI.Network.Device.html#getWifiNetwork">getWifiNetwork</a></li>
420
421 <li data-name="LuCI.Network.Device#isBridge"><a href="LuCI.Network.Device.html#isBridge">isBridge</a></li>
422
423 <li data-name="LuCI.Network.Device#isBridgePort"><a href="LuCI.Network.Device.html#isBridgePort">isBridgePort</a></li>
424
425 <li data-name="LuCI.Network.Device#isUp"><a href="LuCI.Network.Device.html#isUp">isUp</a></li>
426
427 </ul>
428 <ul class="events itemMembers">
429
430 </ul>
431 </li>
432
433 <li class="item" data-name="LuCI.Network.Hosts">
434 <span class="title">
435 <a href="LuCI.Network.Hosts.html">LuCI.Network.Hosts</a>
436
437 </span>
438 <ul class="members itemMembers">
439
440 </ul>
441 <ul class="typedefs itemMembers">
442
443 </ul>
444 <ul class="typedefs itemMembers">
445
446 </ul>
447 <ul class="methods itemMembers">
448
449 <span class="subtitle">Methods</span>
450
451 <li data-name="LuCI.Network.Hosts#getHostnameByIP6Addr"><a href="LuCI.Network.Hosts.html#getHostnameByIP6Addr">getHostnameByIP6Addr</a></li>
452
453 <li data-name="LuCI.Network.Hosts#getHostnameByIPAddr"><a href="LuCI.Network.Hosts.html#getHostnameByIPAddr">getHostnameByIPAddr</a></li>
454
455 <li data-name="LuCI.Network.Hosts#getHostnameByMACAddr"><a href="LuCI.Network.Hosts.html#getHostnameByMACAddr">getHostnameByMACAddr</a></li>
456
457 <li data-name="LuCI.Network.Hosts#getIP6AddrByMACAddr"><a href="LuCI.Network.Hosts.html#getIP6AddrByMACAddr">getIP6AddrByMACAddr</a></li>
458
459 <li data-name="LuCI.Network.Hosts#getIPAddrByMACAddr"><a href="LuCI.Network.Hosts.html#getIPAddrByMACAddr">getIPAddrByMACAddr</a></li>
460
461 <li data-name="LuCI.Network.Hosts#getMACAddrByIP6Addr"><a href="LuCI.Network.Hosts.html#getMACAddrByIP6Addr">getMACAddrByIP6Addr</a></li>
462
463 <li data-name="LuCI.Network.Hosts#getMACAddrByIPAddr"><a href="LuCI.Network.Hosts.html#getMACAddrByIPAddr">getMACAddrByIPAddr</a></li>
464
465 <li data-name="LuCI.Network.Hosts#getMACHints"><a href="LuCI.Network.Hosts.html#getMACHints">getMACHints</a></li>
466
467 </ul>
468 <ul class="events itemMembers">
469
470 </ul>
471 </li>
472
473 <li class="item" data-name="LuCI.Network.Protocol">
474 <span class="title">
475 <a href="LuCI.Network.Protocol.html">LuCI.Network.Protocol</a>
476
477 </span>
478 <ul class="members itemMembers">
479
480 </ul>
481 <ul class="typedefs itemMembers">
482
483 </ul>
484 <ul class="typedefs itemMembers">
485
486 </ul>
487 <ul class="methods itemMembers">
488
489 <span class="subtitle">Methods</span>
490
491 <li data-name="LuCI.Network.Protocol#addDevice"><a href="LuCI.Network.Protocol.html#addDevice">addDevice</a></li>
492
493 <li data-name="LuCI.Network.Protocol#containsDevice"><a href="LuCI.Network.Protocol.html#containsDevice">containsDevice</a></li>
494
495 <li data-name="LuCI.Network.Protocol#deleteDevice"><a href="LuCI.Network.Protocol.html#deleteDevice">deleteDevice</a></li>
496
497 <li data-name="LuCI.Network.Protocol#get"><a href="LuCI.Network.Protocol.html#get">get</a></li>
498
499 <li data-name="LuCI.Network.Protocol#getDevice"><a href="LuCI.Network.Protocol.html#getDevice">getDevice</a></li>
500
501 <li data-name="LuCI.Network.Protocol#getDevices"><a href="LuCI.Network.Protocol.html#getDevices">getDevices</a></li>
502
503 <li data-name="LuCI.Network.Protocol#getDNS6Addrs"><a href="LuCI.Network.Protocol.html#getDNS6Addrs">getDNS6Addrs</a></li>
504
505 <li data-name="LuCI.Network.Protocol#getDNSAddrs"><a href="LuCI.Network.Protocol.html#getDNSAddrs">getDNSAddrs</a></li>
506
507 <li data-name="LuCI.Network.Protocol#getErrors"><a href="LuCI.Network.Protocol.html#getErrors">getErrors</a></li>
508
509 <li data-name="LuCI.Network.Protocol#getExpiry"><a href="LuCI.Network.Protocol.html#getExpiry">getExpiry</a></li>
510
511 <li data-name="LuCI.Network.Protocol#getGateway6Addr"><a href="LuCI.Network.Protocol.html#getGateway6Addr">getGateway6Addr</a></li>
512
513 <li data-name="LuCI.Network.Protocol#getGatewayAddr"><a href="LuCI.Network.Protocol.html#getGatewayAddr">getGatewayAddr</a></li>
514
515 <li data-name="LuCI.Network.Protocol#getI18n"><a href="LuCI.Network.Protocol.html#getI18n">getI18n</a></li>
516
517 <li data-name="LuCI.Network.Protocol#getIfname"><a href="LuCI.Network.Protocol.html#getIfname">getIfname</a></li>
518
519 <li data-name="LuCI.Network.Protocol#getIP6Addr"><a href="LuCI.Network.Protocol.html#getIP6Addr">getIP6Addr</a></li>
520
521 <li data-name="LuCI.Network.Protocol#getIP6Addrs"><a href="LuCI.Network.Protocol.html#getIP6Addrs">getIP6Addrs</a></li>
522
523 <li data-name="LuCI.Network.Protocol#getIP6Prefix"><a href="LuCI.Network.Protocol.html#getIP6Prefix">getIP6Prefix</a></li>
524
525 <li data-name="LuCI.Network.Protocol#getIPAddr"><a href="LuCI.Network.Protocol.html#getIPAddr">getIPAddr</a></li>
526
527 <li data-name="LuCI.Network.Protocol#getIPAddrs"><a href="LuCI.Network.Protocol.html#getIPAddrs">getIPAddrs</a></li>
528
529 <li data-name="LuCI.Network.Protocol#getL2Device"><a href="LuCI.Network.Protocol.html#getL2Device">getL2Device</a></li>
530
531 <li data-name="LuCI.Network.Protocol#getL3Device"><a href="LuCI.Network.Protocol.html#getL3Device">getL3Device</a></li>
532
533 <li data-name="LuCI.Network.Protocol#getMetric"><a href="LuCI.Network.Protocol.html#getMetric">getMetric</a></li>
534
535 <li data-name="LuCI.Network.Protocol#getName"><a href="LuCI.Network.Protocol.html#getName">getName</a></li>
536
537 <li data-name="LuCI.Network.Protocol#getNetmask"><a href="LuCI.Network.Protocol.html#getNetmask">getNetmask</a></li>
538
539 <li data-name="LuCI.Network.Protocol#getOpkgPackage"><a href="LuCI.Network.Protocol.html#getOpkgPackage">getOpkgPackage</a></li>
540
541 <li data-name="LuCI.Network.Protocol#getProtocol"><a href="LuCI.Network.Protocol.html#getProtocol">getProtocol</a></li>
542
543 <li data-name="LuCI.Network.Protocol#getType"><a href="LuCI.Network.Protocol.html#getType">getType</a></li>
544
545 <li data-name="LuCI.Network.Protocol#getUptime"><a href="LuCI.Network.Protocol.html#getUptime">getUptime</a></li>
546
547 <li data-name="LuCI.Network.Protocol#getZoneName"><a href="LuCI.Network.Protocol.html#getZoneName">getZoneName</a></li>
548
549 <li data-name="LuCI.Network.Protocol#isAlias"><a href="LuCI.Network.Protocol.html#isAlias">isAlias</a></li>
550
551 <li data-name="LuCI.Network.Protocol#isBridge"><a href="LuCI.Network.Protocol.html#isBridge">isBridge</a></li>
552
553 <li data-name="LuCI.Network.Protocol#isDynamic"><a href="LuCI.Network.Protocol.html#isDynamic">isDynamic</a></li>
554
555 <li data-name="LuCI.Network.Protocol#isEmpty"><a href="LuCI.Network.Protocol.html#isEmpty">isEmpty</a></li>
556
557 <li data-name="LuCI.Network.Protocol#isFloating"><a href="LuCI.Network.Protocol.html#isFloating">isFloating</a></li>
558
559 <li data-name="LuCI.Network.Protocol#isInstalled"><a href="LuCI.Network.Protocol.html#isInstalled">isInstalled</a></li>
560
561 <li data-name="LuCI.Network.Protocol#isUp"><a href="LuCI.Network.Protocol.html#isUp">isUp</a></li>
562
563 <li data-name="LuCI.Network.Protocol#isVirtual"><a href="LuCI.Network.Protocol.html#isVirtual">isVirtual</a></li>
564
565 <li data-name="LuCI.Network.Protocol#set"><a href="LuCI.Network.Protocol.html#set">set</a></li>
566
567 </ul>
568 <ul class="events itemMembers">
569
570 </ul>
571 </li>
572
573 <li class="item" data-name="LuCI.Network.WifiDevice">
574 <span class="title">
575 <a href="LuCI.Network.WifiDevice.html">LuCI.Network.WifiDevice</a>
576
577 </span>
578 <ul class="members itemMembers">
579
580 </ul>
581 <ul class="typedefs itemMembers">
582
583 </ul>
584 <ul class="typedefs itemMembers">
585
586 </ul>
587 <ul class="methods itemMembers">
588
589 <span class="subtitle">Methods</span>
590
591 <li data-name="LuCI.Network.WifiDevice#addWifiNetwork"><a href="LuCI.Network.WifiDevice.html#addWifiNetwork">addWifiNetwork</a></li>
592
593 <li data-name="LuCI.Network.WifiDevice#deleteWifiNetwork"><a href="LuCI.Network.WifiDevice.html#deleteWifiNetwork">deleteWifiNetwork</a></li>
594
595 <li data-name="LuCI.Network.WifiDevice#get"><a href="LuCI.Network.WifiDevice.html#get">get</a></li>
596
597 <li data-name="LuCI.Network.WifiDevice#getHTModes"><a href="LuCI.Network.WifiDevice.html#getHTModes">getHTModes</a></li>
598
599 <li data-name="LuCI.Network.WifiDevice#getHWModes"><a href="LuCI.Network.WifiDevice.html#getHWModes">getHWModes</a></li>
600
601 <li data-name="LuCI.Network.WifiDevice#getI18n"><a href="LuCI.Network.WifiDevice.html#getI18n">getI18n</a></li>
602
603 <li data-name="LuCI.Network.WifiDevice#getName"><a href="LuCI.Network.WifiDevice.html#getName">getName</a></li>
604
605 <li data-name="LuCI.Network.WifiDevice#getScanList"><a href="LuCI.Network.WifiDevice.html#getScanList">getScanList</a></li>
606
607 <li data-name="LuCI.Network.WifiDevice#getWifiNetwork"><a href="LuCI.Network.WifiDevice.html#getWifiNetwork">getWifiNetwork</a></li>
608
609 <li data-name="LuCI.Network.WifiDevice#getWifiNetworks"><a href="LuCI.Network.WifiDevice.html#getWifiNetworks">getWifiNetworks</a></li>
610
611 <li data-name="LuCI.Network.WifiDevice#isDisabled"><a href="LuCI.Network.WifiDevice.html#isDisabled">isDisabled</a></li>
612
613 <li data-name="LuCI.Network.WifiDevice#isUp"><a href="LuCI.Network.WifiDevice.html#isUp">isUp</a></li>
614
615 <li data-name="LuCI.Network.WifiDevice#set"><a href="LuCI.Network.WifiDevice.html#set">set</a></li>
616
617 </ul>
618 <ul class="events itemMembers">
619
620 </ul>
621 </li>
622
623 <li class="item" data-name="LuCI.Network.WifiNetwork">
624 <span class="title">
625 <a href="LuCI.Network.WifiNetwork.html">LuCI.Network.WifiNetwork</a>
626
627 </span>
628 <ul class="members itemMembers">
629
630 </ul>
631 <ul class="typedefs itemMembers">
632
633 </ul>
634 <ul class="typedefs itemMembers">
635
636 </ul>
637 <ul class="methods itemMembers">
638
639 <span class="subtitle">Methods</span>
640
641 <li data-name="LuCI.Network.WifiNetwork#disconnectClient"><a href="LuCI.Network.WifiNetwork.html#disconnectClient">disconnectClient</a></li>
642
643 <li data-name="LuCI.Network.WifiNetwork#get"><a href="LuCI.Network.WifiNetwork.html#get">get</a></li>
644
645 <li data-name="LuCI.Network.WifiNetwork#getActiveBSSID"><a href="LuCI.Network.WifiNetwork.html#getActiveBSSID">getActiveBSSID</a></li>
646
647 <li data-name="LuCI.Network.WifiNetwork#getActiveEncryption"><a href="LuCI.Network.WifiNetwork.html#getActiveEncryption">getActiveEncryption</a></li>
648
649 <li data-name="LuCI.Network.WifiNetwork#getActiveMode"><a href="LuCI.Network.WifiNetwork.html#getActiveMode">getActiveMode</a></li>
650
651 <li data-name="LuCI.Network.WifiNetwork#getActiveModeI18n"><a href="LuCI.Network.WifiNetwork.html#getActiveModeI18n">getActiveModeI18n</a></li>
652
653 <li data-name="LuCI.Network.WifiNetwork#getActiveSSID"><a href="LuCI.Network.WifiNetwork.html#getActiveSSID">getActiveSSID</a></li>
654
655 <li data-name="LuCI.Network.WifiNetwork#getAssocList"><a href="LuCI.Network.WifiNetwork.html#getAssocList">getAssocList</a></li>
656
657 <li data-name="LuCI.Network.WifiNetwork#getBitRate"><a href="LuCI.Network.WifiNetwork.html#getBitRate">getBitRate</a></li>
658
659 <li data-name="LuCI.Network.WifiNetwork#getBSSID"><a href="LuCI.Network.WifiNetwork.html#getBSSID">getBSSID</a></li>
660
661 <li data-name="LuCI.Network.WifiNetwork#getChannel"><a href="LuCI.Network.WifiNetwork.html#getChannel">getChannel</a></li>
662
663 <li data-name="LuCI.Network.WifiNetwork#getCountryCode"><a href="LuCI.Network.WifiNetwork.html#getCountryCode">getCountryCode</a></li>
664
665 <li data-name="LuCI.Network.WifiNetwork#getDevice"><a href="LuCI.Network.WifiNetwork.html#getDevice">getDevice</a></li>
666
667 <li data-name="LuCI.Network.WifiNetwork#getFrequency"><a href="LuCI.Network.WifiNetwork.html#getFrequency">getFrequency</a></li>
668
669 <li data-name="LuCI.Network.WifiNetwork#getI18n"><a href="LuCI.Network.WifiNetwork.html#getI18n">getI18n</a></li>
670
671 <li data-name="LuCI.Network.WifiNetwork#getID"><a href="LuCI.Network.WifiNetwork.html#getID">getID</a></li>
672
673 <li data-name="LuCI.Network.WifiNetwork#getIfname"><a href="LuCI.Network.WifiNetwork.html#getIfname">getIfname</a></li>
674
675 <li data-name="LuCI.Network.WifiNetwork#getMeshID"><a href="LuCI.Network.WifiNetwork.html#getMeshID">getMeshID</a></li>
676
677 <li data-name="LuCI.Network.WifiNetwork#getMode"><a href="LuCI.Network.WifiNetwork.html#getMode">getMode</a></li>
678
679 <li data-name="LuCI.Network.WifiNetwork#getName"><a href="LuCI.Network.WifiNetwork.html#getName">getName</a></li>
680
681 <li data-name="LuCI.Network.WifiNetwork#getNetwork"><a href="LuCI.Network.WifiNetwork.html#getNetwork">getNetwork</a></li>
682
683 <li data-name="LuCI.Network.WifiNetwork#getNetworkNames"><a href="LuCI.Network.WifiNetwork.html#getNetworkNames">getNetworkNames</a></li>
684
685 <li data-name="LuCI.Network.WifiNetwork#getNetworks"><a href="LuCI.Network.WifiNetwork.html#getNetworks">getNetworks</a></li>
686
687 <li data-name="LuCI.Network.WifiNetwork#getNoise"><a href="LuCI.Network.WifiNetwork.html#getNoise">getNoise</a></li>
688
689 <li data-name="LuCI.Network.WifiNetwork#getShortName"><a href="LuCI.Network.WifiNetwork.html#getShortName">getShortName</a></li>
690
691 <li data-name="LuCI.Network.WifiNetwork#getSignal"><a href="LuCI.Network.WifiNetwork.html#getSignal">getSignal</a></li>
692
693 <li data-name="LuCI.Network.WifiNetwork#getSignalLevel"><a href="LuCI.Network.WifiNetwork.html#getSignalLevel">getSignalLevel</a></li>
694
695 <li data-name="LuCI.Network.WifiNetwork#getSignalPercent"><a href="LuCI.Network.WifiNetwork.html#getSignalPercent">getSignalPercent</a></li>
696
697 <li data-name="LuCI.Network.WifiNetwork#getSSID"><a href="LuCI.Network.WifiNetwork.html#getSSID">getSSID</a></li>
698
699 <li data-name="LuCI.Network.WifiNetwork#getTXPower"><a href="LuCI.Network.WifiNetwork.html#getTXPower">getTXPower</a></li>
700
701 <li data-name="LuCI.Network.WifiNetwork#getTXPowerOffset"><a href="LuCI.Network.WifiNetwork.html#getTXPowerOffset">getTXPowerOffset</a></li>
702
703 <li data-name="LuCI.Network.WifiNetwork#getWifiDevice"><a href="LuCI.Network.WifiNetwork.html#getWifiDevice">getWifiDevice</a></li>
704
705 <li data-name="LuCI.Network.WifiNetwork#getWifiDeviceName"><a href="LuCI.Network.WifiNetwork.html#getWifiDeviceName">getWifiDeviceName</a></li>
706
707 <li data-name="LuCI.Network.WifiNetwork#isClientDisconnectSupported"><a href="LuCI.Network.WifiNetwork.html#isClientDisconnectSupported">isClientDisconnectSupported</a></li>
708
709 <li data-name="LuCI.Network.WifiNetwork#isDisabled"><a href="LuCI.Network.WifiNetwork.html#isDisabled">isDisabled</a></li>
710
711 <li data-name="LuCI.Network.WifiNetwork#isUp"><a href="LuCI.Network.WifiNetwork.html#isUp">isUp</a></li>
712
713 <li data-name="LuCI.Network.WifiNetwork#set"><a href="LuCI.Network.WifiNetwork.html#set">set</a></li>
714
715 </ul>
716 <ul class="events itemMembers">
717
718 </ul>
719 </li>
720
721 <li class="item" data-name="LuCI.Poll">
722 <span class="title">
723 <a href="LuCI.Poll.html">LuCI.Poll</a>
724
725 </span>
726 <ul class="members itemMembers">
727
728 </ul>
729 <ul class="typedefs itemMembers">
730
731 </ul>
732 <ul class="typedefs itemMembers">
733
734 </ul>
735 <ul class="methods itemMembers">
736
737 <span class="subtitle">Methods</span>
738
739 <li data-name="LuCI.Poll#active"><a href="LuCI.Poll.html#active">active</a></li>
740
741 <li data-name="LuCI.Poll#add"><a href="LuCI.Poll.html#add">add</a></li>
742
743 <li data-name="LuCI.Poll#remove"><a href="LuCI.Poll.html#remove">remove</a></li>
744
745 <li data-name="LuCI.Poll#start"><a href="LuCI.Poll.html#start">start</a></li>
746
747 <li data-name="LuCI.Poll#stop"><a href="LuCI.Poll.html#stop">stop</a></li>
748
749 </ul>
750 <ul class="events itemMembers">
751
752 </ul>
753 </li>
754
755 <li class="item" data-name="LuCI.Request">
756 <span class="title">
757 <a href="LuCI.Request.html">LuCI.Request</a>
758
759 </span>
760 <ul class="members itemMembers">
761
762 </ul>
763 <ul class="typedefs itemMembers">
764
765 <span class="subtitle">Typedefs</span>
766
767 <li data-name="LuCI.Request.interceptorFn"><a href="LuCI.Request.html#.interceptorFn">interceptorFn</a></li>
768
769 <li data-name="LuCI.Request.RequestOptions"><a href="LuCI.Request.html#.RequestOptions">RequestOptions</a></li>
770
771 </ul>
772 <ul class="typedefs itemMembers">
773
774 </ul>
775 <ul class="methods itemMembers">
776
777 <span class="subtitle">Methods</span>
778
779 <li data-name="LuCI.Request#addInterceptor"><a href="LuCI.Request.html#addInterceptor">addInterceptor</a></li>
780
781 <li data-name="LuCI.Request#expandURL"><a href="LuCI.Request.html#expandURL">expandURL</a></li>
782
783 <li data-name="LuCI.Request#get"><a href="LuCI.Request.html#get">get</a></li>
784
785 <li data-name="LuCI.Request#post"><a href="LuCI.Request.html#post">post</a></li>
786
787 <li data-name="LuCI.Request#removeInterceptor"><a href="LuCI.Request.html#removeInterceptor">removeInterceptor</a></li>
788
789 <li data-name="LuCI.Request#request"><a href="LuCI.Request.html#request">request</a></li>
790
791 </ul>
792 <ul class="events itemMembers">
793
794 </ul>
795 </li>
796
797 <li class="item" data-name="LuCI.Request.poll">
798 <span class="title">
799 <a href="LuCI.Request.poll.html">LuCI.Request.poll</a>
800
801 </span>
802 <ul class="members itemMembers">
803
804 </ul>
805 <ul class="typedefs itemMembers">
806
807 <span class="subtitle">Typedefs</span>
808
809 <li data-name="LuCI.Request.poll~callbackFn"><a href="LuCI.Request.poll.html#~callbackFn">callbackFn</a></li>
810
811 </ul>
812 <ul class="typedefs itemMembers">
813
814 </ul>
815 <ul class="methods itemMembers">
816
817 <span class="subtitle">Methods</span>
818
819 <li data-name="LuCI.Request.poll#active"><a href="LuCI.Request.poll.html#active">active</a></li>
820
821 <li data-name="LuCI.Request.poll#add"><a href="LuCI.Request.poll.html#add">add</a></li>
822
823 <li data-name="LuCI.Request.poll#remove"><a href="LuCI.Request.poll.html#remove">remove</a></li>
824
825 <li data-name="LuCI.Request.poll#start"><a href="LuCI.Request.poll.html#start">start</a></li>
826
827 <li data-name="LuCI.Request.poll#stop"><a href="LuCI.Request.poll.html#stop">stop</a></li>
828
829 </ul>
830 <ul class="events itemMembers">
831
832 </ul>
833 </li>
834
835 <li class="item" data-name="LuCI.Response">
836 <span class="title">
837 <a href="LuCI.Response.html">LuCI.Response</a>
838
839 </span>
840 <ul class="members itemMembers">
841
842 <span class="subtitle">Members</span>
843
844 <li data-name="LuCI.Response#duration"><a href="LuCI.Response.html#duration">duration</a></li>
845
846 <li data-name="LuCI.Response#headers"><a href="LuCI.Response.html#headers">headers</a></li>
847
848 <li data-name="LuCI.Response#ok"><a href="LuCI.Response.html#ok">ok</a></li>
849
850 <li data-name="LuCI.Response#status"><a href="LuCI.Response.html#status">status</a></li>
851
852 <li data-name="LuCI.Response#statusText"><a href="LuCI.Response.html#statusText">statusText</a></li>
853
854 <li data-name="LuCI.Response#url"><a href="LuCI.Response.html#url">url</a></li>
855
856 </ul>
857 <ul class="typedefs itemMembers">
858
859 </ul>
860 <ul class="typedefs itemMembers">
861
862 </ul>
863 <ul class="methods itemMembers">
864
865 <span class="subtitle">Methods</span>
866
867 <li data-name="LuCI.Response#clone"><a href="LuCI.Response.html#clone">clone</a></li>
868
869 <li data-name="LuCI.Response#json"><a href="LuCI.Response.html#json">json</a></li>
870
871 <li data-name="LuCI.Response#text"><a href="LuCI.Response.html#text">text</a></li>
872
873 </ul>
874 <ul class="events itemMembers">
875
876 </ul>
877 </li>
878
879 <li class="item" data-name="LuCI.rpc">
880 <span class="title">
881 <a href="LuCI.rpc.html">LuCI.rpc</a>
882
883 </span>
884 <ul class="members itemMembers">
885
886 </ul>
887 <ul class="typedefs itemMembers">
888
889 <span class="subtitle">Typedefs</span>
890
891 <li data-name="LuCI.rpc.DeclareOptions"><a href="LuCI.rpc.html#.DeclareOptions">DeclareOptions</a></li>
892
893 <li data-name="LuCI.rpc~filterFn"><a href="LuCI.rpc.html#~filterFn">filterFn</a></li>
894
895 <li data-name="LuCI.rpc~interceptorFn"><a href="LuCI.rpc.html#~interceptorFn">interceptorFn</a></li>
896
897 <li data-name="LuCI.rpc~invokeFn"><a href="LuCI.rpc.html#~invokeFn">invokeFn</a></li>
898
899 </ul>
900 <ul class="typedefs itemMembers">
901
902 </ul>
903 <ul class="methods itemMembers">
904
905 <span class="subtitle">Methods</span>
906
907 <li data-name="LuCI.rpc#addInterceptor"><a href="LuCI.rpc.html#addInterceptor">addInterceptor</a></li>
908
909 <li data-name="LuCI.rpc#declare"><a href="LuCI.rpc.html#declare">declare</a></li>
910
911 <li data-name="LuCI.rpc#getBaseURL"><a href="LuCI.rpc.html#getBaseURL">getBaseURL</a></li>
912
913 <li data-name="LuCI.rpc#getSessionID"><a href="LuCI.rpc.html#getSessionID">getSessionID</a></li>
914
915 <li data-name="LuCI.rpc#getStatusText"><a href="LuCI.rpc.html#getStatusText">getStatusText</a></li>
916
917 <li data-name="LuCI.rpc#list"><a href="LuCI.rpc.html#list">list</a></li>
918
919 <li data-name="LuCI.rpc#removeInterceptor"><a href="LuCI.rpc.html#removeInterceptor">removeInterceptor</a></li>
920
921 <li data-name="LuCI.rpc#setBaseURL"><a href="LuCI.rpc.html#setBaseURL">setBaseURL</a></li>
922
923 <li data-name="LuCI.rpc#setSessionID"><a href="LuCI.rpc.html#setSessionID">setSessionID</a></li>
924
925 </ul>
926 <ul class="events itemMembers">
927
928 </ul>
929 </li>
930
931 <li class="item" data-name="LuCI.uci">
932 <span class="title">
933 <a href="LuCI.uci.html">LuCI.uci</a>
934
935 </span>
936 <ul class="members itemMembers">
937
938 </ul>
939 <ul class="typedefs itemMembers">
940
941 <span class="subtitle">Typedefs</span>
942
943 <li data-name="LuCI.uci.ChangeRecord"><a href="LuCI.uci.html#.ChangeRecord">ChangeRecord</a></li>
944
945 <li data-name="LuCI.uci.SectionObject"><a href="LuCI.uci.html#.SectionObject">SectionObject</a></li>
946
947 <li data-name="LuCI.uci~sectionsFn"><a href="LuCI.uci.html#~sectionsFn">sectionsFn</a></li>
948
949 </ul>
950 <ul class="typedefs itemMembers">
951
952 </ul>
953 <ul class="methods itemMembers">
954
955 <span class="subtitle">Methods</span>
956
957 <li data-name="LuCI.uci#add"><a href="LuCI.uci.html#add">add</a></li>
958
959 <li data-name="LuCI.uci#apply"><a href="LuCI.uci.html#apply">apply</a></li>
960
961 <li data-name="LuCI.uci#changes"><a href="LuCI.uci.html#changes">changes</a></li>
962
963 <li data-name="LuCI.uci#createSID"><a href="LuCI.uci.html#createSID">createSID</a></li>
964
965 <li data-name="LuCI.uci#get"><a href="LuCI.uci.html#get">get</a></li>
966
967 <li data-name="LuCI.uci#get_first"><a href="LuCI.uci.html#get_first">get_first</a></li>
968
969 <li data-name="LuCI.uci#load"><a href="LuCI.uci.html#load">load</a></li>
970
971 <li data-name="LuCI.uci#move"><a href="LuCI.uci.html#move">move</a></li>
972
973 <li data-name="LuCI.uci#remove"><a href="LuCI.uci.html#remove">remove</a></li>
974
975 <li data-name="LuCI.uci#resolveSID"><a href="LuCI.uci.html#resolveSID">resolveSID</a></li>
976
977 <li data-name="LuCI.uci#save"><a href="LuCI.uci.html#save">save</a></li>
978
979 <li data-name="LuCI.uci#sections"><a href="LuCI.uci.html#sections">sections</a></li>
980
981 <li data-name="LuCI.uci#set"><a href="LuCI.uci.html#set">set</a></li>
982
983 <li data-name="LuCI.uci#set_first"><a href="LuCI.uci.html#set_first">set_first</a></li>
984
985 <li data-name="LuCI.uci#unload"><a href="LuCI.uci.html#unload">unload</a></li>
986
987 <li data-name="LuCI.uci#unset"><a href="LuCI.uci.html#unset">unset</a></li>
988
989 <li data-name="LuCI.uci#unset_first"><a href="LuCI.uci.html#unset_first">unset_first</a></li>
990
991 </ul>
992 <ul class="events itemMembers">
993
994 </ul>
995 </li>
996
997 <li class="item" data-name="LuCI.view">
998 <span class="title">
999 <a href="LuCI.view.html">LuCI.view</a>
1000
1001 </span>
1002 <ul class="members itemMembers">
1003
1004 </ul>
1005 <ul class="typedefs itemMembers">
1006
1007 </ul>
1008 <ul class="typedefs itemMembers">
1009
1010 </ul>
1011 <ul class="methods itemMembers">
1012
1013 <span class="subtitle">Methods</span>
1014
1015 <li data-name="LuCI.view#addFooter"><a href="LuCI.view.html#addFooter">addFooter</a></li>
1016
1017 <li data-name="LuCI.view#handleReset"><a href="LuCI.view.html#handleReset">handleReset</a></li>
1018
1019 <li data-name="LuCI.view#handleSave"><a href="LuCI.view.html#handleSave">handleSave</a></li>
1020
1021 <li data-name="LuCI.view#handleSaveApply"><a href="LuCI.view.html#handleSaveApply">handleSaveApply</a></li>
1022
1023 <li data-name="LuCI.view#load"><a href="LuCI.view.html#load">load</a></li>
1024
1025 <li data-name="LuCI.view#render"><a href="LuCI.view.html#render">render</a></li>
1026
1027 </ul>
1028 <ul class="events itemMembers">
1029
1030 </ul>
1031 </li>
1032
1033 <li class="item" data-name="LuCI.XHR">
1034 <span class="title">
1035 <a href="LuCI.XHR.html">LuCI.XHR</a>
1036
1037 </span>
1038 <ul class="members itemMembers">
1039
1040 </ul>
1041 <ul class="typedefs itemMembers">
1042
1043 </ul>
1044 <ul class="typedefs itemMembers">
1045
1046 </ul>
1047 <ul class="methods itemMembers">
1048
1049 <span class="subtitle">Methods</span>
1050
1051 <li data-name="LuCI.XHR#abort"><a href="LuCI.XHR.html#abort">abort</a></li>
1052
1053 <li data-name="LuCI.XHR#busy"><a href="LuCI.XHR.html#busy">busy</a></li>
1054
1055 <li data-name="LuCI.XHR#cancel"><a href="LuCI.XHR.html#cancel">cancel</a></li>
1056
1057 <li data-name="LuCI.XHR#get"><a href="LuCI.XHR.html#get">get</a></li>
1058
1059 <li data-name="LuCI.XHR#post"><a href="LuCI.XHR.html#post">post</a></li>
1060
1061 <li data-name="LuCI.XHR#send_form"><a href="LuCI.XHR.html#send_form">send_form</a></li>
1062
1063 </ul>
1064 <ul class="events itemMembers">
1065
1066 </ul>
1067 </li>
1068
1069 </ul>
1070 </div>
1071 <div class="main">
1072 <h1 class="page-title" data-filename="luci.js.html">Source: luci.js</h1>
1073
1074
1075
1076
1077 <section>
1078 <article>
1079 <pre id="source-code" class="prettyprint source "><code>/**
1080 * @class LuCI
1081 * @classdesc
1082 *
1083 * This is the LuCI base class. It is automatically instantiated and
1084 * accessible using the global `L` variable.
1085 *
1086 * @param {Object} env
1087 * The environment settings to use for the LuCI runtime.
1088 */
1089
1090 (function(window, document, undefined) {
1091 'use strict';
1092
1093 /* Object.assign polyfill for IE */
1094 if (typeof Object.assign !== 'function') {
1095 Object.defineProperty(Object, 'assign', {
1096 value: function assign(target, varArgs) {
1097 if (target == null)
1098 throw new TypeError('Cannot convert undefined or null to object');
1099
1100 var to = Object(target);
1101
1102 for (var index = 1; index &lt; arguments.length; index++)
1103 if (arguments[index] != null)
1104 for (var nextKey in arguments[index])
1105 if (Object.prototype.hasOwnProperty.call(arguments[index], nextKey))
1106 to[nextKey] = arguments[index][nextKey];
1107
1108 return to;
1109 },
1110 writable: true,
1111 configurable: true
1112 });
1113 }
1114
1115 /* Promise.finally polyfill */
1116 if (typeof Promise.prototype.finally !== 'function') {
1117 Promise.prototype.finally = function(fn) {
1118 var onFinally = function(cb) {
1119 return Promise.resolve(fn.call(this)).then(cb);
1120 };
1121
1122 return this.then(
1123 function(result) { return onFinally.call(this, function() { return result }) },
1124 function(reason) { return onFinally.call(this, function() { return Promise.reject(reason) }) }
1125 );
1126 };
1127 }
1128
1129 /*
1130 * Class declaration and inheritance helper
1131 */
1132
1133 var toCamelCase = function(s) {
1134 return s.replace(/(?:^|[\. -])(.)/g, function(m0, m1) { return m1.toUpperCase() });
1135 };
1136
1137 /**
1138 * @class Class
1139 * @hideconstructor
1140 * @memberof LuCI
1141 * @classdesc
1142 *
1143 * `LuCI.Class` is the abstract base class all LuCI classes inherit from.
1144 *
1145 * It provides simple means to create subclasses of given classes and
1146 * implements prototypal inheritance.
1147 */
1148 var superContext = null, Class = Object.assign(function() {}, {
1149 /**
1150 * Extends this base class with the properties described in
1151 * `properties` and returns a new subclassed Class instance
1152 *
1153 * @memberof LuCI.Class
1154 *
1155 * @param {Object&lt;string, *>} properties
1156 * An object describing the properties to add to the new
1157 * subclass.
1158 *
1159 * @returns {LuCI.Class}
1160 * Returns a new LuCI.Class sublassed from this class, extended
1161 * by the given properties and with its prototype set to this base
1162 * class to enable inheritance. The resulting value represents a
1163 * class constructor and can be instantiated with `new`.
1164 */
1165 extend: function(properties) {
1166 var props = {
1167 __base__: { value: this.prototype },
1168 __name__: { value: properties.__name__ || 'anonymous' }
1169 };
1170
1171 var ClassConstructor = function() {
1172 if (!(this instanceof ClassConstructor))
1173 throw new TypeError('Constructor must not be called without "new"');
1174
1175 if (Object.getPrototypeOf(this).hasOwnProperty('__init__')) {
1176 if (typeof(this.__init__) != 'function')
1177 throw new TypeError('Class __init__ member is not a function');
1178
1179 this.__init__.apply(this, arguments)
1180 }
1181 else {
1182 this.super('__init__', arguments);
1183 }
1184 };
1185
1186 for (var key in properties)
1187 if (!props[key] &amp;&amp; properties.hasOwnProperty(key))
1188 props[key] = { value: properties[key], writable: true };
1189
1190 ClassConstructor.prototype = Object.create(this.prototype, props);
1191 ClassConstructor.prototype.constructor = ClassConstructor;
1192 Object.assign(ClassConstructor, this);
1193 ClassConstructor.displayName = toCamelCase(props.__name__.value + 'Class');
1194
1195 return ClassConstructor;
1196 },
1197
1198 /**
1199 * Extends this base class with the properties described in
1200 * `properties`, instantiates the resulting subclass using
1201 * the additional optional arguments passed to this function
1202 * and returns the resulting subclassed Class instance.
1203 *
1204 * This function serves as a convenience shortcut for
1205 * {@link LuCI.Class.extend Class.extend()} and subsequent
1206 * `new`.
1207 *
1208 * @memberof LuCI.Class
1209 *
1210 * @param {Object&lt;string, *>} properties
1211 * An object describing the properties to add to the new
1212 * subclass.
1213 *
1214 * @param {...*} [new_args]
1215 * Specifies arguments to be passed to the subclass constructor
1216 * as-is in order to instantiate the new subclass.
1217 *
1218 * @returns {LuCI.Class}
1219 * Returns a new LuCI.Class instance extended by the given
1220 * properties with its prototype set to this base class to
1221 * enable inheritance.
1222 */
1223 singleton: function(properties /*, ... */) {
1224 return Class.extend(properties)
1225 .instantiate(Class.prototype.varargs(arguments, 1));
1226 },
1227
1228 /**
1229 * Calls the class constructor using `new` with the given argument
1230 * array being passed as variadic parameters to the constructor.
1231 *
1232 * @memberof LuCI.Class
1233 *
1234 * @param {Array&lt;*>} params
1235 * An array of arbitrary values which will be passed as arguments
1236 * to the constructor function.
1237 *
1238 * @param {...*} [new_args]
1239 * Specifies arguments to be passed to the subclass constructor
1240 * as-is in order to instantiate the new subclass.
1241 *
1242 * @returns {LuCI.Class}
1243 * Returns a new LuCI.Class instance extended by the given
1244 * properties with its prototype set to this base class to
1245 * enable inheritance.
1246 */
1247 instantiate: function(args) {
1248 return new (Function.prototype.bind.apply(this,
1249 Class.prototype.varargs(args, 0, null)))();
1250 },
1251
1252 /* unused */
1253 call: function(self, method) {
1254 if (typeof(this.prototype[method]) != 'function')
1255 throw new ReferenceError(method + ' is not defined in class');
1256
1257 return this.prototype[method].apply(self, self.varargs(arguments, 1));
1258 },
1259
1260 /**
1261 * Checks whether the given class value is a subclass of this class.
1262 *
1263 * @memberof LuCI.Class
1264 *
1265 * @param {LuCI.Class} classValue
1266 * The class object to test.
1267 *
1268 * @returns {boolean}
1269 * Returns `true` when the given `classValue` is a subclass of this
1270 * class or `false` if the given value is not a valid class or not
1271 * a subclass of this class'.
1272 */
1273 isSubclass: function(classValue) {
1274 return (classValue != null &amp;&amp;
1275 typeof(classValue) == 'function' &amp;&amp;
1276 classValue.prototype instanceof this);
1277 },
1278
1279 prototype: {
1280 /**
1281 * Extract all values from the given argument array beginning from
1282 * `offset` and prepend any further given optional parameters to
1283 * the beginning of the resulting array copy.
1284 *
1285 * @memberof LuCI.Class
1286 * @instance
1287 *
1288 * @param {Array&lt;*>} args
1289 * The array to extract the values from.
1290 *
1291 * @param {number} offset
1292 * The offset from which to extract the values. An offset of `0`
1293 * would copy all values till the end.
1294 *
1295 * @param {...*} [extra_args]
1296 * Extra arguments to add to prepend to the resultung array.
1297 *
1298 * @returns {Array&lt;*>}
1299 * Returns a new array consisting of the optional extra arguments
1300 * and the values extracted from the `args` array beginning with
1301 * `offset`.
1302 */
1303 varargs: function(args, offset /*, ... */) {
1304 return Array.prototype.slice.call(arguments, 2)
1305 .concat(Array.prototype.slice.call(args, offset));
1306 },
1307
1308 /**
1309 * Walks up the parent class chain and looks for a class member
1310 * called `key` in any of the parent classes this class inherits
1311 * from. Returns the member value of the superclass or calls the
1312 * member as function and returns its return value when the
1313 * optional `callArgs` array is given.
1314 *
1315 * This function has two signatures and is sensitive to the
1316 * amount of arguments passed to it:
1317 * - `super('key')` -
1318 * Returns the value of `key` when found within one of the
1319 * parent classes.
1320 * - `super('key', ['arg1', 'arg2'])` -
1321 * Calls the `key()` method with parameters `arg1` and `arg2`
1322 * when found within one of the parent classes.
1323 *
1324 * @memberof LuCI.Class
1325 * @instance
1326 *
1327 * @param {string} key
1328 * The name of the superclass member to retrieve.
1329 *
1330 * @param {Array&lt;*>} [callArgs]
1331 * An optional array of function call parameters to use. When
1332 * this parameter is specified, the found member value is called
1333 * as function using the values of this array as arguments.
1334 *
1335 * @throws {ReferenceError}
1336 * Throws a `ReferenceError` when `callArgs` are specified and
1337 * the found member named by `key` is not a function value.
1338 *
1339 * @returns {*|null}
1340 * Returns the value of the found member or the return value of
1341 * the call to the found method. Returns `null` when no member
1342 * was found in the parent class chain or when the call to the
1343 * superclass method returned `null`.
1344 */
1345 super: function(key, callArgs) {
1346 for (superContext = Object.getPrototypeOf(superContext ||
1347 Object.getPrototypeOf(this));
1348 superContext &amp;&amp; !superContext.hasOwnProperty(key);
1349 superContext = Object.getPrototypeOf(superContext)) { }
1350
1351 if (!superContext)
1352 return null;
1353
1354 var res = superContext[key];
1355
1356 if (arguments.length > 1) {
1357 if (typeof(res) != 'function')
1358 throw new ReferenceError(key + ' is not a function in base class');
1359
1360 if (typeof(callArgs) != 'object')
1361 callArgs = this.varargs(arguments, 1);
1362
1363 res = res.apply(this, callArgs);
1364 }
1365
1366 superContext = null;
1367
1368 return res;
1369 },
1370
1371 /**
1372 * Returns a string representation of this class.
1373 *
1374 * @returns {string}
1375 * Returns a string representation of this class containing the
1376 * constructor functions `displayName` and describing the class
1377 * members and their respective types.
1378 */
1379 toString: function() {
1380 var s = '[' + this.constructor.displayName + ']', f = true;
1381 for (var k in this) {
1382 if (this.hasOwnProperty(k)) {
1383 s += (f ? ' {\n' : '') + ' ' + k + ': ' + typeof(this[k]) + '\n';
1384 f = false;
1385 }
1386 }
1387 return s + (f ? '' : '}');
1388 }
1389 }
1390 });
1391
1392
1393 /**
1394 * @class
1395 * @memberof LuCI
1396 * @hideconstructor
1397 * @classdesc
1398 *
1399 * The `Headers` class is an internal utility class exposed in HTTP
1400 * response objects using the `response.headers` property.
1401 */
1402 var Headers = Class.extend(/** @lends LuCI.Headers.prototype */ {
1403 __name__: 'LuCI.XHR.Headers',
1404 __init__: function(xhr) {
1405 var hdrs = this.headers = {};
1406 xhr.getAllResponseHeaders().split(/\r\n/).forEach(function(line) {
1407 var m = /^([^:]+):(.*)$/.exec(line);
1408 if (m != null)
1409 hdrs[m[1].trim().toLowerCase()] = m[2].trim();
1410 });
1411 },
1412
1413 /**
1414 * Checks whether the given header name is present.
1415 * Note: Header-Names are case-insensitive.
1416 *
1417 * @instance
1418 * @memberof LuCI.Headers
1419 * @param {string} name
1420 * The header name to check
1421 *
1422 * @returns {boolean}
1423 * Returns `true` if the header name is present, `false` otherwise
1424 */
1425 has: function(name) {
1426 return this.headers.hasOwnProperty(String(name).toLowerCase());
1427 },
1428
1429 /**
1430 * Returns the value of the given header name.
1431 * Note: Header-Names are case-insensitive.
1432 *
1433 * @instance
1434 * @memberof LuCI.Headers
1435 * @param {string} name
1436 * The header name to read
1437 *
1438 * @returns {string|null}
1439 * The value of the given header name or `null` if the header isn't present.
1440 */
1441 get: function(name) {
1442 var key = String(name).toLowerCase();
1443 return this.headers.hasOwnProperty(key) ? this.headers[key] : null;
1444 }
1445 });
1446
1447 /**
1448 * @class
1449 * @memberof LuCI
1450 * @hideconstructor
1451 * @classdesc
1452 *
1453 * The `Response` class is an internal utility class representing HTTP responses.
1454 */
1455 var Response = Class.extend({
1456 __name__: 'LuCI.XHR.Response',
1457 __init__: function(xhr, url, duration, headers, content) {
1458 /**
1459 * Describes whether the response is successful (status codes `200..299`) or not
1460 * @instance
1461 * @memberof LuCI.Response
1462 * @name ok
1463 * @type {boolean}
1464 */
1465 this.ok = (xhr.status >= 200 &amp;&amp; xhr.status &lt;= 299);
1466
1467 /**
1468 * The numeric HTTP status code of the response
1469 * @instance
1470 * @memberof LuCI.Response
1471 * @name status
1472 * @type {number}
1473 */
1474 this.status = xhr.status;
1475
1476 /**
1477 * The HTTP status description message of the response
1478 * @instance
1479 * @memberof LuCI.Response
1480 * @name statusText
1481 * @type {string}
1482 */
1483 this.statusText = xhr.statusText;
1484
1485 /**
1486 * The HTTP headers of the response
1487 * @instance
1488 * @memberof LuCI.Response
1489 * @name headers
1490 * @type {LuCI.Headers}
1491 */
1492 this.headers = (headers != null) ? headers : new Headers(xhr);
1493
1494 /**
1495 * The total duration of the HTTP request in milliseconds
1496 * @instance
1497 * @memberof LuCI.Response
1498 * @name duration
1499 * @type {number}
1500 */
1501 this.duration = duration;
1502
1503 /**
1504 * The final URL of the request, i.e. after following redirects.
1505 * @instance
1506 * @memberof LuCI.Response
1507 * @name url
1508 * @type {string}
1509 */
1510 this.url = url;
1511
1512 /* privates */
1513 this.xhr = xhr;
1514
1515 if (content != null &amp;&amp; typeof(content) == 'object') {
1516 this.responseJSON = content;
1517 this.responseText = null;
1518 }
1519 else if (content != null) {
1520 this.responseJSON = null;
1521 this.responseText = String(content);
1522 }
1523 else {
1524 this.responseJSON = null;
1525 this.responseText = xhr.responseText;
1526 }
1527 },
1528
1529 /**
1530 * Clones the given response object, optionally overriding the content
1531 * of the cloned instance.
1532 *
1533 * @instance
1534 * @memberof LuCI.Response
1535 * @param {*} [content]
1536 * Override the content of the cloned response. Object values will be
1537 * treated as JSON response data, all other types will be converted
1538 * using `String()` and treated as response text.
1539 *
1540 * @returns {LuCI.Response}
1541 * The cloned `Response` instance.
1542 */
1543 clone: function(content) {
1544 var copy = new Response(this.xhr, this.url, this.duration, this.headers, content);
1545
1546 copy.ok = this.ok;
1547 copy.status = this.status;
1548 copy.statusText = this.statusText;
1549
1550 return copy;
1551 },
1552
1553 /**
1554 * Access the response content as JSON data.
1555 *
1556 * @instance
1557 * @memberof LuCI.Response
1558 * @throws {SyntaxError}
1559 * Throws `SyntaxError` if the content isn't valid JSON.
1560 *
1561 * @returns {*}
1562 * The parsed JSON data.
1563 */
1564 json: function() {
1565 if (this.responseJSON == null)
1566 this.responseJSON = JSON.parse(this.responseText);
1567
1568 return this.responseJSON;
1569 },
1570
1571 /**
1572 * Access the response content as string.
1573 *
1574 * @instance
1575 * @memberof LuCI.Response
1576 * @returns {string}
1577 * The response content.
1578 */
1579 text: function() {
1580 if (this.responseText == null &amp;&amp; this.responseJSON != null)
1581 this.responseText = JSON.stringify(this.responseJSON);
1582
1583 return this.responseText;
1584 }
1585 });
1586
1587
1588 var requestQueue = [];
1589
1590 function isQueueableRequest(opt) {
1591 if (!classes.rpc)
1592 return false;
1593
1594 if (opt.method != 'POST' || typeof(opt.content) != 'object')
1595 return false;
1596
1597 if (opt.nobatch === true)
1598 return false;
1599
1600 var rpcBaseURL = Request.expandURL(classes.rpc.getBaseURL());
1601
1602 return (rpcBaseURL != null &amp;&amp; opt.url.indexOf(rpcBaseURL) == 0);
1603 }
1604
1605 function flushRequestQueue() {
1606 if (!requestQueue.length)
1607 return;
1608
1609 var reqopt = Object.assign({}, requestQueue[0][0], { content: [], nobatch: true }),
1610 batch = [];
1611
1612 for (var i = 0; i &lt; requestQueue.length; i++) {
1613 batch[i] = requestQueue[i];
1614 reqopt.content[i] = batch[i][0].content;
1615 }
1616
1617 requestQueue.length = 0;
1618
1619 Request.request(rpcBaseURL, reqopt).then(function(reply) {
1620 var json = null, req = null;
1621
1622 try { json = reply.json() }
1623 catch(e) { }
1624
1625 while ((req = batch.shift()) != null)
1626 if (Array.isArray(json) &amp;&amp; json.length)
1627 req[2].call(reqopt, reply.clone(json.shift()));
1628 else
1629 req[1].call(reqopt, new Error('No related RPC reply'));
1630 }).catch(function(error) {
1631 var req = null;
1632
1633 while ((req = batch.shift()) != null)
1634 req[1].call(reqopt, error);
1635 });
1636 }
1637
1638 /**
1639 * @class
1640 * @memberof LuCI
1641 * @hideconstructor
1642 * @classdesc
1643 *
1644 * The `Request` class allows initiating HTTP requests and provides utilities
1645 * for dealing with responses.
1646 */
1647 var Request = Class.singleton(/** @lends LuCI.Request.prototype */ {
1648 __name__: 'LuCI.Request',
1649
1650 interceptors: [],
1651
1652 /**
1653 * Turn the given relative URL into an absolute URL if necessary.
1654 *
1655 * @instance
1656 * @memberof LuCI.Request
1657 * @param {string} url
1658 * The URL to convert.
1659 *
1660 * @returns {string}
1661 * The absolute URL derived from the given one, or the original URL
1662 * if it already was absolute.
1663 */
1664 expandURL: function(url) {
1665 if (!/^(?:[^/]+:)?\/\//.test(url))
1666 url = location.protocol + '//' + location.host + url;
1667
1668 return url;
1669 },
1670
1671 /**
1672 * @typedef {Object} RequestOptions
1673 * @memberof LuCI.Request
1674 *
1675 * @property {string} [method=GET]
1676 * The HTTP method to use, e.g. `GET` or `POST`.
1677 *
1678 * @property {Object&lt;string, Object|string>} [query]
1679 * Query string data to append to the URL. Non-string values of the
1680 * given object will be converted to JSON.
1681 *
1682 * @property {boolean} [cache=false]
1683 * Specifies whether the HTTP response may be retrieved from cache.
1684 *
1685 * @property {string} [username]
1686 * Provides a username for HTTP basic authentication.
1687 *
1688 * @property {string} [password]
1689 * Provides a password for HTTP basic authentication.
1690 *
1691 * @property {number} [timeout]
1692 * Specifies the request timeout in seconds.
1693 *
1694 * @property {boolean} [credentials=false]
1695 * Whether to include credentials such as cookies in the request.
1696 *
1697 * @property {*} [content]
1698 * Specifies the HTTP message body to send along with the request.
1699 * If the value is a function, it is invoked and the return value
1700 * used as content, if it is a FormData instance, it is used as-is,
1701 * if it is an object, it will be converted to JSON, in all other
1702 * cases it is converted to a string.
1703 *
1704 * @property {Object&lt;string, string>} [header]
1705 * Specifies HTTP headers to set for the request.
1706 *
1707 * @property {function} [progress]
1708 * An optional request callback function which receives ProgressEvent
1709 * instances as sole argument during the HTTP request transfer.
1710 */
1711
1712 /**
1713 * Initiate an HTTP request to the given target.
1714 *
1715 * @instance
1716 * @memberof LuCI.Request
1717 * @param {string} target
1718 * The URL to request.
1719 *
1720 * @param {LuCI.Request.RequestOptions} [options]
1721 * Additional options to configure the request.
1722 *
1723 * @returns {Promise&lt;LuCI.Response>}
1724 * The resulting HTTP response.
1725 */
1726 request: function(target, options) {
1727 var state = { xhr: new XMLHttpRequest(), url: this.expandURL(target), start: Date.now() },
1728 opt = Object.assign({}, options, state),
1729 content = null,
1730 contenttype = null,
1731 callback = this.handleReadyStateChange;
1732
1733 return new Promise(function(resolveFn, rejectFn) {
1734 opt.xhr.onreadystatechange = callback.bind(opt, resolveFn, rejectFn);
1735 opt.method = String(opt.method || 'GET').toUpperCase();
1736
1737 if ('query' in opt) {
1738 var q = (opt.query != null) ? Object.keys(opt.query).map(function(k) {
1739 if (opt.query[k] != null) {
1740 var v = (typeof(opt.query[k]) == 'object')
1741 ? JSON.stringify(opt.query[k])
1742 : String(opt.query[k]);
1743
1744 return '%s=%s'.format(encodeURIComponent(k), encodeURIComponent(v));
1745 }
1746 else {
1747 return encodeURIComponent(k);
1748 }
1749 }).join('&amp;') : '';
1750
1751 if (q !== '') {
1752 switch (opt.method) {
1753 case 'GET':
1754 case 'HEAD':
1755 case 'OPTIONS':
1756 opt.url += ((/\?/).test(opt.url) ? '&amp;' : '?') + q;
1757 break;
1758
1759 default:
1760 if (content == null) {
1761 content = q;
1762 contenttype = 'application/x-www-form-urlencoded';
1763 }
1764 }
1765 }
1766 }
1767
1768 if (!opt.cache)
1769 opt.url += ((/\?/).test(opt.url) ? '&amp;' : '?') + (new Date()).getTime();
1770
1771 if (isQueueableRequest(opt)) {
1772 requestQueue.push([opt, rejectFn, resolveFn]);
1773 requestAnimationFrame(flushRequestQueue);
1774 return;
1775 }
1776
1777 if ('username' in opt &amp;&amp; 'password' in opt)
1778 opt.xhr.open(opt.method, opt.url, true, opt.username, opt.password);
1779 else
1780 opt.xhr.open(opt.method, opt.url, true);
1781
1782 opt.xhr.responseType = 'text';
1783
1784 if ('overrideMimeType' in opt.xhr)
1785 opt.xhr.overrideMimeType('application/octet-stream');
1786
1787 if ('timeout' in opt)
1788 opt.xhr.timeout = +opt.timeout;
1789
1790 if ('credentials' in opt)
1791 opt.xhr.withCredentials = !!opt.credentials;
1792
1793 if (opt.content != null) {
1794 switch (typeof(opt.content)) {
1795 case 'function':
1796 content = opt.content(xhr);
1797 break;
1798
1799 case 'object':
1800 if (!(opt.content instanceof FormData)) {
1801 content = JSON.stringify(opt.content);
1802 contenttype = 'application/json';
1803 }
1804 else {
1805 content = opt.content;
1806 }
1807 break;
1808
1809 default:
1810 content = String(opt.content);
1811 }
1812 }
1813
1814 if ('headers' in opt)
1815 for (var header in opt.headers)
1816 if (opt.headers.hasOwnProperty(header)) {
1817 if (header.toLowerCase() != 'content-type')
1818 opt.xhr.setRequestHeader(header, opt.headers[header]);
1819 else
1820 contenttype = opt.headers[header];
1821 }
1822
1823 if ('progress' in opt &amp;&amp; 'upload' in opt.xhr)
1824 opt.xhr.upload.addEventListener('progress', opt.progress);
1825
1826 if (contenttype != null)
1827 opt.xhr.setRequestHeader('Content-Type', contenttype);
1828
1829 try {
1830 opt.xhr.send(content);
1831 }
1832 catch (e) {
1833 rejectFn.call(opt, e);
1834 }
1835 });
1836 },
1837
1838 handleReadyStateChange: function(resolveFn, rejectFn, ev) {
1839 var xhr = this.xhr,
1840 duration = Date.now() - this.start;
1841
1842 if (xhr.readyState !== 4)
1843 return;
1844
1845 if (xhr.status === 0 &amp;&amp; xhr.statusText === '') {
1846 if (duration >= this.timeout)
1847 rejectFn.call(this, new Error('XHR request timed out'));
1848 else
1849 rejectFn.call(this, new Error('XHR request aborted by browser'));
1850 }
1851 else {
1852 var response = new Response(
1853 xhr, xhr.responseURL || this.url, duration);
1854
1855 Promise.all(Request.interceptors.map(function(fn) { return fn(response) }))
1856 .then(resolveFn.bind(this, response))
1857 .catch(rejectFn.bind(this));
1858 }
1859 },
1860
1861 /**
1862 * Initiate an HTTP GET request to the given target.
1863 *
1864 * @instance
1865 * @memberof LuCI.Request
1866 * @param {string} target
1867 * The URL to request.
1868 *
1869 * @param {LuCI.Request.RequestOptions} [options]
1870 * Additional options to configure the request.
1871 *
1872 * @returns {Promise&lt;LuCI.Response>}
1873 * The resulting HTTP response.
1874 */
1875 get: function(url, options) {
1876 return this.request(url, Object.assign({ method: 'GET' }, options));
1877 },
1878
1879 /**
1880 * Initiate an HTTP POST request to the given target.
1881 *
1882 * @instance
1883 * @memberof LuCI.Request
1884 * @param {string} target
1885 * The URL to request.
1886 *
1887 * @param {*} [data]
1888 * The request data to send, see {@link LuCI.Request.RequestOptions} for details.
1889 *
1890 * @param {LuCI.Request.RequestOptions} [options]
1891 * Additional options to configure the request.
1892 *
1893 * @returns {Promise&lt;LuCI.Response>}
1894 * The resulting HTTP response.
1895 */
1896 post: function(url, data, options) {
1897 return this.request(url, Object.assign({ method: 'POST', content: data }, options));
1898 },
1899
1900 /**
1901 * Interceptor functions are invoked whenever an HTTP reply is received, in the order
1902 * these functions have been registered.
1903 * @callback LuCI.Request.interceptorFn
1904 * @param {LuCI.Response} res
1905 * The HTTP response object
1906 */
1907
1908 /**
1909 * Register an HTTP response interceptor function. Interceptor
1910 * functions are useful to perform default actions on incoming HTTP
1911 * responses, such as checking for expired authentication or for
1912 * implementing request retries before returning a failure.
1913 *
1914 * @instance
1915 * @memberof LuCI.Request
1916 * @param {LuCI.Request.interceptorFn} interceptorFn
1917 * The interceptor function to register.
1918 *
1919 * @returns {LuCI.Request.interceptorFn}
1920 * The registered function.
1921 */
1922 addInterceptor: function(interceptorFn) {
1923 if (typeof(interceptorFn) == 'function')
1924 this.interceptors.push(interceptorFn);
1925 return interceptorFn;
1926 },
1927
1928 /**
1929 * Remove an HTTP response interceptor function. The passed function
1930 * value must be the very same value that was used to register the
1931 * function.
1932 *
1933 * @instance
1934 * @memberof LuCI.Request
1935 * @param {LuCI.Request.interceptorFn} interceptorFn
1936 * The interceptor function to remove.
1937 *
1938 * @returns {boolean}
1939 * Returns `true` if any function has been removed, else `false`.
1940 */
1941 removeInterceptor: function(interceptorFn) {
1942 var oldlen = this.interceptors.length, i = oldlen;
1943 while (i--)
1944 if (this.interceptors[i] === interceptorFn)
1945 this.interceptors.splice(i, 1);
1946 return (this.interceptors.length &lt; oldlen);
1947 },
1948
1949 /**
1950 * @class
1951 * @memberof LuCI.Request
1952 * @hideconstructor
1953 * @classdesc
1954 *
1955 * The `Request.poll` class provides some convience wrappers around
1956 * {@link LuCI.Poll} mainly to simplify registering repeating HTTP
1957 * request calls as polling functions.
1958 */
1959 poll: {
1960 /**
1961 * The callback function is invoked whenever an HTTP reply to a
1962 * polled request is received or when the polled request timed
1963 * out.
1964 *
1965 * @callback LuCI.Request.poll~callbackFn
1966 * @param {LuCI.Response} res
1967 * The HTTP response object.
1968 *
1969 * @param {*} data
1970 * The response JSON if the response could be parsed as such,
1971 * else `null`.
1972 *
1973 * @param {number} duration
1974 * The total duration of the request in milliseconds.
1975 */
1976
1977 /**
1978 * Register a repeating HTTP request with an optional callback
1979 * to invoke whenever a response for the request is received.
1980 *
1981 * @instance
1982 * @memberof LuCI.Request.poll
1983 * @param {number} interval
1984 * The poll interval in seconds.
1985 *
1986 * @param {string} url
1987 * The URL to request on each poll.
1988 *
1989 * @param {LuCI.Request.RequestOptions} [options]
1990 * Additional options to configure the request.
1991 *
1992 * @param {LuCI.Request.poll~callbackFn} [callback]
1993 * {@link LuCI.Request.poll~callbackFn Callback} function to
1994 * invoke for each HTTP reply.
1995 *
1996 * @throws {TypeError}
1997 * Throws `TypeError` when an invalid interval was passed.
1998 *
1999 * @returns {function}
2000 * Returns the internally created poll function.
2001 */
2002 add: function(interval, url, options, callback) {
2003 if (isNaN(interval) || interval &lt;= 0)
2004 throw new TypeError('Invalid poll interval');
2005
2006 var ival = interval >>> 0,
2007 opts = Object.assign({}, options, { timeout: ival * 1000 - 5 });
2008
2009 var fn = function() {
2010 return Request.request(url, options).then(function(res) {
2011 if (!Poll.active())
2012 return;
2013
2014 try {
2015 callback(res, res.json(), res.duration);
2016 }
2017 catch (err) {
2018 callback(res, null, res.duration);
2019 }
2020 });
2021 };
2022
2023 return (Poll.add(fn, ival) ? fn : null);
2024 },
2025
2026 /**
2027 * Remove a polling request that has been previously added using `add()`.
2028 * This function is essentially a wrapper around
2029 * {@link LuCI.Poll.remove LuCI.Poll.remove()}.
2030 *
2031 * @instance
2032 * @memberof LuCI.Request.poll
2033 * @param {function} entry
2034 * The poll function returned by {@link LuCI.Request.poll#add add()}.
2035 *
2036 * @returns {boolean}
2037 * Returns `true` if any function has been removed, else `false`.
2038 */
2039 remove: function(entry) { return Poll.remove(entry) },
2040
2041 /**
2042 * Alias for {@link LuCI.Poll.start LuCI.Poll.start()}.
2043 *
2044 * @instance
2045 * @memberof LuCI.Request.poll
2046 */
2047 start: function() { return Poll.start() },
2048
2049 /**
2050 * Alias for {@link LuCI.Poll.stop LuCI.Poll.stop()}.
2051 *
2052 * @instance
2053 * @memberof LuCI.Request.poll
2054 */
2055 stop: function() { return Poll.stop() },
2056
2057 /**
2058 * Alias for {@link LuCI.Poll.active LuCI.Poll.active()}.
2059 *
2060 * @instance
2061 * @memberof LuCI.Request.poll
2062 */
2063 active: function() { return Poll.active() }
2064 }
2065 });
2066
2067 /**
2068 * @class
2069 * @memberof LuCI
2070 * @hideconstructor
2071 * @classdesc
2072 *
2073 * The `Poll` class allows registering and unregistering poll actions,
2074 * as well as starting, stopping and querying the state of the polling
2075 * loop.
2076 */
2077 var Poll = Class.singleton(/** @lends LuCI.Poll.prototype */ {
2078 __name__: 'LuCI.Poll',
2079
2080 queue: [],
2081
2082 /**
2083 * Add a new operation to the polling loop. If the polling loop is not
2084 * already started at this point, it will be implicitely started.
2085 *
2086 * @instance
2087 * @memberof LuCI.Poll
2088 * @param {function} fn
2089 * The function to invoke on each poll interval.
2090 *
2091 * @param {number} interval
2092 * The poll interval in seconds.
2093 *
2094 * @throws {TypeError}
2095 * Throws `TypeError` when an invalid interval was passed.
2096 *
2097 * @returns {boolean}
2098 * Returns `true` if the function has been added or `false` if it
2099 * already is registered.
2100 */
2101 add: function(fn, interval) {
2102 if (interval == null || interval &lt;= 0)
2103 interval = window.L ? window.L.env.pollinterval : null;
2104
2105 if (isNaN(interval) || typeof(fn) != 'function')
2106 throw new TypeError('Invalid argument to LuCI.Poll.add()');
2107
2108 for (var i = 0; i &lt; this.queue.length; i++)
2109 if (this.queue[i].fn === fn)
2110 return false;
2111
2112 var e = {
2113 r: true,
2114 i: interval >>> 0,
2115 fn: fn
2116 };
2117
2118 this.queue.push(e);
2119
2120 if (this.tick != null &amp;&amp; !this.active())
2121 this.start();
2122
2123 return true;
2124 },
2125
2126 /**
2127 * Remove an operation from the polling loop. If no further operatons
2128 * are registered, the polling loop is implicitely stopped.
2129 *
2130 * @instance
2131 * @memberof LuCI.Poll
2132 * @param {function} fn
2133 * The function to remove.
2134 *
2135 * @throws {TypeError}
2136 * Throws `TypeError` when the given argument isn't a function.
2137 *
2138 * @returns {boolean}
2139 * Returns `true` if the function has been removed or `false` if it
2140 * wasn't found.
2141 */
2142 remove: function(fn) {
2143 if (typeof(fn) != 'function')
2144 throw new TypeError('Invalid argument to LuCI.Poll.remove()');
2145
2146 var len = this.queue.length;
2147
2148 for (var i = len; i > 0; i--)
2149 if (this.queue[i-1].fn === fn)
2150 this.queue.splice(i-1, 1);
2151
2152 if (!this.queue.length &amp;&amp; this.stop())
2153 this.tick = 0;
2154
2155 return (this.queue.length != len);
2156 },
2157
2158 /**
2159 * (Re)start the polling loop. Dispatches a custom `poll-start` event
2160 * to the `document` object upon successful start.
2161 *
2162 * @instance
2163 * @memberof LuCI.Poll
2164 * @returns {boolean}
2165 * Returns `true` if polling has been started (or if no functions
2166 * where registered) or `false` when the polling loop already runs.
2167 */
2168 start: function() {
2169 if (this.active())
2170 return false;
2171
2172 this.tick = 0;
2173
2174 if (this.queue.length) {
2175 this.timer = window.setInterval(this.step, 1000);
2176 this.step();
2177 document.dispatchEvent(new CustomEvent('poll-start'));
2178 }
2179
2180 return true;
2181 },
2182
2183 /**
2184 * Stop the polling loop. Dispatches a custom `poll-stop` event
2185 * to the `document` object upon successful stop.
2186 *
2187 * @instance
2188 * @memberof LuCI.Poll
2189 * @returns {boolean}
2190 * Returns `true` if polling has been stopped or `false` if it din't
2191 * run to begin with.
2192 */
2193 stop: function() {
2194 if (!this.active())
2195 return false;
2196
2197 document.dispatchEvent(new CustomEvent('poll-stop'));
2198 window.clearInterval(this.timer);
2199 delete this.timer;
2200 delete this.tick;
2201 return true;
2202 },
2203
2204 /* private */
2205 step: function() {
2206 for (var i = 0, e = null; (e = Poll.queue[i]) != null; i++) {
2207 if ((Poll.tick % e.i) != 0)
2208 continue;
2209
2210 if (!e.r)
2211 continue;
2212
2213 e.r = false;
2214
2215 Promise.resolve(e.fn()).finally((function() { this.r = true }).bind(e));
2216 }
2217
2218 Poll.tick = (Poll.tick + 1) % Math.pow(2, 32);
2219 },
2220
2221 /**
2222 * Test whether the polling loop is running.
2223 *
2224 * @instance
2225 * @memberof LuCI.Poll
2226 * @returns {boolean} - Returns `true` if polling is active, else `false`.
2227 */
2228 active: function() {
2229 return (this.timer != null);
2230 }
2231 });
2232
2233
2234 var dummyElem = null,
2235 domParser = null,
2236 originalCBIInit = null,
2237 rpcBaseURL = null,
2238 sysFeatures = null,
2239 classes = {};
2240
2241 var LuCI = Class.extend(/** @lends LuCI.prototype */ {
2242 __name__: 'LuCI',
2243 __init__: function(env) {
2244
2245 document.querySelectorAll('script[src*="/luci.js"]').forEach(function(s) {
2246 if (env.base_url == null || env.base_url == '') {
2247 var m = (s.getAttribute('src') || '').match(/^(.*)\/luci\.js(?:\?v=([^?]+))?$/);
2248 if (m) {
2249 env.base_url = m[1];
2250 env.resource_version = m[2];
2251 }
2252 }
2253 });
2254
2255 if (env.base_url == null)
2256 this.error('InternalError', 'Cannot find url of luci.js');
2257
2258 Object.assign(this.env, env);
2259
2260 document.addEventListener('poll-start', function(ev) {
2261 document.querySelectorAll('[id^="xhr_poll_status"]').forEach(function(e) {
2262 e.style.display = (e.id == 'xhr_poll_status_off') ? 'none' : '';
2263 });
2264 });
2265
2266 document.addEventListener('poll-stop', function(ev) {
2267 document.querySelectorAll('[id^="xhr_poll_status"]').forEach(function(e) {
2268 e.style.display = (e.id == 'xhr_poll_status_on') ? 'none' : '';
2269 });
2270 });
2271
2272 var domReady = new Promise(function(resolveFn, rejectFn) {
2273 document.addEventListener('DOMContentLoaded', resolveFn);
2274 });
2275
2276 Promise.all([
2277 domReady,
2278 this.require('ui'),
2279 this.require('rpc'),
2280 this.require('form'),
2281 this.probeRPCBaseURL()
2282 ]).then(this.setupDOM.bind(this)).catch(this.error);
2283
2284 originalCBIInit = window.cbi_init;
2285 window.cbi_init = function() {};
2286 },
2287
2288 /**
2289 * Captures the current stack trace and throws an error of the
2290 * specified type as a new exception. Also logs the exception as
2291 * error to the debug console if it is available.
2292 *
2293 * @instance
2294 * @memberof LuCI
2295 *
2296 * @param {Error|string} [type=Error]
2297 * Either a string specifying the type of the error to throw or an
2298 * existing `Error` instance to copy.
2299 *
2300 * @param {string} [fmt=Unspecified error]
2301 * A format string which is used to form the error message, together
2302 * with all subsequent optional arguments.
2303 *
2304 * @param {...*} [args]
2305 * Zero or more variable arguments to the supplied format string.
2306 *
2307 * @throws {Error}
2308 * Throws the created error object with the captured stack trace
2309 * appended to the message and the type set to the given type
2310 * argument or copied from the given error instance.
2311 */
2312 raise: function(type, fmt /*, ...*/) {
2313 var e = null,
2314 msg = fmt ? String.prototype.format.apply(fmt, this.varargs(arguments, 2)) : null,
2315 stack = null;
2316
2317 if (type instanceof Error) {
2318 e = type;
2319
2320 if (msg)
2321 e.message = msg + ': ' + e.message;
2322 }
2323 else {
2324 try { throw new Error('stacktrace') }
2325 catch (e2) { stack = (e2.stack || '').split(/\n/) }
2326
2327 e = new (window[type || 'Error'] || Error)(msg || 'Unspecified error');
2328 e.name = type || 'Error';
2329 }
2330
2331 stack = (stack || []).map(function(frame) {
2332 frame = frame.replace(/(.*?)@(.+):(\d+):(\d+)/g, 'at $1 ($2:$3:$4)').trim();
2333 return frame ? ' ' + frame : '';
2334 });
2335
2336 if (!/^ at /.test(stack[0]))
2337 stack.shift();
2338
2339 if (/\braise /.test(stack[0]))
2340 stack.shift();
2341
2342 if (/\berror /.test(stack[0]))
2343 stack.shift();
2344
2345 if (stack.length)
2346 e.message += '\n' + stack.join('\n');
2347
2348 if (window.console &amp;&amp; console.debug)
2349 console.debug(e);
2350
2351 throw e;
2352 },
2353
2354 /**
2355 * A wrapper around {@link LuCI#raise raise()} which also renders
2356 * the error either as modal overlay when `ui.js` is already loaed
2357 * or directly into the view body.
2358 *
2359 * @instance
2360 * @memberof LuCI
2361 *
2362 * @param {Error|string} [type=Error]
2363 * Either a string specifying the type of the error to throw or an
2364 * existing `Error` instance to copy.
2365 *
2366 * @param {string} [fmt=Unspecified error]
2367 * A format string which is used to form the error message, together
2368 * with all subsequent optional arguments.
2369 *
2370 * @param {...*} [args]
2371 * Zero or more variable arguments to the supplied format string.
2372 *
2373 * @throws {Error}
2374 * Throws the created error object with the captured stack trace
2375 * appended to the message and the type set to the given type
2376 * argument or copied from the given error instance.
2377 */
2378 error: function(type, fmt /*, ...*/) {
2379 try {
2380 L.raise.apply(L, Array.prototype.slice.call(arguments));
2381 }
2382 catch (e) {
2383 if (!e.reported) {
2384 if (L.ui)
2385 L.ui.addNotification(e.name || _('Runtime error'),
2386 E('pre', {}, e.message), 'danger');
2387 else
2388 L.dom.content(document.querySelector('#maincontent'),
2389 E('pre', { 'class': 'alert-message error' }, e.message));
2390
2391 e.reported = true;
2392 }
2393
2394 throw e;
2395 }
2396 },
2397
2398 /**
2399 * Return a bound function using the given `self` as `this` context
2400 * and any further arguments as parameters to the bound function.
2401 *
2402 * @instance
2403 * @memberof LuCI
2404 *
2405 * @param {function} fn
2406 * The function to bind.
2407 *
2408 * @param {*} self
2409 * The value to bind as `this` context to the specified function.
2410 *
2411 * @param {...*} [args]
2412 * Zero or more variable arguments which are bound to the function
2413 * as parameters.
2414 *
2415 * @returns {function}
2416 * Returns the bound function.
2417 */
2418 bind: function(fn, self /*, ... */) {
2419 return Function.prototype.bind.apply(fn, this.varargs(arguments, 2, self));
2420 },
2421
2422 /**
2423 * Load an additional LuCI JavaScript class and its dependencies,
2424 * instantiate it and return the resulting class instance. Each
2425 * class is only loaded once. Subsequent attempts to load the same
2426 * class will return the already instantiated class.
2427 *
2428 * @instance
2429 * @memberof LuCI
2430 *
2431 * @param {string} name
2432 * The name of the class to load in dotted notation. Dots will
2433 * be replaced by spaces and joined with the runtime-determined
2434 * base URL of LuCI.js to form an absolute URL to load the class
2435 * file from.
2436 *
2437 * @throws {DependencyError}
2438 * Throws a `DependencyError` when the class to load includes
2439 * circular dependencies.
2440 *
2441 * @throws {NetworkError}
2442 * Throws `NetworkError` when the underlying {@link LuCI.Request}
2443 * call failed.
2444 *
2445 * @throws {SyntaxError}
2446 * Throws `SyntaxError` when the loaded class file code cannot
2447 * be interpreted by `eval`.
2448 *
2449 * @throws {TypeError}
2450 * Throws `TypeError` when the class file could be loaded and
2451 * interpreted, but when invoking its code did not yield a valid
2452 * class instance.
2453 *
2454 * @returns {Promise&lt;LuCI#Class>}
2455 * Returns the instantiated class.
2456 */
2457 require: function(name, from) {
2458 var L = this, url = null, from = from || [];
2459
2460 /* Class already loaded */
2461 if (classes[name] != null) {
2462 /* Circular dependency */
2463 if (from.indexOf(name) != -1)
2464 L.raise('DependencyError',
2465 'Circular dependency: class "%s" depends on "%s"',
2466 name, from.join('" which depends on "'));
2467
2468 return Promise.resolve(classes[name]);
2469 }
2470
2471 url = '%s/%s.js%s'.format(L.env.base_url, name.replace(/\./g, '/'), (L.env.resource_version ? '?v=' + L.env.resource_version : ''));
2472 from = [ name ].concat(from);
2473
2474 var compileClass = function(res) {
2475 if (!res.ok)
2476 L.raise('NetworkError',
2477 'HTTP error %d while loading class file "%s"', res.status, url);
2478
2479 var source = res.text(),
2480 requirematch = /^require[ \t]+(\S+)(?:[ \t]+as[ \t]+([a-zA-Z_]\S*))?$/,
2481 strictmatch = /^use[ \t]+strict$/,
2482 depends = [],
2483 args = '';
2484
2485 /* find require statements in source */
2486 for (var i = 0, off = -1, quote = -1, esc = false; i &lt; source.length; i++) {
2487 var chr = source.charCodeAt(i);
2488
2489 if (esc) {
2490 esc = false;
2491 }
2492 else if (chr == 92) {
2493 esc = true;
2494 }
2495 else if (chr == quote) {
2496 var s = source.substring(off, i),
2497 m = requirematch.exec(s);
2498
2499 if (m) {
2500 var dep = m[1], as = m[2] || dep.replace(/[^a-zA-Z0-9_]/g, '_');
2501 depends.push(L.require(dep, from));
2502 args += ', ' + as;
2503 }
2504 else if (!strictmatch.exec(s)) {
2505 break;
2506 }
2507
2508 off = -1;
2509 quote = -1;
2510 }
2511 else if (quote == -1 &amp;&amp; (chr == 34 || chr == 39)) {
2512 off = i + 1;
2513 quote = chr;
2514 }
2515 }
2516
2517 /* load dependencies and instantiate class */
2518 return Promise.all(depends).then(function(instances) {
2519 var _factory, _class;
2520
2521 try {
2522 _factory = eval(
2523 '(function(window, document, L%s) { %s })\n\n//# sourceURL=%s\n'
2524 .format(args, source, res.url));
2525 }
2526 catch (error) {
2527 L.raise('SyntaxError', '%s\n in %s:%s',
2528 error.message, res.url, error.lineNumber || '?');
2529 }
2530
2531 _factory.displayName = toCamelCase(name + 'ClassFactory');
2532 _class = _factory.apply(_factory, [window, document, L].concat(instances));
2533
2534 if (!Class.isSubclass(_class))
2535 L.error('TypeError', '"%s" factory yields invalid constructor', name);
2536
2537 if (_class.displayName == 'AnonymousClass')
2538 _class.displayName = toCamelCase(name + 'Class');
2539
2540 var ptr = Object.getPrototypeOf(L),
2541 parts = name.split(/\./),
2542 instance = new _class();
2543
2544 for (var i = 0; ptr &amp;&amp; i &lt; parts.length - 1; i++)
2545 ptr = ptr[parts[i]];
2546
2547 if (ptr)
2548 ptr[parts[i]] = instance;
2549
2550 classes[name] = instance;
2551
2552 return instance;
2553 });
2554 };
2555
2556 /* Request class file */
2557 classes[name] = Request.get(url, { cache: true }).then(compileClass);
2558
2559 return classes[name];
2560 },
2561
2562 /* DOM setup */
2563 probeRPCBaseURL: function() {
2564 if (rpcBaseURL == null) {
2565 try {
2566 rpcBaseURL = window.sessionStorage.getItem('rpcBaseURL');
2567 }
2568 catch (e) { }
2569 }
2570
2571 if (rpcBaseURL == null) {
2572 var rpcFallbackURL = this.url('admin/ubus');
2573
2574 rpcBaseURL = Request.get('/ubus/').then(function(res) {
2575 return (rpcBaseURL = (res.status == 400) ? '/ubus/' : rpcFallbackURL);
2576 }, function() {
2577 return (rpcBaseURL = rpcFallbackURL);
2578 }).then(function(url) {
2579 try {
2580 window.sessionStorage.setItem('rpcBaseURL', url);
2581 }
2582 catch (e) { }
2583
2584 return url;
2585 });
2586 }
2587
2588 return Promise.resolve(rpcBaseURL);
2589 },
2590
2591 probeSystemFeatures: function() {
2592 var sessionid = classes.rpc.getSessionID();
2593
2594 if (sysFeatures == null) {
2595 try {
2596 var data = JSON.parse(window.sessionStorage.getItem('sysFeatures'));
2597
2598 if (this.isObject(data) &amp;&amp; this.isObject(data[sessionid]))
2599 sysFeatures = data[sessionid];
2600 }
2601 catch (e) {}
2602 }
2603
2604 if (!this.isObject(sysFeatures)) {
2605 sysFeatures = classes.rpc.declare({
2606 object: 'luci',
2607 method: 'getFeatures',
2608 expect: { '': {} }
2609 })().then(function(features) {
2610 try {
2611 var data = {};
2612 data[sessionid] = features;
2613
2614 window.sessionStorage.setItem('sysFeatures', JSON.stringify(data));
2615 }
2616 catch (e) {}
2617
2618 sysFeatures = features;
2619
2620 return features;
2621 });
2622 }
2623
2624 return Promise.resolve(sysFeatures);
2625 },
2626
2627 /**
2628 * Test whether a particular system feature is available, such as
2629 * hostapd SAE support or an installed firewall. The features are
2630 * queried once at the beginning of the LuCI session and cached in
2631 * `SessionStorage` throughout the lifetime of the associated tab or
2632 * browser window.
2633 *
2634 * @instance
2635 * @memberof LuCI
2636 *
2637 * @param {string} feature
2638 * The feature to test. For detailed list of known feature flags,
2639 * see `/modules/luci-base/root/usr/libexec/rpcd/luci`.
2640 *
2641 * @param {string} [subfeature]
2642 * Some feature classes like `hostapd` provide sub-feature flags,
2643 * such as `sae` or `11w` support. The `subfeature` argument can
2644 * be used to query these.
2645 *
2646 * @return {boolean|null}
2647 * Return `true` if the queried feature (and sub-feature) is available
2648 * or `false` if the requested feature isn't present or known.
2649 * Return `null` when a sub-feature was queried for a feature which
2650 * has no sub-features.
2651 */
2652 hasSystemFeature: function() {
2653 var ft = sysFeatures[arguments[0]];
2654
2655 if (arguments.length == 2)
2656 return this.isObject(ft) ? ft[arguments[1]] : null;
2657
2658 return (ft != null &amp;&amp; ft != false);
2659 },
2660
2661 /* private */
2662 notifySessionExpiry: function() {
2663 Poll.stop();
2664
2665 L.ui.showModal(_('Session expired'), [
2666 E('div', { class: 'alert-message warning' },
2667 _('A new login is required since the authentication session expired.')),
2668 E('div', { class: 'right' },
2669 E('div', {
2670 class: 'btn primary',
2671 click: function() {
2672 var loc = window.location;
2673 window.location = loc.protocol + '//' + loc.host + loc.pathname + loc.search;
2674 }
2675 }, _('To login…')))
2676 ]);
2677
2678 L.raise('SessionError', 'Login session is expired');
2679 },
2680
2681 /* private */
2682 setupDOM: function(res) {
2683 var domEv = res[0],
2684 uiClass = res[1],
2685 rpcClass = res[2],
2686 formClass = res[3],
2687 rpcBaseURL = res[4];
2688
2689 rpcClass.setBaseURL(rpcBaseURL);
2690
2691 rpcClass.addInterceptor(function(msg, req) {
2692 if (!L.isObject(msg) || !L.isObject(msg.error) || msg.error.code != -32002)
2693 return;
2694
2695 if (!L.isObject(req) || (req.object == 'session' &amp;&amp; req.method == 'access'))
2696 return;
2697
2698 return rpcClass.declare({
2699 'object': 'session',
2700 'method': 'access',
2701 'params': [ 'scope', 'object', 'function' ],
2702 'expect': { access: true }
2703 })('uci', 'luci', 'read').catch(L.notifySessionExpiry);
2704 });
2705
2706 Request.addInterceptor(function(res) {
2707 var isDenied = false;
2708
2709 if (res.status == 403 &amp;&amp; res.headers.get('X-LuCI-Login-Required') == 'yes')
2710 isDenied = true;
2711
2712 if (!isDenied)
2713 return;
2714
2715 L.notifySessionExpiry();
2716 });
2717
2718 return this.probeSystemFeatures().finally(this.initDOM);
2719 },
2720
2721 /* private */
2722 initDOM: function() {
2723 originalCBIInit();
2724 Poll.start();
2725 document.dispatchEvent(new CustomEvent('luci-loaded'));
2726 },
2727
2728 /**
2729 * The `env` object holds environment settings used by LuCI, such
2730 * as request timeouts, base URLs etc.
2731 *
2732 * @instance
2733 * @memberof LuCI
2734 */
2735 env: {},
2736
2737 /**
2738 * Construct a relative URL path from the given prefix and parts.
2739 * The resulting URL is guaranteed to only contain the characters
2740 * `a-z`, `A-Z`, `0-9`, `_`, `.`, `%`, `,`, `;`, and `-` as well
2741 * as `/` for the path separator.
2742 *
2743 * @instance
2744 * @memberof LuCI
2745 *
2746 * @param {string} [prefix]
2747 * The prefix to join the given parts with. If the `prefix` is
2748 * omitted, it defaults to an empty string.
2749 *
2750 * @param {string[]} [parts]
2751 * An array of parts to join into an URL path. Parts may contain
2752 * slashes and any of the other characters mentioned above.
2753 *
2754 * @return {string}
2755 * Return the joined URL path.
2756 */
2757 path: function(prefix, parts) {
2758 var url = [ prefix || '' ];
2759
2760 for (var i = 0; i &lt; parts.length; i++)
2761 if (/^(?:[a-zA-Z0-9_.%,;-]+\/)*[a-zA-Z0-9_.%,;-]+$/.test(parts[i]))
2762 url.push('/', parts[i]);
2763
2764 if (url.length === 1)
2765 url.push('/');
2766
2767 return url.join('');
2768 },
2769
2770 /**
2771 * Construct an URL pathrelative to the script path of the server
2772 * side LuCI application (usually `/cgi-bin/luci`).
2773 *
2774 * The resulting URL is guaranteed to only contain the characters
2775 * `a-z`, `A-Z`, `0-9`, `_`, `.`, `%`, `,`, `;`, and `-` as well
2776 * as `/` for the path separator.
2777 *
2778 * @instance
2779 * @memberof LuCI
2780 *
2781 * @param {string[]} [parts]
2782 * An array of parts to join into an URL path. Parts may contain
2783 * slashes and any of the other characters mentioned above.
2784 *
2785 * @return {string}
2786 * Returns the resulting URL path.
2787 */
2788 url: function() {
2789 return this.path(this.env.scriptname, arguments);
2790 },
2791
2792 /**
2793 * Construct an URL path relative to the global static resource path
2794 * of the LuCI ui (usually `/luci-static/resources`).
2795 *
2796 * The resulting URL is guaranteed to only contain the characters
2797 * `a-z`, `A-Z`, `0-9`, `_`, `.`, `%`, `,`, `;`, and `-` as well
2798 * as `/` for the path separator.
2799 *
2800 * @instance
2801 * @memberof LuCI
2802 *
2803 * @param {string[]} [parts]
2804 * An array of parts to join into an URL path. Parts may contain
2805 * slashes and any of the other characters mentioned above.
2806 *
2807 * @return {string}
2808 * Returns the resulting URL path.
2809 */
2810 resource: function() {
2811 return this.path(this.env.resource, arguments);
2812 },
2813
2814 /**
2815 * Return the complete URL path to the current view.
2816 *
2817 * @instance
2818 * @memberof LuCI
2819 *
2820 * @return {string}
2821 * Returns the URL path to the current view.
2822 */
2823 location: function() {
2824 return this.path(this.env.scriptname, this.env.requestpath);
2825 },
2826
2827
2828 /**
2829 * Tests whether the passed argument is a JavaScript object.
2830 * This function is meant to be an object counterpart to the
2831 * standard `Array.isArray()` function.
2832 *
2833 * @instance
2834 * @memberof LuCI
2835 *
2836 * @param {*} [val]
2837 * The value to test
2838 *
2839 * @return {boolean}
2840 * Returns `true` if the given value is of type object and
2841 * not `null`, else returns `false`.
2842 */
2843 isObject: function(val) {
2844 return (val != null &amp;&amp; typeof(val) == 'object');
2845 },
2846
2847 /**
2848 * Return an array of sorted object keys, optionally sorted by
2849 * a different key or a different sorting mode.
2850 *
2851 * @instance
2852 * @memberof LuCI
2853 *
2854 * @param {object} obj
2855 * The object to extract the keys from. If the given value is
2856 * not an object, the function will return an empty array.
2857 *
2858 * @param {string} [key]
2859 * Specifies the key to order by. This is mainly useful for
2860 * nested objects of objects or objects of arrays when sorting
2861 * shall not be performed by the primary object keys but by
2862 * some other key pointing to a value within the nested values.
2863 *
2864 * @param {string} [sortmode]
2865 * May be either `addr` or `num` to override the natural
2866 * lexicographic sorting with a sorting suitable for IP/MAC style
2867 * addresses or numeric values respectively.
2868 *
2869 * @return {string[]}
2870 * Returns an array containing the sorted keys of the given object.
2871 */
2872 sortedKeys: function(obj, key, sortmode) {
2873 if (obj == null || typeof(obj) != 'object')
2874 return [];
2875
2876 return Object.keys(obj).map(function(e) {
2877 var v = (key != null) ? obj[e][key] : e;
2878
2879 switch (sortmode) {
2880 case 'addr':
2881 v = (v != null) ? v.replace(/(?:^|[.:])([0-9a-fA-F]{1,4})/g,
2882 function(m0, m1) { return ('000' + m1.toLowerCase()).substr(-4) }) : null;
2883 break;
2884
2885 case 'num':
2886 v = (v != null) ? +v : null;
2887 break;
2888 }
2889
2890 return [ e, v ];
2891 }).filter(function(e) {
2892 return (e[1] != null);
2893 }).sort(function(a, b) {
2894 return (a[1] > b[1]);
2895 }).map(function(e) {
2896 return e[0];
2897 });
2898 },
2899
2900 /**
2901 * Converts the given value to an array. If the given value is of
2902 * type array, it is returned as-is, values of type object are
2903 * returned as one-element array containing the object, empty
2904 * strings and `null` values are returned as empty array, all other
2905 * values are converted using `String()`, trimmed, split on white
2906 * space and returned as array.
2907 *
2908 * @instance
2909 * @memberof LuCI
2910 *
2911 * @param {*} val
2912 * The value to convert into an array.
2913 *
2914 * @return {Array&lt;*>}
2915 * Returns the resulting array.
2916 */
2917 toArray: function(val) {
2918 if (val == null)
2919 return [];
2920 else if (Array.isArray(val))
2921 return val;
2922 else if (typeof(val) == 'object')
2923 return [ val ];
2924
2925 var s = String(val).trim();
2926
2927 if (s == '')
2928 return [];
2929
2930 return s.split(/\s+/);
2931 },
2932
2933 /**
2934 * Returns a promise resolving with either the given value or or with
2935 * the given default in case the input value is a rejecting promise.
2936 *
2937 * @instance
2938 * @memberof LuCI
2939 *
2940 * @param {*} value
2941 * The value to resolve the promise with.
2942 *
2943 * @param {*} defvalue
2944 * The default value to resolve the promise with in case the given
2945 * input value is a rejecting promise.
2946 *
2947 * @returns {Promise&lt;*>}
2948 * Returns a new promise resolving either to the given input value or
2949 * to the given default value on error.
2950 */
2951 resolveDefault: function(value, defvalue) {
2952 return Promise.resolve(value).catch(function() { return defvalue });
2953 },
2954
2955 /**
2956 * The request callback function is invoked whenever an HTTP
2957 * reply to a request made using the `L.get()`, `L.post()` or
2958 * `L.poll()` function is timed out or received successfully.
2959 *
2960 * @instance
2961 * @memberof LuCI
2962 *
2963 * @callback LuCI.requestCallbackFn
2964 * @param {XMLHTTPRequest} xhr
2965 * The XMLHTTPRequest instance used to make the request.
2966 *
2967 * @param {*} data
2968 * The response JSON if the response could be parsed as such,
2969 * else `null`.
2970 *
2971 * @param {number} duration
2972 * The total duration of the request in milliseconds.
2973 */
2974
2975 /**
2976 * Issues a GET request to the given url and invokes the specified
2977 * callback function. The function is a wrapper around
2978 * {@link LuCI.Request#request Request.request()}.
2979 *
2980 * @deprecated
2981 * @instance
2982 * @memberof LuCI
2983 *
2984 * @param {string} url
2985 * The URL to request.
2986 *
2987 * @param {Object&lt;string, string>} [args]
2988 * Additional query string arguments to append to the URL.
2989 *
2990 * @param {LuCI.requestCallbackFn} cb
2991 * The callback function to invoke when the request finishes.
2992 *
2993 * @return {Promise&lt;null>}
2994 * Returns a promise resolving to `null` when concluded.
2995 */
2996 get: function(url, args, cb) {
2997 return this.poll(null, url, args, cb, false);
2998 },
2999
3000 /**
3001 * Issues a POST request to the given url and invokes the specified
3002 * callback function. The function is a wrapper around
3003 * {@link LuCI.Request#request Request.request()}. The request is
3004 * sent using `application/x-www-form-urlencoded` encoding and will
3005 * contain a field `token` with the current value of `LuCI.env.token`
3006 * by default.
3007 *
3008 * @deprecated
3009 * @instance
3010 * @memberof LuCI
3011 *
3012 * @param {string} url
3013 * The URL to request.
3014 *
3015 * @param {Object&lt;string, string>} [args]
3016 * Additional post arguments to append to the request body.
3017 *
3018 * @param {LuCI.requestCallbackFn} cb
3019 * The callback function to invoke when the request finishes.
3020 *
3021 * @return {Promise&lt;null>}
3022 * Returns a promise resolving to `null` when concluded.
3023 */
3024 post: function(url, args, cb) {
3025 return this.poll(null, url, args, cb, true);
3026 },
3027
3028 /**
3029 * Register a polling HTTP request that invokes the specified
3030 * callback function. The function is a wrapper around
3031 * {@link LuCI.Request.poll#add Request.poll.add()}.
3032 *
3033 * @deprecated
3034 * @instance
3035 * @memberof LuCI
3036 *
3037 * @param {number} interval
3038 * The poll interval to use. If set to a value less than or equal
3039 * to `0`, it will default to the global poll interval configured
3040 * in `LuCI.env.pollinterval`.
3041 *
3042 * @param {string} url
3043 * The URL to request.
3044 *
3045 * @param {Object&lt;string, string>} [args]
3046 * Specifies additional arguments for the request. For GET requests,
3047 * the arguments are appended to the URL as query string, for POST
3048 * requests, they'll be added to the request body.
3049 *
3050 * @param {LuCI.requestCallbackFn} cb
3051 * The callback function to invoke whenever a request finishes.
3052 *
3053 * @param {boolean} [post=false]
3054 * When set to `false` or not specified, poll requests will be made
3055 * using the GET method. When set to `true`, POST requests will be
3056 * issued. In case of POST requests, the request body will contain
3057 * an argument `token` with the current value of `LuCI.env.token` by
3058 * default, regardless of the parameters specified with `args`.
3059 *
3060 * @return {function}
3061 * Returns the internally created function that has been passed to
3062 * {@link LuCI.Request.poll#add Request.poll.add()}. This value can
3063 * be passed to {@link LuCI.Poll.remove Poll.remove()} to remove the
3064 * polling request.
3065 */
3066 poll: function(interval, url, args, cb, post) {
3067 if (interval !== null &amp;&amp; interval &lt;= 0)
3068 interval = this.env.pollinterval;
3069
3070 var data = post ? { token: this.env.token } : null,
3071 method = post ? 'POST' : 'GET';
3072
3073 if (!/^(?:\/|\S+:\/\/)/.test(url))
3074 url = this.url(url);
3075
3076 if (args != null)
3077 data = Object.assign(data || {}, args);
3078
3079 if (interval !== null)
3080 return Request.poll.add(interval, url, { method: method, query: data }, cb);
3081 else
3082 return Request.request(url, { method: method, query: data })
3083 .then(function(res) {
3084 var json = null;
3085 if (/^application\/json\b/.test(res.headers.get('Content-Type')))
3086 try { json = res.json() } catch(e) {}
3087 cb(res.xhr, json, res.duration);
3088 });
3089 },
3090
3091 /**
3092 * Deprecated wrapper around {@link LuCI.Poll.remove Poll.remove()}.
3093 *
3094 * @deprecated
3095 * @instance
3096 * @memberof LuCI
3097 *
3098 * @param {function} entry
3099 * The polling function to remove.
3100 *
3101 * @return {boolean}
3102 * Returns `true` when the function has been removed or `false` if
3103 * it could not be found.
3104 */
3105 stop: function(entry) { return Poll.remove(entry) },
3106
3107 /**
3108 * Deprecated wrapper around {@link LuCI.Poll.stop Poll.stop()}.
3109 *
3110 * @deprecated
3111 * @instance
3112 * @memberof LuCI
3113 *
3114 * @return {boolean}
3115 * Returns `true` when the polling loop has been stopped or `false`
3116 * when it didn't run to begin with.
3117 */
3118 halt: function() { return Poll.stop() },
3119
3120 /**
3121 * Deprecated wrapper around {@link LuCI.Poll.start Poll.start()}.
3122 *
3123 * @deprecated
3124 * @instance
3125 * @memberof LuCI
3126 *
3127 * @return {boolean}
3128 * Returns `true` when the polling loop has been started or `false`
3129 * when it was already running.
3130 */
3131 run: function() { return Poll.start() },
3132
3133
3134 /**
3135 * @class
3136 * @memberof LuCI
3137 * @hideconstructor
3138 * @classdesc
3139 *
3140 * The `dom` class provides convenience method for creating and
3141 * manipulating DOM elements.
3142 */
3143 dom: Class.singleton(/* @lends LuCI.dom.prototype */ {
3144 __name__: 'LuCI.DOM',
3145
3146 /**
3147 * Tests whether the given argument is a valid DOM `Node`.
3148 *
3149 * @instance
3150 * @memberof LuCI.dom
3151 * @param {*} e
3152 * The value to test.
3153 *
3154 * @returns {boolean}
3155 * Returns `true` if the value is a DOM `Node`, else `false`.
3156 */
3157 elem: function(e) {
3158 return (e != null &amp;&amp; typeof(e) == 'object' &amp;&amp; 'nodeType' in e);
3159 },
3160
3161 /**
3162 * Parses a given string as HTML and returns the first child node.
3163 *
3164 * @instance
3165 * @memberof LuCI.dom
3166 * @param {string} s
3167 * A string containing an HTML fragment to parse. Note that only
3168 * the first result of the resulting structure is returned, so an
3169 * input value of `&lt;div>foo&lt;/div> &lt;div>bar&lt;/div>` will only return
3170 * the first `div` element node.
3171 *
3172 * @returns {Node}
3173 * Returns the first DOM `Node` extracted from the HTML fragment or
3174 * `null` on parsing failures or if no element could be found.
3175 */
3176 parse: function(s) {
3177 var elem;
3178
3179 try {
3180 domParser = domParser || new DOMParser();
3181 elem = domParser.parseFromString(s, 'text/html').body.firstChild;
3182 }
3183 catch(e) {}
3184
3185 if (!elem) {
3186 try {
3187 dummyElem = dummyElem || document.createElement('div');
3188 dummyElem.innerHTML = s;
3189 elem = dummyElem.firstChild;
3190 }
3191 catch (e) {}
3192 }
3193
3194 return elem || null;
3195 },
3196
3197 /**
3198 * Tests whether a given `Node` matches the given query selector.
3199 *
3200 * This function is a convenience wrapper around the standard
3201 * `Node.matches("selector")` function with the added benefit that
3202 * the `node` argument may be a non-`Node` value, in which case
3203 * this function simply returns `false`.
3204 *
3205 * @instance
3206 * @memberof LuCI.dom
3207 * @param {*} node
3208 * The `Node` argument to test the selector against.
3209 *
3210 * @param {string} [selector]
3211 * The query selector expression to test against the given node.
3212 *
3213 * @returns {boolean}
3214 * Returns `true` if the given node matches the specified selector
3215 * or `false` when the node argument is no valid DOM `Node` or the
3216 * selector didn't match.
3217 */
3218 matches: function(node, selector) {
3219 var m = this.elem(node) ? node.matches || node.msMatchesSelector : null;
3220 return m ? m.call(node, selector) : false;
3221 },
3222
3223 /**
3224 * Returns the closest parent node that matches the given query
3225 * selector expression.
3226 *
3227 * This function is a convenience wrapper around the standard
3228 * `Node.closest("selector")` function with the added benefit that
3229 * the `node` argument may be a non-`Node` value, in which case
3230 * this function simply returns `null`.
3231 *
3232 * @instance
3233 * @memberof LuCI.dom
3234 * @param {*} node
3235 * The `Node` argument to find the closest parent for.
3236 *
3237 * @param {string} [selector]
3238 * The query selector expression to test against each parent.
3239 *
3240 * @returns {Node|null}
3241 * Returns the closest parent node matching the selector or
3242 * `null` when the node argument is no valid DOM `Node` or the
3243 * selector didn't match any parent.
3244 */
3245 parent: function(node, selector) {
3246 if (this.elem(node) &amp;&amp; node.closest)
3247 return node.closest(selector);
3248
3249 while (this.elem(node))
3250 if (this.matches(node, selector))
3251 return node;
3252 else
3253 node = node.parentNode;
3254
3255 return null;
3256 },
3257
3258 /**
3259 * Appends the given children data to the given node.
3260 *
3261 * @instance
3262 * @memberof LuCI.dom
3263 * @param {*} node
3264 * The `Node` argument to append the children to.
3265 *
3266 * @param {*} [children]
3267 * The childrens to append to the given node.
3268 *
3269 * When `children` is an array, then each item of the array
3270 * will be either appended as child element or text node,
3271 * depending on whether the item is a DOM `Node` instance or
3272 * some other non-`null` value. Non-`Node`, non-`null` values
3273 * will be converted to strings first before being passed as
3274 * argument to `createTextNode()`.
3275 *
3276 * When `children` is a function, it will be invoked with
3277 * the passed `node` argument as sole parameter and the `append`
3278 * function will be invoked again, with the given `node` argument
3279 * as first and the return value of the `children` function as
3280 * second parameter.
3281 *
3282 * When `children` is is a DOM `Node` instance, it will be
3283 * appended to the given `node`.
3284 *
3285 * When `children` is any other non-`null` value, it will be
3286 * converted to a string and appened to the `innerHTML` property
3287 * of the given `node`.
3288 *
3289 * @returns {Node|null}
3290 * Returns the last children `Node` appended to the node or `null`
3291 * if either the `node` argument was no valid DOM `node` or if the
3292 * `children` was `null` or didn't result in further DOM nodes.
3293 */
3294 append: function(node, children) {
3295 if (!this.elem(node))
3296 return null;
3297
3298 if (Array.isArray(children)) {
3299 for (var i = 0; i &lt; children.length; i++)
3300 if (this.elem(children[i]))
3301 node.appendChild(children[i]);
3302 else if (children !== null &amp;&amp; children !== undefined)
3303 node.appendChild(document.createTextNode('' + children[i]));
3304
3305 return node.lastChild;
3306 }
3307 else if (typeof(children) === 'function') {
3308 return this.append(node, children(node));
3309 }
3310 else if (this.elem(children)) {
3311 return node.appendChild(children);
3312 }
3313 else if (children !== null &amp;&amp; children !== undefined) {
3314 node.innerHTML = '' + children;
3315 return node.lastChild;
3316 }
3317
3318 return null;
3319 },
3320
3321 /**
3322 * Replaces the content of the given node with the given children.
3323 *
3324 * This function first removes any children of the given DOM
3325 * `Node` and then adds the given given children following the
3326 * rules outlined below.
3327 *
3328 * @instance
3329 * @memberof LuCI.dom
3330 * @param {*} node
3331 * The `Node` argument to replace the children of.
3332 *
3333 * @param {*} [children]
3334 * The childrens to replace into the given node.
3335 *
3336 * When `children` is an array, then each item of the array
3337 * will be either appended as child element or text node,
3338 * depending on whether the item is a DOM `Node` instance or
3339 * some other non-`null` value. Non-`Node`, non-`null` values
3340 * will be converted to strings first before being passed as
3341 * argument to `createTextNode()`.
3342 *
3343 * When `children` is a function, it will be invoked with
3344 * the passed `node` argument as sole parameter and the `append`
3345 * function will be invoked again, with the given `node` argument
3346 * as first and the return value of the `children` function as
3347 * second parameter.
3348 *
3349 * When `children` is is a DOM `Node` instance, it will be
3350 * appended to the given `node`.
3351 *
3352 * When `children` is any other non-`null` value, it will be
3353 * converted to a string and appened to the `innerHTML` property
3354 * of the given `node`.
3355 *
3356 * @returns {Node|null}
3357 * Returns the last children `Node` appended to the node or `null`
3358 * if either the `node` argument was no valid DOM `node` or if the
3359 * `children` was `null` or didn't result in further DOM nodes.
3360 */
3361 content: function(node, children) {
3362 if (!this.elem(node))
3363 return null;
3364
3365 var dataNodes = node.querySelectorAll('[data-idref]');
3366
3367 for (var i = 0; i &lt; dataNodes.length; i++)
3368 delete this.registry[dataNodes[i].getAttribute('data-idref')];
3369
3370 while (node.firstChild)
3371 node.removeChild(node.firstChild);
3372
3373 return this.append(node, children);
3374 },
3375
3376 /**
3377 * Sets attributes or registers event listeners on element nodes.
3378 *
3379 * @instance
3380 * @memberof LuCI.dom
3381 * @param {*} node
3382 * The `Node` argument to set the attributes or add the event
3383 * listeners for. When the given `node` value is not a valid
3384 * DOM `Node`, the function returns and does nothing.
3385 *
3386 * @param {string|Object&lt;string, *>} key
3387 * Specifies either the attribute or event handler name to use,
3388 * or an object containing multiple key, value pairs which are
3389 * each added to the node as either attribute or event handler,
3390 * depending on the respective value.
3391 *
3392 * @param {*} [val]
3393 * Specifies the attribute value or event handler function to add.
3394 * If the `key` parameter is an `Object`, this parameter will be
3395 * ignored.
3396 *
3397 * When `val` is of type function, it will be registered as event
3398 * handler on the given `node` with the `key` parameter being the
3399 * event name.
3400 *
3401 * When `val` is of type object, it will be serialized as JSON and
3402 * added as attribute to the given `node`, using the given `key`
3403 * as attribute name.
3404 *
3405 * When `val` is of any other type, it will be added as attribute
3406 * to the given `node` as-is, with the underlying `setAttribute()`
3407 * call implicitely turning it into a string.
3408 */
3409 attr: function(node, key, val) {
3410 if (!this.elem(node))
3411 return null;
3412
3413 var attr = null;
3414
3415 if (typeof(key) === 'object' &amp;&amp; key !== null)
3416 attr = key;
3417 else if (typeof(key) === 'string')
3418 attr = {}, attr[key] = val;
3419
3420 for (key in attr) {
3421 if (!attr.hasOwnProperty(key) || attr[key] == null)
3422 continue;
3423
3424 switch (typeof(attr[key])) {
3425 case 'function':
3426 node.addEventListener(key, attr[key]);
3427 break;
3428
3429 case 'object':
3430 node.setAttribute(key, JSON.stringify(attr[key]));
3431 break;
3432
3433 default:
3434 node.setAttribute(key, attr[key]);
3435 }
3436 }
3437 },
3438
3439 /**
3440 * Creates a new DOM `Node` from the given `html`, `attr` and
3441 * `data` parameters.
3442 *
3443 * This function has multiple signatures, it can be either invoked
3444 * in the form `create(html[, attr[, data]])` or in the form
3445 * `create(html[, data])`. The used variant is determined from the
3446 * type of the second argument.
3447 *
3448 * @instance
3449 * @memberof LuCI.dom
3450 * @param {*} html
3451 * Describes the node to create.
3452 *
3453 * When the value of `html` is of type array, a `DocumentFragment`
3454 * node is created and each item of the array is first converted
3455 * to a DOM `Node` by passing it through `create()` and then added
3456 * as child to the fragment.
3457 *
3458 * When the value of `html` is a DOM `Node` instance, no new
3459 * element will be created but the node will be used as-is.
3460 *
3461 * When the value of `html` is a string starting with `&lt;`, it will
3462 * be passed to `dom.parse()` and the resulting value is used.
3463 *
3464 * When the value of `html` is any other string, it will be passed
3465 * to `document.createElement()` for creating a new DOM `Node` of
3466 * the given name.
3467 *
3468 * @param {Object&lt;string, *>} [attr]
3469 * Specifies an Object of key, value pairs to set as attributes
3470 * or event handlers on the created node. Refer to
3471 * {@link LuCI.dom#attr dom.attr()} for details.
3472 *
3473 * @param {*} [data]
3474 * Specifies children to append to the newly created element.
3475 * Refer to {@link LuCI.dom#append dom.append()} for details.
3476 *
3477 * @throws {InvalidCharacterError}
3478 * Throws an `InvalidCharacterError` when the given `html`
3479 * argument contained malformed markup (such as not escaped
3480 * `&amp;` characters in XHTML mode) or when the given node name
3481 * in `html` contains characters which are not legal in DOM
3482 * element names, such as spaces.
3483 *
3484 * @returns {Node}
3485 * Returns the newly created `Node`.
3486 */
3487 create: function() {
3488 var html = arguments[0],
3489 attr = arguments[1],
3490 data = arguments[2],
3491 elem;
3492
3493 if (!(attr instanceof Object) || Array.isArray(attr))
3494 data = attr, attr = null;
3495
3496 if (Array.isArray(html)) {
3497 elem = document.createDocumentFragment();
3498 for (var i = 0; i &lt; html.length; i++)
3499 elem.appendChild(this.create(html[i]));
3500 }
3501 else if (this.elem(html)) {
3502 elem = html;
3503 }
3504 else if (html.charCodeAt(0) === 60) {
3505 elem = this.parse(html);
3506 }
3507 else {
3508 elem = document.createElement(html);
3509 }
3510
3511 if (!elem)
3512 return null;
3513
3514 this.attr(elem, attr);
3515 this.append(elem, data);
3516
3517 return elem;
3518 },
3519
3520 registry: {},
3521
3522 /**
3523 * Attaches or detaches arbitrary data to and from a DOM `Node`.
3524 *
3525 * This function is useful to attach non-string values or runtime
3526 * data that is not serializable to DOM nodes. To decouple data
3527 * from the DOM, values are not added directly to nodes, but
3528 * inserted into a registry instead which is then referenced by a
3529 * string key stored as `data-idref` attribute in the node.
3530 *
3531 * This function has multiple signatures and is sensitive to the
3532 * number of arguments passed to it.
3533 *
3534 * - `dom.data(node)` -
3535 * Fetches all data associated with the given node.
3536 * - `dom.data(node, key)` -
3537 * Fetches a specific key associated with the given node.
3538 * - `dom.data(node, key, val)` -
3539 * Sets a specific key to the given value associated with the
3540 * given node.
3541 * - `dom.data(node, null)` -
3542 * Clears any data associated with the node.
3543 * - `dom.data(node, key, null)` -
3544 * Clears the given key associated with the node.
3545 *
3546 * @instance
3547 * @memberof LuCI.dom
3548 * @param {Node} node
3549 * The DOM `Node` instance to set or retrieve the data for.
3550 *
3551 * @param {string|null} [key]
3552 * This is either a string specifying the key to retrieve, or
3553 * `null` to unset the entire node data.
3554 *
3555 * @param {*|null} [val]
3556 * This is either a non-`null` value to set for a given key or
3557 * `null` to remove the given `key` from the specified node.
3558 *
3559 * @returns {*}
3560 * Returns the get or set value, or `null` when no value could
3561 * be found.
3562 */
3563 data: function(node, key, val) {
3564 var id = node.getAttribute('data-idref');
3565
3566 /* clear all data */
3567 if (arguments.length > 1 &amp;&amp; key == null) {
3568 if (id != null) {
3569 node.removeAttribute('data-idref');
3570 val = this.registry[id]
3571 delete this.registry[id];
3572 return val;
3573 }
3574
3575 return null;
3576 }
3577
3578 /* clear a key */
3579 else if (arguments.length > 2 &amp;&amp; key != null &amp;&amp; val == null) {
3580 if (id != null) {
3581 val = this.registry[id][key];
3582 delete this.registry[id][key];
3583 return val;
3584 }
3585
3586 return null;
3587 }
3588
3589 /* set a key */
3590 else if (arguments.length > 2 &amp;&amp; key != null &amp;&amp; val != null) {
3591 if (id == null) {
3592 do { id = Math.floor(Math.random() * 0xffffffff).toString(16) }
3593 while (this.registry.hasOwnProperty(id));
3594
3595 node.setAttribute('data-idref', id);
3596 this.registry[id] = {};
3597 }
3598
3599 return (this.registry[id][key] = val);
3600 }
3601
3602 /* get all data */
3603 else if (arguments.length == 1) {
3604 if (id != null)
3605 return this.registry[id];
3606
3607 return null;
3608 }
3609
3610 /* get a key */
3611 else if (arguments.length == 2) {
3612 if (id != null)
3613 return this.registry[id][key];
3614 }
3615
3616 return null;
3617 },
3618
3619 /**
3620 * Binds the given class instance ot the specified DOM `Node`.
3621 *
3622 * This function uses the `dom.data()` facility to attach the
3623 * passed instance of a Class to a node. This is needed for
3624 * complex widget elements or similar where the corresponding
3625 * class instance responsible for the element must be retrieved
3626 * from DOM nodes obtained by `querySelector()` or similar means.
3627 *
3628 * @instance
3629 * @memberof LuCI.dom
3630 * @param {Node} node
3631 * The DOM `Node` instance to bind the class to.
3632 *
3633 * @param {Class} inst
3634 * The Class instance to bind to the node.
3635 *
3636 * @throws {TypeError}
3637 * Throws a `TypeError` when the given instance argument isn't
3638 * a valid Class instance.
3639 *
3640 * @returns {Class}
3641 * Returns the bound class instance.
3642 */
3643 bindClassInstance: function(node, inst) {
3644 if (!(inst instanceof Class))
3645 L.error('TypeError', 'Argument must be a class instance');
3646
3647 return this.data(node, '_class', inst);
3648 },
3649
3650 /**
3651 * Finds a bound class instance on the given node itself or the
3652 * first bound instance on its closest parent node.
3653 *
3654 * @instance
3655 * @memberof LuCI.dom
3656 * @param {Node} node
3657 * The DOM `Node` instance to start from.
3658 *
3659 * @returns {Class|null}
3660 * Returns the founds class instance if any or `null` if no bound
3661 * class could be found on the node itself or any of its parents.
3662 */
3663 findClassInstance: function(node) {
3664 var inst = null;
3665
3666 do {
3667 inst = this.data(node, '_class');
3668 node = node.parentNode;
3669 }
3670 while (!(inst instanceof Class) &amp;&amp; node != null);
3671
3672 return inst;
3673 },
3674
3675 /**
3676 * Finds a bound class instance on the given node itself or the
3677 * first bound instance on its closest parent node and invokes
3678 * the specified method name on the found class instance.
3679 *
3680 * @instance
3681 * @memberof LuCI.dom
3682 * @param {Node} node
3683 * The DOM `Node` instance to start from.
3684 *
3685 * @param {string} method
3686 * The name of the method to invoke on the found class instance.
3687 *
3688 * @param {...*} params
3689 * Additional arguments to pass to the invoked method as-is.
3690 *
3691 * @returns {*|null}
3692 * Returns the return value of the invoked method if a class
3693 * instance and method has been found. Returns `null` if either
3694 * no bound class instance could be found, or if the found
3695 * instance didn't have the requested `method`.
3696 */
3697 callClassMethod: function(node, method /*, ... */) {
3698 var inst = this.findClassInstance(node);
3699
3700 if (inst == null || typeof(inst[method]) != 'function')
3701 return null;
3702
3703 return inst[method].apply(inst, inst.varargs(arguments, 2));
3704 },
3705
3706 /**
3707 * The ignore callback function is invoked by `isEmpty()` for each
3708 * child node to decide whether to ignore a child node or not.
3709 *
3710 * When this function returns `false`, the node passed to it is
3711 * ignored, else not.
3712 *
3713 * @callback LuCI.dom~ignoreCallbackFn
3714 * @param {Node} node
3715 * The child node to test.
3716 *
3717 * @returns {boolean}
3718 * Boolean indicating whether to ignore the node or not.
3719 */
3720
3721 /**
3722 * Tests whether a given DOM `Node` instance is empty or appears
3723 * empty.
3724 *
3725 * Any element child nodes which have the CSS class `hidden` set
3726 * or for which the optionally passed `ignoreFn` callback function
3727 * returns `false` are ignored.
3728 *
3729 * @instance
3730 * @memberof LuCI.dom
3731 * @param {Node} node
3732 * The DOM `Node` instance to test.
3733 *
3734 * @param {LuCI.dom~ignoreCallbackFn} [ignoreFn]
3735 * Specifies an optional function which is invoked for each child
3736 * node to decide whether the child node should be ignored or not.
3737 *
3738 * @returns {boolean}
3739 * Returns `true` if the node does not have any children or if
3740 * any children node either has a `hidden` CSS class or a `false`
3741 * result when testing it using the given `ignoreFn`.
3742 */
3743 isEmpty: function(node, ignoreFn) {
3744 for (var child = node.firstElementChild; child != null; child = child.nextElementSibling)
3745 if (!child.classList.contains('hidden') &amp;&amp; (!ignoreFn || !ignoreFn(child)))
3746 return false;
3747
3748 return true;
3749 }
3750 }),
3751
3752 Poll: Poll,
3753 Class: Class,
3754 Request: Request,
3755
3756 /**
3757 * @class
3758 * @memberof LuCI
3759 * @hideconstructor
3760 * @classdesc
3761 *
3762 * The `view` class forms the basis of views and provides a standard
3763 * set of methods to inherit from.
3764 */
3765 view: Class.extend(/* @lends LuCI.view.prototype */ {
3766 __name__: 'LuCI.View',
3767
3768 __init__: function() {
3769 var vp = document.getElementById('view');
3770
3771 L.dom.content(vp, E('div', { 'class': 'spinning' }, _('Loading view…')));
3772
3773 return Promise.resolve(this.load())
3774 .then(L.bind(this.render, this))
3775 .then(L.bind(function(nodes) {
3776 var vp = document.getElementById('view');
3777
3778 L.dom.content(vp, nodes);
3779 L.dom.append(vp, this.addFooter());
3780 }, this)).catch(L.error);
3781 },
3782
3783 /**
3784 * The load function is invoked before the view is rendered.
3785 *
3786 * The invocation of this function is wrapped by
3787 * `Promise.resolve()` so it may return Promises if needed.
3788 *
3789 * The return value of the function (or the resolved values
3790 * of the promise returned by it) will be passed as first
3791 * argument to `render()`.
3792 *
3793 * This function is supposed to be overwritten by subclasses,
3794 * the default implementation does nothing.
3795 *
3796 * @instance
3797 * @abstract
3798 * @memberof LuCI.view
3799 *
3800 * @returns {*|Promise&lt;*>}
3801 * May return any value or a Promise resolving to any value.
3802 */
3803 load: function() {},
3804
3805 /**
3806 * The render function is invoked after the
3807 * {@link LuCI.view#load load()} function and responsible
3808 * for setting up the view contents. It must return a DOM
3809 * `Node` or `DocumentFragment` holding the contents to
3810 * insert into the view area.
3811 *
3812 * The invocation of this function is wrapped by
3813 * `Promise.resolve()` so it may return Promises if needed.
3814 *
3815 * The return value of the function (or the resolved values
3816 * of the promise returned by it) will be inserted into the
3817 * main content area using
3818 * {@link LuCI.dom#append dom.append()}.
3819 *
3820 * This function is supposed to be overwritten by subclasses,
3821 * the default implementation does nothing.
3822 *
3823 * @instance
3824 * @abstract
3825 * @memberof LuCI.view
3826 * @param {*|null} load_results
3827 * This function will receive the return value of the
3828 * {@link LuCI.view#load view.load()} function as first
3829 * argument.
3830 *
3831 * @returns {Node|Promise&lt;Node>}
3832 * Should return a DOM `Node` value or a `Promise` resolving
3833 * to a `Node` value.
3834 */
3835 render: function() {},
3836
3837 /**
3838 * The handleSave function is invoked when the user clicks
3839 * the `Save` button in the page action footer.
3840 *
3841 * The default implementation should be sufficient for most
3842 * views using {@link form#Map form.Map()} based forms - it
3843 * will iterate all forms present in the view and invoke
3844 * the {@link form#Map#save Map.save()} method on each form.
3845 *
3846 * Views not using `Map` instances or requiring other special
3847 * logic should overwrite `handleSave()` with a custom
3848 * implementation.
3849 *
3850 * To disable the `Save` page footer button, views extending
3851 * this base class should overwrite the `handleSave` function
3852 * with `null`.
3853 *
3854 * The invocation of this function is wrapped by
3855 * `Promise.resolve()` so it may return Promises if needed.
3856 *
3857 * @instance
3858 * @memberof LuCI.view
3859 * @param {Event} ev
3860 * The DOM event that triggered the function.
3861 *
3862 * @returns {*|Promise&lt;*>}
3863 * Any return values of this function are discarded, but
3864 * passed through `Promise.resolve()` to ensure that any
3865 * returned promise runs to completion before the button
3866 * is reenabled.
3867 */
3868 handleSave: function(ev) {
3869 var tasks = [];
3870
3871 document.getElementById('maincontent')
3872 .querySelectorAll('.cbi-map').forEach(function(map) {
3873 tasks.push(L.dom.callClassMethod(map, 'save'));
3874 });
3875
3876 return Promise.all(tasks);
3877 },
3878
3879 /**
3880 * The handleSaveApply function is invoked when the user clicks
3881 * the `Save &amp; Apply` button in the page action footer.
3882 *
3883 * The default implementation should be sufficient for most
3884 * views using {@link form#Map form.Map()} based forms - it
3885 * will first invoke
3886 * {@link LuCI.view.handleSave view.handleSave()} and then
3887 * call {@link ui#changes#apply ui.changes.apply()} to start the
3888 * modal config apply and page reload flow.
3889 *
3890 * Views not using `Map` instances or requiring other special
3891 * logic should overwrite `handleSaveApply()` with a custom
3892 * implementation.
3893 *
3894 * To disable the `Save &amp; Apply` page footer button, views
3895 * extending this base class should overwrite the
3896 * `handleSaveApply` function with `null`.
3897 *
3898 * The invocation of this function is wrapped by
3899 * `Promise.resolve()` so it may return Promises if needed.
3900 *
3901 * @instance
3902 * @memberof LuCI.view
3903 * @param {Event} ev
3904 * The DOM event that triggered the function.
3905 *
3906 * @returns {*|Promise&lt;*>}
3907 * Any return values of this function are discarded, but
3908 * passed through `Promise.resolve()` to ensure that any
3909 * returned promise runs to completion before the button
3910 * is reenabled.
3911 */
3912 handleSaveApply: function(ev) {
3913 return this.handleSave(ev).then(function() {
3914 L.ui.changes.apply(true);
3915 });
3916 },
3917
3918 /**
3919 * The handleReset function is invoked when the user clicks
3920 * the `Reset` button in the page action footer.
3921 *
3922 * The default implementation should be sufficient for most
3923 * views using {@link form#Map form.Map()} based forms - it
3924 * will iterate all forms present in the view and invoke
3925 * the {@link form#Map#save Map.reset()} method on each form.
3926 *
3927 * Views not using `Map` instances or requiring other special
3928 * logic should overwrite `handleReset()` with a custom
3929 * implementation.
3930 *
3931 * To disable the `Reset` page footer button, views extending
3932 * this base class should overwrite the `handleReset` function
3933 * with `null`.
3934 *
3935 * The invocation of this function is wrapped by
3936 * `Promise.resolve()` so it may return Promises if needed.
3937 *
3938 * @instance
3939 * @memberof LuCI.view
3940 * @param {Event} ev
3941 * The DOM event that triggered the function.
3942 *
3943 * @returns {*|Promise&lt;*>}
3944 * Any return values of this function are discarded, but
3945 * passed through `Promise.resolve()` to ensure that any
3946 * returned promise runs to completion before the button
3947 * is reenabled.
3948 */
3949 handleReset: function(ev) {
3950 var tasks = [];
3951
3952 document.getElementById('maincontent')
3953 .querySelectorAll('.cbi-map').forEach(function(map) {
3954 tasks.push(L.dom.callClassMethod(map, 'reset'));
3955 });
3956
3957 return Promise.all(tasks);
3958 },
3959
3960 /**
3961 * Renders a standard page action footer if any of the
3962 * `handleSave()`, `handleSaveApply()` or `handleReset()`
3963 * functions are defined.
3964 *
3965 * The default implementation should be sufficient for most
3966 * views - it will render a standard page footer with action
3967 * buttons labeled `Save`, `Save &amp; Apply` and `Reset`
3968 * triggering the `handleSave()`, `handleSaveApply()` and
3969 * `handleReset()` functions respectively.
3970 *
3971 * When any of these `handle*()` functions is overwritten
3972 * with `null` by a view extending this class, the
3973 * corresponding button will not be rendered.
3974 *
3975 * @instance
3976 * @memberof LuCI.view
3977 * @returns {DocumentFragment}
3978 * Returns a `DocumentFragment` containing the footer bar
3979 * with buttons for each corresponding `handle*()` action
3980 * or an empty `DocumentFragment` if all three `handle*()`
3981 * methods are overwritten with `null`.
3982 */
3983 addFooter: function() {
3984 var footer = E([]);
3985
3986 if (this.handleSaveApply || this.handleSave || this.handleReset) {
3987 footer.appendChild(E('div', { 'class': 'cbi-page-actions' }, [
3988 this.handleSaveApply ? E('button', {
3989 'class': 'cbi-button cbi-button-apply',
3990 'click': L.ui.createHandlerFn(this, 'handleSaveApply')
3991 }, [ _('Save &amp; Apply') ]) : '', ' ',
3992 this.handleSave ? E('button', {
3993 'class': 'cbi-button cbi-button-save',
3994 'click': L.ui.createHandlerFn(this, 'handleSave')
3995 }, [ _('Save') ]) : '', ' ',
3996 this.handleReset ? E('button', {
3997 'class': 'cbi-button cbi-button-reset',
3998 'click': L.ui.createHandlerFn(this, 'handleReset')
3999 }, [ _('Reset') ]) : ''
4000 ]));
4001 }
4002
4003 return footer;
4004 }
4005 })
4006 });
4007
4008 /**
4009 * @class
4010 * @memberof LuCI
4011 * @deprecated
4012 * @classdesc
4013 *
4014 * The `LuCI.XHR` class is a legacy compatibility shim for the
4015 * functionality formerly provided by `xhr.js`. It is registered as global
4016 * `window.XHR` symbol for compatibility with legacy code.
4017 *
4018 * New code should use {@link LuCI.Request} instead to implement HTTP
4019 * request handling.
4020 */
4021 var XHR = Class.extend(/** @lends LuCI.XHR.prototype */ {
4022 __name__: 'LuCI.XHR',
4023 __init__: function() {
4024 if (window.console &amp;&amp; console.debug)
4025 console.debug('Direct use XHR() is deprecated, please use L.Request instead');
4026 },
4027
4028 _response: function(cb, res, json, duration) {
4029 if (this.active)
4030 cb(res, json, duration);
4031 delete this.active;
4032 },
4033
4034 /**
4035 * This function is a legacy wrapper around
4036 * {@link LuCI#get LuCI.get()}.
4037 *
4038 * @instance
4039 * @deprecated
4040 * @memberof LuCI.XHR
4041 *
4042 * @param {string} url
4043 * The URL to request
4044 *
4045 * @param {Object} [data]
4046 * Additional query string data
4047 *
4048 * @param {LuCI.requestCallbackFn} [callback]
4049 * Callback function to invoke on completion
4050 *
4051 * @param {number} [timeout]
4052 * Request timeout to use
4053 *
4054 * @return {Promise&lt;null>}
4055 */
4056 get: function(url, data, callback, timeout) {
4057 this.active = true;
4058 L.get(url, data, this._response.bind(this, callback), timeout);
4059 },
4060
4061 /**
4062 * This function is a legacy wrapper around
4063 * {@link LuCI#post LuCI.post()}.
4064 *
4065 * @instance
4066 * @deprecated
4067 * @memberof LuCI.XHR
4068 *
4069 * @param {string} url
4070 * The URL to request
4071 *
4072 * @param {Object} [data]
4073 * Additional data to append to the request body.
4074 *
4075 * @param {LuCI.requestCallbackFn} [callback]
4076 * Callback function to invoke on completion
4077 *
4078 * @param {number} [timeout]
4079 * Request timeout to use
4080 *
4081 * @return {Promise&lt;null>}
4082 */
4083 post: function(url, data, callback, timeout) {
4084 this.active = true;
4085 L.post(url, data, this._response.bind(this, callback), timeout);
4086 },
4087
4088 /**
4089 * Cancels a running request.
4090 *
4091 * This function does not actually cancel the underlying
4092 * `XMLHTTPRequest` request but it sets a flag which prevents the
4093 * invocation of the callback function when the request eventually
4094 * finishes or timed out.
4095 *
4096 * @instance
4097 * @deprecated
4098 * @memberof LuCI.XHR
4099 */
4100 cancel: function() { delete this.active },
4101
4102 /**
4103 * Checks the running state of the request.
4104 *
4105 * @instance
4106 * @deprecated
4107 * @memberof LuCI.XHR
4108 *
4109 * @returns {boolean}
4110 * Returns `true` if the request is still running or `false` if it
4111 * already completed.
4112 */
4113 busy: function() { return (this.active === true) },
4114
4115 /**
4116 * Ignored for backwards compatibility.
4117 *
4118 * This function does nothing.
4119 *
4120 * @instance
4121 * @deprecated
4122 * @memberof LuCI.XHR
4123 */
4124 abort: function() {},
4125
4126 /**
4127 * Existing for backwards compatibility.
4128 *
4129 * This function simply throws an `InternalError` when invoked.
4130 *
4131 * @instance
4132 * @deprecated
4133 * @memberof LuCI.XHR
4134 *
4135 * @throws {InternalError}
4136 * Throws an `InternalError` with the message `Not implemented`
4137 * when invoked.
4138 */
4139 send_form: function() { L.error('InternalError', 'Not implemented') },
4140 });
4141
4142 XHR.get = function() { return window.L.get.apply(window.L, arguments) };
4143 XHR.post = function() { return window.L.post.apply(window.L, arguments) };
4144 XHR.poll = function() { return window.L.poll.apply(window.L, arguments) };
4145 XHR.stop = Request.poll.remove.bind(Request.poll);
4146 XHR.halt = Request.poll.stop.bind(Request.poll);
4147 XHR.run = Request.poll.start.bind(Request.poll);
4148 XHR.running = Request.poll.active.bind(Request.poll);
4149
4150 window.XHR = XHR;
4151 window.LuCI = LuCI;
4152 })(window, document);
4153 </code></pre>
4154 </article>
4155 </section>
4156
4157
4158
4159
4160
4161
4162
4163
4164 <footer>
4165 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Nov 07 2019 12:36:05 GMT+0100 (Central European Standard Time)
4166 </footer>
4167 </div>
4168 </div>
4169 <script>prettyPrint();</script>
4170 <script src="scripts/jaguar.js"></script>
4171 </body>
4172 </html>