summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/htdocs/luci-static/resources/ui.js
diff options
context:
space:
mode:
Diffstat (limited to 'modules/luci-base/htdocs/luci-static/resources/ui.js')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/ui.js79
1 files changed, 47 insertions, 32 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/ui.js b/modules/luci-base/htdocs/luci-static/resources/ui.js
index 99e1548a43..caae812812 100644
--- a/modules/luci-base/htdocs/luci-static/resources/ui.js
+++ b/modules/luci-base/htdocs/luci-static/resources/ui.js
@@ -2,6 +2,7 @@
'require rpc';
'require uci';
'require validation';
+'require fs';
var modalDiv = null,
tooltipDiv = null,
@@ -1470,26 +1471,6 @@ var UIFileUpload = UIElement.extend({
}, options);
},
- callFileStat: rpc.declare({
- 'object': 'file',
- 'method': 'stat',
- 'params': [ 'path' ],
- 'expect': { '': {} }
- }),
-
- callFileList: rpc.declare({
- 'object': 'file',
- 'method': 'list',
- 'params': [ 'path' ],
- 'expect': { 'entries': [] }
- }),
-
- callFileRemove: rpc.declare({
- 'object': 'file',
- 'method': 'remove',
- 'params': [ 'path' ]
- }),
-
bind: function(browserEl) {
this.node = browserEl;
@@ -1502,7 +1483,7 @@ var UIFileUpload = UIElement.extend({
},
render: function() {
- return Promise.resolve(this.value != null ? this.callFileStat(this.value) : null).then(L.bind(function(stat) {
+ return L.resolveDefault(this.value != null ? fs.stat(this.value) : null).then(L.bind(function(stat) {
var label;
if (L.isObject(stat) && stat.type != 'directory')
@@ -1647,15 +1628,11 @@ var UIFileUpload = UIElement.extend({
hidden.value = '';
}
- return this.callFileRemove(path).then(L.bind(function(parent, ev, rc) {
- if (rc == 0)
- return this.handleSelect(parent, null, ev);
- else if (rc == 6)
- alert(_('Delete permission denied'));
- else
- alert(_('Delete request failed: %d %s').format(rc, rpc.getStatusText(rc)));
-
- }, this, parent, ev));
+ return fs.remove(path).then(L.bind(function(parent, ev) {
+ return this.handleSelect(parent, null, ev);
+ }, this, parent, ev)).catch(function(err) {
+ alert(_('Delete request failed: %s').format(err.message));
+ });
}
},
@@ -1817,7 +1794,7 @@ var UIFileUpload = UIElement.extend({
if (fileStat == null) {
L.dom.content(ul, E('em', { 'class': 'spinning' }, _('Loading directory contents…')));
- this.callFileList(path).then(L.bind(this.renderListing, this, browser, path));
+ L.resolveDefault(fs.list(path), []).then(L.bind(this.renderListing, this, browser, path));
}
else {
var button = this.node.firstElementChild,
@@ -1849,7 +1826,7 @@ var UIFileUpload = UIElement.extend({
ev.preventDefault();
- return this.callFileList(path).then(L.bind(function(button, browser, path, list) {
+ return L.resolveDefault(fs.list(path), []).then(L.bind(function(button, browser, path, list) {
document.querySelectorAll('.cbi-filebrowser.open').forEach(function(browserEl) {
L.dom.findClassInstance(browserEl).handleCancel(ev);
});
@@ -2237,6 +2214,44 @@ return L.Class.extend({
}
}),
+ /* Reconnect handling */
+ pingDevice: function(proto, ipaddr) {
+ var target = '%s://%s%s?%s'.format(proto || 'http', ipaddr || window.location.host, L.resource('icons/loading.gif'), Math.random());
+
+ return new Promise(function(resolveFn, rejectFn) {
+ var img = new Image();
+
+ img.onload = resolveFn;
+ img.onerror = rejectFn;
+
+ window.setTimeout(rejectFn, 1000);
+
+ img.src = target;
+ });
+ },
+
+ awaitReconnect: function(/* ... */) {
+ var ipaddrs = arguments.length ? arguments : [ window.location.host ];
+
+ window.setTimeout(L.bind(function() {
+ L.Poll.add(L.bind(function() {
+ var tasks = [], reachable = false;
+
+ for (var i = 0; i < 2; i++)
+ for (var j = 0; j < ipaddrs.length; j++)
+ tasks.push(this.pingDevice(i ? 'https' : 'http', ipaddrs[j])
+ .then(function(ev) { reachable = ev.target.src.replace(/^(https?:\/\/[^\/]+).*$/, '$1/') }, function() {}));
+
+ return Promise.all(tasks).then(function() {
+ if (reachable) {
+ L.Poll.stop();
+ window.location = reachable;
+ }
+ });
+ }, this));
+ }, this), 5000);
+ },
+
/* UCI Changes */
changes: L.Class.singleton({
init: function() {