2018-03-26 01:41:29 +08:00
|
|
|
import treeService from './tree.js';
|
2019-03-19 05:33:19 +08:00
|
|
|
import treeCache from './tree_cache.js';
|
2018-03-31 01:20:36 +08:00
|
|
|
import server from './server.js';
|
2018-03-25 23:09:17 +08:00
|
|
|
|
|
|
|
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-03-25 23:09:17 +08:00
|
|
|
}
|
2018-01-14 07:02:41 +08:00
|
|
|
|
2018-03-25 23:09:17 +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
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (!resp.success) {
|
|
|
|
alert(resp.message);
|
|
|
|
return;
|
2018-01-14 07:02:41 +08:00
|
|
|
}
|
|
|
|
|
2019-03-19 05:33:19 +08:00
|
|
|
const afterBranch = await treeCache.getBranch(afterBranchId);
|
|
|
|
|
2019-10-26 15:51:08 +08:00
|
|
|
await treeService.reloadNotes([noteId, afterBranch.parentNoteId]);
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
cloneNoteAfter,
|
|
|
|
cloneNoteTo
|
|
|
|
};
|