Skip to content
Snippets Groups Projects
Commit 1a22bbce authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Fix MAC selection on register new host

On page load we have to check the machine type to enable / disable
item_id and check / uncheck the random MAC
parent db9b9152
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,21 @@ $(document).ready(function() { ...@@ -12,6 +12,21 @@ $(document).ready(function() {
); );
} }
// Enable / disable item_id field depending on machine_type
// Item can only be assigned for physical hosts
// And check / uncheck random_mac checkbox
function update_machine_type_attributes() {
var machine_type = $("#machine_type_id option:selected").text();
if( machine_type.startsWith("Physical") ) {
$("#item_id").prop("disabled", false);
$("#random_mac").prop("checked", false).change();
} else {
$("#item_id").val("");
$("#item_id").prop("disabled", true);
$("#random_mac").prop("checked", true).change();
}
}
// If random_mac is checked, generate a random address // If random_mac is checked, generate a random address
// Empty the field otherwise // Empty the field otherwise
function fill_mac_address() { function fill_mac_address() {
...@@ -43,29 +58,13 @@ $(document).ready(function() { ...@@ -43,29 +58,13 @@ $(document).ready(function() {
set_default_ip(); set_default_ip();
}); });
// Enable / disable item_id on edit host first page load // On register and edit host first page load
if( $("#editHostForm").length ) { if( $("#hostForm").length || $("#editHostForm").length ) {
var machine_type = $("#machine_type_id option:selected").text(); update_machine_type_attributes();
if( machine_type == "Physical" ) {
$("#item_id").prop("disabled", false);
} else {
$("#item_id").prop("disabled", true);
}
} }
// Enable / disable item_id field depending on machine_type
// Item can only be assigned for physical hosts
// And check / uncheck random_mac checkbox
$("#machine_type_id").on('change', function() { $("#machine_type_id").on('change', function() {
var machine_type = $("#machine_type_id option:selected").text(); update_machine_type_attributes();
if( machine_type == "Physical" ) {
$("#item_id").prop("disabled", false);
$("#random_mac").prop("checked", false).change();
} else {
$("#item_id").val("");
$("#item_id").prop("disabled", true);
$("#random_mac").prop("checked", true).change();
}
}); });
// Prefill interface name with hostname // Prefill interface name with hostname
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment