From 8c11aad97bcca27555de1883e046efbd664b30b1 Mon Sep 17 00:00:00 2001 From: life Date: Sat, 21 Nov 2015 13:58:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=94=A8=E6=88=B7=E5=8F=91?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6,=20=E6=89=93=E5=BC=80=E5=90=84=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node_modules/user.js | 16 +++++ public/js/app/page.js | 115 ++++++++++++++++-------------- public/plugins/accounts/plugin.js | 23 ++++-- 3 files changed, 98 insertions(+), 56 deletions(-) diff --git a/node_modules/user.js b/node_modules/user.js index adc90143..a599eb1b 100644 --- a/node_modules/user.js +++ b/node_modules/user.js @@ -269,6 +269,22 @@ User = { return base + '/' + userId; }, + // 得到用户真正的DBpath, 看是否有HasDB + getUserRealDBPath: function (userId, callback) { + var me = this; + me.getUser(userId, function (user) { + if (!user) { + return callback(false); + } + if (user.HasDB) { + callback(me.getUserDBPath(userId)); + } + else { + callback(Evt.getDBPath()); + } + }); + }, + // 删除用户的文件目录 deleteUserImagesAndAttachsPath: function (userId) { var me = this; diff --git a/public/js/app/page.js b/public/js/app/page.js index b5d1bc8b..aaf48b5d 100644 --- a/public/js/app/page.js +++ b/public/js/app/page.js @@ -1456,6 +1456,11 @@ function initPage(initedCallback) { UserService.getAllUsers(function(users) { userMenu(users); }); + Api.on('deleteUser', function () { + UserService.getAllUsers(function(users) { + userMenu(users); + }); + }); setLayoutWidth(); } else { @@ -1930,6 +1935,53 @@ function setMacTopMenu() { gui.Menu.setApplicationMenu(menu); } +function getShortHost(host) { + if (!host) { + host = 'https://leanote.com'; + } + var ret = /http(s*):\/\/([a-zA-Z0-9\.\-]+)/.exec(host); + if(ret && ret.length == 3) { + host = ret[2]; + } + return host; +} + +function toggleAccount(user) { + if (!user) { + return; + } + UserService.saveCurUser({UserId: user.UserId}, function () { + reloadApp(); + }); +} + +function getToggleUserMenus(allUsers) { + if (!allUsers || !allUsers.length) { + return null; + } + var userMenus = new gui.Menu(); + for (var i = 0; i < allUsers.length; ++i) { + var user = allUsers[i]; + if (user.Username && user.UserId) { + var label = user.Username; + + var otherLabel = user.IsLocal ? getMsg('Local') : getShortHost(user.Host); + label += ' (' + otherLabel + ')'; + + userMenus.append(new gui.MenuItem({ + label: label, + enabled: !user.IsActive, + click: (function(user) { + return function() { + toggleAccount(user); + } + })(user) + })); + } + } + return userMenus; +} + // user function userMenu(allUsers) { // ---------- @@ -1945,17 +1997,6 @@ function userMenu(allUsers) { //------------------- // 右键菜单 - function getShortHost(host) { - if (!host) { - host = 'https://leanote.com'; - } - var ret = /http(s*):\/\/([a-zA-Z0-9\.\-]+)/.exec(host); - if(ret && ret.length == 3) { - host = ret[2]; - } - return host; - } - function menu() { var me = this; // this.target = ''; @@ -1983,41 +2024,10 @@ function userMenu(allUsers) { }); // 所有用户 - var allUsersMenu; - if (allUsers) { - function toggleAccount(user) { - if (!user) { - return; - } - UserService.saveCurUser({UserId: user.UserId}, function () { - reloadApp(); - }); - } - var userMenus = new gui.Menu(); - for (var i = 0; i < allUsers.length; ++i) { - var user = allUsers[i]; - if (user.Username && user.UserId) { - var label = user.Username; - - var otherLabel = user.IsLocal ? getMsg('Local') : getShortHost(user.Host); - label += ' (' + otherLabel + ')'; - - userMenus.append(new gui.MenuItem({ - label: label, - enabled: !user.IsActive, - click: (function(user) { - return function() { - toggleAccount(user); - } - })(user) - })); - } - } - allUsersMenu = new gui.MenuItem({ - label: getMsg('Switch account'), - submenu: userMenus - }); - } + var allUsersMenu = new gui.MenuItem({ + label: getMsg('Switch account'), + submenu: getToggleUserMenus(allUsers) + }); this.checkForUpdates = new gui.MenuItem({ label: getMsg('Check for updates'), @@ -2026,6 +2036,7 @@ function userMenu(allUsers) { } }); + this.menu.append(this.email); if (!UserInfo.IsLocal) {//hide sync menu for local account this.blog = new gui.MenuItem({ @@ -2121,9 +2132,14 @@ function userMenu(allUsers) { var userMenuSys = new menu(); - $('#myProfile').click(function(e) { + $('#myProfile').off().click(function(e) { userMenuSys.popup(e); }); +} + +$(function() { + initUploadImage(); + Writting.init(); // disable drag & drop document.body.addEventListener('dragover', function(e){ @@ -2134,11 +2150,6 @@ function userMenu(allUsers) { e.preventDefault(); e.stopPropagation(); }, false); -} - -$(function() { - initUploadImage(); - Writting.init(); }); // markdown editor v2 diff --git a/public/plugins/accounts/plugin.js b/public/plugins/accounts/plugin.js index bcfa13ed..e2acbd05 100644 --- a/public/plugins/accounts/plugin.js +++ b/public/plugins/accounts/plugin.js @@ -22,7 +22,10 @@ define(function() { "Open Images/Attachs Dir": "打开图片附件目录", "Delete": "删除", "Options": "操作", - "Current": "当前" + "Current": "当前", + + "Error": "错误", + "No such account": "无该帐户" }, 'zh-hk': { 'Accounts': '帐户管理', @@ -101,8 +104,18 @@ define(function() { db: function (userId) { me.dbOptimization(userId); }, - 'open-db-dir': '', - 'open-files-dir': '', + 'open-db-dir': function (userId) { + Api.userService.getUserRealDBPath(userId, function(path) { + if (!path) { + Api.gui.dialog.showErrorBox(me.getMsg("Error"), me.getMsg("No such account")); + return; + } + Api.gui.Shell.showItemInFolder(path); + }); + }, + 'open-files-dir': function (userId) { + Api.gui.Shell.showItemInFolder(Api.userService.getUserImagesAndAttachBasePath(userId)); + }, 'delete': function (userId, $targetBtn) { me.deleteUser(userId); @@ -198,7 +211,7 @@ define(function() { Api.loading.show(); Api.userService.getUser(userId, function (user) { if (!user) { - alert('Error'); + Api.gui.dialog.showErrorBox(me.getMsg("Error"), me.getMsg("No such account")); Api.loading.hide(); return; } @@ -461,6 +474,8 @@ define(function() { Api.loading.show(); Api.userService.getUser(userId, function (user) { me._deleteUser(user, function() { + Api.trigger('deleteUser'); + Api.loading.setMsg(me.getMsg('Deleted')); Api.loading.hide(2000); });