From: Jo-Philipp Wich Date: Tue, 9 Mar 2010 02:05:49 +0000 (+0000) Subject: luci-0.9: backport CBI from trunk, adds tab support, auto-hiding of commit notificati... X-Git-Tag: 0.9.0~51 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=3441fe8c822f49fab971417eded39868e8d5b3e6;p=oweals%2Fluci.git luci-0.9: backport CBI from trunk, adds tab support, auto-hiding of commit notifications and better layout control --- diff --git a/libs/cbi/htdocs/luci-static/resources/cbi.js b/libs/cbi/htdocs/luci-static/resources/cbi.js index 77c59e511..247228d22 100644 --- a/libs/cbi/htdocs/luci-static/resources/cbi.js +++ b/libs/cbi/htdocs/luci-static/resources/cbi.js @@ -2,7 +2,7 @@ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth - Copyright 2008 Jo-Philipp Wich + Copyright 2008-2009 Jo-Philipp Wich Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,6 +14,8 @@ */ var cbi_d = []; +var cbi_t = []; +var cbi_c = []; function cbi_d_add(field, dep, next) { var obj = document.getElementById(field); @@ -43,7 +45,18 @@ function cbi_d_checkvalue(target, ref) { var t = document.getElementById(target); var value; - if (!t || !t.value) { + if (!t) { + var tl = document.getElementsByName(target); + + if( tl.length > 0 && tl[0].type == 'radio' ) + for( var i = 0; i < tl.length; i++ ) + if( tl[i].checked ) { + value = tl[i].value; + break; + } + + value = value ? value : ""; + } else if (!t.value) { value = ""; } else { value = t.value; @@ -57,15 +70,26 @@ function cbi_d_checkvalue(target, ref) { } function cbi_d_check(deps) { + var reverse; + var def = false; for (var i=0; i FORM_PROCEED + and (not newcurrent or not self:get(newcurrent)) then + return self:_run_hook("on_done") or FORM_DONE else - self.current = newcurrent + self.current = newcurrent or self.current self.active = self:get(self.current) if type(self.active) ~= "function" then - self.active:parse(false) - return FROM_PROCEED + self.active:populate_delegator(self) + local stat = self.active:parse(false) + if stat == FORM_SKIP then + return self:parse(...) + else + return FORM_PROCEED + end else return self:parse(...) end @@ -659,6 +707,10 @@ function SimpleForm.parse(self, readinput, ...) return FORM_SKIP end + if self:formvalue("cbi.cancel") and self:_run_hooks("on_cancel") then + return FORM_DONE + end + if self:submitstate() then Node.parse(self, 1, ...) end @@ -781,6 +833,19 @@ function AbstractSection.__init__(self, map, sectiontype, ...) self.dynamic = false end +-- Define a tab for the section +function AbstractSection.tab(self, tab, title, desc) + self.tabs = self.tabs or { } + self.tab_names = self.tab_names or { } + + self.tab_names[#self.tab_names+1] = tab + self.tabs[tab] = { + title = title, + description = desc, + childs = { } + } +end + -- Appends a new option function AbstractSection.option(self, class, option, ...) -- Autodetect from UVL @@ -812,6 +877,31 @@ function AbstractSection.option(self, class, option, ...) end end +-- Appends a new tabbed option +function AbstractSection.taboption(self, tab, ...) + + assert(tab and self.tabs and self.tabs[tab], + "Cannot assign option to not existing tab %q" % tostring(tab)) + + local l = self.tabs[tab].childs + local o = AbstractSection.option(self, ...) + + if o then l[#l+1] = o end + + return o +end + +-- Render a single tab +function AbstractSection.render_tab(self, tab, ...) + + assert(tab and self.tabs and self.tabs[tab], + "Cannot render not existing tab %q" % tostring(tab)) + + for _, node in ipairs(self.tabs[tab].childs) do + node:render(...) + end +end + -- Parse optional options function AbstractSection.parse_optionals(self, section) if not self.optional then @@ -1215,6 +1305,7 @@ function AbstractValue.__init__(self, map, section, option, ...) self.tag_reqerror = {} self.tag_error = {} self.deps = {} + self.subdeps = {} --self.cast = "string" self.track_missing = false @@ -1356,6 +1447,7 @@ function AbstractValue.render(self, s, scope) scope.section = s scope.cbid = self:cbid(s) scope.striptags = luci.util.striptags + scope.pcdata = luci.util.pcdata scope.ifattr = function(cond,key,val) if cond then @@ -1544,7 +1636,7 @@ function ListValue.value(self, key, val, ...) table.insert(self.vallist, tostring(val)) for i, deps in ipairs({...}) do - table.insert(self.deps, {add = "-"..key, deps=deps}) + self.subdeps[#self.subdeps + 1] = {add = "-"..key, deps=deps} end end diff --git a/libs/cbi/luasrc/view/cbi/map.htm b/libs/cbi/luasrc/view/cbi/map.htm index 949edea5c..620203a4d 100644 --- a/libs/cbi/luasrc/view/cbi/map.htm +++ b/libs/cbi/luasrc/view/cbi/map.htm @@ -14,10 +14,25 @@ $Id$ -%>
-

<%=self.title%>

-
<%=self.description%>
+ <% if self.title and #self.title > 0 then %> +

+ <% + if self.breadcrumb then + local elem + for _, elem in ipairs(self.breadcrumb) do + -%> + <%=luci.util.pcdata(elem[2])%> » + <% + end + end + -%> + <%=self.title%> +

+ <% end %> + + <% if self.description and #self.description > 0 then %>
<%=self.description%>
<% end %> <%- if self._apply then -%> -
+
<%:cbi_applying%>
    <%- local fp = self._apply() @@ -30,6 +45,12 @@ $Id$ fp:close() -%>
+ <%- end -%> <%- self:render_children() %>
diff --git a/libs/cbi/luasrc/view/cbi/nsection.htm b/libs/cbi/luasrc/view/cbi/nsection.htm index d766464bd..d096ac3a0 100644 --- a/libs/cbi/luasrc/view/cbi/nsection.htm +++ b/libs/cbi/luasrc/view/cbi/nsection.htm @@ -1,7 +1,7 @@ <%# LuCI - Lua Configuration Interface Copyright 2008 Steven Barth -Copyright 2008 Jo-Philipp Wich +Copyright 2008-2009 Jo-Philipp Wich Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ $Id$
<%- end %> + <%+cbi/tabmenu%>
<%+cbi/ucisection%>
diff --git a/libs/cbi/luasrc/view/cbi/tabcontainer.htm b/libs/cbi/luasrc/view/cbi/tabcontainer.htm new file mode 100644 index 000000000..b620622d6 --- /dev/null +++ b/libs/cbi/luasrc/view/cbi/tabcontainer.htm @@ -0,0 +1,21 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2009 Jo-Philipp Wich + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id: tabcontainer.htm 5269 2009-08-16 03:29:46Z jow $ + +-%> + +<% for tab, data in pairs(self.tabs) do %> +
style="display:none"<% end %>> + <% if data.description then %>
<%=data.description%>
<% end %> + <% self:render_tab(tab, section, scope or {}) %> +
+ +<% end %> diff --git a/libs/cbi/luasrc/view/cbi/tabmenu.htm b/libs/cbi/luasrc/view/cbi/tabmenu.htm new file mode 100644 index 000000000..da538c2b7 --- /dev/null +++ b/libs/cbi/luasrc/view/cbi/tabmenu.htm @@ -0,0 +1,27 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2009 Jo-Philipp Wich + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id: tabmenu.htm 5398 2009-10-10 22:18:50Z jow $ + +-%> + +<%- if self.tabs then %> +
    + <%- self.selected_tab = luci.http.formvalue("tab." .. self.config .. "." .. section) %> + <%- for _, tab in ipairs(self.tab_names) do if #self.tabs[tab].childs > 0 then %> + + <%- if not self.selected_tab then self.selected_tab = tab end %> +
  • + <%=self.tabs[tab].title%> + <% if tab == self.selected_tab then %><% end %> +
  • + <% end end -%> +
+<% end -%> diff --git a/libs/cbi/luasrc/view/cbi/tsection.htm b/libs/cbi/luasrc/view/cbi/tsection.htm index db723f92a..7fdd7f4ff 100644 --- a/libs/cbi/luasrc/view/cbi/tsection.htm +++ b/libs/cbi/luasrc/view/cbi/tsection.htm @@ -24,12 +24,15 @@ $Id$ <%- end %> - <% section = k; isempty = false %> + + <%- section = k; isempty = false -%> <% if not self.anonymous then -%> -

<%=k:upper()%>

+

<%=section:upper()%>

<%- end %> + <%+cbi/tabmenu%> +
<%+cbi/ucisection%>