Persist service variables

This commit is contained in:
Matthew Penner 2020-04-11 14:46:30 -06:00
parent dec6868a55
commit a7dab69711
2 changed files with 41 additions and 14 deletions

View file

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

View file

@ -309,11 +309,31 @@
@section('footer-scripts') @section('footer-scripts')
@parent @parent
{!! Theme::js('vendor/lodash/lodash.js') !!} {!! Theme::js('vendor/lodash/lodash.js') !!}
<script type="application/javascript">
// Persist 'Service Variables'
function serviceVariablesUpdated(eggId, ids) {
@if (old('egg_id'))
// Check if the egg id matches.
if (eggId != '{{ old('egg_id') }}') {
return;
}
@if (old('environment'))
@foreach (old('environment') as $key => $value)
$('#' + ids['{{ $key }}']).val('{{ $value }}');
@endforeach
@endif
@endif
}
// END Persist 'Service Variables'
</script>
{!! Theme::js('js/admin/new-server.js') !!} {!! Theme::js('js/admin/new-server.js') !!}
<script type="application/javascript"> <script type="application/javascript">
$(document).ready(function() { $(document).ready(function() {
<!-- Persist 'Server Owner' select2 --> // Persist 'Server Owner' select2
@if (old('owner_id')) @if (old('owner_id'))
$.ajax({ $.ajax({
url: '/admin/users/accounts.json?user_id={{ old('owner_id') }}', url: '/admin/users/accounts.json?user_id={{ old('owner_id') }}',
@ -324,19 +344,19 @@
@else @else
initUserIdSelect(); initUserIdSelect();
@endif @endif
<!-- END Persist 'Server Owner' select2 --> // END Persist 'Server Owner' select2
<!-- Persist 'Node' select2 --> // Persist 'Node' select2
@if (old('node_id')) @if (old('node_id'))
$('#pNodeId').val('{{ old('node_id') }}').change(); $('#pNodeId').val('{{ old('node_id') }}').change();
<!-- Persist 'Default Allocation' select2 --> // Persist 'Default Allocation' select2
@if (old('allocation_id')) @if (old('allocation_id'))
$('#pAllocation').val('{{ old('allocation_id') }}').change(); $('#pAllocation').val('{{ old('allocation_id') }}').change();
@endif @endif
<!-- END Persist 'Default Allocation' select2 --> // END Persist 'Default Allocation' select2
<!-- Persist 'Additional Allocations' select2 --> // Persist 'Additional Allocations' select2
@if (old('allocation_additional')) @if (old('allocation_additional'))
const additional_allocations = []; const additional_allocations = [];
@ -346,27 +366,27 @@
$('#pAllocationAdditional').val(additional_allocations).change(); $('#pAllocationAdditional').val(additional_allocations).change();
@endif @endif
<!-- END Persist 'Additional Allocations' select2 --> // END Persist 'Additional Allocations' select2
@endif @endif
<!-- END Persist 'Node' select2 --> // END Persist 'Node' select2
<!-- Persist 'Nest' select2 --> // Persist 'Nest' select2
@if (old('nest_id')) @if (old('nest_id'))
$('#pNestId').val('{{ old('nest_id') }}').change(); $('#pNestId').val('{{ old('nest_id') }}').change();
<!-- Persist 'Egg' select2 --> // Persist 'Egg' select2
@if (old('egg_id')) @if (old('egg_id'))
$('#pEggId').val('{{ old('egg_id') }}').change(); $('#pEggId').val('{{ old('egg_id') }}').change();
@endif @endif
<!-- END Persist 'Egg' select2 --> // END Persist 'Egg' select2
<!-- Persist 'Data Pack' select2 --> // Persist 'Data Pack' select2
@if (old('pack_id')) @if (old('pack_id'))
$('#pPackId').val('{{ old('pack_id') }}').change(); $('#pPackId').val('{{ old('pack_id') }}').change();
@endif @endif
<!-- END Persist 'Data Pack' select2 --> // END Persist 'Data Pack' select2
@endif @endif
<!-- END Persist 'Nest' select2 --> // END Persist 'Nest' select2
}); });
</script> </script>
@endsection @endsection