From 11b6e7bc9952bc062d6c96cff3f0a15a3f73b9da Mon Sep 17 00:00:00 2001 From: life Date: Sat, 7 Feb 2015 22:44:42 +0800 Subject: [PATCH] =?UTF-8?q?Notebook=20=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Notebook 添加/子 [ok] 重命名 [ok] 移动 [ok] 删除 [ok] list trash [ok] Note add [todo, markdown] delete [ok] deleteTrash [ok] --- node_modules/note.js | 16 +++++++++++++++ node_modules/notebook.js | 39 +++++++++++++++++++++++++++++++++++-- note.html | 2 ++ public/js/app/notebook.js | 41 ++++++++++++++++++++++++++++++++++++--- test.js | 2 +- 5 files changed, 94 insertions(+), 6 deletions(-) diff --git a/node_modules/note.js b/node_modules/note.js index 38f267d7..8ba27f95 100644 --- a/node_modules/note.js +++ b/node_modules/note.js @@ -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) { diff --git a/node_modules/notebook.js b/node_modules/notebook.js index b9413ecb..e8ba1296 100644 --- a/node_modules/notebook.js +++ b/node_modules/notebook.js @@ -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(); diff --git a/note.html b/note.html index 83e75133..b94adb16 100755 --- a/note.html +++ b/note.html @@ -146,6 +146,7 @@ function log(o) { +