批量公开, 取消公开为博客完成

This commit is contained in:
life
2015-10-24 12:26:41 +08:00
parent 17b2b9f2fa
commit 51174399d2
4 changed files with 94 additions and 51 deletions

19
node_modules/note.js generated vendored
View File

@@ -161,7 +161,22 @@ var Note = {
}, },
// 公开/取消为博客 // 公开/取消为博客
setNote2Blog: function(noteId, isBlog, callback) { setNote2Blog: function(noteIds, isBlog, callback) {
var me = this;
var ok = false;
async.eachSeries(noteIds, function(noteId, cb) {
me._setNote2Blog(noteId, isBlog, function (ret) {
if (ret) {
ok = true;
}
cb();
});
}, function () {
callback(ok);
});
},
_setNote2Blog: function(noteId, isBlog, callback) {
var me = this; var me = this;
me.getNote(noteId, function(note) { me.getNote(noteId, function(note) {
if(note) { if(note) {
@@ -169,7 +184,7 @@ var Note = {
return callback && callback(true); return callback && callback(true);
} }
// 更新, 设置isDirty // 更新, 设置isDirty
db.notes.update({NoteId: noteId}, { $set: {IsBlog: isBlog, IsDirty: true} }, {}, function (err, numReplaced) { db.notes.update({_id: note._id}, { $set: {IsBlog: isBlog, IsDirty: true} }, {}, function (err, numReplaced) {
return callback && callback(true); return callback && callback(true);
}); });
} else { } else {

View File

@@ -1619,45 +1619,33 @@ Note.searchNote = function() {
// Note.lastSearch.abort(); // Note.lastSearch.abort();
} }
//---------- //---------------
//设为blog/unset //设为blog/unset
Note.setNote2Blog = function(target) {
var noteId = $(target).attr("noteId");
var note = Note.cache[noteId]; Note.setNote2Blog = function(target, isBlog) {
var isBlog = true; var me = Note;
if(note.IsBlog != undefined) {
isBlog = !note.IsBlog; var noteIds;
if (me.inBatch) {
noteIds = me.getBatchNoteIds();
}
else {
noteIds = [$(target).attr('noteId')];
}
if (isEmpty(noteIds)) {
return;
} }
// 标志添加/去掉 // 是新笔记 或 当前笔记就是它的, 则先保存之
function setBlog() { Note.curChangedSaveIt(true, function() {
// alert(noteId + " => " + isBlog); NoteService.setNote2Blog(noteIds, isBlog, function(ret) {
NoteService.setNote2Blog(noteId, isBlog, function(ret) {
if(ret) { if(ret) {
// 触发同步 // 触发同步
incrSync(); incrSync();
// Note.setNoteCache({NoteId: noteId, IsBlog: isBlog}, false); // 不清空NotesByNotebookId缓存
// 同步后会设置
/*
if(isBlog) {
$(target).find(".item-blog").removeAttr('style');
} else {
$(target).find(".item-blog").hide();
}
*/
} }
}); });
} });
// 是新笔记 或 当前笔记就是它的, 则先保存之
if(note.IsNew || note.curNoteId == noteId) {
Note.curChangedSaveIt(true, function(note) {
setBlog();
});
} else {
setBlog();
}
}; };
// 设置notebook的blog状态 // 设置notebook的blog状态
@@ -1785,7 +1773,8 @@ Note.copyNote = function(target, data, isShared) {
var note = me.getNote(noteId); var note = me.getNote(noteId);
if (note) { if (note) {
// trash不能复制, 不能复制给自己 // trash不能复制, 不能复制给自己
if (note.IsTrash || note.NotebookId == toNotebookId) { // 因为contexmenu不能disable有子menu的项, 所以允许复制trash
if (/*note.IsTrash || */note.NotebookId == toNotebookId) {
continue; continue;
} }
needNoteIds.push(noteId); needNoteIds.push(noteId);
@@ -2278,13 +2267,13 @@ Note.initContextmenu = function() {
this.publicBlog = new gui.MenuItem({ this.publicBlog = new gui.MenuItem({
label: getMsg("Public as blog"), label: getMsg("Public as blog"),
click: function(e) { click: function(e) {
Note.setNote2Blog(self.target); Note.setNote2Blog(self.target, true);
} }
}); });
this.unPublicBlog = new gui.MenuItem({ this.unPublicBlog = new gui.MenuItem({
label: getMsg("Cancel public"), label: getMsg("Cancel public"),
click: function(e) { click: function(e) {
Note.setNote2Blog(self.target); Note.setNote2Blog(self.target, false);
} }
}); });
@@ -2305,6 +2294,7 @@ Note.initContextmenu = function() {
} }
}); });
// 本地笔记不能公开为博客
if (!UserInfo.IsLocal) { if (!UserInfo.IsLocal) {
this.menu.append(this.publicBlog); this.menu.append(this.publicBlog);
this.menu.append(this.unPublicBlog); this.menu.append(this.unPublicBlog);
@@ -2322,8 +2312,10 @@ Note.initContextmenu = function() {
var exportMenus = Api.getExportMenus() || []; var exportMenus = Api.getExportMenus() || [];
for(var i = 0; i < exportMenus.length; ++i) { for(var i = 0; i < exportMenus.length; ++i) {
(function(j) { (function(j) {
var menu = exportMenus[j]; var menu = exportMenus[j];
var clickBac = menu.click; var clickBac = menu.click;
var menuItem = new gui.MenuItem({ var menuItem = new gui.MenuItem({
label: menu.label, label: menu.label,
click: function(e) { click: function(e) {
@@ -2331,9 +2323,13 @@ Note.initContextmenu = function() {
clickBac && clickBac(note); clickBac && clickBac(note);
} }
}); });
exportMenus[i].menu = menuItem;
exportsSubMenus.append(menuItem); exportsSubMenus.append(menuItem);
})(i); })(i);
} }
if(exportMenus.length > 0) { if(exportMenus.length > 0) {
this.exports = new gui.MenuItem({ this.exports = new gui.MenuItem({
label: getMsg('Export'), label: getMsg('Export'),
@@ -2346,31 +2342,54 @@ Note.initContextmenu = function() {
this.menu.append(this.exports); this.menu.append(this.exports);
} }
T = this;
this.enable = function(name, ok) { this.enable = function(name, ok) {
this[name].enabled = ok; this[name].enabled = ok;
} }
// 控制disable
this.popup = function(e, target) { this.popup = function(e, target) {
self.target = target; self.target = target;
var noteId = $(target).attr('noteId'); var noteIds;
if (Note.inBatch) {
var note = Note.getNote(noteId); noteIds = Note.getBatchNoteIds();
if(!note) { }
return; else {
noteIds = [$(target).attr("noteId")];
} }
var notebookId = note.NotebookId;
if(note.IsTrash) { // 导出的enabled
this.copy.enabled = false; for(var i = 0; i < exportMenus.length; ++i) {
} else { exportMenus[i].menu.enabled = exportMenus[i].enabled(noteIds);
}
// 批量, 除了导出pdf都可以操作
if (Note.inBatch) {
this.copy.enabled = true; this.copy.enabled = true;
} this.move.enabled = true;
this.publicBlog.enabled = true;
if(note.IsBlog) {
this.publicBlog.enabled = false;
this.unPublicBlog.enabled = true; this.unPublicBlog.enabled = true;
} else { } else {
this.publicBlog.enabled = true; var note = Note.getNote(noteIds[0]);
this.unPublicBlog.enabled = false; if (!note) {
return;
}
if(note.IsTrash || Notebook.curNotebookIsTrash()) {
this.copy.enabled = false; // 没用
this.publicBlog.enabled = false;
this.unPublicBlog.enabled = false;
} else {
this.copy.enabled = true;
if(note.IsBlog) {
this.publicBlog.enabled = false;
this.unPublicBlog.enabled = true;
} else {
this.publicBlog.enabled = true;
this.unPublicBlog.enabled = false;
}
}
} }
this.menu.popup(gui.getCurrentWindow(), e.originalEvent.x, e.originalEvent.y); this.menu.popup(gui.getCurrentWindow(), e.originalEvent.x, e.originalEvent.y);

View File

@@ -203,6 +203,9 @@ define(function() {
var menu = { var menu = {
label: Api.getMsg('plugin.export_html.export'), label: Api.getMsg('plugin.export_html.export'),
enabled: function(noteIds) {
return true;
},
click: (function() { click: (function() {
return function(note) { return function(note) {
me.exportHTML(note); me.exportHTML(note);

View File

@@ -116,6 +116,12 @@ define(function() {
var menu = { var menu = {
label: Api.getMsg('plugin.export_pdf.export'), label: Api.getMsg('plugin.export_pdf.export'),
enabled: function(noteIds) {
if (noteIds && noteIds.length == 1) {
return true;
}
return false;
},
click: (function() { click: (function() {
return function(note) { return function(note) {
if (UserInfo.IsLocal) { if (UserInfo.IsLocal) {