mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-15 07:31:33 +00:00
批量复制完成
This commit is contained in:
22
node_modules/common.js
generated
vendored
22
node_modules/common.js
generated
vendored
@@ -26,6 +26,28 @@ var Common = {
|
||||
objectId: function() {
|
||||
return ObjectId()
|
||||
},
|
||||
|
||||
// 是否是数组
|
||||
isArray: function(obj) {
|
||||
return Object.prototype.toString.call(obj) === '[object Array]';
|
||||
},
|
||||
/**
|
||||
* 是否为空
|
||||
* 可判断任意类型,string array
|
||||
*/
|
||||
isEmpty: function(obj) {
|
||||
if(!obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(isArray(obj)) {
|
||||
if(obj.length == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
_uuid: 1,
|
||||
uuid: function() {
|
||||
this._uuid++;
|
||||
|
30
node_modules/note.js
generated
vendored
30
node_modules/note.js
generated
vendored
@@ -10,7 +10,6 @@ var Notebook = require('notebook');
|
||||
var Server = require('server');
|
||||
var Common = require('common');
|
||||
var Web = require('web');
|
||||
var async = require('async');
|
||||
|
||||
// var Notes = db.notes;
|
||||
|
||||
@@ -372,7 +371,7 @@ var Note = {
|
||||
// 重新统计另一个notebookId的笔记数
|
||||
moveNote: function(noteIds, notebookId, callback) {
|
||||
var me = this;
|
||||
if (!noteIds) {
|
||||
if (Common.isEmpty(noteIds)) {
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
@@ -1025,7 +1024,27 @@ var Note = {
|
||||
},
|
||||
|
||||
// 复制笔记到某笔记本下, 本地使用
|
||||
copyNote: function(noteId, notebookId, callback) {
|
||||
copyNote: function(noteIds, notebookId, callback) {
|
||||
var me = this;
|
||||
var newNotes = [];
|
||||
if (Common.isEmpty(noteIds)) {
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
async.eachSeries(noteIds, function(noteId, cbTop) {
|
||||
me._copyNote(noteId, notebookId, function (newNote) {
|
||||
newNotes.push(newNote);
|
||||
cbTop();
|
||||
});
|
||||
}, function () {
|
||||
// 重新统计下
|
||||
Notebook.reCountNotebookNumberNotes(notebookId);
|
||||
callback(newNotes);
|
||||
});
|
||||
},
|
||||
|
||||
// 复制单个笔记
|
||||
_copyNote: function (noteId, notebookId, callback) {
|
||||
var me = this;
|
||||
me.getNote(noteId, function(note) {
|
||||
if(!note) {
|
||||
@@ -1073,15 +1092,14 @@ var Note = {
|
||||
*/
|
||||
}, function() {
|
||||
note.Attachs = newAttachs;
|
||||
console.log('conflict 复制后的');
|
||||
console.log(note.Attachs);
|
||||
// console.log('conflict 复制后的');
|
||||
// console.log(note.Attachs);
|
||||
db.notes.insert(note, function(err, newNote) {
|
||||
if(err) {
|
||||
callback(false);
|
||||
} else {
|
||||
callback(newNote);
|
||||
// 重新统计下
|
||||
Notebook.reCountNotebookNumberNotes(newNote.NotebookId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@@ -1768,95 +1768,58 @@ Note.moveNote = function(target, data) {
|
||||
|
||||
// 重置, 因为可能移动后笔记下没笔记了
|
||||
me.batch.reset();
|
||||
|
||||
return;
|
||||
|
||||
var noteId = $(target).attr("noteId");
|
||||
var note = Note.cache[noteId];
|
||||
var notebookId = data.notebookId;
|
||||
|
||||
if(!note.IsTrash && note.NotebookId == notebookId) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 修改数量
|
||||
Notebook.incrNotebookNumberNotes(notebookId);
|
||||
if(!note.IsTrash) {
|
||||
Notebook.minusNotebookNumberNotes(note.NotebookId);
|
||||
}
|
||||
|
||||
NoteService.moveNote(noteId, notebookId, function(ret) {
|
||||
// });
|
||||
// ajaxGet("/note/moveNote", {noteId: noteId, notebookId: notebookId}, function(ret) {
|
||||
if(ret && ret.NoteId) {
|
||||
if(note.IsTrash) {
|
||||
Note.changeToNext(target);
|
||||
$(target).remove();
|
||||
Note.clearCacheByNotebookId(notebookId);
|
||||
} else {
|
||||
// 不是trash, 移动, 那么判断是当前是否是all下
|
||||
// 不在all下, 就删除之
|
||||
// 如果当前是active, 那么clearNoteInfo之
|
||||
if(!Notebook.curActiveNotebookIsAll()) {
|
||||
Note.changeToNext(target);
|
||||
if($(target).hasClass("item-active")) {
|
||||
Note.clearNoteInfo();
|
||||
}
|
||||
$(target).remove();
|
||||
} else {
|
||||
// 不移动, 那么要改变其notebook title
|
||||
$(target).find(".note-notebook").html(Notebook.getNotebookTitle(notebookId));
|
||||
}
|
||||
|
||||
// 重新清空cache 之前的和之后的
|
||||
Note.clearCacheByNotebookId(note.NotebookId);
|
||||
Note.clearCacheByNotebookId(notebookId);
|
||||
}
|
||||
|
||||
// 改变缓存
|
||||
Note.setNoteCache(ret)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 复制
|
||||
// data是自动传来的, 是contextmenu数据
|
||||
Note.copyNote = function(target, data, isShared) {
|
||||
var noteId = $(target).attr("noteId");
|
||||
var note = Note.cache[noteId];
|
||||
var notebookId = data.notebookId;
|
||||
var me = Note;
|
||||
|
||||
var toNotebookId = data.notebookId;
|
||||
var noteIds;
|
||||
if (Note.inBatch) {
|
||||
noteIds = me.getBatchNoteIds();
|
||||
}
|
||||
else {
|
||||
noteIds = [$(target).attr('noteId')];
|
||||
}
|
||||
|
||||
// 得到需要复制的
|
||||
var needNoteIds = [];
|
||||
for (var i = 0; i < noteIds.length; ++i) {
|
||||
var noteId = noteIds[i];
|
||||
var note = me.getNote(noteId);
|
||||
if (note) {
|
||||
// trash不能复制, 不能复制给自己
|
||||
if(note.IsTrash || note.NotebookId == notebookId) {
|
||||
if (note.IsTrash || note.NotebookId == toNotebookId) {
|
||||
continue;
|
||||
}
|
||||
needNoteIds.push(noteId);
|
||||
}
|
||||
}
|
||||
if (needNoteIds.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
var url = "/note/copyNote";
|
||||
var data = {noteId: noteId, notebookId: notebookId};
|
||||
if(isShared) {
|
||||
url = "/note/copySharedNote";
|
||||
data.fromUserId = note.UserId;
|
||||
}
|
||||
*/
|
||||
|
||||
NoteService.copyNote(noteId, notebookId, function(newNote) {
|
||||
if(newNote && newNote.NoteId) {
|
||||
NoteService.copyNote(needNoteIds, toNotebookId, function(notes) {
|
||||
if(!isEmpty(notes)) {
|
||||
// 重新清空cache 之后的
|
||||
Note.clearCacheByNotebookId(notebookId);
|
||||
Note.clearCacheByNotebookId(toNotebookId);
|
||||
for (var i = 0; i < notes.length; ++i) {
|
||||
var note = notes[i];
|
||||
if (!note.NoteId) {
|
||||
continue;
|
||||
}
|
||||
// 改变缓存, 添加之
|
||||
Note.setNoteCache(newNote)
|
||||
Note.setNoteCache(note);
|
||||
|
||||
// 增加数量
|
||||
Notebook.incrNotebookNumberNotes(notebookId)
|
||||
} else {
|
||||
alert('error');
|
||||
Notebook.incrNotebookNumberNotes(toNotebookId)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
// 删除笔记标签
|
||||
// item = {noteId => usn}
|
||||
Note.deleteNoteTag = function(item, tag) {
|
||||
|
Reference in New Issue
Block a user