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

16
node_modules/note.js generated vendored
View File

@@ -121,6 +121,7 @@ var Note = {
var query = {
UserId: userId,
IsTrash: false,
LocalIsDelete: false, // 未删除的
};
if(notebookId) {
query['NotebookId'] = notebookId;
@@ -178,6 +179,17 @@ var Note = {
});
},
// 笔记本下是否有笔记
hasNotes: function(notebookId, callback) {
Notes.count({NotebookId: notebookId, IsTrash: false, LocalIsDelete: false}, function(err, n) {
console.log(n);
if(err || n > 0) {
return callback(true);
}
callback(false);
});
},
// 得到笔记
getNote: function(noteId, callback) {
var me = this;
@@ -365,6 +377,7 @@ var Note = {
note.IsDirty = false;
note.ServerNoteId = note.NoteId;
note.NoteId = Common.objectId();
note.LocalIsDelete = false;
// 附件操作
var files = note.Files || [];
@@ -405,6 +418,7 @@ var Note = {
note.IsDirty = false;
note.InitSync = true;
note.LocalIsNew = false;
note.LocalIsDelete = false;
// 附件处理
var files = note.Files || [];
@@ -496,6 +510,7 @@ var Note = {
note.IsDirty = false;
note.InitSync = false;
note.LocalIsNew = false;
// note.LocalIsDelete = false;
// note.UserId = User.getCurActiveUserId();
//
console.log("updateNoteForceForSendChange");
@@ -567,6 +582,7 @@ var Note = {
note.IsDirty = false;
note.InitSync = true;
note.LocalIsNew = false;
note.LocalIsDelete = false;
// 文件操作
Notebook.getNotebookIdByServerNotebookId(note.NotebookId, function(localNotebookId) {

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();