5f6381f058def5c78ac0d713e79b3c22ec1c814c
[project/luci.git] / libs / web / luasrc / view / cbi / tblsection.htm
1 <%-
2 local rowcnt = 1
3 function rowstyle()
4 rowcnt = rowcnt + 1
5 return (rowcnt % 2) + 1
6 end
7
8 function width(o)
9 if o.width then
10 if type(o.width) == 'number' then
11 return ' style="width:%dpx"' % o.width
12 end
13 return ' style="width:%s"' % o.width
14 end
15 return ''
16 end
17 -%>
18
19 <!-- tblsection -->
20 <fieldset class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
21 <% if self.title and #self.title > 0 then -%>
22 <legend><%=self.title%></legend>
23 <%- end %>
24 <%- if self.sortable then -%>
25 <input type="hidden" id="cbi.sts.<%=self.config%>.<%=self.sectiontype%>" name="cbi.sts.<%=self.config%>.<%=self.sectiontype%>" value="" />
26 <%- end -%>
27 <div class="cbi-section-descr"><%=self.description%></div>
28 <div class="cbi-section-node">
29 <%- local count = 0 -%>
30 <table class="cbi-section-table">
31 <tr class="cbi-section-table-titles">
32 <%- if not self.anonymous then -%>
33 <%- if self.sectionhead then -%>
34 <th class="cbi-section-table-cell"><%=self.sectionhead%></th>
35 <%- else -%>
36 <th>&#160;</th>
37 <%- end -%>
38 <%- end -%>
39 <%- for i, k in pairs(self.children) do if not k.optional then -%>
40 <th class="cbi-section-table-cell"<%=width(k)%>>
41 <%- if k.titleref then -%><a title="<%=self.titledesc or translate('Go to relevant configuration page')%>" class="cbi-title-ref" href="<%=k.titleref%>"><%- end -%>
42 <%-=k.title-%>
43 <%- if k.titleref then -%></a><%- end -%>
44 </th>
45 <%- count = count + 1; end; end; if self.sortable then -%>
46 <th class="cbi-section-table-cell"><%:Sort%></th>
47 <%- end; if self.extedit or self.addremove then -%>
48 <th class="cbi-section-table-cell">&#160;</th>
49 <%- count = count + 1; end -%>
50 </tr>
51 <tr class="cbi-section-table-descr">
52 <%- if not self.anonymous then -%>
53 <%- if self.sectiondesc then -%>
54 <th class="cbi-section-table-cell"><%=self.sectiondesc%></th>
55 <%- else -%>
56 <th></th>
57 <%- end -%>
58 <%- end -%>
59 <%- for i, k in pairs(self.children) do if not k.optional then -%>
60 <th class="cbi-section-table-cell"<%=width(k)%>><%=k.description%></th>
61 <%- end; end; if self.sortable then -%>
62 <th class="cbi-section-table-cell"></th>
63 <%- end; if self.extedit or self.addremove then -%>
64 <th class="cbi-section-table-cell"></th>
65 <%- end -%>
66 </tr>
67 <%- local isempty = true
68 for i, k in ipairs(self:cfgsections()) do
69 section = k
70 isempty = false
71 scope = { valueheader = "cbi/cell_valueheader", valuefooter = "cbi/cell_valuefooter" }
72 -%>
73 <tr class="cbi-section-table-row<% if self.extedit or self.rowcolors then %> cbi-rowstyle-<%=rowstyle()%><% end %>" id="cbi-<%=self.config%>-<%=section%>">
74 <% if not self.anonymous then -%>
75 <th><h3><%=(type(self.sectiontitle) == "function") and self:sectiontitle(section) or k%></h3></th>
76 <%- end %>
77
78
79 <%-
80 for k, node in ipairs(self.children) do
81 if not node.optional then
82 node:render(section, scope or {})
83 end
84 end
85 -%>
86
87 <%- if self.sortable then -%>
88 <td class="cbi-section-table-cell" style="padding:3px; white-space:nowrap">
89 <a href="#" onclick="return cbi_row_swap(this, true, 'cbi.sts.<%=self.config%>.<%=self.sectiontype%>')" title="<%:Move up%>"><img src="<%=resource%>/cbi/up.gif" alt="<%:Move up%>" /></a>
90 <a href="#" onclick="return cbi_row_swap(this, false, 'cbi.sts.<%=self.config%>.<%=self.sectiontype%>')" title="<%:Move down%>"><img src="<%=resource%>/cbi/down.gif" alt="<%:Move down%>" /></a>
91 </td>
92 <%- end -%>
93
94 <%- if self.extedit or self.addremove then -%>
95 <td class="cbi-section-table-cell" style="padding:3px; white-space:nowrap">
96 <%- if self.extedit then -%>
97 <a href="
98 <%- if type(self.extedit) == "string" then -%>
99 <%=self.extedit:format(section)%>
100 <%- elseif type(self.extedit) == "function" then -%>
101 <%=self:extedit(section)%>
102 <%- end -%>
103 " title="<%:Edit%>"><img style="border: none" src="<%=resource%>/cbi/edit.gif" alt="<%:Edit%>" /></a>
104 <%- end; if self.addremove then %>
105 <input type="image" value="<%:Delete%>" onclick="this.form.cbi_state='del-section'; return true" name="cbi.rts.<%=self.config%>.<%=k%>" alt="<%:Delete%>" title="<%:Delete%>" src="<%=resource%>/cbi/remove.gif" />
106 <%- end -%>
107 </td>
108 <%- end -%>
109 </tr>
110 <%- end -%>
111
112 <%- if isempty then -%>
113 <tr class="cbi-section-table-row">
114 <td colspan="<%=count%>"><em><br /><%:This section contains no values yet%></em></td>
115 </tr>
116 <%- end -%>
117 </table>
118
119 <% if self.error then %>
120 <div class="cbi-section-error">
121 <ul><% for _, c in pairs(self.error) do for _, e in ipairs(c) do -%>
122 <li><%=pcdata(e):gsub("\n","<br />")%></li>
123 <%- end end %></ul>
124 </div>
125 <% end %>
126
127 <%- if self.addremove then -%>
128 <% if self.template_addremove then include(self.template_addremove) else -%>
129 <div class="cbi-section-create cbi-tblsection-create">
130 <% if self.anonymous then %>
131 <input class="cbi-button cbi-button-add" type="submit" value="<%:Add%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" title="<%:Add%>" />
132 <% else %>
133 <% if self.invalid_cts then -%><div class="cbi-section-error"><% end %>
134 <input type="text" class="cbi-section-create-name" id="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" />
135 <script type="text/javascript">cbi_validate_field('cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>', true, 'uciname');</script>
136 <input class="cbi-button cbi-button-add" type="submit" onclick="this.form.cbi_state='add-section'; return true" value="<%:Add%>" title="<%:Add%>" />
137 <% if self.invalid_cts then -%>
138 <br /><%:Invalid%></div>
139 <%- end %>
140 <% end %>
141 </div>
142 <%- end %>
143 <%- end -%>
144 </div>
145 </fieldset>
146 <!-- /tblsection -->