69 lines
2.4 KiB
JavaScript
69 lines
2.4 KiB
JavaScript
$(function() {
|
|
function replaceTemplate(template, values) {
|
|
var output = String(template || '');
|
|
$.each(values, function(key, value) {
|
|
output = output.split(key).join(value);
|
|
});
|
|
return output;
|
|
}
|
|
|
|
var $category = $('#scm-category-input');
|
|
var $hookEnabled = $('#scm-hook-enabled');
|
|
|
|
function applyCategoryUi() {
|
|
var category = String($category.val() || '').toLowerCase();
|
|
var isServerApp = category === 'server-side application';
|
|
var showHookRows = isServerApp || $hookEnabled.is(':checked');
|
|
$('.scm-row-server-app').toggle(showHookRows);
|
|
if (isServerApp) {
|
|
$hookEnabled.prop('checked', true);
|
|
}
|
|
}
|
|
|
|
$category.on('input change', applyCategoryUi);
|
|
$hookEnabled.on('change', applyCategoryUi);
|
|
applyCategoryUi();
|
|
|
|
var $userSelect = $('#scm-user-addon-select');
|
|
var $userWorkshopRows = $('.scm-user-workshop-row');
|
|
var $userWorkshopId = $('#scm-user-workshop-id');
|
|
var $userPreview = $('#scm-user-target-path-preview');
|
|
|
|
function updateUserWorkshopUi() {
|
|
if ($userSelect.length === 0) return;
|
|
var $selected = $userSelect.find('option:selected');
|
|
var installMethod = String($selected.data('installMethod') || '');
|
|
var isWorkshop = installMethod === 'steam_workshop';
|
|
$userWorkshopRows.toggle(isWorkshop);
|
|
if (!isWorkshop) {
|
|
return;
|
|
}
|
|
|
|
if (!$userWorkshopId.val()) {
|
|
$userWorkshopId.val(String($selected.data('workshopItemId') || ''));
|
|
}
|
|
var workshopId = $.trim($userWorkshopId.val());
|
|
var workshopAppId = String($userPreview.data('workshopAppId') || '');
|
|
var folderName = workshopId ? '@' + workshopId : '@{WORKSHOP_ID}';
|
|
var targetTemplate = String($userPreview.data('targetTemplate') || $userPreview.text() || '');
|
|
var previewValues = {
|
|
'{SERVER_ROOT}': String($userPreview.data('serverRoot') || ''),
|
|
'{GAME_ROOT}': String($userPreview.data('gameRoot') || ''),
|
|
'{WORKSHOP_ID}': workshopId || '{WORKSHOP_ID}',
|
|
'{WORKSHOP_APP_ID}': workshopAppId || '{WORKSHOP_APP_ID}',
|
|
'{STEAM_APP_ID}': String($userPreview.data('steamAppId') || '{STEAM_APP_ID}'),
|
|
'{FOLDER_NAME}': folderName,
|
|
'{MOD_FOLDER}': folderName
|
|
};
|
|
$userPreview.text(replaceTemplate(targetTemplate, previewValues));
|
|
}
|
|
|
|
if ($userSelect.length) {
|
|
$userSelect.on('change', function() {
|
|
$userWorkshopId.val(String($(this).find('option:selected').data('workshopItemId') || ''));
|
|
updateUserWorkshopUi();
|
|
});
|
|
$userWorkshopId.on('input', updateUserWorkshopUi);
|
|
updateUserWorkshopUi();
|
|
}
|
|
});
|