Add luci, based upon commit : ae8ddb0ca6dfe98cb842fe2c01b36c4df55a0894
[librecmc/librecmc.git] / package / luci / modules / luci-base / luasrc / view / cbi / tblsection.htm
1 <%-
2 local rowcnt = 0
3
4 function rowstyle()
5         rowcnt = rowcnt + 1
6         if rowcnt % 2 == 0 then
7                 return " cbi-rowstyle-1"
8         else
9                 return " cbi-rowstyle-2"
10         end
11 end
12
13 function width(o)
14         if o.width then
15                 if type(o.width) == 'number' then
16                         return ' style="width:%dpx"' % o.width
17                 end
18                 return ' style="width:%s"' % o.width
19         end
20         return ''
21 end
22
23 local has_titles = false
24 local has_descriptions = false
25
26 local anonclass = (not self.anonymous or self.sectiontitle) and "named" or "anonymous"
27 local titlename = ifattr(not self.anonymous or self.sectiontitle, "data-title", translate("Name"))
28
29 local i, k
30 for i, k in pairs(self.children) do
31         if not k.typename then
32                 k.typename = k.template and k.template:gsub("^.+/", "") or ""
33         end
34
35         if not has_titles and k.title and #k.title > 0 then
36                 has_titles = true
37         end
38
39         if not has_descriptions and k.description and #k.description > 0 then
40                 has_descriptions = true
41         end
42 end
43
44 function render_titles()
45         if not has_titles then
46                 return
47         end
48
49         %><div class="tr cbi-section-table-titles <%=anonclass%>"<%=titlename%>><%
50
51         local i, k
52         for i, k in ipairs(self.children) do
53                 if not k.optional then
54                         %><div class="th cbi-section-table-cell"<%=
55                                 width(k) .. attr('data-type', k.typename) %>><%
56
57                         if k.titleref then
58                                 %><a title="<%=self.titledesc or translate('Go to relevant configuration page')%>" class="cbi-title-ref" href="<%=k.titleref%>"><%
59                         end
60
61                         write(k.title)
62
63                         if k.titleref then
64                                 %></a><%
65                         end
66
67                         %></div><%
68                 end
69         end
70
71         if self.sortable or self.extedit or self.addremove then
72                 %><div class="th cbi-section-table-cell cbi-section-actions"></div><%
73         end
74
75         %></div><%
76
77         rowcnt = rowcnt + 1
78 end
79
80 function render_descriptions()
81         if not has_descriptions then
82                 return
83         end
84
85         %><div class="tr cbi-section-table-descr <%=anonclass%>"><%
86
87         local i, k
88         for i, k in ipairs(self.children) do
89                 if not k.optional then
90                         %><div class="th cbi-section-table-cell"<%=
91                                 width(k) .. attr("data-type", k.typename) %>><%
92
93                         write(k.description)
94
95                         %></div><%
96                 end
97         end
98
99         if self.sortable or self.extedit or self.addremove then
100                 %><div class="th cbi-section-table-cell cbi-section-actions"></div><%
101         end
102
103         %></div><%
104
105         rowcnt = rowcnt + 1
106 end
107
108 -%>
109
110 <!-- tblsection -->
111 <div class="cbi-section cbi-tblsection" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
112         <% if self.title and #self.title > 0 then -%>
113                 <h3><%=self.title%></h3>
114         <%- end %>
115         <%- if self.sortable then -%>
116                 <input type="hidden" id="cbi.sts.<%=self.config%>.<%=self.sectiontype%>" name="cbi.sts.<%=self.config%>.<%=self.sectiontype%>" value="" />
117         <%- end -%>
118         <div class="cbi-section-descr"><%=self.description%></div>
119         <div class="table cbi-section-table">
120                 <%-
121                         render_titles()
122                         render_descriptions()
123
124                         local isempty, section, i, k = true, nil, nil
125                     for i, k in ipairs(self:cfgsections()) do
126                                 isempty = false
127                                 section = k
128
129                                 local sectionname = striptags((type(self.sectiontitle) == "function") and self:sectiontitle(section) or k)
130                                 local sectiontitle = ifattr(sectionname and (not self.anonymous or self.sectiontitle), "data-title", sectionname, true)
131                                 local colorclass = (self.extedit or self.rowcolors) and rowstyle() or ""
132                                 local scope = {
133                                         valueheader = "cbi/cell_valueheader",
134                                         valuefooter = "cbi/cell_valuefooter"
135                                 }
136                 -%>
137                 <div class="tr cbi-section-table-row<%=colorclass%>" id="cbi-<%=self.config%>-<%=section%>"<%=sectiontitle%>>
138                         <%-
139                                 local node
140                                 for k, node in ipairs(self.children) do
141                                         if not node.optional then
142                                                 node:render(section, scope or {})
143                                         end
144                                 end
145                         -%>
146
147                         <%- if self.sortable or self.extedit or self.addremove then -%>
148                                 <div class="td cbi-section-table-cell nowrap cbi-section-actions">
149                                         <div>
150                                                 <%- if self.sortable then -%>
151                                                         <input class="cbi-button cbi-button-up" type="button" value="<%:Up%>" onclick="return cbi_row_swap(this, true, 'cbi.sts.<%=self.config%>.<%=self.sectiontype%>')" title="<%:Move up%>" />
152                                                         <input class="cbi-button cbi-button-down" type="button" value="<%:Down%>" onclick="return cbi_row_swap(this, false, 'cbi.sts.<%=self.config%>.<%=self.sectiontype%>')" title="<%:Move down%>" />
153                                                 <% end; if self.extedit then -%>
154                                                         <input class="cbi-button cbi-button-edit" type="button" value="<%:Edit%>"
155                                                         <%- if type(self.extedit) == "string" then
156                                                         %> onclick="location.href='<%=self.extedit:format(section)%>'"
157                                                         <%- elseif type(self.extedit) == "function" then
158                                                         %> onclick="location.href='<%=self:extedit(section)%>'"
159                                                         <%- end
160                                                         %> alt="<%:Edit%>" title="<%:Edit%>" />
161                                                 <% end; if self.addremove then %>
162                                                         <input class="cbi-button cbi-button-remove" type="submit" value="<%:Delete%>"  onclick="this.form.cbi_state='del-section'; return true" name="cbi.rts.<%=self.config%>.<%=k%>" alt="<%:Delete%>" title="<%:Delete%>" />
163                                                 <%- end -%>
164                                         </div>
165                                 </div>
166                         <%- end -%>
167                 </div>
168                 <%- end -%>
169
170                 <%- if isempty then -%>
171                 <div class="tr cbi-section-table-row placeholder">
172                         <div class="td"><em><%:This section contains no values yet%></em></div>
173                 </div>
174                 <%- end -%>
175         </div>
176
177         <% if self.error then %>
178                 <div class="cbi-section-error">
179                         <ul><% for _, c in pairs(self.error) do for _, e in ipairs(c) do -%>
180                                 <li><%=pcdata(e):gsub("\n","<br />")%></li>
181                         <%- end end %></ul>
182                 </div>
183         <% end %>
184
185         <%- if self.addremove then -%>
186                 <% if self.template_addremove then include(self.template_addremove) else -%>
187                 <div class="cbi-section-create cbi-tblsection-create">
188                         <% if self.anonymous then %>
189                                 <input class="cbi-button cbi-button-add" type="submit" value="<%:Add%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" title="<%:Add%>" />
190                         <% else %>
191                                 <% if self.invalid_cts then -%>
192                                         <div class="cbi-section-error"><%:Invalid%></div>
193                                 <%- end %>
194                                 <div>
195                                         <input type="text" class="cbi-section-create-name" id="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" data-type="uciname" data-optional="true" />
196                                 </div>
197                                 <input class="cbi-button cbi-button-add" type="submit" onclick="this.form.cbi_state='add-section'; return true" value="<%:Add%>" title="<%:Add%>" />
198                         <% end %>
199                 </div>
200                 <%- end %>
201         <%- end -%>
202 </div>
203 <!-- /tblsection -->