成功后才显示blog标志, 可点
This commit is contained in:
life
2015-03-16 00:36:47 +08:00
parent 238223d7b4
commit 88be5705ad
9 changed files with 164 additions and 82 deletions

4
node_modules/api.js generated vendored
View File

@@ -507,7 +507,8 @@ var Api = {
Content: note.Content,
IsMarkdown: note.IsMarkdown,
Tags: note.Tags,
IsBlog: false, // TODO 这里永远设为非blog note.IsBlog,
// IsBlog: false, // TODO 这里永远设为非blog note.IsBlog,
IsBlog: note.IsBlog,
Files: note.Files,
FileDatas: note.FileDatas,
}
@@ -560,6 +561,7 @@ var Api = {
usn: note.Usn,
isTrash: note.IsTrash,
content: note.Content,
isBlog: note.IsBlog, // 是否是博客
Files: note.Files,
FileDatas: note.FileDatas,
tags: note.Tags, // 新添加

25
node_modules/note.js generated vendored
View File

@@ -153,6 +153,24 @@ var Note = {
}
},
// 公开/取消为博客
setNote2Blog: function(noteId, isBlog, callback) {
var me = this;
me.getNote(noteId, function(note) {
if(note) {
if(note.IsBlog == isBlog) {
return callback && callback(true);
}
// 更新, 设置isDirty
Notes.update({NoteId: noteId}, { $set: {IsBlog: isBlog, IsDirty: true} }, {}, function (err, numReplaced) {
return callback && callback(true);
});
} else {
return callback && callback(false);
}
});
},
// 添加笔记历史
/*
type NoteContentHistory struct {
@@ -1102,6 +1120,13 @@ var Note = {
// 处理删除的
Web.deleteSyncNote(noteSyncInfo.deletes);
// 为了博客
var changeAdds = noteSyncInfo.changeAdds || [];
var changeUpdates = noteSyncInfo.changeUpdates || [];
changeAdds = changeAdds.concat(changeUpdates);
Web.updateNoteCacheForServer(changeAdds);
},
// 得到所有文件要传的基本信息和传送的数据

7
node_modules/sync.js generated vendored
View File

@@ -72,7 +72,7 @@ var Sync = {
// 同步信息
me._syncInfo = {
notebook: {ok: false, changeAdds: [], changeConflicts: [], changeNeedAdds: [], adds: [], deletes: [], updates: []},
note: {ok: false, adds: [], changeAdds: [], changeConflicts: [], changeNeedAdds: [], deletes: [], updates: [], conflicts: []},
note: {ok: false, adds: [], changeAdds: [], changeConflicts: [], changeUpdates:[], changeNeedAdds: [], deletes: [], updates: [], conflicts: []},
tag: {ok: false, adds: [], changeAdds: [], changeConflicts: [], changeNeedAdds: [], deletes: [], updates: [], conflicts: []},
};
@@ -736,7 +736,7 @@ var Sync = {
// 一个一个同步执行, 因为要有
async.eachSeries(notes, function(note, cb) {
if(note.LocalIsNew) {
// 添加
// 添加, newNote的返回不会很多值(server端)
Api.addNote(note, function(newNote) {
if(!Common.isOk(newNote)) {
return cb();
@@ -744,6 +744,8 @@ var Sync = {
newNote.ServerNoteId = newNote.NoteId;
newNote.NoteId = note.NoteId;
newNote.IsBlog = note.IsBlog; // 前端要用
me._syncInfo.note.changeAdds.push(newNote);
Note.updateNoteForceForSendChange(newNote, true);
@@ -785,6 +787,7 @@ var Sync = {
ret.ServerNoteId = ret.NoteId;
ret.NoteId = note.NoteId;
Note.updateNoteForceForSendChange(ret, false);
me._syncInfo.note.changeUpdates.push(note);
me.checkNeedIncSyncAgain(ret.Usn);

4
node_modules/web.js generated vendored
View File

@@ -74,6 +74,10 @@ var Web = {
var me = this;
me.Note.fixSyncConflict(note, newNote);
},
updateNoteCacheForServer: function(notes) {
var me = this;
me.Note.updateNoteCacheForServer(notes);
},
//--------------
syncFinished: function() {

View File

@@ -446,7 +446,9 @@ h1, h2, h3 {
}
.item-blog {
top: 1px;
// top: 1px;
bottom: 0;
right: 45px;
// 暂不支持
display: none;
}
@@ -484,7 +486,7 @@ h1, h2, h3 {
}
}
#noteItemList .item:hover {
.item-setting, .item-star {
.item-setting, .item-star, .item-blog {
display: block;
}
&.item-conflict {

View File

@@ -427,7 +427,8 @@ h3 {
opacity: 0.8;
}
#noteItemList .item-blog {
top: 1px;
bottom: 0;
right: 45px;
display: none;
}
#noteItemList .item-setting {
@@ -454,7 +455,8 @@ h3 {
color: yellow !important;
}
#noteItemList .item:hover .item-setting,
#noteItemList .item:hover .item-star {
#noteItemList .item:hover .item-star,
#noteItemList .item:hover .item-blog {
display: block;
}
#noteItemList .item:hover.item-conflict .item-conflict-info {

View File

@@ -1136,10 +1136,10 @@ Note.newNote = function(notebookId, isShare, fromUserId, isMarkdown) {
}
// notebook是否是Blog
if(!notebook.IsBlog) {
// if(!notebook.IsBlog) {
newItem = $(newItem);
newItem.find(".item-blog").hide();
}
// }
// 是否在当前notebook下, 不是则切换过去, 并得到该notebook下所有的notes, 追加到后面!
if(!Notebook.isCurNotebook(notebookId)) {
@@ -1462,44 +1462,6 @@ Note.exportPDF = function(target) {
});
};
// 长微博
Note.html2Image = function(target) {
var noteId = $(target).attr("noteId");
showDialog("html2ImageDialog", {title: "分享到社区", postShow: function() {
ajaxGet("/note/html2Image", {noteId: noteId}, function(ret) {
if (typeof ret == "object" && ret.Ok) {
$("#leanoteDialog .weibo span").html("生成成功, 右键图片保存到本地.")
$("#leanoteDialog .weibo img").attr("src", ret.Id + "?" + ((new Date()).getTime()));
$("#leanoteDialog .btn-share").removeClass("disabled");
var note = Note.cache[noteId];
var pic = UrlPrefix + ret.Id;
var title = encodeURI(note.Title + " (" + UserInfo.Username + "分享. 来自leanote.com)");
var windowParam = 'width=700, height=580, top=180, left=320, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no';
$("#leanoteDialog .sendWeiboBtn").click(function() {
var url = "http://service.weibo.com/share/share.php?title=" + title;
url += "&pic=" + pic;
window.open(url, '分享到新浪微博', windowParam);
});
$("#leanoteDialog .sendTxWeiboBtn").click(function() {
var _appkey = '801542571';
var url = "http://share.v.t.qq.com/index.php?c=share&a=index&appkey=" + _appkey +"&title=" + title +"&url=&pic=" + pic
window.open(url, '分享到腾讯微博', windowParam);
});
$("#leanoteDialog .sendQQBtn").click(function() {
var url = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + UrlPrefix + '&title=' + title + '&pics=' + pic;
window.open(url, '分享QQ空间', windowParam);
});
$("#leanoteDialog .sendRRBtn").click(function() {
var url = 'http://widget.renren.com/dialog/share?resourceUrl=' + UrlPrefix + '&srcUrl=' + UrlPrefix + '&title=' + title + '&pic=' + pic;
window.open(url, '分享人人网', windowParam);
});
} else {
$("#leanoteDialog .weibo").html("对不起, 我们出错了!")
}
});
}});
}
//--------------
// read only
@@ -1641,18 +1603,37 @@ Note.setNote2Blog = function(target) {
if(note.IsBlog != undefined) {
isBlog = !note.IsBlog;
}
// 标志添加/去掉
function setBlog() {
// alert(noteId + " => " + isBlog);
NoteService.setNote2Blog(noteId, isBlog, function(ret) {
if(ret) {
// 触发同步
incrSync();
// Note.setNoteCache({NoteId: noteId, IsBlog: isBlog}, false); // 不清空NotesByNotebookId缓存
// 同步后会设置
/*
if(isBlog) {
$(target).find(".item-blog").show();
$(target).find(".item-blog").removeAttr('style');
} else {
$(target).find(".item-blog").hide();
}
ajaxPost("/note/setNote2Blog", {noteId: noteId, isBlog: isBlog}, function(ret) {
if(ret) {
Note.setNoteCache({NoteId: noteId, IsBlog: isBlog}, false); // 不清空NotesByNotebookId缓存
*/
}
});
}
}
// 是新笔记 或 当前笔记就是它的, 则先保存之
if(note.IsNew || note.curNoteId == noteId) {
Note.curChangedSaveIt(true, function(note) {
setBlog();
});
} else {
setBlog();
}
};
// 设置notebook的blog状态
// 当修改notebook是否是blog时调用
@@ -1676,7 +1657,7 @@ Note.setAllNoteBlogStatus = function(notebookId, isBlog) {
notes[i].IsBlog = isBlog;
}
}
}
};
// 移动
Note.moveNote = function(target, data) {
@@ -1726,7 +1707,7 @@ Note.moveNote = function(target, data) {
Note.setNoteCache(ret)
}
});
}
};
// 复制
// data是自动传来的, 是contextmenu数据
@@ -2205,6 +2186,13 @@ Note.initContextmenu = function() {
Note.deleteNote(self.target);
}
});
this.publicBlog = new gui.MenuItem({
label: getMsg("Public as blog"),
click: function(e) {
Note.setNote2Blog(self.target);
}
});
this.move = new gui.MenuItem({
label: getMsg("move"),
click: function(e) {
@@ -2220,6 +2208,7 @@ Note.initContextmenu = function() {
this.move.submenu = ms[0];
this.copy.submenu = ms[1];
this.menu.append(this.publicBlog);
this.menu.append(this.del);
this.menu.append(this.move);
this.menu.append(this.copy);
@@ -2256,6 +2245,12 @@ Note.initContextmenu = function() {
this.copy.enabled = true;
}
if(note.IsBlog) {
this.publicBlog['label'] = 'Cancel public';
} else {
this.publicBlog['label'] = 'Public as blog';
}
this.menu.popup(e.originalEvent.x, e.originalEvent.y);
// notebookMenuForMove.enabled = true;
@@ -2672,7 +2667,10 @@ $(function() {
e.stopPropagation();
// 得到ID
var noteId = $(this).parent().attr('noteId');
window.open("/blog/view/" + noteId);
var note = Note.getNote(noteId);
if(note.ServerNoteId) {
openExternal(UserInfo.Host + '/blog/post/' + note.ServerNoteId);
}
});
// note setting
@@ -2756,21 +2754,37 @@ Note.fixSyncConflict = function(note, newNote) {
}
};
// 添加同步的notes
Note.addSync = function(notes) {
// 设置博客是否可以见
Note.setNoteBlogVisible = function(noteId, isBlog) {
var target = $(tt('[noteId="?"]', noteId));
if(target.length) {
if(isBlog) {
target.find(".item-blog").removeAttr('style');
} else {
target.find(".item-blog").hide();
}
}
};
// --> adds
// changeAdds 有了serverId
Note.updateNoteCacheForServer = function(notes) {
if(isEmpty(notes)) {
return;
}
for(var i in notes) {
var note = notes[i];
Note.addNoteCache(note);
// 添加到当前的笔记列表中
var newHtmlObject = Note._getNoteHtmlObjct(note);
log(newHtmlObject);
$('#noteItemList').prepend(newHtmlObject);
// alert(note.NoteId + " " + note.IsBlog);
Note.addNoteCache({NoteId: note.NoteId,
ServerNoteId: note.ServerNoteId,
IsBlog: note.IsBlog,
});
Note.setNoteBlogVisible(note.NoteId, note.IsBlog);
}
}
};
// 更新
// --> send changes
Note.updateSync = function(notes) {
if(isEmpty(notes)) {
return;
@@ -2790,6 +2804,10 @@ Note.updateSync = function(notes) {
Note.reRenderNote(Note.curNoteId);
}
// 设置当前是否是博客
// alert(note.NoteId + " " + note.IsBlog);
Note.setNoteBlogVisible(note.NoteId, note.IsBlog);
// 如果是trash, 且当前不在trash目录下, 且有该笔记, 则删除之
if(!curNotebookIsTrash && note.IsTrash) {
var target = $(tt('[noteId="?"]', note.NoteId));
@@ -2803,6 +2821,25 @@ Note.updateSync = function(notes) {
}
};
// 添加同步的notes
// <-- server
Note.addSync = function(notes) {
if(isEmpty(notes)) {
return;
}
for(var i in notes) {
var note = notes[i];
Note.addNoteCache(note);
// alert(note.ServerNoteId);
// 添加到当前的笔记列表中
var newHtmlObject = Note._getNoteHtmlObjct(note);
$('#noteItemList').prepend(newHtmlObject);
Note.setNoteBlogVisible(note.NoteId, note.IsBlog);
}
};
// 删除
Note.deleteSync = function(notes) {
if(isEmpty(notes)) {

View File

@@ -1460,10 +1460,7 @@ var Pren = {
var re = new RegExp("^((https|http|ftp|rtsp|mms|emailto)://).+");
return re.test(str_url);
}
// 浏览器打开
function openExternal(url) {
gui.Shell.openExternal(url);
}
// 防止在本窗口打开
me.presentationO.on('click', 'a', function(e) {
e.preventDefault();
@@ -1519,13 +1516,12 @@ function userMenu() {
function menu() {
var me = this;
// this.target = '';
UserInfo.Host = UserInfo.Host || 'http://leanote.com';
var shortHost = UserInfo.Host;
if(shortHost) {
var ret = /http(s*):\/\/([a-zA-Z0-9\.\-]+)/.exec(shortHost);
if(ret && ret.length == 3) {
shortHost = ret[2];
}
}
this.menu = new gui.Menu();
this.email = new gui.MenuItem({
@@ -1534,6 +1530,12 @@ function userMenu() {
click: function(e) {
}
});
this.blog = new gui.MenuItem({
label: 'My blog',
click: function(e) {
openExternal(UserInfo.Host + '/blog/' + UserInfo.UserId);
}
});
this.switchAccount = new gui.MenuItem({
label: 'Switch account',
click: function(e) {
@@ -1581,11 +1583,12 @@ function userMenu() {
this.theme.submenu = themeSubmenus;
this.menu.append(this.email);
this.menu.append(this.blog);
this.menu.append(this.switchAccount);
this.menu.append(new gui.MenuItem({ type: 'separator' }));
this.menu.append(this.theme);
var height = 130;
var height = 150;
if(!isMac()) {
this.menu.append(new gui.MenuItem({ type: 'separator' }));
@@ -1598,13 +1601,12 @@ function userMenu() {
}
}));
*/
height = 220;
height = 240;
}
this.menu.append(new gui.MenuItem({ type: 'separator' }));
this.menu.append(this.sync);
this.popup = function(e) {
this.menu.popup(10, $('body').height() - height);
}

View File

@@ -1443,6 +1443,11 @@ function getMainWinParams() {
};
}
// 浏览器打开
function openExternal(url) {
gui.Shell.openExternal(url);
}
// loadToolIcons();
ContextTips.init();