smapsection.htm 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <%#
  2. Copyright 2009 Daniel Dickinson
  3. Licensed to the public under the Apache License 2.0.
  4. -%>
  5. <%-
  6. local rowcnt = 1
  7. function rowstyle()
  8. rowcnt = rowcnt + 1
  9. return (rowcnt % 2) + 1
  10. end
  11. -%>
  12. <!-- smapsection -->
  13. <fieldset class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
  14. <% if self.title and #self.title > 0 then -%>
  15. <legend><%=self.title%></legend>
  16. <%- end %>
  17. <div class="cbi-section-descr"><%=self.description%></div>
  18. <div class="cbi-section-node">
  19. <%- local count = 0 -%>
  20. <table class="cbi-section-table">
  21. <tr class="cbi-section-table-titles">
  22. <%- if not self.anonymous then -%>
  23. <%- if self.sectionhead then -%>
  24. <th class="cbi-section-table-cell"><%=self.sectionhead%></th>
  25. <%- else -%>
  26. <th>&#160;</th>
  27. <%- end -%>
  28. <%- end -%>
  29. <%- for i, k in pairs(self.children) do if not k.optional then -%>
  30. <th class="cbi-section-table-cell">
  31. <%- if k.titleref then -%><a title="<%=self.titledesc or translate('Go to relevant configuration page')%>" class="cbi-title-ref" href="<%=k.titleref%>"><%- end -%>
  32. <%-=k.title-%>
  33. <%- if k.titleref then -%></a><%- end -%>
  34. </th>
  35. <%- count = count + 1; end; end; if self.extedit or self.addremove then -%>
  36. <th class="cbi-section-table-cell">&#160;</th>
  37. <%- count = count + 1; end -%>
  38. </tr>
  39. <tr class="cbi-section-table-descr">
  40. <%- if not self.anonymous then -%>
  41. <%- if self.sectiondesc then -%>
  42. <th class="cbi-section-table-cell"><%=self.sectiondesc%></th>
  43. <%- else -%>
  44. <th></th>
  45. <%- end -%>
  46. <%- end -%>
  47. <%- for i, k in pairs(self.children) do if not k.optional then -%>
  48. <th class="cbi-section-table-cell"><%=k.description%></th>
  49. <%- end; end; if self.extedit or self.addremove then -%>
  50. <th class="cbi-section-table-cell"></th>
  51. <%- end -%>
  52. </tr>
  53. <%- local isempty = true
  54. for i, k in ipairs(self:cfgsections()) do
  55. section = k
  56. isempty = false
  57. scope = { valueheader = "cbi/cell_valueheader", valuefooter = "cbi/cell_valuefooter" }
  58. -%>
  59. <tr class="cbi-section-table-row<% if self.extedit or self.rowcolors then %> cbi-rowstyle-<%=rowstyle()%><% end %>" id="cbi-<%=self.config%>-<%=section%>">
  60. <% if not self.anonymous then -%>
  61. <th><h3><%=k%></h3></th>
  62. <%- end %>
  63. <%- for k, node in ipairs(self.children) do -%>
  64. <%- if not node.optional then -%>
  65. <%- nodevalue = node:cfgvalue(section) -%>
  66. <%- if nodevalue and ( nodevalue ~= "" ) and string.find(nodevalue, 'http://', 1, plain) then
  67. node.href = nodevalue
  68. node.template = "diag/smapvalue"
  69. end
  70. -%>
  71. <%- node:render(section, scope or {}) -%>
  72. <%- end -%>
  73. <%- end -%>
  74. <%- if self.extedit or self.addremove then -%>
  75. <td class="cbi-section-table-cell">
  76. <%- if self.extedit then -%>
  77. <a href="
  78. <%- if type(self.extedit) == "string" then -%>
  79. <%=self.extedit:format(section)%>
  80. <%- elseif type(self.extedit) == "function" then -%>
  81. <%=self:extedit(section)%>
  82. <%- end -%>
  83. " title="<%:Edit%>"><img style="border: none" src="<%=resource%>/cbi/edit.gif" alt="<%:Edit%>" /></a>
  84. <%- end; if self.addremove then %>
  85. <input type="image" value="<%:Delete%>" name="cbi.rts.<%=self.config%>.<%=k%>" alt="<%:Delete%>" title="<%:Delete%>" src="<%=resource%>/cbi/remove.gif" />
  86. <%- end -%>
  87. </td>
  88. <%- end -%>
  89. </tr>
  90. <%- end -%>
  91. <%- if isempty then -%>
  92. <tr class="cbi-section-table-row">
  93. <td colspan="<%=count%>"><em><br /><%:This section contains no values yet%></em></td>
  94. </tr>
  95. <%- end -%>
  96. </table>
  97. <% if self.error then %>
  98. <div class="cbi-section-error">
  99. <ul><% for _, c in pairs(self.error) do for _, e in ipairs(c) do -%>
  100. <li><%=luci.util.pcdata(e):gsub("\n","<br />")%></li>
  101. <%- end end %></ul>
  102. </div>
  103. <% end %>
  104. <%- if self.addremove then -%>
  105. <% if self.template_addremove then include(self.template_addremove) else -%>
  106. <div class="cbi-section-create cbi-smapsection-create">
  107. <% if self.anonymous then %>
  108. <input class="cbi-button cbi-button-add" type="submit" value="<%:Add%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" title="<%:Add%>" />
  109. <% else %>
  110. <% if self.invalid_cts then -%><div class="cbi-section-error"><% end %>
  111. <input type="text" class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" />
  112. <input class="cbi-button cbi-button-add" type="submit" value="<%:Add%>" title="<%:Add%>" />
  113. <% if self.invalid_cts then -%>
  114. <br /><%:Invalid%></div>
  115. <%- end %>
  116. <% end %>
  117. </div>
  118. <%- end %>
  119. <%- end -%>
  120. </div>
  121. </fieldset>
  122. <!-- /smapsection -->