mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-18 09:24:55 +00:00
import leanote ok
This commit is contained in:
216
public/plugins/import_leanote/plugin.js
Normal file
216
public/plugins/import_leanote/plugin.js
Normal file
@@ -0,0 +1,216 @@
|
||||
/**
|
||||
* 导入leanote, 重构
|
||||
* @author life@leanote.com
|
||||
* @date 2015/04/09
|
||||
*/
|
||||
define(function() {
|
||||
var importService = nodeRequire('./public/plugins/import_leanote/import');
|
||||
|
||||
var leanote = {
|
||||
|
||||
langs: {
|
||||
'en-us': {
|
||||
'importLeanote': 'Import Leanote',
|
||||
},
|
||||
'zh-cn': {
|
||||
'importLeanote': '导入Leanote',
|
||||
'Choose Leanote files(.enex)': '选择Leanote文件(.enex)',
|
||||
'Close': "关闭",
|
||||
'Import to': "导入至",
|
||||
"Done! %s notes imported!": "完成, 成功导入 %s 个笔记!",
|
||||
"Import file: %s Success!": "文件 %s 导入成功!",
|
||||
"Import file: %s Failure, is leanote file ?": "文件 %s 导入失败! 是Leanote文件?",
|
||||
"Import: %s Success!": "导入笔记: %s 成功!"
|
||||
},
|
||||
'zh-hk': {
|
||||
'importLeanote': '導入Leanote',
|
||||
'Choose Leanote files(.enex)': '選擇Leanote文件(.enex)',
|
||||
'Close': "關閉",
|
||||
"Import to": "導入至",
|
||||
"Done! %s notes imported!": "完成, 成功導入 %s 個筆記!",
|
||||
"Import file: %s Success!": "文件 %s 導入成功!",
|
||||
"Import file: %s Failure, is leanote file ?": "文件 %s 導入失敗! 是Leanote文件?",
|
||||
"Import: %s Success!": "導入筆記: %s 成功!"
|
||||
}
|
||||
},
|
||||
|
||||
_tpl: `
|
||||
<style>
|
||||
#importLeanoteDialog .tab-pane {
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
padding-top: 20px;
|
||||
}
|
||||
#importLeanoteDialog .alert {
|
||||
margin-top: 10px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
}
|
||||
</style>
|
||||
<div class="modal fade bs-modal-sm" id="importLeanoteDialog" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
|
||||
<div class="modal-dialog modal-sm">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title" class="modalTitle"><span class="lang">Import to</span> <span id="importDialogNotebook"></span></h4>
|
||||
</div>
|
||||
<div class="modal-body" id="">
|
||||
<div role="tabpanel">
|
||||
|
||||
<!-- Nav tabs -->
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
<li role="presentation" class="active"><a href="#leanoteTab" aria-controls="leanoteTab" role="tab" data-toggle="tab">Leanote</a></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
<div role="tabpanel" class="tab-pane active" id="leanoteTab">
|
||||
<!-- import -->
|
||||
<a id="chooseLeanoteFile" class="btn btn-success btn-choose-file">
|
||||
<i class="fa fa-upload"></i>
|
||||
<span class="lang">Choose Leanote files(.leanote)</span>
|
||||
</a>
|
||||
<!-- 消息 -->
|
||||
<div id="importLeanoteMsg" class="alert alert-info">
|
||||
<div class="curImportFile"></div>
|
||||
<div class="curImportNote"></div>
|
||||
<div class="allImport"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="youdaoTab">
|
||||
<!-- 文件选择框 -->
|
||||
<input id="importLeanoteInput" type="file" nwsaveas="" accept=".enex" multiple style="" style="display: none"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer ">
|
||||
<button type="button" class="btn btn-default upgrade-cancel-btn lang" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
`,
|
||||
_importDialog: null,
|
||||
_curNotebook: null,
|
||||
_inited: false,
|
||||
|
||||
getMsg: function(txt, data) {
|
||||
return Api.getMsg(txt, 'plugin.import_leanote', data)
|
||||
},
|
||||
|
||||
init: function() {
|
||||
var me = this;
|
||||
me._inited = true;
|
||||
$('body').append(me._tpl);
|
||||
me._importDialog = $("#importLeanoteDialog");
|
||||
|
||||
me._importDialog.find('.lang').each(function() {
|
||||
var txt = $.trim($(this).text());
|
||||
$(this).text(me.getMsg(txt));
|
||||
});
|
||||
|
||||
// 导入, 选择文件
|
||||
$('#chooseLeanoteFile').click(function() {
|
||||
|
||||
Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(),
|
||||
{
|
||||
properties: ['openFile', 'multiSelections'],
|
||||
filters: [
|
||||
{ name: 'Leanote', extensions: ['leanote'] }
|
||||
]
|
||||
},
|
||||
function(paths) {
|
||||
if(!paths) {
|
||||
return;
|
||||
}
|
||||
|
||||
var notebookId = me._curNotebook.NotebookId;
|
||||
|
||||
var n = 0;
|
||||
|
||||
me.clear();
|
||||
|
||||
importService.importFromLeanote(notebookId, paths,
|
||||
// 全局
|
||||
function(ok) {
|
||||
// $('#importLeanoteMsg .curImportFile').html("");
|
||||
// $('#importLeanoteMsg .curImportNote').html("");
|
||||
setTimeout(function() {
|
||||
$('#importLeanoteMsg .allImport').html(me.getMsg('Done! %s notes imported!', n));
|
||||
}, 500);
|
||||
},
|
||||
// 单个文件
|
||||
function(ok, filename) {
|
||||
if(ok) {
|
||||
$('#importLeanoteMsg .curImportFile').html(me.getMsg("Import file: %s Success!", filename));
|
||||
} else {
|
||||
$('#importLeanoteMsg .curImportFile').html(me.getMsg("Import file: %s Failure, is leanote file ?", filename));
|
||||
}
|
||||
},
|
||||
// 单个笔记
|
||||
function(note) {
|
||||
if(note) {
|
||||
n++;
|
||||
$('#importLeanoteMsg .curImportNote').html(me.getMsg("Import: %s Success!", note.Title));
|
||||
|
||||
// 插入到当前笔记中
|
||||
Note.addSync([note]);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
clear: function() {
|
||||
$('#importLeanoteMsg .curImportFile').html("");
|
||||
$('#importLeanoteMsg .curImportNote').html("");
|
||||
$('#importLeanoteMsg .allImport').html('');
|
||||
},
|
||||
|
||||
open: function(notebook) {
|
||||
var me = this;
|
||||
if(!notebook) {
|
||||
return;
|
||||
}
|
||||
if(!me._inited) {
|
||||
me.init();
|
||||
}
|
||||
me.clear();
|
||||
|
||||
$('#importDialogNotebook').html(notebook.Title);
|
||||
|
||||
me._curNotebook = notebook;
|
||||
var notebookId = notebook.NotebookId;
|
||||
me._importDialog.modal('show');
|
||||
},
|
||||
|
||||
// 打开前要执行的
|
||||
onOpen: function() {
|
||||
var me = this;
|
||||
var gui = Api.gui;
|
||||
|
||||
Api.addImportMenu({
|
||||
label: Api.getMsg('plugin.import_leanote.importLeanote'),
|
||||
click: (function() {
|
||||
return function(notebook) {
|
||||
me.open(notebook);
|
||||
};
|
||||
})()
|
||||
});
|
||||
},
|
||||
// 打开后
|
||||
onOpenAfter: function() {
|
||||
},
|
||||
// 关闭时需要运行的
|
||||
onClose: function() {
|
||||
}
|
||||
};
|
||||
|
||||
return leanote;
|
||||
});
|
Reference in New Issue
Block a user