2
0

tblsection.htm 6.2 KB

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