move & copy note [ok]

This commit is contained in:
life
2015-02-08 19:15:32 +08:00
parent b1cbb19b2b
commit 41d4529105
4 changed files with 113 additions and 17 deletions

89
node_modules/note.js generated vendored
View File

@@ -186,6 +186,27 @@ var Note = {
}); });
}, },
// 移动note
// 重新统计另一个notebookId的笔记数
moveNote: function(noteId, notebookId, callback) {
var me = this;
me.getNote(noteId, function(note) {
if(note) {
var to = !note.Star;
var preNotebookId = note.NotebookId;
note.NotebookId = notebookId;
Notes.update({_id: note._id}, {$set: {NotebookId: notebookId, IsTrash: false, LocalIsDelete: false, UpdatedTime: new Date()}}, function(err, n) {
// 重新统计
Notebook.reCountNotebookNumberNotes(preNotebookId);
Notebook.reCountNotebookNumberNotes(notebookId);
callback(note);
});
} else {
callback(false);
}
});
},
// 加星或取消 // 加星或取消
star: function(noteId, callback) { star: function(noteId, callback) {
var me = this; var me = this;
@@ -637,6 +658,7 @@ var Note = {
note.IsDirty = true; note.IsDirty = true;
note.LocalIsNew = true; // 新增加的 note.LocalIsNew = true; // 新增加的
note.InitSync = false; // 都是本地的, 相当于新建的笔记 note.InitSync = false; // 都是本地的, 相当于新建的笔记
note.LocalIsDelete = false;
// 只复制有path的 // 只复制有path的
var attachs = note.Attachs || []; var attachs = note.Attachs || [];
@@ -677,8 +699,75 @@ var Note = {
Notes.insert(note, function(err, newNote) { Notes.insert(note, function(err, newNote) {
if(err) { if(err) {
callback(false); callback(false);
} else { } else {
callback(newNote); callback(newNote);
// 重新统计笔记本的笔记数量
Notebook.reCountNotebookNumberNotes(newNote.NotebookId);
}
});
});
});
},
// 复制笔记到某笔记本下, 本地使用
copyNote: function(noteId, notebookId, callback) {
var me = this;
me.getNote(noteId, function(note) {
if(!note) {
callback(false);
return;
}
// 新Id
delete note['_id'];
delete note['ServerNoteId'];
note.NoteId = Common.objectId();
note.IsDirty = true;
note.LocalIsNew = true; // 新增加的
note.InitSync = false; // 都是本地的, 相当于新建的笔记
note.LocalIsDelete = false;
note.IsTrash = false;
note.NotebookId = notebookId;
// 只复制有path的
var attachs = note.Attachs || [];
var newAttachs = [];
async.eachSeries(attachs, function(attach, cb) {
if(!attach.Path) {
return cb();
}
// 新路径
var filePathAttr = Common.splitFile(attach.Path);
filePathAttr.nameNotExt += '_cp_' + attach.FileId; // 另一个
var newPath = filePathAttr.getFullPath();
// 复制之
// try {
Common.copyFile(attach.Path, newPath, function(ret) {
if(ret) {
attach.FileId = Common.objectId();
attach.IsDirty = true;
attach.Path = newPath;
delete attach['ServerFileId'];
newAttachs.push(attach);
}
cb();
});
/*
} catch(e) {
cb();
}
*/
}, function() {
note.Attachs = newAttachs;
console.log('conflict 复制后的');
console.log(note.Attachs);
Notes.insert(note, function(err, newNote) {
if(err) {
callback(false);
} else {
callback(newNote);
// 重新统计下
Notebook.reCountNotebookNumberNotes(newNote.NotebookId);
} }
}); });
}); });

2
node_modules/notebook.js generated vendored
View File

