77 lines
2.1 KiB
HTML
77 lines
2.1 KiB
HTML
|
<script>
|
||
|
function findASNumber(step) {
|
||
|
// extra field foo
|
||
|
var ef = ""
|
||
|
if(step >= 0)
|
||
|
ef = "" + step + "-";
|
||
|
|
||
|
var asNumInp = $('#div_id_'+ef+'number input');
|
||
|
asNumInp.val("");
|
||
|
asNumInp.attr("placeholder", "Getting AS number...");
|
||
|
|
||
|
var blockOpt = $('#id_'+ef+'asblock option:selected');
|
||
|
if(blockOpt.val()) {
|
||
|
$.get("{% url "api:asblock-free-as" %}", {block: blockOpt.text()}, function(data) {
|
||
|
if(data.success) {
|
||
|
asNumInp.attr("placeholder", "")
|
||
|
asNumInp.val(data.number);
|
||
|
} else {
|
||
|
errorMsg = "Nothing returned via API";
|
||
|
if(data.errorMsg)
|
||
|
errorMsg = data.errorMsg;
|
||
|
asNumInp.attr("placeholder", data.errorMsg);
|
||
|
}
|
||
|
});
|
||
|
} else {
|
||
|
asNumInp.attr("placeholder", "No AS Block selected!");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function findPrefix(size, step) {
|
||
|
// extra field foo
|
||
|
var ef = ""
|
||
|
if(step >= 0)
|
||
|
ef = "" + step + "-";
|
||
|
|
||
|
var netInp = $('#div_id_'+ef+'prefix input');
|
||
|
var netInpText = netInp.val();
|
||
|
netInp.val("");
|
||
|
netInp.attr("placeholder", "Searching free prefix...");
|
||
|
|
||
|
var parentRangeOpt = $('#id_'+ef+'parent_range option:selected');
|
||
|
if(parentRangeOpt.val()) {
|
||
|
var prefixLen = 27;
|
||
|
var m = netInpText.match("([0-9.:]+/)?(\\d+)");
|
||
|
console.log(prefixLen)
|
||
|
console.log(netInpText);
|
||
|
if(m) {
|
||
|
prefixLen = m[2];
|
||
|
}
|
||
|
|
||
|
|
||
|
$.get("{% url "api:inetnum-free-subnet" %}", {parentRange: parentRangeOpt.text(), prefixLen: prefixLen}, function(data) {
|
||
|
if(data.success) {
|
||
|
netInp.attr("placeholder", "")
|
||
|
netInp.val(data.network);
|
||
|
} else {
|
||
|
errorMsg = "Nothing returned via API";
|
||
|
if(data.errorMsg)
|
||
|
errorMsg = data.errorMsg;
|
||
|
netInp.attr("placeholder", data.errorMsg);
|
||
|
}
|
||
|
});
|
||
|
} else {
|
||
|
netInp.attr("placeholder", "No Parent Range selected!");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$(document).ready(function() {
|
||
|
console.log("NOOT NOOT");
|
||
|
$('#div_id_number label').append(' <small>(<a onClick="findASNumber();">next free number</a>)</small>');
|
||
|
$('#div_id_0-number label').append(' <small>(<a onClick="findASNumber(0);">next free number</a>)</small>');
|
||
|
$('#div_id_prefix label').append(' <small>(<a onClick="findPrefix(27);">next free /27</a>)</small>');
|
||
|
$('#div_id_1-prefix label').append(' <small>(<a onClick="findPrefix(27, 1);">next free /27</a>)</small>');
|
||
|
});
|
||
|
</script>
|
||
|
|