cbi_tblsection.htm 6.0 KB

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