@@ -185,7 +185,7 @@ var Notebook = {
// 重新统计笔记本的笔记数据 // 重新统计笔记本的笔记数据
reCountNotebookNumberNotes: function(notebookId) { reCountNotebookNumberNotes: function(notebookId) {
db.notes.count({NotebookId: notebookId, IsTrash: false}, function(err, count) { db.notes.count({NotebookId: notebookId, IsTrash: false, LocalIsDelete: false}, function(err, count) {
if(err) { if(err) {
log(err); log(err);
return; return;

View File

@@ -1408,7 +1408,9 @@ Note.moveNote = function(target, data) {
Notebook.minusNotebookNumberNotes(note.NotebookId); Notebook.minusNotebookNumberNotes(note.NotebookId);
} }
ajaxGet("/note/moveNote", {noteId: noteId, notebookId: notebookId}, function(ret) { NoteService.moveNote(noteId, notebookId, function(ret) {
// });
// ajaxGet("/note/moveNote", {noteId: noteId, notebookId: notebookId}, function(ret) {
if(ret && ret.NoteId) { if(ret && ret.NoteId) {
if(note.IsTrash) { if(note.IsTrash) {
Note.changeToNext(target); Note.changeToNext(target);
@@ -1452,24 +1454,29 @@ Note.copyNote = function(target, data, isShared) {
return; return;
} }
/*
var url = "/note/copyNote"; var url = "/note/copyNote";
var data = {noteId: noteId, notebookId: notebookId}; var data = {noteId: noteId, notebookId: notebookId};
if(isShared) { if(isShared) {
url = "/note/copySharedNote"; url = "/note/copySharedNote";
data.fromUserId = note.UserId; data.fromUserId = note.UserId;
} }
*/
ajaxGet(url, data, function(ret) { NoteService.copyNote(noteId, notebookId, function(newNote) {
if(ret && ret.NoteId) { if(newNote && newNote.NoteId) {
// 重新清空cache 之后的 // 重新清空cache 之后的
Note.clearCacheByNotebookId(notebookId); Note.clearCacheByNotebookId(notebookId);
// 改变缓存, 添加之 // 改变缓存, 添加之
Note.setNoteCache(ret) Note.setNoteCache(newNote)
// 增加数量
Notebook.incrNotebookNumberNotes(notebookId)
} else {
alert('error');
} }
}); });
// 增加数量
Notebook.incrNotebookNumberNotes(notebookId)
}; };
@@ -1633,21 +1640,21 @@ Note.initContextmenu = function() {
var noteListMenu = { var noteListMenu = {
width: 180, width: 180,
items: [ items: [
{ text: getMsg("shareToFriends"), alias: 'shareToFriends', icon: "", faIcon: "fa-share-square-o", action: Note.listNoteShareUserInfo}, // { text: getMsg("shareToFriends"), alias: 'shareToFriends', icon: "", faIcon: "fa-share-square-o", action: Note.listNoteShareUserInfo},
{ type: "splitLine" }, // { type: "splitLine" },
{ text: getMsg("publicAsBlog"), alias: 'set2Blog', faIcon: "fa-bold", action: Note.setNote2Blog }, // { text: getMsg("publicAsBlog"), alias: 'set2Blog', faIcon: "fa-bold", action: Note.setNote2Blog },
{ text: getMsg("cancelPublic"), alias: 'unset2Blog', faIcon: "fa-undo", action: Note.setNote2Blog }, // { text: getMsg("cancelPublic"), alias: 'unset2Blog', faIcon: "fa-undo", action: Note.setNote2Blog },
// { type: "splitLine" }, // { type: "splitLine" },
// { text: "分享到社区", alias: 'html2Image', icon: "", action: Note.html2Image}, // { text: "分享到社区", alias: 'html2Image', icon: "", action: Note.html2Image},
// { text: "导出PDF", alias: 'exportPDF', icon: "", action: Note.exportPDF}, // { text: "导出PDF", alias: 'exportPDF', icon: "", action: Note.exportPDF},
{ type: "splitLine" }, // { type: "splitLine" },
{ text: getMsg("delete"), icon: "", faIcon: "fa-trash-o", action: Note.deleteNote }, {text: getMsg("delete"), icon: "", faIcon: "fa-trash-o", action: Note.deleteNote },
{ text: getMsg("move"), alias: "move", faIcon: "fa-arrow-right", {text: getMsg("move"), alias: "move", faIcon: "fa-arrow-right",
type: "group", type: "group",
width: 180, width: 180,
items: notebooksMove items: notebooksMove
}, },
{ text: getMsg("copy"), alias: "copy", icon:"", faIcon: "fa-copy", {text: getMsg("copy"), alias: "copy", icon:"", faIcon: "fa-copy",
type: "group", type: "group",
width: 180, width: 180,
items: notebooksCopy items: notebooksCopy

View File

@@ -26,7 +26,7 @@
} }
.b-m-idisable .b-m-idisable
{ {
color:#808080; color:#ccc;
} }
.b-m-ibody, .b-m-arrow { .b-m-ibody, .b-m-arrow {
overflow: hidden; overflow: hidden;