luci-app-transmission: Allow user to define custom web interface
[oweals/luci.git] / modules / luci-base / 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 local anonclass = (not self.anonymous or self.sectiontitle) and "named" or "anonymous"
19 local titlename = ifattr(not self.anonymous or self.sectiontitle, "data-title", translate("Name"))
20
21 -%>
22
23 <!-- tblsection -->
24 <div class="cbi-section cbi-tblsection" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
25         <% if self.title and #self.title > 0 then -%>
26                 <legend><%=self.title%></legend>
27         <%- end %>
28         <%- if self.sortable then -%>
29                 <input type="hidden" id="cbi.sts.<%=self.config%>.<%=self.sectiontype%>" name="cbi.sts.<%=self.config%>.<%=self.sectiontype%>" value="" />
30         <%- end -%>
31         <div class="cbi-section-descr"><%=self.description%></div>
32         <%- local count = 0 -%>
33         <div class="table cbi-section-table">
34                 <div class="tr cbi-section-table-titles <%=anonclass%>"<%=titlename%>>
35                 <%- for i, k in pairs(self.children) do if not k.optional then -%>
36                         <div class="th cbi-section-table-cell"<%=
37                                 width(k) ..
38                                 attr("data-type", k.template and k.template:gsub("^.+/", "") or "")
39                         %>>
40                         <%- if k.titleref then -%><a title="<%=self.titledesc or translate('Go to relevant configuration page')%>" class="cbi-title-ref" href="<%=k.titleref%>"><%- end -%>
41                                 <%-=k.title-%>
42                         <%- if k.titleref then -%></a><%- end -%>
43                         </div>
44                 <%- count = count + 1; end; end; if self.sortable or self.extedit or self.addremove then -%>
45                         <div class="th cbi-section-table-cell cbi-section-actions"></div>
46                 <%- count = count + 1; end -%>
47                 </div>
48                 <div class="tr cbi-section-table-descr <%=anonclass%>">
49                 <%- for i, k in pairs(self.children) do if not k.optional then -%>
50                         <div class="th cbi-section-table-cell"<%=
51                         width(k) ..
52                         attr("data-type", k.template and k.template:gsub("^.+/", "") or "")
53                 %>><%=k.description%></div>
54                 <%- end; end; if self.sortable or self.extedit or self.addremove then -%>
55                         <div class="th cbi-section-table-cell cbi-section-actions"></div>
56                 <%- end -%>
57                 </div>
58                 <%- local isempty, i, k = true, nil, nil
59                     for i, k in ipairs(self:cfgsections()) do
60                                 isempty = false
61
62                                 local section = k
63                                 local sectionname = striptags((type(self.sectiontitle) == "function") and self:sectiontitle(section) or k)
64                                 local sectiontitle = ifattr(sectionname and (not self.anonymous or self.sectiontitle), "data-title", sectionname)
65                                 local colorclass = (self.extedit or self.rowcolors) and " cbi-rowstyle-%d" % rowstyle() or ""
66                                 local scope = {
67                                         valueheader = "cbi/cell_valueheader",
68                                         valuefooter = "cbi/cell_valuefooter"
69                                 }
70                 -%>
71                 <div class="tr cbi-section-table-row<%=colorclass%>" id="cbi-<%=self.config%>-<%=section%>"<%=sectiontitle%>>
72                         <%-
73                                 local node
74                                 for k, node in ipairs(self.children) do
75                                         if not node.optional then
76                                                 node:render(section, scope or {})
77                                         end
78                                 end
79                         -%>
80
81                         <%- if self.sortable or self.extedit or self.addremove then -%>
82                                 <div class="td cbi-section-table-cell nowrap cbi-section-actions">
83                                         <%- if self.sortable then -%>
84                                                 <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%>" />
85                                                 <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%>" />
86                                         <% end; if self.extedit then -%>
87                                                 <input class="cbi-button cbi-button-edit" type="button" value="<%:Edit%>"
88                                                 <%- if type(self.extedit) == "string" then
89                                                 %> onclick="location.href='<%=self.extedit:format(section)%>'"
90                                                 <%- elseif type(self.extedit) == "function" then
91                                                 %> onclick="location.href='<%=self:extedit(section)%>'"
92                                                 <%- end
93                                                 %> alt="<%:Edit%>" title="<%:Edit%>" />
94                                         <% end; if self.addremove then %>
95                                                 <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%>" />
96                                         <%- end -%>
97                                 </div>
98                         <%- end -%>
99                 </div>
100                 <%- end -%>
101
102                 <%- if isempty then -%>
103                 <div class="tr cbi-section-table-row placeholder">
104                         <div class="td"><em><%:This section contains no values yet%></em></div>
105                 </div>
106                 <%- end -%>
107         </div>
108
109         <% if self.error then %>
110                 <div class="cbi-section-error">
111                         <ul><% for _, c in pairs(self.error) do for _, e in ipairs(c) do -%>
112                                 <li><%=pcdata(e):gsub("\n","<br />")%></li>
113                         <%- end end %></ul>
114                 </div>
115         <% end %>
116
117         <%- if self.addremove then -%>
118                 <% if self.template_addremove then include(self.template_addremove) else -%>
119                 <div class="cbi-section-create cbi-tblsection-create">
120                         <% if self.anonymous then %>
121                                 <input class="cbi-button cbi-button-add" type="submit" value="<%:Add%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" title="<%:Add%>" />
122                         <% else %>
123                                 <% if self.invalid_cts then -%>
124                                         <div class="cbi-section-error"><%:Invalid%></div>
125                                 <%- end %>
126                                 <div>
127                                         <input type="text" class="cbi-section-create-name" id="cbi.cts.<%=self.config%>.<%=self.sectiontype%>." name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>." data-type="uciname" data-optional="true" />
128                                 </div>
129                                 <input class="cbi-button cbi-button-add" type="submit" onclick="this.form.cbi_state='add-section'; return true" value="<%:Add%>" title="<%:Add%>" />
130                         <% end %>
131                 </div>
132                 <%- end %>
133         <%- end -%>
134 </div>
135 <!-- /tblsection -->