2018-03-25 13:41:29 -04:00
|
|
|
import treeService from './tree.js';
|
2018-03-25 21:16:57 -04:00
|
|
|
import protectedSessionHolder from './protected_session_holder.js';
|
2018-03-25 11:09:17 -04:00
|
|
|
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);
|
2018-03-25 11:09:17 -04:00
|
|
|
}
|
2018-02-26 00:07:43 -05:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
let importNoteId;
|
2018-02-26 00:07:43 -05:00
|
|
|
|
2018-08-31 18:22:53 +02:00
|
|
|
function importIntoNote(noteId) {
|
2018-03-25 11:09:17 -04:00
|
|
|
importNoteId = noteId;
|
2018-02-26 00:07:43 -05:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
$("#import-upload").trigger('click');
|
|
|
|
}
|
2018-02-26 00:07:43 -05:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
$("#import-upload").change(async function() {
|
|
|
|
const formData = new FormData();
|
|
|
|
formData.append('upload', this.files[0]);
|
2018-03-24 23:58:58 -04:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
await $.ajax({
|
2018-04-01 20:33:10 -04:00
|
|
|
url: baseApiUrl + 'notes/' + importNoteId + '/import',
|
2018-03-25 11:09:17 -04:00
|
|
|
headers: server.getHeaders(),
|
|
|
|
data: formData,
|
2018-09-03 13:40:40 +02:00
|
|
|
dataType: 'json',
|
2018-03-25 11:09:17 -04:00
|
|
|
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
|
|
|
});
|
2018-03-25 11:09:17 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
export default {
|
2018-11-24 20:58:38 +01:00
|
|
|
exportBranch,
|
2018-08-31 18:22:53 +02:00
|
|
|
importIntoNote
|
2018-03-25 11:09:17 -04:00
|
|
|
};
|