Skip to content

Commit

Permalink
Use mod source list to determine available fields and options (#302)
Browse files Browse the repository at this point in the history
This will:
- title
  • Loading branch information
jskowronski39 authored Oct 22, 2023
2 parents a7e772d + ffc3cc0 commit 18be65c
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions assets/mod/modForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,28 @@ modForm.TYPE_CLIENT_SIDE = 'client_side';
modForm.SOURCE_STEAM_WORKSHOP = 'steam_workshop';
modForm.SOURCE_DIRECTORY = 'directory';

modForm.onModTypeChange = () => {
const $type = $('#mod_form_type');
const $source = $('#mod_form_source');

if ($type.val() === modForm.TYPE_SERVER_SIDE) {
$source.prop('disabled', false);
} else {
$source.val(modForm.SOURCE_STEAM_WORKSHOP);
$source.prop('disabled', true);
modForm.onModSourceChange();
}
};

modForm.onModSourceChange = () => {
const $source = $('#mod_form_source');
const $url = $('#mod_form_url');
const $directory = $('#mod_form_directory');

$url.closest('.form-group').toggleClass('d-none', $source.val() !== modForm.SOURCE_STEAM_WORKSHOP);
$directory.closest('.form-group').toggleClass('d-none', $source.val() !== modForm.SOURCE_DIRECTORY);
const $type = $('#mod_form_type');

if ($source.val() === modForm.SOURCE_STEAM_WORKSHOP) {
$directory.val('');
$type.prop('selectedIndex', 0);
} else if ($source.val() === modForm.SOURCE_DIRECTORY) {
$url.val('');
$type.val(modForm.TYPE_SERVER_SIDE);
}

$url.closest('.form-group').toggleClass('d-none', $source.val() !== modForm.SOURCE_STEAM_WORKSHOP);
$type.prop('disabled', $source.val() !== modForm.SOURCE_STEAM_WORKSHOP);
$directory.closest('.form-group').toggleClass('d-none', $source.val() !== modForm.SOURCE_DIRECTORY);
};

$(() => {
modForm.onModTypeChange();
$('#mod_form_type').on('change', (e) => {
modForm.onModTypeChange();
});

modForm.onModSourceChange();
$('#mod_form_source').on('change', (e) => {
$('#mod_form_source').on('change', () => {
modForm.onModSourceChange();
});
});
Expand Down

0 comments on commit 18be65c

Please sign in to comment.