网络断开时, auth检查

sync还有问题
This commit is contained in:
life
2015-02-11 23:50:02 +08:00
parent 225bcd7cf0
commit 269f68620c
13 changed files with 322 additions and 72 deletions

58
node_modules/api.js generated vendored
View File

@@ -5,6 +5,7 @@ var Note = require('note');
var Tag = require('tag');
var Notebook = require('notebook');
var Common = require('common');
var Web = require('web');
var Tags = db.tags;
var needle = require('needle');
var fs = require('fs');
@@ -20,6 +21,39 @@ function log(o) {
var Api = {
leanoteUrl: 'http://localhost:9000',
baseUrl: 'http://localhost:9000/api',
// 检查错误
checkError: function(error, resp) {
var me = this;
me.unConnected(error);
// 是否需要重新登录
/*{
"Ok": false,
"Code": 1,
"Msg": "NOTLOGIN",
"Id": "",
"List": null,
"Item": null
}*/
var ret = resp;
try {
if(typeof ret == 'object') {
if(!ret['Ok'] && ret['Msg'] == 'NOTLOGIN') {
Web.notLogin();
}
}
} catch(e) {}
},
// 是否断网
unConnected: function(error) {
var me = this;
if(error && error.code == "ECONNREFUSED") {
console.log(error);
Web.unConnected();
return true;
}
return false;
},
getUrl: function(url, param) {
if(!User) {
}
@@ -44,6 +78,7 @@ var Api = {
// log({emai: email, pwd: pwd});
// log(this.getUrl('auth/login', {email: email, pwd: pwd}));
needle.get(this.getUrl('auth/login', {email: email, pwd: pwd}), function(error, response) {
me.checkError(error, response);
if(error) {
return callback && callback(false);
}
@@ -105,12 +140,14 @@ var Api = {
var me = this;
var url = this.getUrl('notebook/getSyncNotebooks', {afterUsn: afterUsn, maxEntry: maxEntry});
needle.get(url, function(error, response) {
me.checkError(error, response);
if(error) {
console.log(error);
return callback && callback(false);
}
var ret = response.body;
log(ret);
log(Common);
console.log(ret);
console.log(response);
if(Common.isOk(ret)) {
callback && callback(ret);
} else {
@@ -123,6 +160,7 @@ var Api = {
var url = this.getUrl('note/getSyncNotes', {afterUsn: afterUsn, maxEntry: maxEntry});
log(url);
needle.get(url, function(error, response) {
me.checkError(error, response);
if(error) {
console.log('note/getSyncNotes');
console.log(error);
@@ -141,6 +179,7 @@ var Api = {
var url = this.getUrl('tag/getSyncTags', {afterUsn: afterUsn, maxEntry: maxEntry});
log(url);
needle.get(url, function(error, response) {
me.checkError(error, response);
if(error) {
console.log('tag/getSyncTags');
console.log(error);
@@ -161,6 +200,7 @@ var Api = {
var url = this.getUrl('user/getSyncState');
log(url);
needle.get(url, function(error, response) {
me.checkError(error, response);
if(error) {
return callback && callback(false);
}
@@ -180,6 +220,7 @@ var Api = {
var url = this.getUrl('note/getNoteContent', {noteId: noteId});
log(url);
needle.get(url, function(error, response) {
me.checkError(error, response);
if(error) {
log(error);
return callback && callback(false);
@@ -206,6 +247,7 @@ var Api = {
var url = me.getUrl('file/getImage', {fileId: fileId});
log(url);
needle.get(url, function(err, resp) {
me.checkError(err, resp);
if(err) {
return callback && callback(false);
}
@@ -254,6 +296,7 @@ var Api = {
var url = me.getUrl('file/getAttach', {fileId: serverFileId});
console.log(url);
needle.get(url, function(err, resp) {
me.checkError(err, resp);
if(err) {
return callback && callback(false);
}
@@ -326,6 +369,8 @@ var Api = {
log('add notebook');
log(data);
needle.post(me.getUrl('notebook/addNotebook'), data, {}, function(err, resp) {
me.checkError(err, resp);
if(err) {
return callback(false);
}
@@ -353,6 +398,7 @@ var Api = {
log('update notebook');
log(data);
needle.post(me.getUrl('notebook/updateNotebook'), data, {}, function(err, resp) {
me.checkError(err, resp);
if(err) {
log('err');
log(err);
@@ -376,6 +422,7 @@ var Api = {
var data = {notebookId: notebook.ServerNotebookId, usn: notebook.Usn};
log('delete notebook');
needle.post(me.getUrl('notebook/deleteNotebook'), data, {}, function(err, resp) {
me.checkError(err, resp);
if(err) {
return callback(false);
}
@@ -412,7 +459,9 @@ var Api = {
// 获取笔记
// noteId是serverNoteId
getNote: function(noteId, callback) {
var me = this;
needle.get(this.getUrl('note/getNote', {NoteId: noteId}), function(error, response) {
me.checkError(error, response);
if(error) {
return callback && callback(false);
}
@@ -458,6 +507,7 @@ var Api = {
try {
needle.post(me.getUrl('note/addNote'), data, {multipart: needMultiple}, function(err, resp) {
me.checkError(err, resp);
if(err) {
return callback(false);
}
@@ -501,6 +551,7 @@ var Api = {
}
needle.post(me.getUrl('note/updateNote'), data, {multipart: needMultiple}, function(err, resp) {
me.checkError(err, resp);
if(err) {
log('err');
log(err);
@@ -528,6 +579,7 @@ var Api = {
// 这里要重新require下, 不然为{}
Note = require('note');
needle.post(me.getUrl('note/deleteTrash'), data, {}, function(err, resp) {
me.checkError(err, resp);
if(err) {
return callback(false);
}
@@ -560,6 +612,7 @@ var Api = {
addTag: function(title, callback) {
var me = this;
needle.post(me.getUrl('tag/addTag'), {tag: title}, {}, function(err, resp) {
me.checkError(err, resp);
if(err) {
return callback && callback(false);
}
@@ -579,6 +632,7 @@ var Api = {
deleteTag: function(tag, callback) {
var me = this;
needle.post(me.getUrl('tag/deleteTag'), {tag: tag.Tag, usn: tag.Usn}, {}, function(err, resp) {
me.checkError(err, resp);
if(err) {
return callback && callback(false);
}

22
node_modules/note.js generated vendored
View File

@@ -42,7 +42,7 @@ var Note = {
updateNoteOrContent: function(noteOrContent, callback) {
var userId = User.getCurActiveUserId();
noteOrContent['UserId'] = userId;
log('update');
console.log('updateNoteOrContent: ' + noteOrContent.NoteId);
var date = new Date();
noteOrContent.UpdatedTime = date;
@@ -445,6 +445,7 @@ var Note = {
// note是服务器传过来的, 需要处理下fix
// NoteId, ServerNoteId, NotebookId(本地的)
addNoteForce: function(note, callback) {
var me = this;
note.InitSync = true; // 刚同步完, 表示content, images, attach没有同步
note.IsDirty = false;
note.ServerNoteId = note.NoteId;
@@ -674,7 +675,7 @@ var Note = {
// 将本地冲突的笔记复制一份
// serverNoteId
// TODO 附件也要复制一份
// 附件也要复制一份
copyNoteForConfict: function(noteId, callback) {
var me = this;
me.getNote(noteId, function(note) {
@@ -684,6 +685,7 @@ var Note = {
}
// 新Id
delete note['_id'];
delete note['ServerNoteId'];
note.NoteId = Common.objectId();
note.ConflictNoteId = noteId; // 与noteId有冲突
note.ConflictTime = new Date(); // 发生冲突时间
@@ -811,12 +813,8 @@ var Note = {
// notes是服务器的数据, 与本地的有冲突
// 1) 将本地的note复制一份
// 2) 服务器替换之前
fixConflicts: function(noteSyncInfo, noteWeb, callback) {
fixConflicts: function(noteSyncInfo, callback) {
var me = this;
// 处理冲突
if(!noteWeb) {
return callback && callback();
}
var conflictNotes = noteSyncInfo.conflicts;
log('fix note conflicts');
@@ -832,7 +830,7 @@ var Note = {
me.updateNoteForceForConflict(note, function(note2) {
if(note2) {
// 前端来处理, 全量sync时不用前端一个个处理
noteWeb && noteWeb.fixSyncConflict(note2, newNote);
Web.fixSyncConflictNote(note2, newNote);
}
cb();
});
@@ -870,7 +868,7 @@ var Note = {
me.updateNoteForceForConflict(serverNote, function(note2) {
if(!note2) {
// 前端来处理, 全量sync时不用前端一个个处理
noteWeb && noteWeb.fixSyncConflict(note2, newNote);
Web.fixSyncConflict(note2, newNote);
}
});
});
@@ -893,16 +891,16 @@ var Note = {
var addNotes = noteSyncInfo.adds;
log('has add...');
log(addNotes);
noteWeb.addSync(addNotes);
Web.addSyncNote(addNotes);
log('has updates...');
log(noteSyncInfo);
log(noteSyncInfo.updates);
// 处理更新的
noteWeb.updateSync(noteSyncInfo.updates);
Web.updateSyncNote(noteSyncInfo.updates);
// 处理删除的
noteWeb.deleteSync(noteSyncInfo.deletes);
Web.deleteSyncNote(noteSyncInfo.deletes);
},
// 得到所有文件要传的基本信息和传送的数据

8
node_modules/notebook.js generated vendored
View File

@@ -395,21 +395,21 @@ var Notebook = {
var adds = notebookSyncInfo.adds;
log('has add...');
log(adds);
notebookWeb.addSync(adds);
Web.addSyncNotebook(adds);
log('has changeAdds')
log(notebookSyncInfo.changeAdds)
notebookWeb.addChange(notebookSyncInfo.changeAdds);
Web.addChangeNotebook(notebookSyncInfo.changeAdds);
log('has updates...');
log(notebookSyncInfo);
log(notebookSyncInfo.updates);
// 处理更新的
notebookWeb.updateSync(notebookSyncInfo.updates);
Web.updateSyncNotebook(notebookSyncInfo.updates);
// 处理删除的
notebookWeb.deleteSync(notebookSyncInfo.deletes);
Web.deleteSyncNotebook(notebookSyncInfo.deletes);
},
// 在send delete笔记时成功

103
node_modules/sync.js generated vendored
View File

@@ -111,7 +111,7 @@ var Sync = {
function canCall() {
// 是最后一块, 且
me._addSyncNotebookNum();
log(me._totalHasSyncNotebookNum + ' ' + me._totalSyncNotebookNum);
console.log(me._totalHasSyncNotebookNum + ' ' + me._totalSyncNotebookNum);
if(me._syncNotebookIsLastChunk && me._totalHasSyncNotebookNum >= me._totalSyncNotebookNum) {
// 防止多次callback
if(!me._syncInfo.notebook.ok) {
@@ -136,8 +136,8 @@ var Sync = {
// 1) 服务器端删除了, 本地肯定删除
if(notebook.IsDeleted) {
log('delete: ');
log(notebook);
console.log('delete: ');
console.log(notebook);
Notebook.getNotebookIdByServerNotebookId(notebookId, function(localNotebookId) {
Notebook.deleteNotebookForce(notebookId, function() {
me._syncInfo.notebook.deletes.push(localNotebookId);
@@ -150,7 +150,7 @@ var Sync = {
Notebook.getNotebookByServerNotebookId(notebookId, function(notebookLocal) {
// 2.1 本地没有, 表示是新建
if(!notebookLocal) {
log('add: ...')
console.log('add: ...')
// TODO
Notebook.addNotebookForce(notebook, function(notebook) {
me._syncInfo.notebook.adds.push(notebook);
@@ -159,7 +159,7 @@ var Sync = {
} else {
// 2.2 本地是否修改了, 需要合并, 使用服务端的数据
if(notebook.IsDirty) {
log('冲突....')
console.log('冲突....')
// 2.3 服务器是最新的, 用服务器的
} else {
}
@@ -179,8 +179,8 @@ var Sync = {
syncNotebook: function(afterUsn, callback) {
var me = this;
Api.getSyncNotebooks(afterUsn, me._notebookMaxEntry, function(notebooks) {
log('syncNotebook')
log(notebooks);
console.log('syncNotebook')
console.log(notebooks);
if(Common.isOk(notebooks)) {
me._totalSyncNotebookNum += notebooks.length;
// 证明可能还有要同步的
@@ -189,7 +189,7 @@ var Sync = {
var last = notebooks[notebooks.length-1];
me.syncNotebook(last.Usn, callback);
} else {
log('no more');
console.log('no more');
me._syncNotebookIsLastChunk = true;
me._syncNotebookToLocal(notebooks, callback);
}
@@ -488,52 +488,73 @@ var Sync = {
var afterInfo = me._syncInfo;
log('处理冲突....');
log(me._syncInfo);
if(me._notebookWeb) {
Notebook.fixConflicts(me._syncInfo.notebook, me._notebookWeb);
}
if(me._noteWeb) {
Note.fixConflicts(me._syncInfo.note, me._noteWeb, function() {
// 如果是incSync, 则要前端处理
if(me.incrSyncStart) {
Notebook.fixConflicts(me._syncInfo.notebook);
Note.fixConflicts(me._syncInfo.note, function() {
// 避免无限循环, 别send changes了
if(!me._needIncrSyncAgain) {
// alert("?")
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>")
console.log(">>>>>>>>_needIncrSyncAgain>>>>>>>>>>>>>>>>>")
// send changes
callback && callback();
}
});
// 添加或删除一些tag
Web.addOrDeleteTagFromSync(me._syncInfo.tag);
}
},
fixConflictsForSendChanges: function(callback) {
var me = this;
me.fixConflicts(function() {
callback();
// 已结束
Web.syncFinished();
me.incrSyncStart = false;
})
},
// 增量同步
incrSyncStart: false,
// 如果第一次insync, 网络错误导致incrSyncStart不结束, 第二次就会永远转动
setSyncFinished: function() {
var me = this;
me.incrSyncStart = false;
},
incrSync: function() {
var me = this;
me._initSyncInfo();
if(me.incrSyncStart) {
return;
}
// 添加或删除一些tag
Web.addOrDeleteTagFromSync(me._syncInfo.tag);
},
me.incrSyncStart = true;
// 增量同步
incrSync: function(notebookWeb, noteWeb) {
var me = this;
me._notebookWeb = notebookWeb;
me._noteWeb = noteWeb;
me._initSyncInfo();
log('inc sync start');
console.log('inc sync start');
// 得到当前LastSyncUsn
User.getLastSyncState(function(lastSyncUsn, lastSyncTime) {
// 没有上次同步的时间, 则需要进行一次全量同步, 不可能会发生
if(!lastSyncUsn) {
log('error!!');
console.log('error!!');
return;
}
// 同步笔记本
me.syncNotebook(lastSyncUsn, function(ok) {
if(ok) {
log('-------incr notebook ok-----------' + lastSyncUsn)
console.log('-------incr notebook ok-----------' + lastSyncUsn)
// 同步笔记
me.syncNote(lastSyncUsn, function(ok) {
if(ok) {
log('-------incr note ok-----------' + lastSyncUsn)
console.log('-------incr note ok-----------' + lastSyncUsn)
// 同步标签
me.syncTag(lastSyncUsn, function() {
log('-------incr tag ok-----------' + lastSyncUsn)
console.log('-------incr tag ok-----------' + lastSyncUsn)
// 更新上次同步时间
me.updateLastSyncState(function() {
// send changes
@@ -541,7 +562,7 @@ var Sync = {
});
});
} else {
log('-------incr note not ok-----------')
console.log('-------incr note not ok-----------')
me.fixConflicts();
}
});
@@ -561,8 +582,8 @@ var Sync = {
var me = this;
// 获取所有笔记本的更改
Notebook.getDirtyNotebooks(function(notebooks) {
log('dirty notebooks');
log(notebooks);
console.log('dirty notebooks');
console.log(notebooks);
if(!notebooks) {
callback && callback();
} else {
@@ -648,8 +669,8 @@ var Sync = {
var me = this;
// 获取所有笔记本的更改
Note.getDirtyNotes(function(notes) {
log('dirty notes');
log(notes);
console.error('>>>>>>>>>>>> dirty notes <<<<<<<<<<<<<<< ');
console.log(notes);
if(!notes) {
callback && callback();
} else {
@@ -690,7 +711,7 @@ var Sync = {
console.log(ret);
if(typeof ret == 'object') {
if(ret.Msg == 'conflict') {
console.log('updateNote 冲突-----------');
console.error('updateNote 冲突-----------');
me._syncInfo.note.changeConflicts.push(note);
}
else if(ret.Msg == 'notExists') {
@@ -766,8 +787,8 @@ var Sync = {
var me = this;
// 获取所有笔记本的更改
Tag.getDirtyTags(function(tags) {
log('dirty tags');
log(tags);
console.log('dirty tags');
console.log(tags);
if(!tags) {
callback && callback();
} else {
@@ -804,11 +825,11 @@ var Sync = {
sendChanges: function() {
var me = this;
log('send changes before...')
console.log('send changes before...')
// 先处理冲突, 可以同时进行
me.fixConflicts(function() {
// send changes
log('send changes');
console.log('send changes');
me._initSyncInfo(); // 重新初始化[]
async.series([
function(cb) {
@@ -823,11 +844,11 @@ var Sync = {
], function() {
// 重新再来一次增量同步
if(me._needIncrSyncAgain) {
log('-- _needIncrSyncAgain -- ')
console.log('-- _needIncrSyncAgain -- ')
me.incrSync(me._notebookWeb, me._noteWeb);
} else {
log('send changes 后解决冲突');
me.fixConflicts();
console.log('send changes 后解决冲突');
me.fixConflictsForSendChanges(function(){});
}
});
});

58
node_modules/web.js generated vendored
View File

@@ -10,6 +10,17 @@ var Web = {
Note: null,
Tag: null,
// 断网处理
unConnected: function() {
var me = this;
me.Note.unConnected();
},
notLogin: function() {
var me = this;
me.Note.notLogin();
},
// 注入前端变量
set: function(notebook, note, attach, tag) {
var me = this;
@@ -19,6 +30,53 @@ var Web = {
me.Tag = tag;
},
addSyncNotebook: function(notebooks) {
var me = this;
me.Notebook.addSync(notebooks);
},
updateSyncNotebook: function(notebooks) {
var me = this;
me.Notebook.updateSync(notebooks);
},
deleteSyncNotebook: function(notebooks) {
var me = this;
me.Notebook.deleteSync(notebooks);
},
addChangeNotebook: function(notebooks) {
var me = this;
me.Notebook.addChange(notebooks);
},
/*
fixNotebookConflicts: function(notebookInfo) {
var me = this;
me.Notebook.fixSyncConflict(notebookInfo);
},
*/
//----------
addSyncNote: function(notes) {
var me = this;
me.Note.addSync(notes);
},
updateSyncNote: function(notes) {
var me = this;
me.Note.updateSync(notes);
},
deleteSyncNote: function(notes) {
var me = this;
me.Note.deleteSync(notes);
},
fixSyncConflictNote: function(note, newNote) {
var me = this;
me.Note.fixSyncConflict(note, newNote);
},
//--------------
syncFinished: function() {
var me = this;
me.Note.syncFinished();
},
// 删除笔记时, 更新左侧导航标签的count
// TODO test
updateTagCount: function(tag) {

View File

@@ -194,13 +194,15 @@ function log(o) {
-->
<div id="notebookBottom" class="clearfix">
<!-- fa-spin -->
<a class="pull-left sync-icon"><i class="fa fa-refresh"></i></a>
<a class="pull-left sync-icon">
<i class="fa fa-refresh" id="syncRefresh"></i>
<i class="fa fa-exclamation-triangle" id="syncWarning" title="Sync error!!"></i>
</a>
<div class="pull-right" id="myProfile">
<div class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown">
<span class="username">
life@leanote.com
lifekkk@leanote.com
</span><i class="fa fa-angle-down account-more"></i>
</a>
<ul class="dropdown-menu li-a " role="menu">

View File

@@ -202,6 +202,11 @@ h1, h2, h3 {
.sync-icon {
margin-left: 10px;
}
#syncWarning {
color: #f0ad4e;
display: none;
cursor: pointer;
}
#myProfile {
.dropdown-menu {
top: -110px;
@@ -212,7 +217,7 @@ h1, h2, h3 {
}
}
position: absolute;
left: 30px;
left: 45px;
right: 0;
text-align: right;
.dropdown-toggle {
@@ -1472,4 +1477,9 @@ top: 4px;
a:hover {
background: none !important;
}
}
.fa-spin {
-webkit-animation: fa-spin 1s infinite linear !important;
animation: fa-spin 1s infinite linear !important;
}

View File

@@ -198,9 +198,14 @@ h3 {
.sync-icon {
margin-left: 10px;
}
#syncWarning {
color: #f0ad4e;
display: none;
cursor: pointer;
}
#myProfile {
position: absolute;
left: 30px;
left: 45px;
right: 0;
text-align: right;
}
@@ -1331,6 +1336,10 @@ h3 {
#tagNav a:hover {
background: none !important;
}
.fa-spin {
-webkit-animation: fa-spin 1s infinite linear !important;
animation: fa-spin 1s infinite linear !important;
}
::selection {
background: #000000;
color: #ffffff;

View File

@@ -198,9 +198,14 @@ h3 {
.sync-icon {
margin-left: 10px;
}
#syncWarning {
color: #f0ad4e;
display: none;
cursor: pointer;
}
#myProfile {
position: absolute;
left: 30px;
left: 45px;
right: 0;
text-align: right;
}
@@ -1331,6 +1336,10 @@ h3 {
#tagNav a:hover {
background: none !important;
}
.fa-spin {
-webkit-animation: fa-spin 1s infinite linear !important;
animation: fa-spin 1s infinite linear !important;
}
::selection {
background: #000000;
color: #ffffff;

View File

@@ -198,9 +198,14 @@ h3 {
.sync-icon {
margin-left: 10px;
}
#syncWarning {
color: #f0ad4e;
display: none;
cursor: pointer;
}
#myProfile {
position: absolute;
left: 30px;
left: 45px;
right: 0;
text-align: right;
}
@@ -1331,6 +1336,10 @@ h3 {
#tagNav a:hover {
background: none !important;
}
.fa-spin {
-webkit-animation: fa-spin 1s infinite linear !important;
animation: fa-spin 1s infinite linear !important;
}
@font-face {
font-family: 'Open Sans';
font-style: normal;

View File

@@ -198,9 +198,14 @@ h3 {
.sync-icon {
margin-left: 10px;
}
#syncWarning {
color: #f0ad4e;
display: none;
cursor: pointer;
}
#myProfile {
position: absolute;
left: 30px;
left: 45px;
right: 0;
text-align: right;
}
@@ -1331,6 +1336,10 @@ h3 {
#tagNav a:hover {
background: none !important;
}
.fa-spin {
-webkit-animation: fa-spin 1s infinite linear !important;
animation: fa-spin 1s infinite linear !important;
}
@font-face {
font-family: 'Open Sans';
font-style: normal;

View File

@@ -38,7 +38,7 @@ Note.isReadOnly = false;
Note.intervalTime = 600000; // 600s, 10mins
Note.startInterval = function() {
Note.interval = setInterval(function() {
log("自动保存开始...")
log("自动保存开始...");
changedNote = Note.curChangedSaveIt(false);
}, Note.intervalTime); // 600s, 10mins
}
@@ -259,6 +259,7 @@ Note.curHasChanged = function(force) {
}
}
// 这里, 总为true, 那么, 总会保存的
// if(!arrayEqual(cacheNote.Tags, tags)) {
hasChanged.hasChanged = true;
hasChanged.Tags = tags;
@@ -443,7 +444,7 @@ Note.curChangedSaveIt = function(force, callback) {
}
showMsg(getMsg("saveSuccess"), 1000);
callback && callback();
callback && callback(ret);
});
return hasChanged;
@@ -1016,14 +1017,74 @@ Note.newNote = function(notebookId, isShare, fromUserId, isMarkdown) {
// 更新数量
Notebook.incrNotebookNumberNotes(notebookId)
}
};
// 同步
Note._syncRefreshE = $('#syncRefresh');
Note._syncWarningE = $('#syncWarning');
Note.showSpin = function() {
var me = this;
me._syncRefreshE.addClass('fa-spin');
};
Note.hideSpin = function() {
var me = this;
me._syncRefreshE.removeClass('fa-spin');
};
// nodejs调用
Note.syncFinished = function() {
var me = this;
me.hideSpin();
me._syncWarningE.hide();
};
Note.sync = function() {
var me = this;
me.showSpin();
SyncService.incrSync();
};
// 断网处理
/*
1. sync出现感叹号
2. 如果是需要重新登录, 则点击后出现重新登录的界面
*/
Note.unConnected = function() {
var me = this;
me._syncWarningE.show();
SyncService.setSyncFinished();
me.hideSpin();
me._syncWarningE.data('reason', 'unConnected');
me._syncWarningE.attr('title', 'Network error');
};
Note.notLogin = function() {
var me = this;
me._syncWarningE.show();
me.hideSpin();
SyncService.setSyncFinished();
me._syncWarningE.data('reason', 'notLogin');
me._syncWarningE.attr('title', 'You need sign in leanote');
};
// 点击感叹号, 处理错误
Note.fixNetOrAuthError = function() {
var me = this;
var reason = me._syncWarningE.data('reason');
if(reason == 'unConnected') {
alert('Network error, please check out your network.');
} else if(reason == 'notLogin') {
// 弹出登录框登录之, 重新弹出
window.open('login.html?ref=needLogin');
}
};
// 保存note ctrl + s
Note.saveNote = function(e) {
var num = e.which ? e.which : e.keyCode;
// 保存
if((e.ctrlKey || e.metaKey) && num == 83 ) { // ctrl + s or command + s
Note.curChangedSaveIt();
Note.curChangedSaveIt(true, function(note) {
console.log('after updated:');
console.log(note);
Note.sync();
});
e.preventDefault();
return false;
} else {
@@ -1603,6 +1664,7 @@ Note.contentSynced = function(noteId, content) {
}
};
// 这里速度不慢, 很快
Note.getContextNotebooks = function(notebooks) {
var moves = [];
@@ -2170,6 +2232,15 @@ $(function() {
Note.renderStarNote($li);
});
// sync
Note._syncRefreshE.click(function() {
Note.sync();
});
Note._syncWarningE.click(function() {
Note.fixNetOrAuthError();
});
});
// 定时器启动

View File

@@ -1306,7 +1306,7 @@ function fullSync(callback) {
// 增量同步
function incrSync() {
log('full sync');
log('incr sync');
SyncService.incrSync(Notebook, Note);
}