批量删除笔记完成

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

View File

@@ -1407,72 +1407,66 @@ Note.changeToNextSkipNotes = function(noteIds) {
}; };
// 删除笔记 // 删除笔记
// 1. 先隐藏, 成功后再移除DOM
// 2. ajax之 noteId
// Share.deleteSharedNote调用
Note.deleteNote = function(target, contextmenuItem, isShared) { Note.deleteNote = function(target, contextmenuItem, isShared) {
var me = Note;
var noteIds;
if (me.inBatch) {
noteIds = me.getBatchNoteIds();
}
else {
noteIds = [$(target).attr('noteId')];
}
if (isEmpty(noteIds)) {
return;
}
// 如果删除的是已选中的, 赶紧设置curNoteId = null // 如果删除的是已选中的, 赶紧设置curNoteId = null
if($(target).hasClass("item-active")) { if(noteIds.length == 1 && $(target).hasClass("item-active")) {
// -1 停止定时器 // -1 停止定时器
Note.stopInterval(); Note.stopInterval();
// 不保存 // 不保存
Note.curNoteId = null; me.clearCurNoteId();
// 清空信息 // 清空信息
Note.clearNoteInfo(); Note.clearNoteInfo();
} }
noteId = $(target).attr("noteId"); var $actives;
if(!noteId) { if(noteIds.length == 1) {
return; $actives = $(target);
}
else {
$actives = me.$itemList.find('.item-active');
} }
// 取消star
Note.unStar(noteId);
// 1 // 1
$(target).hide(); $actives.hide();
// 2 // 2
var note = Note.cache[noteId]; NoteService.deleteNote(noteIds, function(ret) {
var serverFunc = NoteService.deleteNote;
if(note.IsTrash) {
serverFunc = NoteService.deleteTrash;
} else {
// 减少数量
Notebook.minusNotebookNumberNotes(note.NotebookId);
}
if(note.IsNew) {
Note.changeToNext(target);
$(target).remove();
// 删除缓存
if(note) {
Note.clearCacheByNotebookId(note.NotebookId);
delete Note.cache[noteId];
}
return;
}
serverFunc.call(NoteService, noteId, function(ret) {
if(ret) { if(ret) {
Note.changeToNext(target); Note.changeToNextSkipNotes(noteIds);
$actives.remove();
$(target).remove();
// 删除缓存 // 删除缓存
Note.clearCacheByNotebookId(note.NotebookId); for (var i = 0; i < noteIds.length; ++i) {
delete Note.cache[noteId]; var noteId = noteIds[i];
var note = me.getNote(noteId);
if (note) {
// 取消star
Note.unStar(noteId);
showMsg("删除成功!", 500); // 减少数量
} else { Notebook.minusNotebookNumberNotes(note.NotebookId);
// 弹出信息 popup 不用点确认的 Note.clearCacheByNotebookId(note.NotebookId);
$(target).show(); delete Note.cache[noteId];
showMsg("删除失败!", 2000); }
}
} }
}); });
};
me.batch.reset();
return;
};
// 显示共享信息 // 显示共享信息
Note.listNoteShareUserInfo = function(target) { Note.listNoteShareUserInfo = function(target) {