';
note = Note.cache[Note.curNoteId];
var s = "div"
if(note.IsMarkdown) {
s = "pre";
}
for (i in re) {
var content = re[i]
content.Ab = Note.genAbstract(content.Content, 200);
str += tt('
';
Note.starNotesO = $('#starNotes');
Note.renderStars = function(notes) {
var me = this;
var notes = notes || me.starNotes;
me.starNotes = notes;
me.starNotesO.html('');
for(var i = 0; i < notes.length; ++i) {
var note = notes[i];
var t = tt(me.starItemT, note.NoteId, note.Title || 'Untitled');
me.starNotesO.append(t);
}
};
// 点击笔记, 判断是否在star中, 如果在, 则也选中
Note.selectStar = function(noteId) {
var me = this;
var target = me.starNotesO.find('li[data-id="' + noteId + '"]');
me.starNotesO.find('li').removeClass('selected');
target.addClass('selected');
};
// 点击, note
Note.renderStarNote = function(target) {
var me = this;
var noteId = target.data('id');
me.starNotesO.find('li').removeClass('selected');
target.addClass('selected');
// 把当前笔记放在第一位
me.clearAll();
me.renderNotes(me.starNotes);
me.changeNoteForPjax(noteId, true, false);
me.directToNote(noteId);
// $('#curNotebookForLisNote').text("Starred");
Notebook.changeCurNotebookTitle('Starred', true);
};
// 笔记标签改了后, 如果在star中, 则也要改标题
Note.changeStarNoteTitle = function(note) {
var me = this;
var cacheNote = me.getNote(note.NoteId);
if(!cacheNote.Star) {
return;
}
var target = me.starNotesO.find('li[data-id="' + note.NoteId + '"]');
target.find('a').html((note.Title || 'Untitled') + 'X');
};
// 取消star, note delete/trash时取消star
Note.unStar = function(noteId) {
var me = this;
// 删除该stars
var has = false;
for(var i = 0; i < me.starNotes.length; ++i) {
var tNote = me.starNotes[i];
if(tNote.NoteId == noteId) {
var has = true;
me.starNotes.splice(i, 1);
break;
}
}
if(has) {
// 重新渲染之
me.renderStars(me.starNotes);
}
};
// 收藏或取消收藏
Note.star = function(noteId) {
var me = this;
var note = me.getNote(noteId);
if(!note || note.IsTrash) {
return;
}
var $target = $('[noteId="' + noteId + '"]');
NoteService.star(noteId, function(ok, isStarred) {
if(ok) {
note.Star = isStarred;
if(isStarred) {
me.starNotes.unshift(note);
$target.addClass('item-is-star');
} else {
$target.removeClass('item-is-star');
// 删除该stars
for(var i = 0; i < me.starNotes.length; ++i) {
var tNote = me.starNotes[i];
if(tNote.NoteId == noteId) {
me.starNotes.splice(i, 1);
break;
}
}
}
// 重新渲染之
me.renderStars(me.starNotes);
}
});
};
// 显示
Note._curFixNoteId = ''; // 当前要处理的
Note._curFixNoteTarget = '';
Note._conflictTipsElem = $('#conflictTips');
Note._showConflictInfoInited = false;
// 初始化事件
Note._initshowConflictInfo = function() {
var me = this;
// 点击与之冲突的笔记, 则将该笔记显示到它前面, 并选中
Note._conflictTipsElem.find('.conflict-title').click(function() {
var conflictNoteId = $(this).data('id');
var conflictNote = me.getNote(conflictNoteId);
if(!conflictNote) {
alert('The note is not exists');
return;
}
// 是否在该列表中?
var target = $(tt('[noteId="?"]', conflictNoteId)); //
// 如果当前笔记在笔记列表中, 那么生成一个新笔记放在这个笔记上面
if(target.length > 0) {
} else {
target = me._getNoteHtmlObjct(conflictNote);
}
// console.log(">....>");
// console.log(me._curFixNoteTarget);
// console.log(target);
target.insertAfter(me._curFixNoteTarget);
// alert(3);
// me._curFixNoteTarget.insertBefore(target);
// 选中与之冲突的笔记
me.changeNote(conflictNoteId);
});
};
Note.showConflictInfo = function(target, e) {
var me = this;
var $li = $(target).closest('li');
var noteId = $li.attr('noteId');
var note = me.getNote(noteId);
if(!note) {
return;
}
var conflictNoteId = note.ConflictNoteId;
function conflictIsFixed() {
// 去掉item-confict class
// 并且改变
$li.removeClass('item-conflict');
note.ConflictNoteId = "";
NoteService.conflictIsFixed(noteId);
}
if(!conflictNoteId) {
return conflictIsFixed();
}
var conflictNote = me.getNote(conflictNoteId);
if(!conflictNote) {
return conflictIsFixed();
}
me._curFixNoteId = noteId;
me._curFixNoteTarget = $li;
if(!me._showConflictInfoInited) {
me._showConflictInfoInited = true;
me._initshowConflictInfo();
}
// 初始化数据
var titleElem = Note._conflictTipsElem.find('.conflict-title');
titleElem.text(conflictNote.Title);
titleElem.data('id', conflictNoteId);
Note._conflictTipsElem.find('.conflict-resolved').prop('checked', false);
ContextTips.show('#conflictTips', e, function() {
if(Note._conflictTipsElem.find('.conflict-resolved').prop('checked')) {
conflictIsFixed();
}
});
};
// 内容已同步成功
Note.contentSynced = function(noteId, content) {
var me = this;
var note = me.getCurNote();
if(!note) {
return;
}
if(note.InitSync) {
// 重新render内容
note.InitSync = false;
note.Content = content;
if(me.curNoteId == noteId) {
// 重新渲染
Note.changeNote(noteId);
}
}
};
// 这里速度不慢, 很快
Note.getContextNotebooks = function(notebooks) {
var moves = [];
var copys = [];
var copys2 = [];
for(var i in notebooks) {
var notebook = notebooks[i];
var move = {text: notebook.Title, notebookId: notebook.NotebookId, action: Note.moveNote}
var copy = {text: notebook.Title, notebookId: notebook.NotebookId, action: Note.copyNote}
var copy2 = {text: notebook.Title, notebookId: notebook.NotebookId, action: Share.copySharedNote}
if(!isEmpty(notebook.Subs)) {
var mc = Note.getContextNotebooks(notebook.Subs);
move.items = mc[0];
copy.items = mc[1];
copy2.items = mc[2];
move.type = "group";
move.width = 150;
copy.type = "group";
copy.width = 150;
copy2.type = "group";
copy2.width = 150;
}
moves.push(move);
copys.push(copy);
copys2.push(copy2);
}
return [moves, copys, copys2];
};
Note.target = null; // 当前处理的note
Note.menuItemsForMove = {}; // notebookId => menu
Note.menuItemsForCopy = {}; // notebookId => menu
Note.getContextNotebooksSys = function(notebooks) {
var submenuMoves = new gui.Menu();
var submenuCopys = new gui.Menu();
for(var i in notebooks) {
(function(j) {
var notebook = notebooks[j];
var move = new gui.MenuItem({label: notebook.Title, /*notebookId: notebook.NotebookId,*/ click: function() {
Note.moveNote(Note.target, {notebookId: notebook.NotebookId});
}});
var copy = new gui.MenuItem({label: notebook.Title, /*notebookId: notebook.NotebookId, */click: function() {
Note.copyNote(Note.target, {notebookId: notebook.NotebookId});
}});
Note.menuItemsForMove[notebook.NotebookId] = move;
Note.menuItemsForCopy[notebook.NotebookId] = copy;
if(!isEmpty(notebook.Subs)) {
var mc = Note.getContextNotebooksSys(notebook.Subs);
move.submenu = mc[0];
copy.submenu = mc[1];
}
submenuMoves.append(move);
submenuCopys.append(copy);
})(i);
}
return [submenuMoves, submenuCopys];
};
// Notebook调用
Note.contextmenu = null;
Note.notebooksCopy = []; // share会用到
Note.initContextmenu = function() {
var self = Note;
var notebooks = Notebook.everNotebooks;
/*
if(Note.contextmenu) {
Note.contextmenu.destroy();
}
// 得到可move/copy的notebook
var notebooks = Notebook.everNotebooks;
var mc = self.getContextNotebooks(notebooks);
var notebooksMove = mc[0];
var notebooksCopy = mc[1];
self.notebooksCopy = mc[2];
//---------------------
// context menu
//---------------------
var noteListMenu = {
width: 180,
items: [
// { text: getMsg("shareToFriends"), alias: 'shareToFriends', icon: "", faIcon: "fa-share-square-o", action: Note.listNoteShareUserInfo},
// { type: "splitLine" },
// { text: getMsg("publicAsBlog"), alias: 'set2Blog', faIcon: "fa-bold", action: Note.setNote2Blog },
// { text: getMsg("cancelPublic"), alias: 'unset2Blog', faIcon: "fa-undo", action: Note.setNote2Blog },
// { type: "splitLine" },
// { text: "分享到社区", alias: 'html2Image', icon: "", action: Note.html2Image},
// { text: "导出PDF", alias: 'exportPDF', icon: "", action: Note.exportPDF},
// { type: "splitLine" },
{text: getMsg("delete"), icon: "", faIcon: "fa-trash-o", action: Note.deleteNote },
{text: getMsg("move"), alias: "move", faIcon: "fa-arrow-right",
type: "group",
width: 180,
items: notebooksMove
},
{text: getMsg("copy"), alias: "copy", icon:"", faIcon: "fa-copy",
type: "group",
width: 180,
items: notebooksCopy
}
],
onShow: applyrule,
onContextMenu: beforeContextMenu,
parent: "#noteItemList",
children: ".item-my",
}
function menuAction(target) {
// $('#myModal').modal('show')
showDialog("dialogUpdateNotebook", {title: "修改笔记本", postShow: function() {
}});
}
function applyrule(menu) {
var noteId = $(this).attr("noteId");
var note = Note.cache[noteId];
if(!note) {
return;
}
// 要disable的items
var items = [];
// 如果是trash, 什么都不能做
if(note.IsTrash) {
items.push("shareToFriends");
items.push("shareStatus");
items.push("unset2Blog");
items.push("set2Blog");
items.push("copy");
} else {
// 是否已公开为blog
if(!note.IsBlog) {
items.push("unset2Blog");
} else {
items.push("set2Blog");
}
// 移动与复制不能是本notebook下
var notebookTitle = Notebook.getNotebookTitle(note.NotebookId);
items.push("move." + notebookTitle);
items.push("copy." + notebookTitle);
}
menu.applyrule({
name: "target..",
disable: true,
items: items
});
}
function beforeContextMenu() {
return this.id != "target3";
}
// 这里很慢!!
Note.contextmenu = $("#noteItemList .item-my").contextmenu(noteListMenu);
*/
//-------------------
// 右键菜单
function noteMenu() {
var me = this;
// this.target = '';
this.menu = new gui.Menu();
this.del = new gui.MenuItem({
label: getMsg("delete"),
click: function(e) {
Note.deleteNote(self.target);
}
});
this.move = new gui.MenuItem({
label: getMsg("move"),
click: function(e) {
}
});
this.copy = new gui.MenuItem({
label: getMsg("copy"),
click: function(e) {
}
});
var ms = Note.getContextNotebooksSys(notebooks);
this.move.submenu = ms[0];
this.copy.submenu = ms[1];
this.menu.append(this.del);
this.menu.append(this.move);
this.menu.append(this.copy);
// this.menu.append(ms[0]);
// this.menu.append(ms[1]);
// You can have submenu!
// var submenu = new gui.Menu();
// submenu.append(new gui.MenuItem({ label: 'checkbox 啊' , type: 'checkbox'}));
// submenu.append(new gui.MenuItem({ label: 'Item 2', type: 'checkbox'}));
// submenu.append(new gui.MenuItem({ label: 'Item 3'}));
this.enable = function(name, ok) {
this[name].enabled = ok;
}
this.popup = function(e, target) {
self.target = target;
var noteId = $(target).attr('noteId');
var note = Note.getNote(noteId);
if(!note) {
return;
}
var notebookId = note.NotebookId;
// var notebookMenuForMove = self.menuItemsForMove[notebookId];
// var notebookMenuForCopy = self.menuItemsForCopy[notebookId];
// notebookMenuForMove.enabled = false;
// notebookMenuForCopy.enabled = false;
if(note.IsTrash) {
this.copy.enabled = false;
} else {
this.copy.enabled = true;
}
this.menu.popup(e.originalEvent.x, e.originalEvent.y);
// notebookMenuForMove.enabled = true;
// notebookMenuForCopy.enabled = true;
}
}
var noteMenuSys = new noteMenu();
Note.noteMenuSys = noteMenuSys;
};
// 附件
// 笔记的附件需要ajax获取
// 建一张附件表? attachId, noteId, 其它信息
// note里有attach_nums字段记录个数
// [ok]
var Attach = {
loadedNoteAttachs: {}, // noteId => [attch1Info, attach2Info...] // 按笔记
attachsMap: {}, // attachId => attachInfo
getAttach: function(attachId) {
return this.attachsMap[attachId];
},
init: function() {
var self = this;
var me = this;
// 显示attachs
$("#showAttach").click(function(){
self.renderAttachs(Note.curNoteId);
});
// 防止点击隐藏
self.attachListO.click(function(e) {
e.stopPropagation();
});
// 删除
self.attachListO.on("click", ".delete-attach", function(e) {
e.stopPropagation();
var attachId = $(this).closest('li').data("id");
var t = this;
if(confirm("Are you sure to delete it ?")) {
// $(t).button("loading");
self.deleteAttach(attachId);
// $(t).button("reset");
}
});
// 下载
var curAttachId = '';
self.attachListO.on("click", ".download-attach", function(e) {
e.stopPropagation();
var $li = $(this).closest('li');
var attachId = $li.data("id");
curAttachId = attachId;
$('#downloadFileInput').attr('nwsaveas', $li.find('.attach-title').text()).click();
// window.open(UrlPrefix + "/attach/download?attachId=" + attachId);
// location.href = "/attach/download?attachId=" + attachId;
});
// 下载全部
self.downloadAllBtnO.click(function() {
// window.open(UrlPrefix + "/attach/downloadAll?noteId=" + Note.curNoteId);
// location.href = "/attach/downloadAll?noteId=" + Note.curNoteId;
});
// 下载
$('#downloadFileInput').change(function(e) {
var value = $(this).val();
$(this).val('');
var curAttach = me.getAttach(curAttachId);
if(curAttach) {
FileService.download(curAttach.Path, value, function(ok, msg) {
if(!ok) {
alert(msg || "error");
} else {
// TODO 提示下载成功
}
});
} else {
alert('error');
}
});
// make link
self.attachListO.on("click", ".link-attach", function(e) {
e.stopPropagation();
var attachId = $(this).closest('li').data("id");
var attach = self.attachsMap[attachId];
var src = EvtService.getAttachLocalUrl(attachId); // + "/attach/download?attachId=" + attachId;
// http://leanote.com/attach/download?attachId=54f7481638f4112ff000170f
if(LEA.isMarkdownEditor() && MD) {
MD.insertLink(src, attach.Title);
} else {
tinymce.activeEditor.insertContent('' + attach.Title + '');
}
});
// make all link
self.linkAllBtnO.on("click",function(e) {
// 暂不支持
return;
e.stopPropagation();
var note = Note.getCurNote();
if(!note) {
return;
}
var src = EvtService.getAllAttachLocalUrl(note.NoteId); // UrlPrefix + "/attach/downloadAll?noteId=" + Note.curNoteId
// src = 'http://leanote.com/attach/downloadAll?noteId=' + note.NoteId;
var title = note.Title ? note.Title + ".tar.gz" : "all.tar.gz";
if(LEA.isMarkdownEditor() && MD) {
MD.insertLink(src, title);
} else {
tinymce.activeEditor.insertContent('' + title + '');
}
});
// 添加Attach
$('#chooseFile').click(function() {
$('#chooseFileInput').click();
});
// 得到路径, 保存文件即可
$('#chooseFileInput').change(function() {
var files = $(this).val();
$(this).val('');
// 如果是新建的笔记, 必须先保存note
var note = Note.getCurNote();
if(note && note.IsNew) {
Note.curChangedSaveIt(true);
}
FileService.addAttach(files, Note.curNoteId, function(files) {
if(files) {
me.addAttachs(files);
}
});
});
},
attachListO: $("#attachList"),
attachNumO: $("#attachNum"),
attachDropdownO: $("#attachDropdown"),
downloadAllBtnO: $("#downloadAllBtn"),
linkAllBtnO: $("#linkAllBtn"),
// 添加笔记时
clearNoteAttachNum: function() {
var self = this;
self.attachNumO.html("").hide();
},
renderNoteAttachNum: function(noteId, needHide) {
var self = this;
var note = Note.getNote(noteId);
var attachs = note.Attachs;
var attachNum = attachs ? attachs.length : 0;
if(attachNum) {
self.attachNumO.html("(" + attachNum + ")").show();
self.downloadAllBtnO.show();
self.linkAllBtnO.show();
} else {
self.attachNumO.hide();
self.downloadAllBtnO.hide();
self.linkAllBtnO.hide();
}
// 隐藏掉
if(needHide) {
self.attachDropdownO.removeClass("open");
}
},
_renderAttachs: function(attachs) {
var self = this;
// foreach 循环之
/*
leanote官abcefedafadfadfadfadfad方文档.doc
*/
var html = "";
var attachNum = attachs.length;
// console.log(attachs);
for(var i = 0; i < attachNum; ++i) {
var each = attachs[i];
var path = each.Path;
// 本地是否有, 没有, 是否是在显示的时候才去从服务器上抓? 不
var disabled = '';
if(path) {
var d = '';
} else {
d = '...'
disabled = 'disabled';
// 通过后端去下载
NoteService.downloadAttachFromServer(Note.curNoteId, each.ServerFileId, each.FileId);
}
html += '