{% extends "layout2.html" %} {% load i18n %} {% load static %} {% block css_include %} {% endblock %} {% block js_include %} {% endblock %} {% block content %}
{% csrf_token %}

 {% translate "Network" %}

{{form.name}} {{form.name.errors}}
{{form.type}} {{form.type.errors}}
{{form.iface_id.as_hidden}}
{{form.nic}} {{form.nic.errors}}
{{form.carp_vhid}} {{form.carp_vhid.errors}}
{{form.ip}} {{form.ip.errors}}
{{form.prefix_or_netmask}} {{form.prefix_or_netmask.errors}}
{{form.fib}} {{form.fib.errors}}
{{form.vlan}} {{form.vlan.errors}}
{{form.lagg_proto}} {{form.lagg_proto.errors}}
{% endblock %} {% block jquery_code %} if (!String.prototype.endsWith) { String.prototype.endsWith = function(searchString, position) { var subjectString = this.toString(); if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) { position = subjectString.length; } position -= searchString.length; var lastIndex = subjectString.lastIndexOf(searchString, position); return lastIndex !== -1 && lastIndex === position; }; } var require_carp_vhid = false; function show_or_hide_carp_params(){ var current_type = $('#id_type').val(); var nics = $('#id_nic').val(); var vhid = $('#id_carp_vhid').val(); if(vhid != "0") { $('#carp_info').show(); } else if(nics && nics.length > 1 && current_type === "alias") { require_carp_vhid = true; $('#carp_info').show(); } else { require_carp_vhid = false; $('#carp_info').hide(); } } $(function() { $('.select2').select2(); show_or_hide_carp_params(); $('#id_nic').on('change', function(e){ //$('#id_nic').select2('destroy'); var val = $(this).val(); var current_type = $('#id_type').val(); $('#id_nic option').each(function(){ $(this).prop('disabled', false); }); if (val === null){ $('.select2').select2(); return; } show_or_hide_carp_params(); var ids = []; var node_names = []; var interface_names = []; $("#id_nic option:selected").each(function(){ $(this).prop('disabled', false); ids.push($(this).val()); node_names.push($(this).text().split(' - ')[1]); interface_names.push($(this).text().split(' - ')[0]); }) $('#id_nic option').each(function(){ if ($.inArray($(this).val(), ids) === -1){ $(this).prop('disabled', false); // Disable interfaces on the same node for alias/vlan interfaces (CARP only allowed) if (["alias", "vlan"].includes(current_type)) { for (var i in node_names){ if ($(this).text().endsWith(node_names[i])){ $(this).prop('disabled', true); } } } else if (current_type === "lagg") { for (var i in node_names){ if (!$(this).text().endsWith(node_names[i])){ $(this).prop('disabled', true); } } } else { $(this).prop('disabled', true); } } }) $('.select2').select2(); }).trigger('change') $('#id_type').on('change', function(e){ var current_type = $('#id_type').val(); $('.vlan_parameters').hide(); $('.lagg_parameters').hide(); if(current_type === "vlan") { $('.vlan_parameters').show(); } if(current_type === "lagg") { $('.lagg_parameters').show(); } }).trigger('change') $('#netif_edit_form').on('submit', function(e){ PNotify().removeAll() e.preventDefault(); if (require_carp_vhid && $('#id_carp_vhid').val() === "0"){ notify('error', gettext('Error'), gettext('Define a VHID > 0 for a CARP network address')) return false; } return true; }) }); {% endblock %}