trilium/src/public/javascripts/services/cloning.js

35 lines
919 B
JavaScript
Raw Normal View History

import treeService from './tree.js';
import treeCache from './tree_cache.js';
2018-03-31 01:20:36 +08:00
import server from './server.js';
async function cloneNoteTo(childNoteId, parentNoteId, prefix) {
const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId, {
prefix: prefix
});
if (!resp.success) {
alert(resp.message);
return;
2018-01-14 07:02:41 +08:00
}
2019-10-26 15:51:08 +08:00
await treeService.reloadNotes([childNoteId, parentNoteId]);
}
2018-01-14 07:02:41 +08:00
// beware that first arg is noteId and second is branchId!
async function cloneNoteAfter(noteId, afterBranchId) {
const resp = await server.put('notes/' + noteId + '/clone-after/' + afterBranchId);
2018-01-14 07:02:41 +08:00
if (!resp.success) {
alert(resp.message);
return;
2018-01-14 07:02:41 +08:00
}
const afterBranch = await treeCache.getBranch(afterBranchId);
2019-10-26 15:51:08 +08:00
await treeService.reloadNotes([noteId, afterBranch.parentNoteId]);
}
export default {
cloneNoteAfter,
cloneNoteTo
};