50 lines
1.4 KiB
JavaScript
Raw Normal View History

import treeService from './tree.js';
import protectedSessionHolder from './protected_session_holder.js';
import utils from './utils.js';
2018-03-30 15:34:07 -04:00
import server from './server.js';
2018-02-25 10:55:21 -05:00
2018-11-24 20:58:38 +01:00
function exportBranch(branchId, type, format) {
const url = utils.getHost() + `/api/notes/${branchId}/export/${type}/${format}?protectedSessionId=` + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
2018-02-25 10:55:21 -05:00
2018-11-24 20:58:38 +01:00
console.log(url);
2018-09-03 21:06:24 +02:00
2018-11-24 20:58:38 +01:00
utils.download(url);
}
let importNoteId;
function importIntoNote(noteId) {
importNoteId = noteId;
$("#import-upload").trigger('click');
}
$("#import-upload").change(async function() {
const formData = new FormData();
formData.append('upload', this.files[0]);
await $.ajax({
2018-04-01 20:33:10 -04:00
url: baseApiUrl + 'notes/' + importNoteId + '/import',
headers: server.getHeaders(),
data: formData,
2018-09-03 13:40:40 +02:00
dataType: 'json',
type: 'POST',
2018-11-08 10:11:00 +01:00
contentType: false, // NEEDED, DON'T REMOVE THIS
processData: false, // NEEDED, DON'T REMOVE THIS
2018-09-03 13:40:40 +02:00
})
.fail((xhr, status, error) => alert('Import error: ' + xhr.responseText))
.done(async note => {
await treeService.reload();
2018-02-25 10:55:21 -05:00
2018-11-05 00:06:17 +01:00
if (note) {
const node = await treeService.activateNote(note.noteId);
node.setExpanded(true);
}
2018-09-03 13:40:40 +02:00
});
});
export default {
2018-11-24 20:58:38 +01:00
exportBranch,
importIntoNote
};