summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/htdocs
diff options
context:
space:
mode:
Diffstat (limited to 'modules/luci-base/htdocs')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/form.js2
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/luci.js67
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/network.js16
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/ui.js28
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/validation.js4
5 files changed, 85 insertions, 32 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/form.js b/modules/luci-base/htdocs/luci-static/resources/form.js
index 853b01ee3d..508e2c4857 100644
--- a/modules/luci-base/htdocs/luci-static/resources/form.js
+++ b/modules/luci-base/htdocs/luci-static/resources/form.js
@@ -1361,7 +1361,7 @@ var CBIValue = CBIAbstractValue.extend({
if (typeof(this.title) === 'string' && this.title !== '') {
optionEl.appendChild(E('label', {
'class': 'cbi-value-title',
- 'for': 'cbid.%s.%s.%s'.format(config_name, section_id, this.option)
+ 'for': 'widget.cbid.%s.%s.%s'.format(config_name, section_id, this.option)
},
this.titleref ? E('a', {
'class': 'cbi-title-ref',
diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js
index 93ecbac15f..259679f137 100644
--- a/modules/luci-base/htdocs/luci-static/resources/luci.js
+++ b/modules/luci-base/htdocs/luci-static/resources/luci.js
@@ -23,6 +23,20 @@
});
}
+ /* Promise.finally polyfill */
+ if (typeof Promise.prototype.finally !== 'function') {
+ Promise.prototype.finally = function(fn) {
+ var onFinally = function(cb) {
+ return Promise.resolve(fn.call(this)).then(cb);
+ };
+
+ return this.then(
+ function(result) { return onFinally.call(this, function() { return result }) },
+ function(reason) { return onFinally.call(this, function() { return Promise.reject(reason) }) }
+ );
+ };
+ }
+
/*
* Class declaration and inheritance helper
*/
@@ -210,8 +224,7 @@
});
- var requestQueue = [],
- rpcBaseURL = null;
+ var requestQueue = [];
function isQueueableRequest(opt) {
if (!classes.rpc)
@@ -223,8 +236,7 @@
if (opt.nobatch === true)
return false;
- if (rpcBaseURL == null)
- rpcBaseURL = Request.expandURL(classes.rpc.getBaseURL());
+ var rpcBaseURL = Request.expandURL(classes.rpc.getBaseURL());
return (rpcBaseURL != null && opt.url.indexOf(rpcBaseURL) == 0);
}
@@ -331,7 +343,9 @@
opt.xhr.open(opt.method, opt.url, true);
opt.xhr.responseType = 'text';
- opt.xhr.overrideMimeType('application/octet-stream');
+
+ if ('overrideMimeType' in opt.xhr)
+ opt.xhr.overrideMimeType('application/octet-stream');
if ('timeout' in opt)
opt.xhr.timeout = +opt.timeout;
@@ -544,6 +558,7 @@
var dummyElem = null,
domParser = null,
originalCBIInit = null,
+ rpcBaseURL = null,
classes = {};
var LuCI = Class.extend({
@@ -579,7 +594,9 @@
Promise.all([
domReady,
this.require('ui'),
- this.require('form')
+ this.require('rpc'),
+ this.require('form'),
+ this.probeRPCBaseURL()
]).then(this.setupDOM.bind(this)).catch(this.error);
originalCBIInit = window.cbi_init;
@@ -752,7 +769,43 @@
},
/* DOM setup */
- setupDOM: function(ev) {
+ probeRPCBaseURL: function() {
+ if (rpcBaseURL == null) {
+ try {
+ rpcBaseURL = window.sessionStorage.getItem('rpcBaseURL');
+ }
+ catch (e) { }
+ }
+
+ if (rpcBaseURL == null) {
+ var rpcFallbackURL = this.url('admin/ubus');
+
+ rpcBaseURL = Request.get('/ubus/').then(function(res) {
+ return (rpcBaseURL = (res.status == 400) ? '/ubus/' : rpcFallbackURL);
+ }, function() {
+ return (rpcBaseURL = rpcFallbackURL);
+ }).then(function(url) {
+ try {
+ window.sessionStorage.setItem('rpcBaseURL', url);
+ }
+ catch (e) { }
+
+ return url;
+ });
+ }
+
+ return Promise.resolve(rpcBaseURL);
+ },
+
+ setupDOM: function(res) {
+ var domEv = res[0],
+ uiClass = res[1],
+ rpcClass = res[2],
+ formClass = res[3],
+ rpcBaseURL = res[4];
+
+ rpcClass.setBaseURL(rpcBaseURL);
+
Request.addInterceptor(function(res) {
if (res.status != 403 || res.headers.get('X-LuCI-Login-Required') != 'yes')
return;
diff --git a/modules/luci-base/htdocs/luci-static/resources/network.js b/modules/luci-base/htdocs/luci-static/resources/network.js
index 19640604e4..d3d9a1cf57 100644
--- a/modules/luci-base/htdocs/luci-static/resources/network.js
+++ b/modules/luci-base/htdocs/luci-static/resources/network.js
@@ -966,7 +966,7 @@ Network = L.Class.extend({
radiostate = res[1];
netstate = res[2];
sid = netstate.section;
- netid = getWifiNetidBySid(sid);
+ netid = L.toArray(getWifiNetidBySid(sid))[0];
}
else {
res = getWifiStateBySid(netname);
@@ -976,7 +976,7 @@ Network = L.Class.extend({
radiostate = res[1];
netstate = res[2];
sid = netname;
- netid = getWifiNetidBySid(sid);
+ netid = L.toArray(getWifiNetidBySid(sid))[0];
}
else {
res = getWifiNetidBySid(netname);
@@ -1015,9 +1015,9 @@ Network = L.Class.extend({
uci.set('wireless', sid, key, options[key]);
var radioname = existingDevice['.name'],
- netid = getWifiNetidBySid(sid);
+ netid = getWifiNetidBySid(sid) || [];
- return this.instantiateWifiNetwork(sid, radioname, _cache.wifi[radioname], netid, null, { ifname: netid });
+ return this.instantiateWifiNetwork(sid, radioname, _cache.wifi[radioname], netid[0], null, { ifname: netid });
}, this));
},
@@ -1469,7 +1469,7 @@ Protocol = L.Class.extend({
ifname = getWifiNetidByNetname(this.sid);
- return (ifname != null ? L.network.instantiateDevice(ifname, this) : null);
+ return (ifname != null ? L.network.instantiateDevice(ifname[0], this) : null);
}
},
@@ -1552,9 +1552,9 @@ Device = L.Class.extend({
if (wif != null) {
var res = getWifiStateBySid(wif) || [],
- netid = getWifiNetidBySid(wif);
+ netid = getWifiNetidBySid(wif) || [];
- this.wif = new WifiNetwork(wif, res[0], res[1], netid, res[2], { ifname: ifname });
+ this.wif = new WifiNetwork(wif, res[0], res[1], netid[0], res[2], { ifname: ifname });
this.ifname = this.wif.getIfname();
}
@@ -1588,7 +1588,7 @@ Device = L.Class.extend({
},
getType: function() {
- if (this.ifname.charAt(0) == '@')
+ if (this.ifname != null && this.ifname.charAt(0) == '@')
return 'alias';
else if (this.wif != null || isWifiIfname(this.ifname))
return 'wifi';
diff --git a/modules/luci-base/htdocs/luci-static/resources/ui.js b/modules/luci-base/htdocs/luci-static/resources/ui.js
index 28d1fa90ae..9e43c2d125 100644
--- a/modules/luci-base/htdocs/luci-static/resources/ui.js
+++ b/modules/luci-base/htdocs/luci-static/resources/ui.js
@@ -97,6 +97,7 @@ var UITextfield = UIElement.extend({
}
frameEl.appendChild(E('input', {
+ 'id': this.options.id ? 'widget.' + this.options.id : null,
'name': this.options.name,
'type': this.options.password ? 'password' : 'text',
'class': this.options.password ? 'cbi-input-password' : 'cbi-input-text',
@@ -168,6 +169,7 @@ var UICheckbox = UIElement.extend({
}));
frameEl.appendChild(E('input', {
+ 'id': this.options.id ? 'widget.' + this.options.id : null,
'name': this.options.name,
'type': 'checkbox',
'value': this.options.value_enabled,
@@ -224,7 +226,7 @@ var UISelect = UIElement.extend({
},
render: function() {
- var frameEl,
+ var frameEl = E('div', { 'id': this.options.id }),
keys = Object.keys(this.choices);
if (this.options.sort === true)
@@ -233,16 +235,16 @@ var UISelect = UIElement.extend({
keys = this.options.sort;
if (this.options.widget == 'select') {
- frameEl = E('select', {
- 'id': this.options.id,
+ frameEl.appendChild(E('select', {
+ 'id': this.options.id ? 'widget.' + this.options.id : null,
'name': this.options.name,
'size': this.options.size,
'class': 'cbi-input-select',
'multiple': this.options.multi ? '' : null
- });
+ }));
if (this.options.optional)
- frameEl.appendChild(E('option', {
+ frameEl.lastChild.appendChild(E('option', {
'value': '',
'selected': (this.values.length == 0 || this.values[0] == '') ? '' : null
}, this.choices[''] || this.options.placeholder || _('-- Please choose --')));
@@ -251,22 +253,19 @@ var UISelect = UIElement.extend({
if (keys[i] == null || keys[i] == '')
continue;
- frameEl.appendChild(E('option', {
+ frameEl.lastChild.appendChild(E('option', {
'value': keys[i],
'selected': (this.values.indexOf(keys[i]) > -1) ? '' : null
}, this.choices[keys[i]] || keys[i]));
}
}
else {
- frameEl = E('div', {
- 'id': this.options.id
- });
-
var brEl = (this.options.orientation === 'horizontal') ? document.createTextNode(' ') : E('br');
for (var i = 0; i < keys.length; i++) {
frameEl.appendChild(E('label', {}, [
E('input', {
+ 'id': this.options.id ? 'widget.' + this.options.id : null,
'name': this.options.id || this.options.name,
'type': this.options.multi ? 'checkbox' : 'radio',
'class': this.options.multi ? 'cbi-input-checkbox' : 'cbi-input-radio',
@@ -306,7 +305,7 @@ var UISelect = UIElement.extend({
getValue: function() {
if (this.options.widget == 'select')
- return this.node.value;
+ return this.node.firstChild.value;
var radioEls = frameEl.querySelectorAll('input[type="radio"]');
for (var i = 0; i < radioEls.length; i++)
@@ -321,8 +320,8 @@ var UISelect = UIElement.extend({
if (value == null)
value = '';
- for (var i = 0; i < this.node.options.length; i++)
- this.node.options[i].selected = (this.node.options[i].value == value);
+ for (var i = 0; i < this.node.firstChild.options.length; i++)
+ this.node.firstChild.options[i].selected = (this.node.firstChild.options[i].value == value);
return;
}
@@ -1152,6 +1151,7 @@ var UIDynamicList = UIElement.extend({
}
else {
var inputEl = E('input', {
+ 'id': this.options.id ? 'widget.' + this.options.id : null,
'type': 'text',
'class': 'cbi-input-text',
'placeholder': this.options.placeholder
@@ -1978,7 +1978,7 @@ return L.Class.extend({
}
else {
L.ui.changes.displayStatus('warning',
- E('p', _('Apply request failed with status <code>%h</code>%>')
+ E('p', _('Apply request failed with status <code>%h</code>')
.format(r.responseText || r.statusText || r.status)));
window.setTimeout(function() {
diff --git a/modules/luci-base/htdocs/luci-static/resources/validation.js b/modules/luci-base/htdocs/luci-static/resources/validation.js
index 621e5b8bd5..ca544cb15d 100644
--- a/modules/luci-base/htdocs/luci-static/resources/validation.js
+++ b/modules/luci-base/htdocs/luci-static/resources/validation.js
@@ -510,11 +510,11 @@ var ValidatorFactory = L.Class.extend({
day = +RegExp.$3,
days_in_month = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
- function is_leap_year(year) {
+ var is_leap_year = function(year) {
return ((!(year % 4) && (year % 100)) || !(year % 400));
}
- function get_days_in_month(month, year) {
+ var get_days_in_month = function(month, year) {
return (month === 2 && is_leap_year(year)) ? 29 : days_in_month[month - 1];
}