2022-06-16 14:21:24 +02:00
|
|
|
import utils from '../../services/utils.js';
|
|
|
|
import treeService from "../../services/tree.js";
|
|
|
|
import importService from "../../services/import.js";
|
|
|
|
import options from "../../services/options.js";
|
|
|
|
import BasicWidget from "../basic_widget.js";
|
2024-07-23 17:38:22 +08:00
|
|
|
import { t } from "../../services/i18n.js";
|
2022-06-16 14:21:24 +02:00
|
|
|
|
|
|
|
const TPL = `
|
|
|
|
<div class="import-dialog modal fade mx-auto" tabindex="-1" role="dialog">
|
|
|
|
<div class="modal-dialog modal-lg" role="document">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
2024-07-23 17:38:22 +08:00
|
|
|
<h5 class="modal-title">${t('import.importIntoNote')}</h5>
|
|
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="${t('import.close')}">
|
2022-06-16 14:21:24 +02:00
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<form class="import-form">
|
|
|
|
<div class="modal-body">
|
|
|
|
<div class="form-group">
|
2024-07-23 17:38:22 +08:00
|
|
|
<label for="import-file-upload-input"><strong>${t('import.chooseImportFile')}</strong></label>
|
2022-06-16 14:21:24 +02:00
|
|
|
|
|
|
|
<input type="file" class="import-file-upload-input form-control-file" multiple />
|
|
|
|
|
2024-07-23 17:38:22 +08:00
|
|
|
<p>${t('import.importDescription')} <strong class="import-note-title"></strong>.
|
2022-06-16 14:21:24 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-group">
|
2024-07-23 17:38:22 +08:00
|
|
|
<strong>${t('import.options')}:</strong>
|
2022-06-16 14:21:24 +02:00
|
|
|
|
|
|
|
<div class="checkbox">
|
2024-07-23 17:38:22 +08:00
|
|
|
<label data-toggle="tooltip" title="${t('import.safeImportTooltip')}">
|
2022-06-16 14:21:24 +02:00
|
|
|
<input class="safe-import-checkbox" value="1" type="checkbox" checked>
|
2024-07-23 17:38:22 +08:00
|
|
|
<span>${t('import.safeImport')}</span>
|
2022-06-16 14:21:24 +02:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="checkbox">
|
2024-07-23 17:38:22 +08:00
|
|
|
<label data-toggle="tooltip" title="${t('import.explodeArchivesTooltip')}">
|
2022-06-16 14:21:24 +02:00
|
|
|
<input class="explode-archives-checkbox" value="1" type="checkbox" checked>
|
2024-07-23 17:38:22 +08:00
|
|
|
<span>${t('import.explodeArchives')}</span>
|
2022-06-16 14:21:24 +02:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="checkbox">
|
2024-07-23 17:38:22 +08:00
|
|
|
<label data-toggle="tooltip" title="${t('import.shrinkImagesTooltip')}">
|
|
|
|
<input class="shrink-images-checkbox" value="1" type="checkbox" checked> <span>${t('import.shrinkImages')}</span>
|
2022-06-16 14:21:24 +02:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="checkbox">
|
|
|
|
<label>
|
|
|
|
<input class="text-imported-as-text-checkbox" value="1" type="checkbox" checked>
|
2024-07-23 17:38:22 +08:00
|
|
|
${t('import.textImportedAsText')}
|
2022-06-16 14:21:24 +02:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="checkbox">
|
|
|
|
<label>
|
2024-07-23 17:38:22 +08:00
|
|
|
<input class="code-imported-as-code-checkbox" value="1" type="checkbox" checked> ${t('import.codeImportedAsCode')}
|
2022-06-16 14:21:24 +02:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="checkbox">
|
|
|
|
<label>
|
|
|
|
<input class="replace-underscores-with-spaces-checkbox" value="1" type="checkbox" checked>
|
2024-07-23 17:38:22 +08:00
|
|
|
${t('import.replaceUnderscoresWithSpaces')}
|
2022-06-16 14:21:24 +02:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
2024-07-23 17:38:22 +08:00
|
|
|
<button class="import-button btn btn-primary">${t('import.import')}</button>
|
2022-06-16 14:21:24 +02:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
export default class ImportDialog extends BasicWidget {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.parentNoteId = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
doRender() {
|
|
|
|
this.$widget = $(TPL);
|
|
|
|
this.$form = this.$widget.find(".import-form");
|
|
|
|
this.$noteTitle = this.$widget.find(".import-note-title");
|
|
|
|
this.$fileUploadInput = this.$widget.find(".import-file-upload-input");
|
|
|
|
this.$importButton = this.$widget.find(".import-button");
|
|
|
|
this.$safeImportCheckbox = this.$widget.find(".safe-import-checkbox");
|
|
|
|
this.$shrinkImagesCheckbox = this.$widget.find(".shrink-images-checkbox");
|
|
|
|
this.$textImportedAsTextCheckbox = this.$widget.find(".text-imported-as-text-checkbox");
|
|
|
|
this.$codeImportedAsCodeCheckbox = this.$widget.find(".code-imported-as-code-checkbox");
|
|
|
|
this.$explodeArchivesCheckbox = this.$widget.find(".explode-archives-checkbox");
|
|
|
|
this.$replaceUnderscoresWithSpacesCheckbox = this.$widget.find(".replace-underscores-with-spaces-checkbox");
|
|
|
|
|
|
|
|
this.$form.on('submit', () => {
|
|
|
|
// disabling so that import is not triggered again.
|
|
|
|
this.$importButton.attr("disabled", "disabled");
|
|
|
|
|
|
|
|
this.importIntoNote(this.parentNoteId);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$fileUploadInput.on('change', () => {
|
|
|
|
if (this.$fileUploadInput.val()) {
|
|
|
|
this.$importButton.removeAttr("disabled");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.$importButton.attr("disabled", "disabled");
|
|
|
|
}
|
|
|
|
});
|
2022-11-22 23:53:08 +01:00
|
|
|
|
|
|
|
this.$widget.find('[data-toggle="tooltip"]').tooltip({
|
|
|
|
html: true
|
|
|
|
});
|
2022-06-16 14:21:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async showImportDialogEvent({noteId}) {
|
|
|
|
this.parentNoteId = noteId;
|
|
|
|
|
|
|
|
this.$fileUploadInput.val('').trigger('change'); // to trigger Import button disabling listener below
|
|
|
|
|
|
|
|
this.$safeImportCheckbox.prop("checked", true);
|
|
|
|
this.$shrinkImagesCheckbox.prop("checked", options.is('compressImages'));
|
|
|
|
this.$textImportedAsTextCheckbox.prop("checked", true);
|
|
|
|
this.$codeImportedAsCodeCheckbox.prop("checked", true);
|
|
|
|
this.$explodeArchivesCheckbox.prop("checked", true);
|
|
|
|
this.$replaceUnderscoresWithSpacesCheckbox.prop("checked", true);
|
|
|
|
|
|
|
|
this.$noteTitle.text(await treeService.getNoteTitle(this.parentNoteId));
|
|
|
|
|
|
|
|
utils.openDialog(this.$widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
async importIntoNote(parentNoteId) {
|
|
|
|
const files = Array.from(this.$fileUploadInput[0].files); // shallow copy since we're resetting the upload button below
|
|
|
|
|
|
|
|
const boolToString = $el => $el.is(":checked") ? "true" : "false";
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
safeImport: boolToString(this.$safeImportCheckbox),
|
|
|
|
shrinkImages: boolToString(this.$shrinkImagesCheckbox),
|
|
|
|
textImportedAsText: boolToString(this.$textImportedAsTextCheckbox),
|
|
|
|
codeImportedAsCode: boolToString(this.$codeImportedAsCodeCheckbox),
|
|
|
|
explodeArchives: boolToString(this.$explodeArchivesCheckbox),
|
|
|
|
replaceUnderscoresWithSpaces: boolToString(this.$replaceUnderscoresWithSpacesCheckbox)
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$widget.modal('hide');
|
|
|
|
|
2023-05-08 00:02:08 +02:00
|
|
|
await importService.uploadFiles('notes', parentNoteId, files, options);
|
2022-06-16 14:21:24 +02:00
|
|
|
}
|
|
|
|
}
|