').html(errortext));
}
$(".networklist").sortable({
connectWith: "ul.networklist",
placeholder: "ui-state-highlight",
distance: 5,
start:function(e,info){
selected_group.addClass("dragging");
},
stop:function(e,info){
selected_group.removeClass("dragging");
updateForm();
}
}).disableSelection();
},
control_max_instances: function(){
$("#id_count").attr('readonly', false)
$("#id_network li").each(function() {
$input = $(this).find('input');
value = $input.val();
fields = value.split(":")
if ($input.is(":checked") && fields.length == 3){
// fixed ip is associated, dont allow Instance Count > 1
$("#id_count").attr('readonly', true)
return
}
});
},
allow_fixed_ip: function(selected_group){
if (member.allowed() == false)
return
fixed_ip = ""
$("#fixed_ip").val("")
$("#errors").hide().text("")
$("#fixed_ip_div").show()
ptg = $(selected_group).attr('name')
$(selected_group).siblings().css( "background-color", "");
$(selected_group).css('background-color', '#e6e6e6');
selected_element = $(".multiple-checkbox #id_network li input[value^='"+ ptg +"']");
value = selected_element.val();
values = value.split(':');
group = $(selected_group).clone().find('strong').remove().end().text();
$("#group").text(group);
subnets = values[1].split(";")
$('#subnets_table tbody').empty();
for (index=0; index < subnets.length; index++){
subnet_details = subnets[index].split(",")
row = '
'+subnet_details[0]+' | '+
subnet_details[1] +' | ' + subnet_details[2]+' | ';
$('#subnets_table tbody').append(row);
}
$("#fixed_ip").attr("data-ptg", values[0]);
$("#fixed_ip").attr("data-subnet", values[1])
if (values.length == 3)
$("#fixed_ip").val(values[2]);
},
allowed: function(){
if($("#id_count").val() > 1){
$("#errors").show().text("You cannot assign fixed IPs " +
"if more than one instance is requested.")
return false
}
return true
},
associate_fixed_ip: function(){
if (member.allowed() == false)
return
ptg = $("#fixed_ip").attr("data-ptg")
subnet = $("#fixed_ip").attr("data-subnet")
subnet = subnet.replace(";", ":")
fixed_ip = $("#fixed_ip").val()
if (!fixed_ip || 0 === fixed_ip.length ){
$("#errors").show().text("Enter valid IP address")
return
}
$.ajax({
url: 'check_ip_availability',
data: "fixed_ip="+fixed_ip+"&subnets="+subnet,
method: 'get',
success: function(response) {
if(response.inuse){
horizon.alert('success', "IP address '" + fixed_ip +"' is available.")
subnet = subnet.replace(":", ";")
value = ptg + ":" + subnet + ":" + fixed_ip
selected_element = $(".multiple-checkbox #id_network li input[value^='"+ ptg +"']");
selected_element.val(value)
if(fixed_ip){
$("#selected_network li[name^='"+ ptg +"'] strong").html(" ( "+fixed_ip +") Edit IP")
}
$("ul#selected_network li[name^='"+ ptg +"']").css("background-color", "");
$("#fixed_ip_div").hide()
$("#errors").hide().text("")
member.control_max_instances()
}
else{
$("#errors").show().text(response.error)
}
},
error: function(response) {
$("#errors").show().text(response)
}
});
},
disassociate_fixed_ip: function(){
ptg = $("#fixed_ip").attr("data-ptg")
$("#errors").hide().text("")
subnet = $("#fixed_ip").attr("data-subnet")
value = ptg + ":" + subnet
selected_element = $(".multiple-checkbox #id_network li input[value^='"+ ptg +"']");
selected_element.val(value)
$("#selected_network li[name^='"+ ptg +"'] strong").html(" Set IP Address")
$("#fixed_ip_div").hide()
$("ul#selected_network li").css("background-color", "");
member.control_max_instances()
},
groups_init: function() {
// Initialise the drag and drop group list
member.generate_grouplist_html();
// allocate fixed ip
$(document).on('click', "ul#selected_network li", function(e){
member.allow_fixed_ip(this);
e.preventDefault();
e.stopPropagation();
});
$("#set_ip_button").click(function(){
member.associate_fixed_ip();
});
$("#remove").click(function(){
member.disassociate_fixed_ip()
});
help = $("label[for=id_count]").parent().find('span.help-icon')
title = help.attr("title")
title = title + " Fixed IP can be assigned only when Instance Count is 1"
help.attr("title", title)
$(document).on('input', '#id_count',function(){
if($("#id_count").val() > 1){
$("#selected_network li").find("strong").html("");
}
else{
$("#selected_network li").find("strong").html(" Set IP Address")
$("#errors").hide().text("")
}
$("#fixed_ip_div").hide()
})
}
};