// Copyright (c) 2015 - 2017 Dane Everitt // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. $(document).ready(function() { $('#pServiceId').select2({ placeholder: 'Select a Service', }).change(); $('#pOptionId').select2({ placeholder: 'Select a Service Option', }); $('#pPackId').select2({ placeholder: 'Select a Service Pack', }); $('#pLocationId').select2({ placeholder: 'Select a Location', }).change(); $('#pNodeId').select2({ placeholder: 'Select a Node', }); $('#pAllocation').select2({ placeholder: 'Select a Default Allocation', }); $('#pAllocationAdditional').select2({ placeholder: 'Select Additional Allocations', }); $('#pUserId').select2({ ajax: { url: Router.route('admin.users.json'), dataType: 'json', delay: 250, data: function (params) { return { q: params.term, // search term page: params.page, }; }, processResults: function (data, params) { return { results: data }; }, cache: true, }, escapeMarkup: function (markup) { return markup; }, minimumInputLength: 2, templateResult: function (data) { if (data.loading) return data.text; return '
\ User Image \ \ ' + data.name_first + ' ' + data.name_last +' \ \ ' + data.email + ' - ' + data.username + ' \
'; }, templateSelection: function (data) { return '
\ \ User Image \ \ \ ' + data.name_first + ' ' + data.name_last + ' (' + data.email + ') \ \
'; } }); }); function hideLoader() { $('#allocationLoader').hide(); } function showLoader() { $('#allocationLoader').show(); } var lastActiveBox = null; $(document).on('click', function (event) { if (lastActiveBox !== null) { lastActiveBox.removeClass('box-primary'); } lastActiveBox = $(event.target).closest('.box'); lastActiveBox.addClass('box-primary'); }); var currentLocation = null; var curentNode = null; var NodeData = []; $('#pLocationId').on('change', function (event) { showLoader(); currentLocation = $(this).val(); currentNode = null; $.ajax({ method: 'POST', url: Router.route('admin.servers.new.nodes'), headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') }, data: { location: currentLocation }, }).done(function (data) { NodeData = data; $('#pNodeId').html('').select2({data: data}).change(); }).fail(function (jqXHR) { cosole.error(jqXHR); currentLocation = null; }).always(hideLoader); }); $('#pNodeId').on('change', function (event) { currentNode = $(this).val(); $.each(NodeData, function (i, v) { if (v.id == currentNode) { $('#pAllocation').html('').select2({ data: v.allocations, placeholder: 'Select a Default Allocation', }); $('#pAllocationAdditional').html('').select2({ data: v.allocations, placeholder: 'Select Additional Allocations', }) } }); }); $('#pServiceId').on('change', function (event) { $('#pOptionId').html('').select2({ data: $.map(_.get(Pterodactyl.services, $(this).val() + '.options', []), function (item) { return { id: item.id, text: item.name, }; }), }).change(); }); $('#pOptionId').on('change', function (event) { var parentChain = _.get(Pterodactyl.services, $('#pServiceId').val(), null); var objectChain = _.get(parentChain, 'options.' + $(this).val(), null); $('#pDefaultContainer').val(_.get(objectChain, 'docker_image', 'not defined!')); if (!_.get(objectChain, 'startup', false)) { $('#pStartup').val(_.get(parentChain, 'startup', 'ERROR: Startup Not Defined!')); } else { $('#pStartup').val(_.get(objectChain, 'startup')); } $('#pPackId').html('').select2({ data: [{ id: 0, text: 'No Service Pack' }].concat( $.map(_.get(objectChain, 'packs', []), function (item, i) { return { id: item.id, text: item.name + ' (' + item.version + ')', }; }) ), }); $('#appendVariablesTo').html(''); $.each(_.get(objectChain, 'variables', []), function (i, item) { var isRequired = (item.required === 1) ? 'Required ' : ''; var dataAppend = ' \
\ \ \

' + item.description + '
\ Access in Startup: {{' + item.env_variable + '}}
\ Validation Rules: ' + item.rules + '

\
\ '; $('#appendVariablesTo').append(dataAppend); }); });