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) {
Notes.update({NoteId: noteId}, {$set: {IsTrash: true, IsDirty: true}}, function(err, n) {
if(err || !n) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -95,7 +95,7 @@ Note.clearCacheByNotebookId = function(notebookId) {
Note.cacheByNotebookId["all"] = {};
Note.notebookIds[notebookId] = true;
}
}
};
// notebook是否有notes
// called by Notebook
@@ -1870,16 +1870,54 @@ Note.getContextNotebooks = function(notebooks) {
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();
}
// 得到可移动的notebook
// 得到可move/copy的notebook
var notebooks = Notebook.everNotebooks;
var mc = self.getContextNotebooks(notebooks);
@@ -1968,7 +2006,83 @@ Note.initContextmenu = function() {
// 这里很慢!!
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获取
@@ -2385,7 +2499,12 @@ $(function() {
e.preventDefault();
e.stopPropagation();
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() {
return Notebook.curNotebookId == Notebook.trashNotebookId || Notebook.curNotebookId == Notebook.allNotebookId ;
};
Notebook.curNotebookIsTrash = function() {
return Notebook.curNotebookId == Notebook.trashNotebookId;
};
Notebook.renderNotebooks = function(notebooks) {
var self = this;
@@ -467,7 +470,14 @@ Notebook.everNotebooks = [];
Notebook.changeNav = function() {
var self = Notebook;
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);
self.everNavForNewNote = html;
@@ -943,6 +953,19 @@ Notebook.deleteNotebookFromTree = function(notebookId) {
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() {
//-------------------
// 点击notebook
@@ -958,50 +981,28 @@ $(function() {
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() {
var me = this;
this.target = '';
this.menu = new gui.Menu();
this.addSub = new gui.MenuItem({
label: 'Add sub notebook',
click: function(e) {
Notebook.addChildNotebook();
Notebook.addChildNotebook(me.target);
}
});
this.rename = new gui.MenuItem({
label: 'Rename',
click: function(e) {
Notebook.updateNotebookTitle();
Notebook.updateNotebookTitle(me.target);
}
});
this.del = new gui.MenuItem({
label: 'Delete',
click: function(e) {
Notebook.deleteNotebook();
Notebook.deleteNotebook(me.target);
}
});
@@ -1012,61 +1013,61 @@ $(function() {
this.enable = function(name, 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();
// for search
var notebookListMenu2 = {
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: getMsg("rename"), icon: "", action: Notebook.updateNotebookTitle },
{ text: getMsg("delete"), icon: "", alias: 'delete', faIcon: "fa-trash-o", action: Notebook.deleteNotebook }
],
onShow: applyrule,
onContextMenu: beforeContextMenu,
parent: "#notebookListForSearch ",
children: "li a"
// 清空回收站
function newClearTrashMenu() {
var me = this;
this.menu = new gui.Menu();
this.clear = new gui.MenuItem({
label: 'Clear trash',
click: function(e) {
Notebook.clearTrash();
}
});
this.menu.append(this.clear);
this.popup = function(e, target) {
this.menu.popup(e.originalEvent.x, e.originalEvent.y);
}
}
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);
var newClearTrashMenuSys = new newClearTrashMenu();
// 添加笔记本
$("#addNotebookPlus").click(function(e) {
e.stopPropagation();
@@ -1078,20 +1079,20 @@ $(function() {
e.preventDefault();
e.stopPropagation();
var $p = $(this).parent();
// Notebook.contextmenu.showMenu(e, $p);
// alert(newNotebookListMenuSys.popup);
newNotebookListMenuSys.menu.popup(e.originalEvent.x, e.originalEvent.y);
newNotebookListMenuSys.popup(e, $p);
});
$("#notebookList").on('contextmenu', 'li a', function(e) {
newNotebookListMenuSys.popup(e, $(this));
});
$("#notebookList ").on('contextmenu', 'li a', function(e) {
newNotebookListMenuSys.menu.popup(e.originalEvent.x, e.originalEvent.y);
$("#notebookListForSearch").on('contextmenu', 'li a', function(e) {
newNotebookListMenuSys.popup(e, $(this), true);
});
$("#notebookListForSearch").on("click", ".notebook-setting", function(e) {
e.preventDefault();
e.stopPropagation();
var $p = $(this).parent();
Notebook.contextmenuSearch.showMenu(e, $p);
newNotebookListMenuSys.popup(e, $p, true);
});
});