luci-base: add client based view actions
Introduce a new view() target for CBI dispatch nodes, as long with the required template and plumbing work in luci.js to allow requiring view classes. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
5b7924c808
commit
2beb9fa16f
3 changed files with 29 additions and 12 deletions
|
@ -582,19 +582,19 @@
|
||||||
for (var i = 0; ptr && i < parts.length - 1; i++)
|
for (var i = 0; ptr && i < parts.length - 1; i++)
|
||||||
ptr = ptr[parts[i]];
|
ptr = ptr[parts[i]];
|
||||||
|
|
||||||
if (!ptr)
|
if (ptr)
|
||||||
L.error('DependencyError',
|
ptr[parts[i]] = instance;
|
||||||
'Parent "%s" for class "%s" is missing',
|
|
||||||
parts.slice(0, i).join('.'), name);
|
|
||||||
|
|
||||||
classes[name] = ptr[parts[i]] = instance;
|
classes[name] = instance;
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Request class file */
|
/* Request class file */
|
||||||
classes[name] = Request.get(url, { cache: true }).then(compileClass);
|
classes[name] = Request.get(url, { cache: true })
|
||||||
|
.then(compileClass)
|
||||||
|
.catch(L.error);
|
||||||
|
|
||||||
return classes[name];
|
return classes[name];
|
||||||
},
|
},
|
||||||
|
@ -942,18 +942,18 @@
|
||||||
__name__: 'LuCI.View',
|
__name__: 'LuCI.View',
|
||||||
|
|
||||||
__init__: function() {
|
__init__: function() {
|
||||||
var mc = document.getElementById('maincontent');
|
var vp = document.getElementById('view');
|
||||||
|
|
||||||
L.dom.content(mc, E('div', { 'class': 'spinning' }, _('Loading view…')));
|
L.dom.content(vp, E('div', { 'class': 'spinning' }, _('Loading view…')));
|
||||||
|
|
||||||
return Promise.resolve(this.load())
|
return Promise.resolve(this.load())
|
||||||
.then(L.bind(this.render, this))
|
.then(L.bind(this.render, this))
|
||||||
.then(L.bind(function(nodes) {
|
.then(L.bind(function(nodes) {
|
||||||
var mc = document.getElementById('maincontent');
|
var vp = document.getElementById('view');
|
||||||
|
|
||||||
L.dom.content(mc, nodes);
|
L.dom.content(vp, nodes);
|
||||||
L.dom.append(mc, this.addFooter());
|
L.dom.append(vp, this.addFooter());
|
||||||
}, this));
|
}, this)).catch(L.error);
|
||||||
},
|
},
|
||||||
|
|
||||||
load: function() {},
|
load: function() {},
|
||||||
|
|
|
@ -857,6 +857,15 @@ function template(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local _view = function(self, ...)
|
||||||
|
require "luci.template".render("view", { view = self.view })
|
||||||
|
end
|
||||||
|
|
||||||
|
function view(name)
|
||||||
|
return {type = "view", view = name, target = _view}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local function _cbi(self, ...)
|
local function _cbi(self, ...)
|
||||||
local cbi = require "luci.cbi"
|
local cbi = require "luci.cbi"
|
||||||
local tpl = require "luci.template"
|
local tpl = require "luci.template"
|
||||||
|
|
8
modules/luci-base/luasrc/view/view.htm
Normal file
8
modules/luci-base/luasrc/view/view.htm
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<%+header%>
|
||||||
|
|
||||||
|
<div id="view">
|
||||||
|
<div class="spinning"><%:Loading view…%></div>
|
||||||
|
<script type="text/javascript">L.require('view.<%=view%>');</script>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%+footer%>
|
Loading…
Reference in a new issue