mirror of
https://github.com/leanote/desktop-app.git
synced 2026-01-21 01:13:57 +08:00
new note 在 curChangedSave之后再添加
This commit is contained in:
99
node_modules/note.js
generated
vendored
99
node_modules/note.js
generated
vendored
@@ -51,10 +51,6 @@ var Note = {
|
||||
var userId = User.getCurActiveUserId();
|
||||
noteOrContent['UserId'] = userId;
|
||||
|
||||
// console.error("updateNoteOrContent")
|
||||
// console.trace('updateNoteOrContent: ');
|
||||
// console.log(noteOrContent);
|
||||
|
||||
var date = new Date();
|
||||
if (!Common.isValidDate(noteOrContent.UpdatedTime)) {
|
||||
noteOrContent.UpdatedTime = date;
|
||||
@@ -63,52 +59,55 @@ var Note = {
|
||||
noteOrContent['IsDirty'] = true; // 已修改
|
||||
noteOrContent['LocalIsDelete'] = false;
|
||||
|
||||
// 新建笔记, IsNew还是保存着
|
||||
if(noteOrContent.IsNew) {
|
||||
if (!Common.isValidDate(noteOrContent.CreatedTime)) {
|
||||
noteOrContent.CreatedTime = date;
|
||||
}
|
||||
noteOrContent['IsTrash'] = false;
|
||||
delete noteOrContent['IsNew'];
|
||||
noteOrContent['LocalIsNew'] = true;
|
||||
db.notes.insert(noteOrContent, function (err, newDoc) { // Callback is optional
|
||||
if(err) {
|
||||
console.log(err);
|
||||
callback && callback(false);
|
||||
} else {
|
||||
// 为什么又设置成true, 因为js的对象是共享的, callback用到了noteOrContent.IsNew来做判断
|
||||
noteOrContent['IsNew'] = true;
|
||||
callback && callback(newDoc);
|
||||
|
||||
// 重新统计笔记本的笔记数量
|
||||
Notebook.reCountNotebookNumberNotes(noteOrContent.NotebookId);
|
||||
|
||||
me.addNoteHistory(noteOrContent.NoteId, noteOrContent.Content);
|
||||
|
||||
/*
|
||||
// 标签
|
||||
if(noteOrContent.Tags && noteOrContent.Tags.length > 0) {
|
||||
Tag.addTags(noteOrContent.Tags);
|
||||
// 为什么不以noteOrContent.IsNew来判断是否是新建还是更新?
|
||||
// 怕前端重复发请求, 保险起见
|
||||
me.getNote(noteOrContent.NoteId, function(dbNote) {
|
||||
// 新建的
|
||||
if (!dbNote) {
|
||||
// 新建笔记, IsNew还是保存着
|
||||
if(noteOrContent.IsNew) {
|
||||
if (!Common.isValidDate(noteOrContent.CreatedTime)) {
|
||||
noteOrContent.CreatedTime = date;
|
||||
}
|
||||
*/
|
||||
noteOrContent['IsTrash'] = false;
|
||||
delete noteOrContent['IsNew'];
|
||||
noteOrContent['LocalIsNew'] = true;
|
||||
|
||||
db.notes.insert(noteOrContent, function (err, newDoc) { // Callback is optional
|
||||
if(err) {
|
||||
console.log(err);
|
||||
callback && callback(false);
|
||||
} else {
|
||||
// 为什么又设置成true, 因为js的对象是共享的, callback用到了noteOrContent.IsNew来做判断
|
||||
noteOrContent['IsNew'] = true;
|
||||
callback && callback(newDoc);
|
||||
|
||||
// 重新统计笔记本的笔记数量
|
||||
Notebook.reCountNotebookNumberNotes(noteOrContent.NotebookId);
|
||||
|
||||
me.addNoteHistory(noteOrContent.NoteId, noteOrContent.Content);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// 更新笔记
|
||||
} else {
|
||||
var updateFields = ['Desc', 'ImgSrc', 'Title', 'Tags', 'Content'];
|
||||
var updates = {};
|
||||
var needUpdate = false;
|
||||
for(var i in updateFields) {
|
||||
var field = updateFields[i];
|
||||
if(field in noteOrContent) {
|
||||
updates[field] = noteOrContent[field];
|
||||
needUpdate = true;
|
||||
else {
|
||||
callback && callback(false);
|
||||
}
|
||||
}
|
||||
|
||||
if(needUpdate) {
|
||||
var isDirty = false;
|
||||
me.getNote(noteOrContent.NoteId, function(dbNote) {
|
||||
// 更新
|
||||
else {
|
||||
var updateFields = ['Desc', 'ImgSrc', 'Title', 'Tags', 'Content'];
|
||||
var updates = {};
|
||||
var needUpdate = false;
|
||||
for(var i in updateFields) {
|
||||
var field = updateFields[i];
|
||||
if(field in noteOrContent) {
|
||||
updates[field] = noteOrContent[field];
|
||||
needUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(needUpdate) {
|
||||
var isDirty = false;
|
||||
// 只有title, Content, Tags修改了才算是IsDirty
|
||||
if('Content' in updates && dbNote['Content'] != updates['Content']) {
|
||||
isDirty = true;
|
||||
@@ -161,10 +160,12 @@ var Note = {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
else {
|
||||
callback && callback(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 公开/取消为博客
|
||||
|
||||
Reference in New Issue
Block a user