批量删除笔记完成

This commit is contained in:
life
2015-10-24 11:35:23 +08:00
parent e8af6401c0
commit 17b2b9f2fa
2 changed files with 74 additions and 75 deletions

63
node_modules/note.js generated vendored
View File

@@ -310,18 +310,35 @@ var Note = {
});
},
deleteNote: function(noteId, callback) {
deleteNote: function(noteIds, callback) {
var me = this;
async.eachSeries(noteIds, function (noteId, cb) {
me._deleteNote(noteId, function () {
cb();
});
}, function () {
callback(true);
});
},
_deleteNote: function(noteId, callback) {
var me = this;
me.getNote(noteId, function(note) {
if(!note) {
callback(false);
}
// 如果已经是trash, 再删除则彻底删除
if (note.IsTrash) {
me.deleteTrash(note, callback);
return;
}
db.notes.update({NoteId: noteId}, {$set: {IsTrash: true, IsDirty: true}}, function(err, n) {
if(err || !n) {
callback(false);
} else {
callback(true);
// 重新统计
Notebook.reCountNotebookNumberNotes(note.NotebookId);
}
@@ -335,36 +352,24 @@ var Note = {
});
},
// 彻底删除笔记, 如果有tags, 则需要更新tags's count
deleteTrash: function(noteId, callback) {
deleteTrash: function(note, callback) {
var me = this;
me.getNote(noteId, function(note) {
if(note) {
note.LocalIsDelete = true;
note.IsDirty = true;
if(note) {
note.LocalIsDelete = true;
note.IsDirty = true;
// TODO 删除附件
db.notes.update({_id: note._id}, {$set: {IsDirty: true, LocalIsDelete: true}}, function(err, n) {
if(n) {
// 如果有tags, 则重新更新tags' count
me.updateTagCount(note.Tags);
callback(true);
}
callback(false);
});
} else {
// TODO 删除附件
db.notes.update({_id: note._id}, {$set: {IsDirty: true, LocalIsDelete: true}}, function(err, n) {
if(n) {
// 如果有tags, 则重新更新tags' count
me.updateTagCount(note.Tags);
callback(true);
}
callback(false);
}
});
/*
db.notes.update({NoteId: noteId}, {$set: {IsDirty: true, LocalIsDelete: true}}, function(err, n) {
if(err || !n) {
callback(false);
} else {
callback(true);
}
});
*/
});
} else {
callback(false);
}
},
// 移动note