* luci/libs: only create <legend> if there is a title in tblsection template
[project/luci.git] / libs / cbi / luasrc / view / cbi / tblsection.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 -%>
15 <%-
16 local rowcnt = 1
17 function rowstyle()
18         rowcnt = rowcnt + 1
19         return (rowcnt % 2) + 1
20 end
21 -%>
22
23 <!-- tblsection -->
24 <fieldset class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
25         <% if self.title and #self.title > 0 then -%>
26                 <legend><%=self.title%></legend>
27         <%- end %>
28         <div class="cbi-section-descr"><%=self.description%></div>
29         <div class="cbi-section-node">
30                 <%- local count = 0 -%>
31                 <table class="cbi-section-table">
32                         <tr class="cbi-section-table-titles">
33                         <%- if not self.anonymous then -%>
34                                 <th>&nbsp;</th>
35                         <%- end -%>
36                         <%- for i, k in pairs(self.children) do if not k.optional then -%>
37                                 <th class="cbi-section-table-cell"><%=k.title%></th>
38                         <%- count = count + 1; end; end; if self.extedit or self.addremove then -%>
39                                 <th class="cbi-section-table-cell">&nbsp;</th>
40                         <%- count = count + 1; end -%>
41                         </tr>
42                         <tr class="cbi-section-table-descr">
43                         <%- if not self.anonymous then -%>
44                                 <th></th>
45                         <%- end -%>
46                         <%- for i, k in pairs(self.children) do if not k.optional then -%>
47                                 <th class="cbi-section-table-cell"><%=k.description%></th>
48                         <%- end; end; if self.extedit or self.addremove then -%>
49                                 <th class="cbi-section-table-cell"></th>
50                         <%- end -%>
51                         </tr>
52                         <%- local isempty = true
53                             for i, k in ipairs(self:cfgsections()) do
54                                         section = k
55                                         isempty = false
56                                         scope = { valueheader = "cbi/cell_valueheader", valuefooter = "cbi/cell_valuefooter" }
57                         -%>
58                         <tr class="cbi-section-table-row<% if self.extedit then %> cbi-rowstyle-<%=rowstyle()%><% end %>" id="cbi-<%=self.config%>-<%=section%>">
59                                 <% if not self.anonymous then -%>
60                                         <th><h3><%=k%></h3></th>
61                                 <%- end %>
62
63
64                                 <%-
65                                         for k, node in ipairs(self.children) do
66                                                 if not node.optional then
67                                                         node:render(section, scope or {})
68                                                 end
69                                         end
70                                 -%>
71
72                                 <%- if self.extedit or self.addremove then -%>
73                                         <td class="cbi-section-table-cell">
74                                                 <%- if self.extedit then -%>
75                                                         <a href="<%=self.extedit:format(section)%>" title="<%:edit%>"><img style="border: none" src="<%=resource%>/cbi/edit.gif" alt="<%:edit%>" /></a>
76                                                 <%- end; if self.addremove then %>
77                                                         <input type="image" value="<%:cbi_del%>" name="cbi.rts.<%=self.config%>.<%=k%>" alt="<%:cbi_del%>" title="<%:cbi_del%>" src="<%=resource%>/cbi/remove.gif" />
78                                                 <%- end -%>
79                                         </td>
80                                 <%- end -%>
81                         </tr>
82                         <%- end -%>
83
84                         <%- if isempty then -%>
85                         <tr class="cbi-section-table-row">
86                                 <td colspan="<%=count%>"><em><br /><%:cbi_sectempty%></em></td>
87                         </tr>
88                         <%- end -%>
89                 </table>
90                         <%- if self.addremove then -%>
91                         <div class="cbi-section-table-row">
92                                 <td colspan="<%=count%>" class="cbi-section-table-optionals">
93                                         <div class="cbi-section-create">
94                                                 <% if self.anonymous then %>
95                                                         <input class="cbi-button cbi-button-add" type="submit" value="<%:cbi_add%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" title="<%:cbi_add%>" />
96                                                 <% else %>
97                                                         <input type="text" class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" />
98                                                         <input class="cbi-button cbi-button-add" type="submit" value="<%:cbi_add%>" title="<%:cbi_add%>" />
99                                                 <% end %>
100
101                                                 <% if self.err_invalid then %>
102                                                         <div class="cbi-error"><%:cbi_invalid%></div>
103                                                 <% end %>
104                                         </div>
105                                 </td>
106                         </div>
107                         <%- end -%>
108         </div>
109 </fieldset>
110 <!-- /tblsection -->