tblsection.htm 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. <tr class="cbi-section-table-descr">
  50. <%- if not self.anonymous then -%>
  51. <%- if self.sectiondesc then -%>
  52. <th class="cbi-section-table-cell"><%=self.sectiondesc%></th>
  53. <%- else -%>
  54. <th></th>
  55. <%- end -%>
  56. <%- end -%>
  57. <%- for i, k in pairs(self.children) do if not k.optional then -%>
  58. <th class="cbi-section-table-cell"<%=width(k)%>><%=k.description%></th>
  59. <%- end; end; if self.sortable then -%>
  60. <th class="cbi-section-table-cell"></th>
  61. <%- end; if self.extedit or self.addremove then -%>
  62. <th class="cbi-section-table-cell"></th>
  63. <%- end -%>
  64. </tr>
  65. <%- local isempty = true
  66. for i, k in ipairs(self:cfgsections()) do
  67. section = k
  68. isempty = false
  69. scope = { valueheader = "cbi/cell_valueheader", valuefooter = "cbi/cell_valuefooter" }
  70. -%>
  71. <tr class="cbi-section-table-row<% if self.extedit or self.rowcolors then %> cbi-rowstyle-<%=rowstyle()%><% end %>" id="cbi-<%=self.config%>-<%=section%>">
  72. <% if not self.anonymous then -%>
  73. <th><h3><%=(type(self.sectiontitle) == "function") and self:sectiontitle(section) or k%></h3></th>
  74. <%- end %>
  75. <%-
  76. for k, node in ipairs(self.children) do
  77. if not node.optional then
  78. node:render(section, scope or {})
  79. end
  80. end
  81. -%>
  82. <%- if self.sortable then -%>
  83. <td class="cbi-section-table-cell">
  84. <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%>" />
  85. <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%>" />
  86. </td>
  87. <%- end -%>
  88. <%- if self.extedit or self.addremove then -%>
  89. <td class="cbi-section-table-cell">
  90. <%- if self.extedit then -%>
  91. <input class="cbi-button cbi-button-edit" type="button" value="<%:Edit%>"
  92. <%- if type(self.extedit) == "string" then
  93. %> onclick="location.href='<%=self.extedit:format(section)%>'"
  94. <%- elseif type(self.extedit) == "function" then
  95. %> onclick="location.href='<%=self:extedit(section)%>'"
  96. <%- end
  97. %> alt="<%:Edit%>" title="<%:Edit%>" />
  98. <%- end; if self.addremove then %>
  99. <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%>" />
  100. <%- end -%>
  101. </td>
  102. <%- end -%>
  103. </tr>
  104. <%- end -%>
  105. <%- if isempty then -%>
  106. <tr class="cbi-section-table-row">
  107. <td colspan="<%=count%>"><em><br /><%:This section contains no values yet%></em></td>
  108. </tr>
  109. <%- end -%>
  110. </table>
  111. <% if self.error then %>
  112. <div class="cbi-section-error">
  113. <ul><% for _, c in pairs(self.error) do for _, e in ipairs(c) do -%>
  114. <li><%=pcdata(e):gsub("\n","<br />")%></li>
  115. <%- end end %></ul>
  116. </div>
  117. <% end %>
  118. <%- if self.addremove then -%>
  119. <% if self.template_addremove then include(self.template_addremove) else -%>
  120. <div class="cbi-section-create cbi-tblsection-create">
  121. <% if self.anonymous then %>
  122. <input class="cbi-button cbi-button-add" type="submit" value="<%:Add%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" title="<%:Add%>" />
  123. <% else %>
  124. <% if self.invalid_cts then -%><div class="cbi-section-error"><% end %>
  125. <input type="text" class="cbi-section-create-name" id="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" />
  126. <script type="text/javascript">cbi_validate_field('cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>', true, 'uciname');</script>
  127. <input class="cbi-button cbi-button-add" type="submit" onclick="this.form.cbi_state='add-section'; return true" value="<%:Add%>" title="<%:Add%>" />
  128. <% if self.invalid_cts then -%>
  129. <br /><%:Invalid%></div>
  130. <%- end %>
  131. <% end %>
  132. </div>
  133. <%- end %>
  134. <%- end -%>
  135. </div>
  136. </fieldset>
  137. <!-- /tblsection -->