2018-03-26 01:41:29 +08:00
|
|
|
import treeService from './tree.js';
|
2018-03-26 09:16:57 +08:00
|
|
|
import protectedSessionHolder from './protected_session_holder.js';
|
2018-03-25 23:09:17 +08:00
|
|
|
import utils from './utils.js';
|
2018-03-31 03:34:07 +08:00
|
|
|
import server from './server.js';
|
2018-02-25 23:55:21 +08:00
|
|
|
|
2018-05-28 00:26:34 +08:00
|
|
|
function exportBranch(noteId, format) {
|
|
|
|
const url = utils.getHost() + "/api/notes/" + noteId + "/export/" + format +
|
|
|
|
"?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
|
2018-02-25 23:55:21 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
utils.download(url);
|
|
|
|
}
|
2018-02-26 13:07:43 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
let importNoteId;
|
2018-02-26 13:07:43 +08:00
|
|
|
|
2018-04-02 08:33:10 +08:00
|
|
|
function importBranch(noteId) {
|
2018-03-25 23:09:17 +08:00
|
|
|
importNoteId = noteId;
|
2018-02-26 13:07:43 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$("#import-upload").trigger('click');
|
|
|
|
}
|
2018-02-26 13:07:43 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$("#import-upload").change(async function() {
|
|
|
|
const formData = new FormData();
|
|
|
|
formData.append('upload', this.files[0]);
|
2018-03-25 11:58:58 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
await $.ajax({
|
2018-04-02 08:33:10 +08:00
|
|
|
url: baseApiUrl + 'notes/' + importNoteId + '/import',
|
2018-03-25 23:09:17 +08:00
|
|
|
headers: server.getHeaders(),
|
|
|
|
data: formData,
|
|
|
|
type: 'POST',
|
|
|
|
contentType: false, // NEEDED, DON'T OMIT THIS
|
|
|
|
processData: false, // NEEDED, DON'T OMIT THIS
|
2018-05-30 08:32:13 +08:00
|
|
|
}).fail((xhr, status, error) => alert('Import error: ' + xhr.responseText));
|
2018-02-25 23:55:21 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
await treeService.reload();
|
|
|
|
});
|
|
|
|
|
|
|
|
export default {
|
2018-04-02 08:33:10 +08:00
|
|
|
exportBranch,
|
|
|
|
importBranch
|
2018-03-25 23:09:17 +08:00
|
|
|
};
|