libs/web: introduce width property for fields in tblsections
[project/luci.git] / libs / web / 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 function width(o)
23         if o.width then
24                 if type(o.width) == 'number' then
25                         return ' style="width:%dpx"' % o.width
26                 end
27                 return ' style="width:%s"' % o.width
28         end
29         return ''
30 end
31 -%>
32
33 <!-- tblsection -->
34 <fieldset class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
35         <% if self.title and #self.title > 0 then -%>
36                 <legend><%=self.title%></legend>
37         <%- end %>
38         <div class="cbi-section-descr"><%=self.description%></div>
39         <div class="cbi-section-node">
40                 <%- local count = 0 -%>
41                 <table class="cbi-section-table">
42                         <tr class="cbi-section-table-titles">
43                         <%- if not self.anonymous then -%>
44                                 <%- if self.sectionhead then -%>
45                                         <th class="cbi-section-table-cell"><%=self.sectionhead%></th>
46                                 <%- else -%>
47                                         <th>&#160;</th>
48                                 <%- end -%>
49                         <%- end -%>
50                         <%- for i, k in pairs(self.children) do if not k.optional then -%>
51                                 <th class="cbi-section-table-cell"<%=width(k)%>>
52                                 <%- if k.titleref then -%><a title="<%=self.titledesc or translate('Go to relevant configuration page')%>" class="cbi-title-ref" href="<%=k.titleref%>"><%- end -%>
53                                         <%-=k.title-%>
54                                 <%- if k.titleref then -%></a><%- end -%>
55                                 </th>
56                         <%- count = count + 1; end; end; if self.extedit or self.addremove then -%>
57                                 <th class="cbi-section-table-cell">&#160;</th>
58                         <%- count = count + 1; end -%>
59                         </tr>
60                         <tr class="cbi-section-table-descr">
61                         <%- if not self.anonymous then -%>
62                                 <%- if self.sectiondesc then -%>
63                                         <th class="cbi-section-table-cell"><%=self.sectiondesc%></th>
64                                 <%- else -%>
65                                         <th></th>
66                                 <%- end -%>
67                         <%- end -%>
68                         <%- for i, k in pairs(self.children) do if not k.optional then -%>
69                                 <th class="cbi-section-table-cell"<%=width(k)%>><%=k.description%></th>
70                         <%- end; end; if self.extedit or self.addremove then -%>
71                                 <th class="cbi-section-table-cell"></th>
72                         <%- end -%>
73                         </tr>
74                         <%- local isempty = true
75                             for i, k in ipairs(self:cfgsections()) do
76                                         section = k
77                                         isempty = false
78                                         scope = { valueheader = "cbi/cell_valueheader", valuefooter = "cbi/cell_valuefooter" }
79                         -%>
80                         <tr class="cbi-section-table-row<% if self.extedit or self.rowcolors then %> cbi-rowstyle-<%=rowstyle()%><% end %>" id="cbi-<%=self.config%>-<%=section%>">
81                                 <% if not self.anonymous then -%>
82                                         <th><h3><%=(type(self.sectiontitle) == "function") and self:sectiontitle(section) or k%></h3></th>
83                                 <%- end %>
84
85
86                                 <%-
87                                         for k, node in ipairs(self.children) do
88                                                 if not node.optional then
89                                                         node:render(section, scope or {})
90                                                 end
91                                         end
92                                 -%>
93
94                                 <%- if self.extedit or self.addremove then -%>
95                                         <td class="cbi-section-table-cell" style="width:50px">
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%>" 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%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" />
135                                         <script type="text/javascript">cbi_validate_field('cbi.cts.<%=self.config%>.<%=self.sectiontype%>', 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 -->