/* * Copyright (C) 2016-2020 phantombot.github.io/PhantomBot * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ $(function() { var currentLang = ''; // Load file button $('#load-file-button').on('click', function() { $.ajax({ 'url': '/get-lang?webauth=' + getAuth(), 'type': 'GET', 'success': function(data) { helpers.getModal('edit-lang', 'Load Lang File', 'Edit', $('
', { 'role': 'form' }) // Add select box. .append(helpers.getDropdownGroup('file-to-load', 'Lang file: ', 'Choose a File', data.split('\n'))), function() { currentLang = $('#file-to-load').find(':selected').text(); $.ajax({ 'url': '/lang?webauth=' + getAuth(), 'type': 'GET', 'headers': { 'lang-path': $('#file-to-load').find(':selected').text() }, 'success': function(data) { // Load the file loadLang(JSON.parse(data)); // Alert the user. toastr.success('Successfully loaded the file!'); // Close the modal. $('#edit-lang').modal('toggle'); // Enable the insert and save buttons. $('#save-button').prop('disabled', false); $('#add-line-button').prop('disabled', false); } }) }).modal('toggle'); } }); }); // Add line button. $('#add-line-button').on('click', function() { helpers.getModal('add-lang', 'Add Lang Entry', 'Add', $('', { 'role': 'form' }) // ID for the lang. .append(helpers.getInputGroup('lang-id', 'text', 'Lang ID', 'module.name.id')) // Resonse for the lang. .append(helpers.getTextAreaGroup('lang-response', 'text', 'Response', 'Response example!')), function() { const table = $('#langTable').DataTable(), langId = $('#lang-id'), langRes = $('#lang-response'); switch (false) { case helpers.handleInputString(langId): case helpers.handleInputString(langRes): break; default: langId.val(langId.val().replace(/[^a-zA-Z0-9-\.]+/g, '-')); table.row.add([ langId.val(), langRes.val(), $('
', { 'class': 'btn-group' }).append($('