Commit 69bdc4e6 authored by techird's avatar techird

share-edit

parent 64b250b0
......@@ -8,6 +8,7 @@
"white": false,
"quotmark": false,
"browser": true,
"boss": true,
"predef" : [
"module",
"require",
......
......@@ -54,6 +54,8 @@ KityMinder.LANG['zh-cn'] = {
'err_create_share': '分享失败',
'err_mkdir': '目录创建失败',
'err_ls': '读取目录失败',
'err_share_data': '加载分享内容出错',
'err_share_sync_fail': '分享内容同步失败',
'unknownreason': '可能是外星人篡改了代码...',
'pcs_code': {
......@@ -126,6 +128,8 @@ KityMinder.LANG['zh-cn'] = {
}
},
'ui': {
'load_share_for_edit': '正在加载分享的文件...',
'share_sync_success': '分享内容已同步',
'error_detail': '详细信息',
'copy_and_feedback': '复制并反馈',
......@@ -157,7 +161,8 @@ KityMinder.LANG['zh-cn'] = {
'new': '新建 (Ctrl + Alt + N)',
'save': '保存 (Ctrl + S)',
'share': '分享 (Ctrl + Alt + S)',
'feedback': '反馈问题(F1)'
'feedback': '反馈问题(F1)',
'editshare': '编辑'
},
'menu': {
......@@ -212,7 +217,7 @@ KityMinder.LANG['zh-cn'] = {
'email_share': '邮件邀请',
'url_share': '脑图 URL 地址:',
'sns_share': '社交网络分享:',
'sns_share_text': '“{0}” - 我用「百度脑图」制作的思维导图,快看看吧!(地址:{1})',
'sns_share_text': '“{0}” - 我用百度脑图制作的思维导图,快看看吧!(地址:{1})',
'none_share_description': '不分享当前脑图',
'public_share_description': '创建任何人可见的分享',
'share_button_text': '创建',
......
......@@ -17,13 +17,40 @@ KityMinder.registerUI('menu/default', function(minder) {
var $share = minder.getUI('menu/share/share');
var $draft = minder.getUI('menu/open/draft');
setMenuDefaults();
loadLandingFile();
// $menu.show();
// $menu.$tabs.select(5);
function setMenuDefaults() {
// 主菜单默认选中「打开」
$menu.$tabs.select(1);
// 打开菜单默认选中「本地文件」
$open.$tabs.select(2);
if ($draft.hasDraft()) {
// 保存菜单默认选中「导出到本地」
$save.$tabs.select(1);
// 如果用户登陆了,选中「百度云存储」
fio.user.check().then(function(user) {
if (user) {
$save.$tabs.select(0);
}
});
$share.$menu.$tabs.select(0); // 当前脑图
}
function loadLandingFile() {
var pattern = /(?:shareId|share_id)=(\w+)([&#]|$)/;
var match = pattern.exec(window.location) || pattern.exec(document.referrer);
if (match) {
$share.loadShareFile();
}
else if ($draft.hasDraft()) {
// 草稿箱有草稿,默认选中「草稿箱」,并打开最近编辑的文件
$open.$tabs.select(3);
$draft.openLast();
......@@ -43,19 +70,6 @@ KityMinder.registerUI('menu/default', function(minder) {
}
});
}
// 保存菜单默认选中「导出到本地」
$save.$tabs.select(1);
// 如果用户登陆了,选中「百度云存储」
fio.user.check().then(function(user) {
if (user) {
$save.$tabs.select(0);
}
});
$share.$tabs.select(0); // 当前脑图
// $menu.show();
// $menu.$tabs.select(5);
});
});
\ No newline at end of file
......@@ -41,7 +41,7 @@ KityMinder.registerUI('menu/open/netdisk', function(minder) {
return open(file.path);
});
function open(path) {
function open(path, errorHandler) {
$menu.hide();
......@@ -74,10 +74,10 @@ KityMinder.registerUI('menu/open/netdisk', function(minder) {
}
function error(e) {
return notice.error('err_load', e);
return errorHandler && errorHandler(e) || notice.error('err_load', e);
}
return read().then(load, error).then(function() {
return read().then(load)['catch'](error).then(function() {
$(minder.getRenderTarget()).removeClass('loading');
......
......@@ -129,7 +129,7 @@ KityMinder.registerUI('menu/save/download', function(minder) {
netdisk.mute = true;
setTimeout(function() {
netdisk.mute = false;
});
}, 1000);
}
$form.appendTo('body').submit().remove();
......
......@@ -12,6 +12,7 @@ KityMinder.registerUI('menu/share/share', function(minder) {
var $create_menu = $($share_menu.createSub('createshare'));
var $manage_menu = $($share_menu.createSub('manageshare'));
var $doc = minder.getUI('doc');
var notice = minder.getUI('widget/notice');
var BACKEND_URL = 'http://naotu.baidu.com/share.php';
......@@ -20,7 +21,11 @@ KityMinder.registerUI('menu/share/share', function(minder) {
renderCreatePanel().then(bindCreatePanelEvent);
renderManagePanel();
var shareListLoaded = loadShareList().then(bindManageActions);
var shareListLoaded = loadShareList();
shareListLoaded.then(renderShareList);
shareListLoaded.then(bindManageActions);
minder.on('uiready', function() {
minder.getUI('topbar/user').requireLogin($manage_menu);
......@@ -52,10 +57,93 @@ KityMinder.registerUI('menu/share/share', function(minder) {
id: shared.id || shared.shareMinder.id,
record: doc.json
}
}).then(function() {
notice.info(minder.getLang('ui.share_sync_success', doc.title));
})['catch'](function(e) {
notice.error('err_share_sync_failed', e);
});
});
}
});
function loadShareFile() {
var pattern = /(?:shareId|share_id)=(\w+)([&#]|$)/;
var match = pattern.exec(window.location) || pattern.exec(document.referrer);
if (!match) return Promise.resolve(null);
var shareId = match[1];
$(minder.getRenderTarget()).addClass('loading');
shareListLoaded.then(function(list) {
for (var i = 0; i < list.length; i++) {
var id = list[i].id || list[i].shareMinder.id;
if (id == shareId && list[i].path) {
return loadOriginFile(list[i]);
}
}
return loadShare(shareId);
});
}
function loadOriginFile(share) {
var $netdisk = minder.getUI('menu/open/netdisk');
notice.info(minder.getLang('ui.load_share_for_edit', share.title));
return $netdisk.open(share.path, function() {
// 网盘加载失败
return loadShare(share);
});
}
function loadShare(shareId) {
function renderShareData(data) {
if (data.error) {
notice.error('err_share_data', data.error);
return;
}
var content = data.shareMinder.data;
return $doc.load({
source: 'share',
content: content,
protocol: 'json',
saved: true,
ownerId: data.uid,
ownerName: data.uname
});
}
var $container = $(minder.getRenderTarget()).addClass('loading');
return $.pajax({
url: 'http://naotu.baidu.com/share.php',
data: {
action: 'find',
id: shareId
},
dataType: 'json'
}).then(renderShareData)['catch'](function(e) {
notice.error('err_share_data', e);
}).then(function() {
$container.removeClass('loading');
});
}
function getShareByPath(path) {
if (!path || !shareList) return null;
......@@ -151,9 +239,7 @@ KityMinder.registerUI('menu/share/share', function(minder) {
return;
case $target.hasClass('edit-action'):
var $netdisk = minder.getUI('menu/open/netdisk');
$netdisk.open(share.path);
loadOriginFile(share);
return;
}
});
......@@ -316,7 +402,7 @@ KityMinder.registerUI('menu/share/share', function(minder) {
return fio.user.check().then(function(user) {
if (!user) return;
$.pajax(BACKEND_URL, {
return $.pajax(BACKEND_URL, {
type: 'GET',
......@@ -331,7 +417,7 @@ KityMinder.registerUI('menu/share/share', function(minder) {
return (shareList = result.list || []);
}).then(renderShareList);
});
});
}
......@@ -431,5 +517,8 @@ KityMinder.registerUI('menu/share/share', function(minder) {
}
}
return $share_menu;
return {
$menu: $share_menu,
loadShareFile: loadShareFile
};
});
\ No newline at end of file
......@@ -51,6 +51,16 @@
}
}
&.editshare {
margin-right: 5px;
float: right;
&:after {
top: 6.5px;
left: 7px;
background-position: 0 -1060px;
}
}
&:hover {
background-color: @tab-hover;
}
......
......@@ -1973,6 +1973,15 @@ body {
left: 7px;
background-position: 0 -970px;
}
#panel .quick-visit-button.editshare {
margin-right: 5px;
float: right;
}
#panel .quick-visit-button.editshare:after {
top: 6.5px;
left: 7px;
background-position: 0 -1060px;
}
#panel .quick-visit-button:hover {
background-color: #5a6378;
}
......
This diff is collapsed.
ui/theme/default/images/icons.png

19.2 KB | W: | H:

ui/theme/default/images/icons.png

19.9 KB | W: | H:

ui/theme/default/images/icons.png
ui/theme/default/images/icons.png
ui/theme/default/images/icons.png
ui/theme/default/images/icons.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -59,10 +59,10 @@
}
});
$.ajaxSetup({ cache: false });
$.extend($, {
pajax: function(opt) {
opt.cache = false;
return Promise.resolve($.ajax(opt));
pajax: function() {
return Promise.resolve($.ajax.apply($, arguments));
}
});
......
......@@ -25,6 +25,10 @@ KityMinder.registerUI('widget/notice', function (minder) {
className: 'error-dialog'
}).appendTo(document.getElementById('content-wrapper'));
$error.on('ok cancel', function(e) {
if (error.resolve) error.resolve(e);
});
var $error_body = $($error.getBodyElement());
var isBuilded = (function() {
......@@ -205,6 +209,10 @@ KityMinder.registerUI('widget/notice', function (minder) {
$error.show();
$error.getElement().style.top = '180px';
return new Promise(function(resolve) {
error.resolve = resolve;
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment