Skip to content

Commit a7dab69

Browse files
committed
Persist service variables
1 parent dec6868 commit a7dab69

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

public/themes/pterodactyl/js/admin/new-server.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,11 @@ $('#pEggId').on('change', function (event) {
101101
),
102102
});
103103

104+
const variableIds = {};
104105
$('#appendVariablesTo').html('');
105106
$.each(_.get(objectChain, 'variables', []), function (i, item) {
107+
variableIds[item.env_variable] = 'var_ref_' + item.id;
108+
106109
let isRequired = (item.required === 1) ? '<span class="label label-danger">Required</span> ' : '';
107110
let dataAppend = ' \
108111
<div class="form-group col-sm-6"> \
@@ -115,6 +118,10 @@ $('#pEggId').on('change', function (event) {
115118
';
116119
$('#appendVariablesTo').append(dataAppend);
117120
});
121+
122+
// If you receive a warning on this line, it should be fine to ignore. this function is
123+
// defined in "resources/views/admin/servers/new.blade.php" near the bottom of the file.
124+
serviceVariablesUpdated($('#pEggId').val(), variableIds);
118125
});
119126

120127
$('#pAllocation').on('change', function () {

resources/views/admin/servers/new.blade.php

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,31 @@
309309
@section('footer-scripts')
310310
@parent
311311
{!! Theme::js('vendor/lodash/lodash.js') !!}
312+
313+
<script type="application/javascript">
314+
// Persist 'Service Variables'
315+
function serviceVariablesUpdated(eggId, ids) {
316+
@if (old('egg_id'))
317+
// Check if the egg id matches.
318+
if (eggId != '{{ old('egg_id') }}') {
319+
return;
320+
}
321+
322+
@if (old('environment'))
323+
@foreach (old('environment') as $key => $value)
324+
$('#' + ids['{{ $key }}']).val('{{ $value }}');
325+
@endforeach
326+
@endif
327+
@endif
328+
}
329+
// END Persist 'Service Variables'
330+
</script>
331+
312332
{!! Theme::js('js/admin/new-server.js') !!}
313333

314334
<script type="application/javascript">
315335
$(document).ready(function() {
316-
<!-- Persist 'Server Owner' select2 -->
336+
// Persist 'Server Owner' select2
317337
@if (old('owner_id'))
318338
$.ajax({
319339
url: '/admin/users/accounts.json?user_id={{ old('owner_id') }}',
@@ -324,19 +344,19 @@
324344
@else
325345
initUserIdSelect();
326346
@endif
327-
<!-- END Persist 'Server Owner' select2 -->
347+
// END Persist 'Server Owner' select2
328348
329-
<!-- Persist 'Node' select2 -->
349+
// Persist 'Node' select2
330350
@if (old('node_id'))
331351
$('#pNodeId').val('{{ old('node_id') }}').change();
332352
333-
<!-- Persist 'Default Allocation' select2 -->
353+
// Persist 'Default Allocation' select2
334354
@if (old('allocation_id'))
335355
$('#pAllocation').val('{{ old('allocation_id') }}').change();
336356
@endif
337-
<!-- END Persist 'Default Allocation' select2 -->
357+
// END Persist 'Default Allocation' select2
338358
339-
<!-- Persist 'Additional Allocations' select2 -->
359+
// Persist 'Additional Allocations' select2
340360
@if (old('allocation_additional'))
341361
const additional_allocations = [];
342362
@@ -346,27 +366,27 @@
346366
347367
$('#pAllocationAdditional').val(additional_allocations).change();
348368
@endif
349-
<!-- END Persist 'Additional Allocations' select2 -->
369+
// END Persist 'Additional Allocations' select2
350370
@endif
351-
<!-- END Persist 'Node' select2 -->
371+
// END Persist 'Node' select2
352372
353-
<!-- Persist 'Nest' select2 -->
373+
// Persist 'Nest' select2
354374
@if (old('nest_id'))
355375
$('#pNestId').val('{{ old('nest_id') }}').change();
356376
357-
<!-- Persist 'Egg' select2 -->
377+
// Persist 'Egg' select2
358378
@if (old('egg_id'))
359379
$('#pEggId').val('{{ old('egg_id') }}').change();
360380
@endif
361-
<!-- END Persist 'Egg' select2 -->
381+
// END Persist 'Egg' select2
362382
363-
<!-- Persist 'Data Pack' select2 -->
383+
// Persist 'Data Pack' select2
364384
@if (old('pack_id'))
365385
$('#pPackId').val('{{ old('pack_id') }}').change();
366386
@endif
367-
<!-- END Persist 'Data Pack' select2 -->
387+
// END Persist 'Data Pack' select2
368388
@endif
369-
<!-- END Persist 'Nest' select2 -->
389+
// END Persist 'Nest' select2
370390
});
371391
</script>
372392
@endsection

0 commit comments

Comments
 (0)