40 lines
1.0 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-04-01 20:33:10 -04:00
function exportBranch(noteId) {
const url = utils.getHost() + "/api/notes/" + noteId + "/export?protectedSessionId="
+ encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
2018-02-25 10:55:21 -05:00
utils.download(url);
}
let importNoteId;
2018-04-01 20:33:10 -04:00
function importBranch(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,
type: 'POST',
contentType: false, // NEEDED, DON'T OMIT THIS
processData: false, // NEEDED, DON'T OMIT THIS
});
2018-02-25 10:55:21 -05:00
await treeService.reload();
});
export default {
2018-04-01 20:33:10 -04:00
exportBranch,
importBranch
};