<%= form_for @v_lan , as: :v_lan, method: (@v_lan.id.blank? ? "post" : "put"), html: { class: "form-horizontal vlan-form" , role: "form"} do |f| %>

VLan Configuration - <%= (@v_lan.id.blank? ? "New" : "Edit") %>

<%= f.label :v_lan_id, "VLan ID*".html_safe, :class=>"col-sm-4 control-label" %>
<%= f.select :v_lan_id, (3..4096).to_a, {}, :class => 'form-control', :data => { validation: 'required' } %>
<%=f.label :net_mask, "Net Mask ".html_safe, :class=>"col-sm-4 control-label"%>
<%= f.text_field :net_mask,:class=>"form-control ip-mask", :placeholder=>"Net Mask", 'data-validation' => 'required ip' %>
<%=f.label :ip_address, "IP Address ".html_safe, :class=>"col-sm-4 control-label"%>
<%= f.text_field :ip_address,:class=>"form-control ip-mask", :placeholder=>"IP Address", 'data-validation' => 'required ip' %>
<%=f.label :gateway, "Gateway".html_safe, :class=>"col-sm-4 control-label"%>
<%= f.text_field :gateway,:class=>"form-control ip-mask", :placeholder=>"Gateway", 'data-validation' => 'required ip'%>
<%=f.label :enable_dhcp_on_v_lan, "Enable DHCP Relay on VLAN", :class=>"col-sm-4 control-label"%>
<%= f.check_box :enable_dhcp_on_v_lan %>
<%=f.label :dns_mode, "DNS Mode".html_safe, :class=>"col-sm-4 control-label"%>
<%=f.select(:dns_mode, NetworkSsid::DNS_MODE, {}, :class=>"form-control", :data => { validation: 'required'}) %>
<%=f.label :dns1, "Primary DNS".html_safe, :class=>"col-sm-4 control-label"%>
<%= f.text_field :dns1,:class => "form-control ip-mask", :placeholder => "Primary DNS", 'data-validation' => 'required ip' %>
<%=f.label :dns2, "Secondary DNS".html_safe, :class=>"col-sm-4 control-label"%>
<%= f.text_field :dns2,:class=>"form-control ip-mask", :placeholder=>"Secondary DNS", 'data-validation' => 'required ip'%>
<%=f.label :dhcp_relay_server, "DHCP MAPPING".html_safe, :class=>"col-sm-4 control-label"%>
<%=f.select(:dhcp_relay_server, [["Disable","1"],["Enable","2"],['Relay','3']],{},:class=>"form-control dhcp_server",'data-validation'=> "required" )%>
<% (@v_lan.dhcp_ranges || []).each_with_index do |dhcp,index|%>
>
<%= text_field_tag 'v_lan[dhcp_ranges][][START]',dhcp['START'],:class=>"form-control dhcp_start",:style=>"width:140px",:placeholder=>"DHCP Start",:data => { validation: 'required ip dhcp_check ip-range-check ip-conflict-dhcp_start'}%>
<%= text_field_tag 'v_lan[dhcp_ranges][][END]',dhcp['END'],:class=>"form-control dhcp_end",:style=>"width:140px", :placeholder=>"DHCP End",:data => { validation: 'required ip dhcp_check ip-range-check ip-conflict-dhcp_end'}%>
<%=link_to " X ","javascript:void(0);", {:class => "remove_range icon-delete btn btn-sm btn-danger"} %>
<% end %>
<% (@v_lan.dhcp_mappings || []).each_with_index do |dhcp,index|%>
>
<%= text_field_tag 'v_lan[dhcp_mappings][][IPADDR]',dhcp['IPADDR'],:class=>"form-control dhcp_ip",:style=>"width:140px",:placeholder=>"IPAddress",:data => { validation: 'required-check ip dhcp_ip-range-check ip-conflict-dhcp_ip dhcp_range_check','dependent-field' => '.dhcp_mac'}%>
<%= text_field_tag 'v_lan[dhcp_mappings][][MAC]',dhcp['MAC'],:class=>"form-control dhcp_mac",:style=>"width:140px", :placeholder=>"MAC",:data => { validation: 'required-check dhcp-mac_id','dependent-field' => '.dhcp_ip'}%>
<%=link_to " X ","javascript:void(0);", {:class => "remove_mapping icon-delete btn btn-sm btn-danger"} %>
<% end %>

<%=f.label :wired_mode, "Wired Mode".html_safe, :class=>"col-sm-4 control-label"%>
<%=f.select(:wired_mode, [["Default","1"],["Custom","2"]],{},:class=>"form-control wired_mode",'data-validation'=> "required" )%>
<%=link_to " Add PORT".html_safe,"javascript:void(0);", {:class => "btn btn-warning add_port pull-right"} %>


#
<%= label_tag :PORTVLANID,'PVLANID'%>
<%= label_tag :Untagged,'TAGGED' %>
<%= label_tag :VLAN, 'VLAN'%>
<%= label_tag 'Action'%>

<%= hidden_field_tag 'port_id',0,:class => "port_id" %>
<%= select_tag(:pvlan, [[]],:class=>"form-control",'data-validation'=> "" ) %>
<%= check_box_tag :tagged ,'',:class => 'vlan_tagged'%>
<%= text_field_tag('vlans[]', [[]],:class=>"form-control vlans",'data-validation'=> "" ) %>
<%=link_to " X ","javascript:void(0);", {:class => "icon-delete btn btn-danger remove_port"} %>

<%if @v_lan.id.blank? @name = 'Create Configuration' @url = '/v_lans' @method = 'POST' else @name = 'Update Configuration' @url = "/v_lans/#{@v_lan.id}" @method = "PATCH" end %>
<%= f.submit @name,:class=>"btn btn-success vlan_submit",'data-url' => @url,'data-method' => @method%> <%= link_to "Cancel", v_lans_path, :class => "btn btn-primary" %>
<% end %>