summaryrefslogtreecommitdiffhomepage
path: root/libs/web/luasrc/view/cbi/tblsection.htm
blob: 63214467f64fbf15869dc9bb3a646224fb77efe9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<%#
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

$Id$

-%>
<%-
local rowcnt = 1
function rowstyle()
	rowcnt = rowcnt + 1
	return (rowcnt % 2) + 1
end

function width(o)
	if o.width then
		if type(o.width) == 'number' then
			return ' style="width:%dpx"' % o.width
		end
		return ' style="width:%s"' % o.width
	end
	return ''
end
-%>

<!-- tblsection -->
<fieldset class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
	<% if self.title and #self.title > 0 then -%>
		<legend><%=self.title%></legend>
	<%- end %>
	<%- if self.sortable then -%>
		<input type="hidden" id="cbi.sts.<%=self.config%>.<%=self.sectiontype%>" name="cbi.sts.<%=self.config%>.<%=self.sectiontype%>" value="" />
	<%- end -%>
	<div class="cbi-section-descr"><%=self.description%></div>
	<div class="cbi-section-node">
		<%- local count = 0 -%>
		<table class="cbi-section-table">
			<tr class="cbi-section-table-titles">
			<%- if not self.anonymous then -%>
				<%- if self.sectionhead then -%>
					<th class="cbi-section-table-cell"><%=self.sectionhead%></th>
				<%- else -%>
					<th>&#160;</th>
				<%- end -%>
			<%- end -%>
			<%- for i, k in pairs(self.children) do if not k.optional then -%>
				<th class="cbi-section-table-cell"<%=width(k)%>>
				<%- if k.titleref then -%><a title="<%=self.titledesc or translate('Go to relevant configuration page')%>" class="cbi-title-ref" href="<%=k.titleref%>"><%- end -%>
					<%-=k.title-%>
				<%- if k.titleref then -%></a><%- end -%>
				</th>
			<%- count = count + 1; end; end; if self.sortable then -%>
				<th class="cbi-section-table-cell"><%:Sort%></th>
			<%- end; if self.extedit or self.addremove then -%>
				<th class="cbi-section-table-cell">&#160;</th>
			<%- count = count + 1; end -%>
			</tr>
			<tr class="cbi-section-table-descr">
			<%- if not self.anonymous then -%>
				<%- if self.sectiondesc then -%>
					<th class="cbi-section-table-cell"><%=self.sectiondesc%></th>
				<%- else -%>
					<th></th>
				<%- end -%>
			<%- end -%>
			<%- for i, k in pairs(self.children) do if not k.optional then -%>
				<th class="cbi-section-table-cell"<%=width(k)%>><%=k.description%></th>
			<%- end; end; if self.sortable then -%>
				<th class="cbi-section-table-cell"></th>
			<%- end; if self.extedit or self.addremove then -%>
				<th class="cbi-section-table-cell"></th>
			<%- end -%>
			</tr>
			<%- local isempty = true
			    for i, k in ipairs(self:cfgsections()) do
					section = k
					isempty = false
					scope = { valueheader = "cbi/cell_valueheader", valuefooter = "cbi/cell_valuefooter" }
			-%>
			<tr class="cbi-section-table-row<% if self.extedit or self.rowcolors then %> cbi-rowstyle-<%=rowstyle()%><% end %>" id="cbi-<%=self.config%>-<%=section%>">
				<% if not self.anonymous then -%>
					<th><h3><%=(type(self.sectiontitle) == "function") and self:sectiontitle(section) or k%></h3></th>
				<%- end %>


				<%-
					for k, node in ipairs(self.children) do
						if not node.optional then
							node:render(section, scope or {})
						end
					end
				-%>

				<%- if self.sortable then -%>
					<td class="cbi-section-table-cell" style="width:50px">
						<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>
						<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>
					</td>
				<%- end -%>

				<%- if self.extedit or self.addremove then -%>
					<td class="cbi-section-table-cell" style="width:50px">
						<%- if self.extedit then -%>
							<a href="
							<%- if type(self.extedit) == "string" then -%>
								<%=self.extedit:format(section)%>
							<%- elseif type(self.extedit) == "function" then -%>
								<%=self:extedit(section)%>
							<%- end -%>
							" title="<%:Edit%>"><img style="border: none" src="<%=resource%>/cbi/edit.gif" alt="<%:Edit%>" /></a>
						<%- end; if self.addremove then %>
							<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" />
						<%- end -%>
					</td>
				<%- end -%>
			</tr>
			<%- end -%>

			<%- if isempty then -%>
			<tr class="cbi-section-table-row">
				<td colspan="<%=count%>"><em><br /><%:This section contains no values yet%></em></td>
			</tr>
			<%- end -%>
		</table>

		<% if self.error then %>
			<div class="cbi-section-error">
				<ul><% for _, c in pairs(self.error) do for _, e in ipairs(c) do -%>
					<li><%=pcdata(e):gsub("\n","<br />")%></li>
				<%- end end %></ul>
			</div>
		<% end %>

		<%- if self.addremove then -%>
			<% if self.template_addremove then include(self.template_addremove) else -%>
			<div class="cbi-section-create cbi-tblsection-create">
				<% if self.anonymous then %>
					<input class="cbi-button cbi-button-add" type="submit" value="<%:Add%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" title="<%:Add%>" />
				<% else %>
					<% if self.invalid_cts then -%><div class="cbi-section-error"><% end %>
					<input type="text" class="cbi-section-create-name" id="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" />
					<script type="text/javascript">cbi_validate_field('cbi.cts.<%=self.config%>.<%=self.sectiontype%>', true, 'uciname');</script>
					<input class="cbi-button cbi-button-add" type="submit" onclick="this.form.cbi_state='add-section'; return true" value="<%:Add%>" title="<%:Add%>" />
					<% if self.invalid_cts then -%>
						<br /><%:Invalid%></div>
					<%- end %>
				<% end %>
			</div>
			<%- end %>
		<%- end -%>
	</div>
</fieldset>
<!-- /tblsection -->