Notebook 操作

Notebook
     添加/子 [ok]
     重命名 [ok]
     移动 [ok]
     删除 [ok]
     list trash [ok]
Note
     add [todo, markdown]
     delete [ok]
     deleteTrash [ok]
This commit is contained in:
life
2015-02-07 22:44:42 +08:00
parent 6b574aa208
commit 11b6e7bc99
5 changed files with 94 additions and 6 deletions

39
node_modules/notebook.js generated vendored
View File

@@ -131,6 +131,32 @@ var Notebook = {
});
},
// 拖动笔记本
// 当前笔记在parentNotebookId下, 且该parentNotebookId下的所有子孩子的id
dragNotebooks: function(curNotebookId, parentNotebookId, siblingNotebookIds) {
var me = this;
console.log(curNotebookId);
console.log(parentNotebookId);
console.log(siblingNotebookIds);
// 先更新curNotebookId的父
me.getNotebook(curNotebookId, function(notebook) {
if(!notebook) {
console.log('not fount');
return;
}
// 先更新之
// NB.update({NotebookId: notebookId}, {$set: {ParentNotebookId: parentNotebookId, IsDirty: true, UpdatedTime: new Date()}}, function(err, n) {
// });
siblingNotebookIds = siblingNotebookIds || [];
// 再更新所有子孩子的seq
for(var i = 0; i < siblingNotebookIds.length; ++i) {
var siblingNotebookId = siblingNotebookIds[i];
console.log('siblingNotebookId: ' + siblingNotebookId);
NB.update({NotebookId: siblingNotebookId}, {$set: {ParentNotebookId: parentNotebookId, Seq: i, IsDirty: true, UpdatedTime: new Date()}});
}
});
},
// 修改笔记本
updateNotebook: function(notebookId, callback) {
@@ -138,9 +164,18 @@ var Notebook = {
// 删除笔记本
deleteNotebook: function(notebookId, callback) {
NB.update({NotebookId: notebookId}, {$set: {LocalIsDelete: true, IsDirty: true, UpdatedTime: new Date()}}, function(err, n) {
callback(true);
// 先检查是否有笔记, 如果有, 则不准删除
var Note = require('note');
Note.hasNotes(notebookId, function(has) {
if(has) {
callback(false, 'This notebook has notes, please delete notes firstly.');
} else {
NB.update({NotebookId: notebookId}, {$set: {LocalIsDelete: true, IsDirty: true, UpdatedTime: new Date()}}, function(err, n) {
callback(true);
});
}
});
/*
NB.remove({NotebookId: notebookId}, function(err, n) {
callback();