new note 在 curChangedSave之后再添加

This commit is contained in:
life
2015-12-06 18:06:56 +08:00
parent 8255c35302
commit 497ae3fb3b
2 changed files with 111 additions and 110 deletions

99
node_modules/note.js generated vendored
View File

@@ -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);
}
}
}
});
},
// 公开/取消为博客

View File

@@ -1086,87 +1086,87 @@ Note.newNoteSeq = function () {
// isShare时fromUserId才有用
// 3.8 add isMarkdown
Note.newNote = function(notebookId, isShare, fromUserId, isMarkdown) {
var me = this;
// 切换编辑器
switchEditor(isMarkdown);
Note.hideEditorMask();
Note.stopInterval();
// 保存当前的笔记
Note.curChangedSaveIt(true);
Note.batch.reset();
var note = {
NoteId: getObjectId(),
Title: '',
Tags:[],
Desc: '',
Content: '',
NotebookId: notebookId,
IsNew: true,
FromUserId: fromUserId,
IsMarkdown: isMarkdown,
CreatedTime: new Date(),
UpdatedTime: new Date()
}; // 是新的
// 保存当前的笔记
Note.curChangedSaveIt(true, function () {
var note = {
NoteId: getObjectId(),
Title: '',
Tags:[],
Desc: '',
Content: '',
NotebookId: notebookId,
IsNew: true,
FromUserId: fromUserId,
IsMarkdown: isMarkdown,
CreatedTime: new Date(),
UpdatedTime: new Date()
}; // 是新的
// 添加到缓存中
Note.addNoteCache(note);
// 添加到缓存中
Note.addNoteCache(note);
// 清空附件数
Attach.clearNoteAttachNum();
// 清空附件数
Attach.clearNoteAttachNum();
// 是否是为共享的notebook添加笔记, 如果是, 则还要记录fromUserId
var newItem = "";
// 是否是为共享的notebook添加笔记, 如果是, 则还要记录fromUserId
var newItem = "";
var baseClasses = "item-my";
if(isShare) {
baseClasses = "item-shared";
}
var baseClasses = "item-my";
if(isShare) {
baseClasses = "item-shared";
}
var notebook = Notebook.getNotebook(notebookId);
var notebookTitle = notebook ? notebook.Title : "";
var curDate = getCurDatetime();
if(isShare) {
newItem = tt(Note.newItemTpl, baseClasses, this.newNoteSeq(), fromUserId, note.NoteId, note.Title, notebookTitle, curDate, "");
} else {
newItem = tt(Note.newItemTpl, baseClasses, this.newNoteSeq(), "", note.NoteId, note.Title, notebookTitle, curDate, "");
}
var notebook = Notebook.getNotebook(notebookId);
var notebookTitle = notebook ? notebook.Title : "";
var curDate = getCurDatetime();
newItem = $(newItem);
newItem.find(".item-blog").hide();
newItem = tt(Note.newItemTpl, baseClasses, me.newNoteSeq(), "", note.NoteId, note.Title, notebookTitle, curDate, "");
// 是否在当前notebook下, 不是则切换过去, 并得到该notebook下所有的notes, 追加到后面!
if(!Notebook.isCurNotebook(notebookId)) {
// 先清空所有
Note.clearAll();
newItem = $(newItem);
newItem.find(".item-blog").hide();
// 插入到第一个位置
Note.noteItemListO.prepend(newItem);
// 是否在当前notebook下, 不是则切换过去, 并得到该notebook下所有的notes, 追加到后面!
if(!Notebook.isCurNotebook(notebookId)) {
// 先清空所有
Note.clearAll();
// 改变为当前的notebookId
// 会得到该notebookId的其它笔记
Notebook.changeNotebookForNewNote(notebookId);
} else {
// 插入到第一个位置
Note.noteItemListO.prepend(newItem);
}
// 插入到第一个位置
Note.noteItemListO.prepend(newItem);
Note.selectTarget($(tt('[noteId="?"]', note.NoteId)));
// 改变为当前的notebookId
// 会得到该notebookId的其它笔记
Notebook.changeNotebookForNewNote(notebookId);
} else {
// 插入到第一个位置
Note.noteItemListO.prepend(newItem);
}
setTimeout(function() {
$("#noteTitle").focus();
Note.selectTarget($(tt('[noteId="?"]', note.NoteId)));
setTimeout(function() {
$("#noteTitle").focus();
});
Note.renderNote(note);
Note.renderNoteContent(note);
Note.setCurNoteId(note.NoteId);
// 更新数量
Notebook.incrNotebookNumberNotes(notebookId);
// 切换到写模式
Note.toggleWriteable(true);
});
Note.renderNote(note);
Note.renderNoteContent(note);
Note.setCurNoteId(note.NoteId);
// 更新数量
Notebook.incrNotebookNumberNotes(notebookId);
// 切换到写模式
Note.toggleWriteable(true);
};
// 同步