2017-03-25 04:11:37 +01:00
|
|
|
<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()) {
|
2017-03-25 04:43:20 +01:00
|
|
|
var prefixLen = null;
|
2017-03-25 04:11:37 +01:00
|
|
|
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>');
|
2017-03-25 04:43:20 +01:00
|
|
|
$('#div_id_prefix label').append(' <small>(<a onClick="findPrefix(27);">next free /27 or /60</a>)</small>');
|
|
|
|
$('#div_id_1-prefix label').append(' <small>(<a onClick="findPrefix(27, 1);">next free /27 or /60</a>)</small>');
|
2017-03-25 04:11:37 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|