mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
75 lines
2.3 KiB
JavaScript
75 lines
2.3 KiB
JavaScript
import utils from '../services/utils.js';
|
|
import treeUtils from "../services/tree_utils.js";
|
|
import importService from "../services/import.js";
|
|
|
|
const $dialog = $("#import-dialog");
|
|
const $form = $("#import-form");
|
|
const $noteTitle = $dialog.find(".import-note-title");
|
|
const $fileUploadInput = $("#import-file-upload-input");
|
|
const $importButton = $("#import-button");
|
|
const $safeImportCheckbox = $("#safe-import-checkbox");
|
|
const $shrinkImagesCheckbox = $("#shrink-images-checkbox");
|
|
const $textImportedAsTextCheckbox = $("#text-imported-as-text-checkbox");
|
|
const $codeImportedAsCodeCheckbox = $("#code-imported-as-code-checkbox");
|
|
const $explodeArchivesCheckbox = $("#explode-archives-checkbox");
|
|
|
|
let parentNoteId = null;
|
|
|
|
export async function showDialog(noteId) {
|
|
utils.closeActiveDialog();
|
|
|
|
$fileUploadInput.val('').trigger('change'); // to trigger Import button disabling listener below
|
|
|
|
$safeImportCheckbox.prop("checked", true);
|
|
$shrinkImagesCheckbox.prop("checked", true);
|
|
$textImportedAsTextCheckbox.prop("checked", true);
|
|
$codeImportedAsCodeCheckbox.prop("checked", true);
|
|
$explodeArchivesCheckbox.prop("checked", true);
|
|
|
|
glob.activeDialog = $dialog;
|
|
|
|
parentNoteId = noteId;
|
|
|
|
$noteTitle.text(await treeUtils.getNoteTitle(parentNoteId));
|
|
|
|
$dialog.modal();
|
|
}
|
|
|
|
$form.on('submit', () => {
|
|
// disabling so that import is not triggered again.
|
|
$importButton.attr("disabled", "disabled");
|
|
|
|
importIntoNote(parentNoteId);
|
|
|
|
return false;
|
|
});
|
|
|
|
async function importIntoNote(parentNoteId) {
|
|
const files = Array.from($fileUploadInput[0].files); // shallow copy since we're resetting the upload button below
|
|
|
|
const options = {
|
|
safeImport: boolToString($safeImportCheckbox),
|
|
shrinkImages: boolToString($shrinkImagesCheckbox),
|
|
textImportedAsText: boolToString($textImportedAsTextCheckbox),
|
|
codeImportedAsCode: boolToString($codeImportedAsCodeCheckbox),
|
|
explodeArchives: boolToString($explodeArchivesCheckbox)
|
|
};
|
|
|
|
$dialog.modal('hide');
|
|
|
|
await importService.uploadFiles(parentNoteId, files, options);
|
|
}
|
|
|
|
function boolToString($el) {
|
|
return $el.is(":checked") ? "true" : "false";
|
|
}
|
|
|
|
$fileUploadInput.on('change', () => {
|
|
if ($fileUploadInput.val()) {
|
|
$importButton.removeAttr("disabled");
|
|
}
|
|
else {
|
|
$importButton.attr("disabled", "disabled");
|
|
}
|
|
});
|