All user data for FoundryVTT. Includes worlds, systems, modules, and any asset in the "foundryuserdata" directory. Does NOT include the FoundryVTT installation itself.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.1 KiB

  1. import { importSettingsFromJSON, exportSettingsToJSON } from '../scripts/settings.js';
  2. export default class ImportExport extends FormApplication {
  3. static get defaultOptions() {
  4. return mergeObject(super.defaultOptions, {
  5. id: 'token-variants-import-export',
  6. classes: ['sheet'],
  7. template: 'modules/token-variants/templates/importExport.html',
  8. resizable: false,
  9. minimizable: false,
  10. title: 'Import/Export',
  11. width: 250,
  12. });
  13. }
  14. /**
  15. * @param {JQuery} html
  16. */
  17. activateListeners(html) {
  18. super.activateListeners(html);
  19. html.find('.import').click(this._importFromJSONDialog.bind(this));
  20. html.find('.export').click(() => {
  21. exportSettingsToJSON();
  22. this.close();
  23. });
  24. }
  25. async _importFromJSONDialog() {
  26. const content = await renderTemplate('templates/apps/import-data.html', {
  27. entity: 'token-variants',
  28. name: 'settings',
  29. });
  30. let dialog = new Promise((resolve, reject) => {
  31. new Dialog(
  32. {
  33. title: game.i18n.localize('token-variants.settings.import-export.window.import-dialog'),
  34. content: content,
  35. buttons: {
  36. import: {
  37. icon: '<i class="fas fa-file-import"></i>',
  38. label: game.i18n.localize('token-variants.common.import'),
  39. callback: (html) => {
  40. const form = html.find('form')[0];
  41. if (!form.data.files.length)
  42. return ui.notifications?.error('You did not upload a data file!');
  43. readTextFromFile(form.data.files[0]).then((json) => {
  44. importSettingsFromJSON(json);
  45. resolve(true);
  46. });
  47. },
  48. },
  49. no: {
  50. icon: '<i class="fas fa-times"></i>',
  51. label: 'Cancel',
  52. callback: (html) => resolve(false),
  53. },
  54. },
  55. default: 'import',
  56. },
  57. {
  58. width: 400,
  59. }
  60. ).render(true);
  61. });
  62. this.close();
  63. return await dialog;
  64. }
  65. }