context-menu

todo, theme context-menu
This commit is contained in:
life
2015-03-03 22:04:27 +08:00
parent c1c393e864
commit 55b650a086
16 changed files with 245 additions and 100 deletions

7
node_modules/note.js generated vendored
View File

@@ -243,6 +243,13 @@ var Note = {
}); });
}, },
clearTrash: function(callback) {
var me = this;
var userId = User.getCurActiveUserId();
Notes.update({UserId: userId, IsTrash: true}, {$set: {LocalIsDelete: true, IsDirty: true}}, {multi: true}, function(err, n) {
callback && callback();
});
},
deleteNote: function(noteId, callback) { deleteNote: function(noteId, callback) {
Notes.update({NoteId: noteId}, {$set: {IsTrash: true, IsDirty: true}}, function(err, n) { Notes.update({NoteId: noteId}, {$set: {IsTrash: true, IsDirty: true}}, function(err, n) {
if(err || !n) { if(err || !n) {

View File

@@ -6,8 +6,8 @@
"window": { "window": {
"toolbar": true, "toolbar": true,
"frame": false, "frame": true,
"transparent": true, "transparent": false,
"min_width": 400, "min_width": 400,
"min_height": 200, "min_height": 200,

View File

@@ -999,7 +999,7 @@ h1, h2, h3 {
position: relative; position: relative;
height: 110px; height: 110px;
overflow: hidden; overflow: hidden;
cursor: pointer; cursor: default;
border: 1px solid @borderColor; border: 1px solid @borderColor;
border-radius: 3px; border-radius: 3px;
margin-top: 5px; margin-top: 5px;
@@ -1345,6 +1345,9 @@ top: 4px;
text-align: center; text-align: center;
font-style: 16px; font-style: 16px;
text-overflow:ellipsis; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; overflow:hidden;
span {
cursor: default;
}
} }
#searchNote { #searchNote {
margin-top: 2px; margin-top: 2px;
@@ -1594,7 +1597,7 @@ html,body, #page, #pageInner {
} }
body { body {
// #notesAndSort { // #notesAndSort {
// -webkit-user-select: none; -webkit-user-select: none; // input, textarea还是可以选择的
-webkit-app-region: drag; -webkit-app-region: drag;
border: 1px solid #ccc; border: 1px solid #ccc;
// for shadow // for shadow
@@ -1607,7 +1610,6 @@ body {
} }
#page { #page {
#pageInner { #pageInner {
} }
} }
#leftNotebook { #leftNotebook {

View File

@@ -920,7 +920,7 @@ h3 {
position: relative; position: relative;
height: 110px; height: 110px;
overflow: hidden; overflow: hidden;
cursor: pointer; cursor: default;
border: 1px solid #ebeff2; border: 1px solid #ebeff2;
border-radius: 3px; border-radius: 3px;
margin-top: 5px; margin-top: 5px;
@@ -1226,6 +1226,9 @@ h3 {
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
} }
#myNotebookNavForListNav span {
cursor: default;
}
#searchNote { #searchNote {
margin-top: 2px; margin-top: 2px;
} }
@@ -1441,6 +1444,7 @@ body,
background: transparent; background: transparent;
} }
body { body {
-webkit-user-select: none;
-webkit-app-region: drag; -webkit-app-region: drag;
border: 1px solid #ccc; border: 1px solid #ccc;
left: 5px; left: 5px;

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 KiB

View File

@@ -920,7 +920,7 @@ h3 {
position: relative; position: relative;
height: 110px; height: 110px;
overflow: hidden; overflow: hidden;
cursor: pointer; cursor: default;
border: 1px solid #ebeff2; border: 1px solid #ebeff2;
border-radius: 3px; border-radius: 3px;
margin-top: 5px; margin-top: 5px;
@@ -1226,6 +1226,9 @@ h3 {
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
} }
#myNotebookNavForListNav span {
cursor: default;
}
#searchNote { #searchNote {
margin-top: 2px; margin-top: 2px;
} }
@@ -1441,6 +1444,7 @@ body,
background: transparent; background: transparent;
} }
body { body {
-webkit-user-select: none;
-webkit-app-region: drag; -webkit-app-region: drag;
border: 1px solid #ccc; border: 1px solid #ccc;
left: 5px; left: 5px;

View File

@@ -920,7 +920,7 @@ h3 {
position: relative; position: relative;
height: 110px; height: 110px;
overflow: hidden; overflow: hidden;
cursor: pointer; cursor: default;
border: 1px solid #ebeff2; border: 1px solid #ebeff2;
border-radius: 3px; border-radius: 3px;
margin-top: 5px; margin-top: 5px;
@@ -1226,6 +1226,9 @@ h3 {
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
} }
#myNotebookNavForListNav span {
cursor: default;
}
#searchNote { #searchNote {
margin-top: 2px; margin-top: 2px;
} }
@@ -1441,6 +1444,7 @@ body,
background: transparent; background: transparent;
} }
body { body {
-webkit-user-select: none;
-webkit-app-region: drag; -webkit-app-region: drag;
border: 1px solid #ccc; border: 1px solid #ccc;
left: 5px; left: 5px;

View File

@@ -920,7 +920,7 @@ h3 {
position: relative; position: relative;
height: 110px; height: 110px;
overflow: hidden; overflow: hidden;
cursor: pointer; cursor: default;
border: 1px solid #ebeff2; border: 1px solid #ebeff2;
border-radius: 3px; border-radius: 3px;
margin-top: 5px; margin-top: 5px;
@@ -1226,6 +1226,9 @@ h3 {
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
} }
#myNotebookNavForListNav span {
cursor: default;
}
#searchNote { #searchNote {
margin-top: 2px; margin-top: 2px;
} }
@@ -1441,6 +1444,7 @@ body,
background: transparent; background: transparent;
} }
body { body {
-webkit-user-select: none;
-webkit-app-region: drag; -webkit-app-region: drag;
border: 1px solid #ccc; border: 1px solid #ccc;
left: 5px; left: 5px;

View File

@@ -95,7 +95,7 @@ Note.clearCacheByNotebookId = function(notebookId) {
Note.cacheByNotebookId["all"] = {}; Note.cacheByNotebookId["all"] = {};
Note.notebookIds[notebookId] = true; Note.notebookIds[notebookId] = true;
} }
} };
// notebook是否有notes // notebook是否有notes
// called by Notebook // called by Notebook
@@ -1870,16 +1870,54 @@ Note.getContextNotebooks = function(notebooks) {
copys2.push(copy2); copys2.push(copy2);
} }
return [moves, copys, copys2]; 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调用 // Notebook调用
Note.contextmenu = null; Note.contextmenu = null;
Note.notebooksCopy = []; // share会用到 Note.notebooksCopy = []; // share会用到
Note.initContextmenu = function() { Note.initContextmenu = function() {
var self = Note; var self = Note;
var notebooks = Notebook.everNotebooks;
/*
if(Note.contextmenu) { if(Note.contextmenu) {
Note.contextmenu.destroy(); Note.contextmenu.destroy();
} }
// 得到可移动的notebook // 得到可move/copy的notebook
var notebooks = Notebook.everNotebooks; var notebooks = Notebook.everNotebooks;
var mc = self.getContextNotebooks(notebooks); var mc = self.getContextNotebooks(notebooks);
@@ -1968,7 +2006,83 @@ Note.initContextmenu = function() {
// 这里很慢!! // 这里很慢!!
Note.contextmenu = $("#noteItemList .item-my").contextmenu(noteListMenu); 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获取 // 笔记的附件需要ajax获取
@@ -2385,7 +2499,12 @@ $(function() {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
var $p = $(this).parent(); var $p = $(this).parent();
Note.contextmenu.showMenu(e, $p); Note.noteMenuSys.popup(e, $p);
});
$("#noteItemList").on("contextmenu", "li", function(e) {
e.preventDefault();
e.stopPropagation();
Note.noteMenuSys.popup(e, $(this));
}); });
// 收藏 // 收藏

View File

@@ -290,6 +290,9 @@ Notebook.trashNotebookId = "-1";
Notebook.curNotebookIsTrashOrAll = function() { Notebook.curNotebookIsTrashOrAll = function() {
return Notebook.curNotebookId == Notebook.trashNotebookId || Notebook.curNotebookId == Notebook.allNotebookId ; return Notebook.curNotebookId == Notebook.trashNotebookId || Notebook.curNotebookId == Notebook.allNotebookId ;
}; };
Notebook.curNotebookIsTrash = function() {
return Notebook.curNotebookId == Notebook.trashNotebookId;
};
Notebook.renderNotebooks = function(notebooks) { Notebook.renderNotebooks = function(notebooks) {
var self = this; var self = this;
@@ -467,7 +470,14 @@ Notebook.everNotebooks = [];
Notebook.changeNav = function() { Notebook.changeNav = function() {
var self = Notebook; var self = Notebook;
var notebooks = Notebook.tree.getNodes(); var notebooks = Notebook.tree.getNodes();
var pureNotebooks = notebooks.slice(1, -1); // 不含新和垃圾 var pureNotebooks = []; // 不含新和垃圾
for(var i = 0; i < notebooks.length; ++i) {
var notebookId = notebooks[i].NotebookId;
if(Notebook.isAllNotebookId(notebookId) || Notebook.isTrashNotebookId(notebookId)) {
} else {
pureNotebooks.push(notebooks[i]);
}
}
var html = self.getChangedNotebooks(pureNotebooks); var html = self.getChangedNotebooks(pureNotebooks);
self.everNavForNewNote = html; self.everNavForNewNote = html;
@@ -943,6 +953,19 @@ Notebook.deleteNotebookFromTree = function(notebookId) {
Notebook.changeNav(); Notebook.changeNav();
}; };
// 清空垃圾
Notebook.clearTrash = function() {
var me = this;
if(confirm('Are you sure ?')) {
NoteService.clearTrash(function() {
if(Notebook.curNotebookId == Notebook.trashNotebookId) {
Note.clearAll();
Note.showEditorMask();
}
});
}
};
$(function() { $(function() {
//------------------- //-------------------
// 点击notebook // 点击notebook
@@ -958,50 +981,28 @@ $(function() {
Notebook.changeNotebook(notebookId); Notebook.changeNotebook(notebookId);
}); });
// 修改笔记本标题, blur后修改标题之
/*
enterBlur("#notebookList", "input#editNotebookTitle");
$("#notebookList").on("blur", "input#editNotebookTitle", Notebook.doUpdateNotebookTitle);
*/
//------------------- //-------------------
// 右键菜单 // 右键菜单
var notebookListMenu = {
width: 180,
items: [
// { text: getMsg("shareToFriends"), alias: 'shareToFriends', icon: "", faIcon: "fa-share-square-o", action: Notebook.listNotebookShareUserInfo},
// { type: "splitLine" },
// { text: getMsg("publicAsBlog"), alias: 'set2Blog', faIcon: "fa-bold", action: Notebook.setNotebook2Blog },
// { text: getMsg("cancelPublic"), alias: 'unset2Blog',faIcon: "fa-undo", action: Notebook.setNotebook2Blog }, // Unset
// { type: "splitLine" },
{ text: 'Add sub notebook', faIcon: "fa-sitemap", action: Notebook.addChildNotebook },
{ text: getMsg("rename"), faIcon: "fa-pencil", action: Notebook.updateNotebookTitle },
{ text: getMsg("delete"), icon: "", alias: 'delete', faIcon: "fa-trash-o", action: Notebook.deleteNotebook }
],
onShow: applyrule,
onContextMenu: beforeContextMenu,
parent: "#notebookList ",
children: "li a"
};
function newNotebookListMenu() { function newNotebookListMenu() {
var me = this;
this.target = '';
this.menu = new gui.Menu(); this.menu = new gui.Menu();
this.addSub = new gui.MenuItem({ this.addSub = new gui.MenuItem({
label: 'Add sub notebook', label: 'Add sub notebook',
click: function(e) { click: function(e) {
Notebook.addChildNotebook(); Notebook.addChildNotebook(me.target);
} }
}); });
this.rename = new gui.MenuItem({ this.rename = new gui.MenuItem({
label: 'Rename', label: 'Rename',
click: function(e) { click: function(e) {
Notebook.updateNotebookTitle(); Notebook.updateNotebookTitle(me.target);
} }
}); });
this.del = new gui.MenuItem({ this.del = new gui.MenuItem({
label: 'Delete', label: 'Delete',
click: function(e) { click: function(e) {
Notebook.deleteNotebook(); Notebook.deleteNotebook(me.target);
} }
}); });
@@ -1012,61 +1013,61 @@ $(function() {
this.enable = function(name, ok) { this.enable = function(name, ok) {
this[name].enabled = ok; this[name].enabled = ok;
} }
this.popup = function(e, target, isSearch) {
me.target = target;
var notebookId = $(target).attr("notebookId");
if(Notebook.isTrashNotebookId(notebookId)) {
newClearTrashMenuSys.popup(e);
return;
}
if(Notebook.isAllNotebookId(notebookId)) {
return;
}
var notebook = Notebook.cache[notebookId];
if(!notebook) {
return;
}
// 是否已公开为blog
/*
if(!notebook.IsBlog) {
items.push("unset2Blog");
} else {
items.push("set2Blog");
}
*/
// 是否还有笔记
if(Note.notebookHasNotes(notebookId)) {
this.del.enabled = false;
} else {
this.del.enabled = true;
}
if(isSearch) {
this.addSub.enabled = false;
} else {
this.addSub.enabled = true;
}
this.menu.popup(e.originalEvent.x, e.originalEvent.y);
}
} }
var newNotebookListMenuSys = new newNotebookListMenu(); var newNotebookListMenuSys = new newNotebookListMenu();
// for search // 清空回收站
var notebookListMenu2 = { function newClearTrashMenu() {
width: 180, var me = this;
items: [ this.menu = new gui.Menu();
// { text: getMsg("shareToFriends"), alias: 'shareToFriends', icon: "", faIcon: "fa-share-square-o", action: Notebook.listNotebookShareUserInfo}, this.clear = new gui.MenuItem({
// { type: "splitLine" }, label: 'Clear trash',
// { text: getMsg("publicAsBlog"), alias: 'set2Blog', faIcon: "fa-bold", action: Notebook.setNotebook2Blog }, click: function(e) {
// { text: getMsg("cancelPublic"), alias: 'unset2Blog',faIcon: "fa-undo", action: Notebook.setNotebook2Blog }, // Unset Notebook.clearTrash();
// { type: "splitLine" }, }
{ text: getMsg("rename"), icon: "", action: Notebook.updateNotebookTitle }, });
{ text: getMsg("delete"), icon: "", alias: 'delete', faIcon: "fa-trash-o", action: Notebook.deleteNotebook } this.menu.append(this.clear);
], this.popup = function(e, target) {
onShow: applyrule, this.menu.popup(e.originalEvent.x, e.originalEvent.y);
onContextMenu: beforeContextMenu, }
parent: "#notebookListForSearch ",
children: "li a"
} }
var newClearTrashMenuSys = new newClearTrashMenu();
function applyrule(menu) {
var notebookId = $(this).attr("notebookId");
var notebook = Notebook.cache[notebookId];
if(!notebook) {
return;
}
// disabled的items
var items = [];
// 是否已公开为blog
if(!notebook.IsBlog) {
items.push("unset2Blog");
} else {
items.push("set2Blog");
}
// 是否还有笔记
if(Note.notebookHasNotes(notebookId)) {
items.push("delete");
}
menu.applyrule({
name: "target2",
disable: true,
items: items
});
}
// 哪个不能
function beforeContextMenu() {
var notebookId = $(this).attr("notebookId");
return !Notebook.isTrashNotebookId(notebookId) && !Notebook.isAllNotebookId(notebookId);
}
// Notebook.contextmenu = $("#notebookList li a").contextmenu(notebookListMenu);
Notebook.contextmenuSearch = $("#notebookListForSearch li a").contextmenu(notebookListMenu2);
// 添加笔记本 // 添加笔记本
$("#addNotebookPlus").click(function(e) { $("#addNotebookPlus").click(function(e) {
e.stopPropagation(); e.stopPropagation();
@@ -1078,20 +1079,20 @@ $(function() {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
var $p = $(this).parent(); var $p = $(this).parent();
// Notebook.contextmenu.showMenu(e, $p); newNotebookListMenuSys.popup(e, $p);
// alert(newNotebookListMenuSys.popup); });
newNotebookListMenuSys.menu.popup(e.originalEvent.x, e.originalEvent.y); $("#notebookList").on('contextmenu', 'li a', function(e) {
newNotebookListMenuSys.popup(e, $(this));
}); });
$("#notebookList ").on('contextmenu', 'li a', function(e) { $("#notebookListForSearch").on('contextmenu', 'li a', function(e) {
newNotebookListMenuSys.menu.popup(e.originalEvent.x, e.originalEvent.y); newNotebookListMenuSys.popup(e, $(this), true);
}); });
$("#notebookListForSearch").on("click", ".notebook-setting", function(e) { $("#notebookListForSearch").on("click", ".notebook-setting", function(e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
var $p = $(this).parent(); var $p = $(this).parent();
Notebook.contextmenuSearch.showMenu(e, $p); newNotebookListMenuSys.popup(e, $p, true);
}); });
}); });