From fb96d9468ed2152253db2e667f39dec3790270a9 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Sat, 11 Apr 2020 12:35:27 -0600 Subject: [PATCH] Prevent primary allocation from being an additional allocation at the same time when creating a server --- .../themes/pterodactyl/js/admin/new-server.js | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/public/themes/pterodactyl/js/admin/new-server.js b/public/themes/pterodactyl/js/admin/new-server.js index 5a7393b4f..3da41da0f 100644 --- a/public/themes/pterodactyl/js/admin/new-server.js +++ b/public/themes/pterodactyl/js/admin/new-server.js @@ -21,18 +21,23 @@ $(document).ready(function() { $('#pNestId').select2({ placeholder: 'Select a Nest', }).change(); + $('#pEggId').select2({ placeholder: 'Select a Nest Egg', }); + $('#pPackId').select2({ placeholder: 'Select a Service Pack', }); + $('#pNodeId').select2({ placeholder: 'Select a Node', }).change(); + $('#pAllocation').select2({ placeholder: 'Select a Default Allocation', }); + $('#pAllocationAdditional').select2({ placeholder: 'Select Additional Allocations', }); @@ -97,10 +102,8 @@ $('#pNodeId').on('change', function () { data: v.allocations, placeholder: 'Select a Default Allocation', }); - $('#pAllocationAdditional').html('').select2({ - data: v.allocations, - placeholder: 'Select Additional Allocations', - }) + + updateAdditionalAllocations(); } }); }); @@ -154,3 +157,31 @@ $('#pEggId').on('change', function (event) { $('#appendVariablesTo').append(dataAppend); }); }); + +$('#pAllocation').on('change', function () { + updateAdditionalAllocations(); +}); + +function updateAdditionalAllocations() { + let currentAllocation = $('#pAllocation').val(); + let currentNode = $('#pNodeId').val(); + + $.each(Pterodactyl.nodeData, function (i, v) { + if (v.id == currentNode) { + let allocations = []; + + for (let i = 0; i < v.allocations.length; i++) { + const allocation = v.allocations[i]; + + if (allocation.id != currentAllocation) { + allocations.push(allocation); + } + } + + $('#pAllocationAdditional').html('').select2({ + data: allocations, + placeholder: 'Select Additional Allocations', + }); + } + }); +}