1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-25 10:32:31 +01:00

Add multiplicators to certain inputs, closes #154

Allows for users to enter `10g` into a memory field and have it
converted to 10GB equivalent in MB.
This commit is contained in:
Dane Everitt 2016-11-26 19:56:19 -05:00
parent 90cd2b677e
commit e47bb6ef0f
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
5 changed files with 29 additions and 9 deletions

View File

@ -46,4 +46,24 @@ $(document).ready(function () {
centerModal($(this));
});
$(window).on('resize', centerModal);
// Idea code for multiplicators submitted by @Taronyuu on Github
// https://github.com/Pterodactyl/Panel/issues/154#issuecomment-257116078
$('input[data-multiplicator="true"]').on('change', function () {
var value = $(this).val();
if (!/^\d+$/.test(value)) {
var multiplicator = value.replace(/[0-9]/g, '').toLowerCase();
value = value.replace(/\D/g, '');
if (multiplicator === 't') {
value = value * (1024 * 1024);
}
if (multiplicator === 'g') {
value = value * 1024;
}
}
$(this).val(value);
});
});

View File

@ -92,14 +92,14 @@
<div class="form-group col-md-6 col-xs-6">
<label for="memory" class="control-label">Total Memory</label>
<div class="input-group">
<input type="text" name="memory" class="form-control" value="{{ old('memory') }}"/>
<input type="text" name="memory" data-multiplicator="true" class="form-control" value="{{ old('memory') }}"/>
<span class="input-group-addon">MB</span>
</div>
</div>
<div class="form-group col-md-6 col-xs-6">
<label for="memory_overallocate" class="control-label">Overallocate</label>
<div class="input-group">
<input type="text" name="memory_overallocate" class="form-control" value="{{ old('memory_overallocate', 0) }}"/>
<input type="text" name="memory_overallocate" data-multiplicator="true" class="form-control" value="{{ old('memory_overallocate', 0) }}"/>
<span class="input-group-addon">%</span>
</div>
</div>

View File

@ -183,7 +183,7 @@
<div class="form-group col-md-3 col-xs-6">
<label for="memory" class="control-label">Total Memory</label>
<div class="input-group">
<input type="text" name="memory" class="form-control" value="{{ old('memory', $node->memory) }}"/>
<input type="text" name="memory" class="form-control" data-multiplicator="true" value="{{ old('memory', $node->memory) }}"/>
<span class="input-group-addon">MB</span>
</div>
</div>
@ -197,7 +197,7 @@
<div class="form-group col-md-3 col-xs-6">
<label for="disk" class="control-label">Disk Space</label>
<div class="input-group">
<input type="text" name="disk" class="form-control" value="{{ old('disk', $node->disk) }}"/>
<input type="text" name="disk" class="form-control" data-multiplicator="true" value="{{ old('disk', $node->disk) }}"/>
<span class="input-group-addon">MB</span>
</div>
</div>

View File

@ -118,14 +118,14 @@
<div class="form-group col-md-4 col-xs-4">
<label for="memory" class="control-label">Memory</label>
<div class="input-group">
<input type="text" name="memory" class="form-control" value="{{ old('memory') }}"/>
<input type="text" name="memory" data-multiplicator="true" class="form-control" value="{{ old('memory') }}"/>
<span class="input-group-addon">MB</span>
</div>
</div>
<div class="form-group col-md-4 col-xs-4">
<label for="memory" class="control-label">Swap</label>
<div class="input-group">
<input type="text" name="swap" class="form-control" value="{{ old('swap', 0) }}"/>
<input type="text" name="swap" data-multiplicator="true" class="form-control" value="{{ old('swap', 0) }}"/>
<span class="input-group-addon">MB</span>
</div>
</div>
@ -150,7 +150,7 @@
<div class="form-group col-md-4 col-xs-4">
<label for="disk" class="control-label">Disk Space</label>
<div class="input-group">
<input type="text" name="disk" class="form-control" value="{{ old('disk') }}"/>
<input type="text" name="disk" data-multiplicator="true" class="form-control" value="{{ old('disk') }}"/>
<span class="input-group-addon">MB</span>
</div>
</div>

View File

@ -228,14 +228,14 @@
<div class="col-md-6 form-group {{ $errors->has('memory') ? 'has-error' : '' }}">
<label for="memory" class="control-label">Allocated Memory</label>
<div class="input-group">
<input type="text" name="memory" class="form-control" value="{{ old('memory', $server->memory) }}"/>
<input type="text" name="memory" data-multiplicator="true" class="form-control" value="{{ old('memory', $server->memory) }}"/>
<span class="input-group-addon">MB</span>
</div>
</div>
<div class="col-md-6 form-group {{ $errors->has('swap') ? 'has-error' : '' }}">
<label for="swap" class="control-label">Allocated Swap</label>
<div class="input-group">
<input type="text" name="swap" class="form-control" value="{{ old('swap', $server->swap) }}"/>
<input type="text" name="swap" data-multiplicator="true" class="form-control" value="{{ old('swap', $server->swap) }}"/>
<span class="input-group-addon">MB</span>
</div>
<p class="text-muted"><small>Setting this to <code>0</code> will disable swap space on this server.</small></p>