tblsection.htm 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <%-
  2. local rowcnt = 1
  3. function rowstyle()
  4. rowcnt = rowcnt + 1
  5. return (rowcnt % 2) + 1
  6. end
  7. function width(o)
  8. if o.width then
  9. if type(o.width) == 'number' then
  10. return ' style="width:%dpx"' % o.width
  11. end
  12. return ' style="width:%s"' % o.width
  13. end
  14. return ''
  15. end
  16. -%>
  17. <!-- tblsection -->
  18. <fieldset class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
  19. <% if self.title and #self.title > 0 then -%>
  20. <legend><%=self.title%></legend>
  21. <%- end %>
  22. <%- if self.sortable then -%>
  23. <input type="hidden" id="cbi.sts.<%=self.config%>.<%=self.sectiontype%>" name="cbi.sts.<%=self.config%>.<%=self.sectiontype%>" value="" />
  24. <%- end -%>
  25. <div class="cbi-section-descr"><%=self.description%></div>
  26. <div class="cbi-section-node">
  27. <%- local count = 0 -%>
  28. <table class="cbi-section-table">
  29. <tr class="cbi-section-table-titles">
  30. <%- if not self.anonymous then -%>
  31. <%- if self.sectionhead then -%>
  32. <th class="cbi-section-table-cell"><%=self.sectionhead%></th>
  33. <%- else -%>
  34. <th>&#160;</th>
  35. <%- end -%>
  36. <%- end -%>
  37. <%- for i, k in pairs(self.children) do if not k.optional then -%>
  38. <th class="cbi-section-table-cell"<%=width(k)%>>
  39. <%- if k.titleref then -%><a title="<%=self.titledesc or translate('Go to relevant configuration page')%>" class="cbi-title-ref" href="<%=k.titleref%>"><%- end -%>
  40. <%-=k.title-%>
  41. <%- if k.titleref then -%></a><%- end -%>
  42. </th>
  43. <%- count = count + 1; end; end; if self.sortable then -%>
  44. <th class="cbi-section-table-cell"><%:Sort%></th>
  45. <%- end; if self.extedit or self.addremove then -%>
  46. <th class="cbi-section-table-cell">&#160;</th>
  47. <%- count = count + 1; end -%>
  48. </tr>
  49. <%-
  50. local nodescr = true
  51. for i, k in pairs(self.children) do
  52. if k.description ~= nil and k.description ~= '' then
  53. nodescr = false
  54. break
  55. end
  56. end
  57. -%>
  58. <%- if not nodescr then -%>
  59. <tr class="cbi-section-table-descr">
  60. <%- if not self.anonymous then -%>
  61. <%- if self.sectiondesc then -%>
  62. <th class="cbi-section-table-cell"><%=self.sectiondesc%></th>
  63. <%- else -%>
  64. <th></th>
  65. <%- end -%>
  66. <%- end -%>
  67. <%- for i, k in pairs(self.children) do if not k.optional then -%>
  68. <th class="cbi-section-table-cell"<%=width(k)%>><%=k.description%></th>
  69. <%- end; end; if self.sortable then -%>
  70. <th class="cbi-section-table-cell"></th>
  71. <%- end; if self.extedit or self.addremove then -%>
  72. <th class="cbi-section-table-cell"></th>
  73. <%- end -%>
  74. </tr>
  75. <%- end -%>
  76. <%- local isempty = true
  77. for i, k in ipairs(self:cfgsections()) do
  78. section = k
  79. isempty = false
  80. scope = { valueheader = "cbi/cell_valueheader", valuefooter = "cbi/cell_valuefooter" }
  81. -%>
  82. <tr class="cbi-section-table-row<% if self.extedit or self.rowcolors then %> cbi-rowstyle-<%=rowstyle()%><% end %>" id="cbi-<%=self.config%>-<%=section%>">
  83. <% if not self.anonymous then -%>
  84. <th><h3><%=(type(self.sectiontitle) == "function") and self:sectiontitle(section) or k%></h3></th>
  85. <%- end %>
  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. <%- if self.sortable then -%>
  94. <td class="cbi-section-table-cell">
  95. <input class="cbi-button cbi-button-up" type="button" value="" onclick="return cbi_row_swap(this, true, 'cbi.sts.<%=self.config%>.<%=self.sectiontype%>')" alt="<%:Move up%>" title="<%:Move up%>" />
  96. <input class="cbi-button cbi-button-down" type="button" value="" onclick="return cbi_row_swap(this, false, 'cbi.sts.<%=self.config%>.<%=self.sectiontype%>')" alt="<%:Move down%>" title="<%:Move down%>" />
  97. </td>
  98. <%- end -%>
  99. <%- if self.extedit or self.addremove then -%>
  100. <td class="cbi-section-table-cell">
  101. <%- if self.extedit then -%>
  102. <input class="cbi-button cbi-button-edit" type="button" value="<%:Edit%>"
  103. <%- if type(self.extedit) == "string" then
  104. %> onclick="location.href='<%=self.extedit:format(section)%>'"
  105. <%- elseif type(self.extedit) == "function" then
  106. %> onclick="location.href='<%=self:extedit(section)%>'"
  107. <%- end
  108. %> alt="<%:Edit%>" title="<%:Edit%>" />
  109. <%- end; if self.addremove then %>
  110. <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%>" />
  111. <%- end -%>
  112. </td>
  113. <%- end -%>
  114. </tr>
  115. <%- end -%>
  116. <%- if isempty then -%>
  117. <tr class="cbi-section-table-row">
  118. <td colspan="<%=count%>"><em><br /><%:This section contains no values yet%></em></td>
  119. </tr>
  120. <%- end -%>
  121. </table>
  122. <% if self.error then %>
  123. <div class="cbi-section-error">
  124. <ul><% for _, c in pairs(self.error) do for _, e in ipairs(c) do -%>
  125. <li><%=pcdata(e):gsub("\n","<br />")%></li>
  126. <%- end end %></ul>
  127. </div>
  128. <% end %>
  129. <%- if self.addremove then -%>
  130. <% if self.template_addremove then include(self.template_addremove) else -%>
  131. <div class="cbi-section-create cbi-tblsection-create">
  132. <% if self.anonymous then %>
  133. <input class="cbi-button cbi-button-add" type="submit" value="<%:Add%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" title="<%:Add%>" />
  134. <% else %>
  135. <% if self.invalid_cts then -%><div class="cbi-section-error"><% end %>
  136. <input type="text" class="cbi-section-create-name" id="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" />
  137. <script type="text/javascript">cbi_validate_field('cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>', true, 'uciname');</script>
  138. <input class="cbi-button cbi-button-add" type="submit" onclick="this.form.cbi_state='add-section'; return true" value="<%:Add%>" title="<%:Add%>" />
  139. <% if self.invalid_cts then -%>
  140. <br /><%:Invalid%></div>
  141. <%- end %>
  142. <% end %>
  143. </div>
  144. <%- end %>
  145. <%- end -%>
  146. </div>
  147. </fieldset>
  148. <!-- /tblsection -->