luci-app-firewall: align custom cbi teplates with new code
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 10 Feb 2016 17:13:53 +0000 (18:13 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 10 Feb 2016 17:13:53 +0000 (18:13 +0100)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
applications/luci-app-firewall/luasrc/view/firewall/cbi_addforward.htm
applications/luci-app-firewall/luasrc/view/firewall/cbi_addsnat.htm

index 3c46e22..4a5bcfd 100644 (file)
                        ezl[#ezl+1] = z
                end
        end
                        ezl[#ezl+1] = z
                end
        end
+
+       local keys, vals = { }, { }
+       luci.sys.net.ipv4_hints(function(ip, name)
+               keys[#keys+1] = ip
+               vals[#vals+1] = '%s (%s)' %{ ip, name }
+       end)
 -%>
 <div class="cbi-section-create cbi-tblsection-create">
        <br />
 -%>
 <div class="cbi-section-create cbi-tblsection-create">
        <br />
@@ -46,7 +52,7 @@
                                </select>
                        </td>
                        <td class="cbi-section-table-cell" style="width:110px">
                                </select>
                        </td>
                        <td class="cbi-section-table-cell" style="width:110px">
-                               <input type="text" class="cbi-input-text" id="_newfwd.extport" name="_newfwd.extport" />
+                               <input type="text" class="cbi-input-text" id="_newfwd.extport" name="_newfwd.extport" data-type="portrange" data-optional="true" />
                        </td>
                        <td class="cbi-section-table-cell" style="width:55px">
                                <select class="cbi-input-select" id="_newfwd.intzone" name="_newfwd.intzone">
                        </td>
                        <td class="cbi-section-table-cell" style="width:55px">
                                <select class="cbi-input-select" id="_newfwd.intzone" name="_newfwd.intzone">
                                </select>
                        </td>
                        <td class="cbi-section-table-cell" style="width:110px">
                                </select>
                        </td>
                        <td class="cbi-section-table-cell" style="width:110px">
-                               <input type="text" class="cbi-input-text" id="_newfwd.intaddr" name="_newfwd.intaddr" />
+                               <input type="text" class="cbi-input-text" id="_newfwd.intaddr" name="_newfwd.intaddr" data-type="host" data-optional="true"<%=
+                                       ifattr(#keys > 0, "data-choices", luci.util.serialize_json({keys, vals}))
+                               %>/>
                        </td>
                        <td class="cbi-section-table-cell" style="width:110px">
                        </td>
                        <td class="cbi-section-table-cell" style="width:110px">
-                               <input type="text" class="cbi-input-text" id="_newfwd.intport" name="_newfwd.intport" />
+                               <input type="text" class="cbi-input-text" id="_newfwd.intport" name="_newfwd.intport" data-type="portrange" data-optional="true" />
                        </td>
                        <td class="cbi-section-table-cell">
                                <input type="submit" class="cbi-button cbi-button-add" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" value="<%:Add%>" />
                        </td>
                        <td class="cbi-section-table-cell">
                                <input type="submit" class="cbi-button cbi-button-add" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" value="<%:Add%>" />
        </table>
 
        <script type="text/javascript">//<![CDATA[
        </table>
 
        <script type="text/javascript">//<![CDATA[
-               cbi_validate_field('_newfwd.extport', true, 'portrange');
-               cbi_validate_field('_newfwd.intaddr', true, 'host');
-               cbi_validate_field('_newfwd.intport', true, 'portrange');
-
-               cbi_combobox_init('_newfwd.intaddr', {
-                       <% first = true; luci.sys.net.ipv4_hints(function(ip, name) %>
-                               <%- if first then first = false else %>,<% end -%>'<%=ip%>': '<%=ip%> (<%=name%>)'
-                       <%- end) %> }, '', '<%: -- custom -- %>');
-
                cbi_bind(document.getElementById('_newfwd.extport'), 'blur',
                        function() {
                                var n = document.getElementById('_newfwd.name');
                cbi_bind(document.getElementById('_newfwd.extport'), 'blur',
                        function() {
                                var n = document.getElementById('_newfwd.name');
                                        }
                                }
                        });
                                        }
                                }
                        });
-
-
-               cbi_validate_field('cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>', true, 'uciname');
        //]]></script>
 </div>
        //]]></script>
 </div>
index 4e1681c..817c046 100644 (file)
@@ -3,6 +3,14 @@
        local nw = require "luci.model.network".init()
        local wz = fw:get_zone("wan")
        local lz = fw:get_zone("lan")
        local nw = require "luci.model.network".init()
        local wz = fw:get_zone("wan")
        local lz = fw:get_zone("lan")
+
+       local keys, vals, a, k, v = {}, {}
+       for k, v in ipairs(nw:get_interfaces()) do
+               for k, a in ipairs(v:ipaddrs()) do
+                       keys[#keys+1] = a:host():string()
+                       vals[#vals+1] = '%s (%s)' %{ a:host(), v:shortname() }
+               end
+       end
 %>
 
 <div class="cbi-section-create cbi-tblsection-create">
 %>
 
 <div class="cbi-section-create cbi-tblsection-create">
                                        </select>
                                </td>
                                <td class="cbi-section-table-cell" style="width:110px">
                                        </select>
                                </td>
                                <td class="cbi-section-table-cell" style="width:110px">
-                                       <input type="text" class="cbi-input-text" id="_newsnat.dip" name="_newsnat.dip" />
+                                       <input type="text" class="cbi-input-text" id="_newsnat.dip" name="_newsnat.dip" placeholder="<%:Do not rewrite%>" data-type="ip4addr" data-optional="true"<%=
+                                               ifattr(#keys > 0, "data-choices", luci.util.serialize_json({ keys, vals }))
+                                       %> />
                                </td>
                                <td class="cbi-section-table-cell" style="width:110px">
                                </td>
                                <td class="cbi-section-table-cell" style="width:110px">
-                                       <input type="text" class="cbi-input-text" id="_newsnat.dport" name="_newsnat.dport" placeholder="<%:Do not rewrite%>" />
+                                       <input type="text" class="cbi-input-text" id="_newsnat.dport" name="_newsnat.dport" placeholder="<%:Do not rewrite%>" data-type="portrange" data-optional="true" />
                                </td>
                                <td class="cbi-section-table-cell">
                                        <input type="submit" class="cbi-button cbi-button-link" name="_newsnat.submit" value="<%:Add and edit...%>" />
                                </td>
                        </tr>
                </table>
                                </td>
                                <td class="cbi-section-table-cell">
                                        <input type="submit" class="cbi-button cbi-button-link" name="_newsnat.submit" value="<%:Add and edit...%>" />
                                </td>
                        </tr>
                </table>
-
-               <script type="text/javascript">//<![CDATA[
-                       cbi_validate_field('_newsnat.dport', true, 'portrange');
-                       cbi_validate_field('_newsnat.dip', true, 'ip4addr');
-                       cbi_combobox_init('_newsnat.dip', {
-                               <% local c, k, v = 0; for k, v in ipairs(nw:get_interfaces()) do -%>
-                                       <%- local a; for k, a in ipairs(v:ipaddrs()) do c = c + 1 -%>
-                                               <% if c > 1 then %>,<% end %>'<%=a:host():string()%>': '<%=a:host():string()%> (<%=v:shortname()%>)'
-                                       <%- end %>
-                               <%- end %> }, '<%: -- Please choose -- %>', '<%: -- custom -- %>');
-               //]]></script>
        <% else %>
                <input type="submit" class="cbi-button cbi-button-add" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" value="<%:Add%>" />
        <% end %>
        <% else %>
                <input type="submit" class="cbi-button cbi-button-add" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" value="<%:Add%>" />
        <% end %>