mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-16 08:01:53 +00:00
save/recover state
This commit is contained in:
17
node_modules/common.js
generated
vendored
17
node_modules/common.js
generated
vendored
@@ -124,6 +124,23 @@ var Common = {
|
|||||||
ret.nameNotExt = ret.name;
|
ret.nameNotExt = ret.name;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
},
|
||||||
|
// 2014-01-06T18:29:48.802+08:00
|
||||||
|
goNowToDate: function (goNow) {
|
||||||
|
if(!goNow) {
|
||||||
|
return new Date();
|
||||||
|
}
|
||||||
|
// new Date();
|
||||||
|
if(typeof goNow == 'object') {
|
||||||
|
alert(3);
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
var str = goNow.substr(0, 10) + " " + goNow.substr(11, 8);
|
||||||
|
try {
|
||||||
|
return new Date(str);
|
||||||
|
} catch(e) {
|
||||||
|
return new Date();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
module.exports = Common;
|
module.exports = Common;
|
||||||
|
7
node_modules/evt.js
generated
vendored
7
node_modules/evt.js
generated
vendored
@@ -26,6 +26,9 @@ var Evt = {
|
|||||||
getAttachLocalUrl: function(fileId) {
|
getAttachLocalUrl: function(fileId) {
|
||||||
return this.localUrl + '/api/file/getAttach?fileId=' + fileId;
|
return this.localUrl + '/api/file/getAttach?fileId=' + fileId;
|
||||||
},
|
},
|
||||||
|
getAllAttachLocalUrl: function(noteId) {
|
||||||
|
return this.localUrl + '/api/file/getAllAttachs?noteId=' + noteId;
|
||||||
|
},
|
||||||
// 项目绝对地址
|
// 项目绝对地址
|
||||||
getBasePath: function() {
|
getBasePath: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
@@ -39,8 +42,8 @@ var Evt = {
|
|||||||
},
|
},
|
||||||
setDataBasePath: function(dataBasePath) {
|
setDataBasePath: function(dataBasePath) {
|
||||||
var me = this;
|
var me = this;
|
||||||
console.log('...........')
|
// console.log('...........')
|
||||||
console.log(dataBasePath);
|
// console.log(dataBasePath);
|
||||||
me.dataBasePath = dataBasePath;
|
me.dataBasePath = dataBasePath;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
23
node_modules/note.js
generated
vendored
23
node_modules/note.js
generated
vendored
@@ -365,8 +365,9 @@ var Note = {
|
|||||||
var reg2 = new RegExp(Evt.leanoteUrl + '/api/file/getAttach', 'g');
|
var reg2 = new RegExp(Evt.leanoteUrl + '/api/file/getAttach', 'g');
|
||||||
content = content.replace(reg2, Evt.localUrl + '/api/file/getAttach');
|
content = content.replace(reg2, Evt.localUrl + '/api/file/getAttach');
|
||||||
|
|
||||||
var reg3 = new RegExp(Evt.leanoteUrl + '/api/file/getAllAttach', 'g');
|
// api/file/getAllAttachs?noteId=xxxxxxxxx, 这里的noteId是服务器上的noteId啊
|
||||||
content = content.replace(reg3, Evt.localUrl + '/api/file/getAllAttach');
|
var reg3 = new RegExp(Evt.leanoteUrl + '/api/file/getAllAttachs', 'g');
|
||||||
|
content = content.replace(reg3, Evt.localUrl + '/api/file/getAllAttachs');
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
},
|
},
|
||||||
@@ -384,8 +385,8 @@ var Note = {
|
|||||||
var reg2 = new RegExp(Evt.localUrl + '/api/file/getAttach', 'g');
|
var reg2 = new RegExp(Evt.localUrl + '/api/file/getAttach', 'g');
|
||||||
content = content.replace(reg2, Evt.leanoteUrl + '/api/file/getAttach');
|
content = content.replace(reg2, Evt.leanoteUrl + '/api/file/getAttach');
|
||||||
|
|
||||||
var reg3 = new RegExp(Evt.localUrl + '/api/file/getAllAttach', 'g');
|
var reg3 = new RegExp(Evt.localUrl + '/api/file/getAllAttachs', 'g');
|
||||||
content = content.replace(reg3, Evt.leanoteUrl + '/api/file/getAllAttach');
|
content = content.replace(reg3, Evt.leanoteUrl + '/api/file/getAllAttachs');
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
},
|
},
|
||||||
@@ -546,6 +547,10 @@ var Note = {
|
|||||||
note.NoteId = Common.objectId();
|
note.NoteId = Common.objectId();
|
||||||
note.LocalIsDelete = false;
|
note.LocalIsDelete = false;
|
||||||
|
|
||||||
|
console.error('add note' + note.Title + Common.goNowToDate(note.CreatedTime));
|
||||||
|
note.CreatedTime = Common.goNowToDate(note.CreatedTime);
|
||||||
|
note.UpdatedTime = Common.goNowToDate(note.UpdatedTime);
|
||||||
|
|
||||||
// 附件操作
|
// 附件操作
|
||||||
var files = note.Files || [];
|
var files = note.Files || [];
|
||||||
var attachs = [];
|
var attachs = [];
|
||||||
@@ -567,6 +572,9 @@ var Note = {
|
|||||||
console.log(err);
|
console.log(err);
|
||||||
callback && callback(false);
|
callback && callback(false);
|
||||||
} else {
|
} else {
|
||||||
|
// console.log("?????????")
|
||||||
|
// console.log(note);
|
||||||
|
// console.log(note.CreatedTime);
|
||||||
callback && callback(newDoc);
|
callback && callback(newDoc);
|
||||||
|
|
||||||
// 下载内容, 图片, 附件
|
// 下载内容, 图片, 附件
|
||||||
@@ -660,6 +668,10 @@ var Note = {
|
|||||||
console.log(everNote.NoteId);
|
console.log(everNote.NoteId);
|
||||||
console.log(everNote);
|
console.log(everNote);
|
||||||
|
|
||||||
|
// 不要服务器上的
|
||||||
|
delete note['UpdatedTime'];
|
||||||
|
delete note['CreatedTime'];
|
||||||
|
|
||||||
Notes.update({NoteId: note.NoteId}, {$set: note}, {}, function (err, cnt) { // Callback is optional
|
Notes.update({NoteId: note.NoteId}, {$set: note}, {}, function (err, cnt) { // Callback is optional
|
||||||
console.log('re:');
|
console.log('re:');
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@@ -740,6 +752,8 @@ var Note = {
|
|||||||
console.log(everAttachs);
|
console.log(everAttachs);
|
||||||
|
|
||||||
delete note['Files'];
|
delete note['Files'];
|
||||||
|
delete note['UpdatedTime'];
|
||||||
|
delete note['CreatedTime'];
|
||||||
|
|
||||||
Notes.update({NoteId: note.NoteId}, {$set: note}, function(err, n) {
|
Notes.update({NoteId: note.NoteId}, {$set: note}, function(err, n) {
|
||||||
if(err || !n) {
|
if(err || !n) {
|
||||||
@@ -991,7 +1005,6 @@ var Note = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
})(i);
|
})(i);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 服务器没有, 但是是发送更新的, 所以需要作为添加以后再send changes
|
// 服务器没有, 但是是发送更新的, 所以需要作为添加以后再send changes
|
||||||
|
4
node_modules/notebook.js
generated
vendored
4
node_modules/notebook.js
generated
vendored
@@ -278,6 +278,10 @@ var Notebook = {
|
|||||||
} else {
|
} else {
|
||||||
// 否则, 就用服务器上的
|
// 否则, 就用服务器上的
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notebook.CreatedTime = Common.goNowToDate(notebook.CreatedTime);
|
||||||
|
notebook.UpdatedTime = Common.goNowToDate(notebook.UpdatedTime);
|
||||||
|
|
||||||
NB.insert(notebook, function (err, newDoc) { // Callback is optional
|
NB.insert(notebook, function (err, newDoc) { // Callback is optional
|
||||||
if(err) {
|
if(err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
20
node_modules/user.js
generated
vendored
20
node_modules/user.js
generated
vendored
@@ -227,6 +227,26 @@ User = {
|
|||||||
db.g.update({_id: '1'}, {$set: data}, {upsert: true}, function() {
|
db.g.update({_id: '1'}, {$set: data}, {upsert: true}, function() {
|
||||||
callback && callback();
|
callback && callback();
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* [saveCurState description]
|
||||||
|
* @param {[type]} state [description]
|
||||||
|
* @return {[type]} [description]
|
||||||
|
User.saveCurState({
|
||||||
|
StarredOpened: StarredOpened,
|
||||||
|
NotebookOpened: NotebookOpened,
|
||||||
|
TagOpened: TagOpened,
|
||||||
|
CurNoteId: CurNoteId,
|
||||||
|
CurIsStarred: CurIsStarred,
|
||||||
|
CurNotebookId: CurNotebookId,
|
||||||
|
CurTag: CurTag
|
||||||
|
}, callback);
|
||||||
|
*/
|
||||||
|
saveCurState: function(state, callback) {
|
||||||
|
state = state || {};
|
||||||
|
db.g.update({_id: '1'}, {$set: state}, {upsert: true}, function() {
|
||||||
|
callback && callback();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -106,7 +106,7 @@ function log(o) {
|
|||||||
<a class="tool-max"></a>
|
<a class="tool-max"></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="folderNote closed" id="myShareNotebooks">
|
<div class="folderNote closed" id="myStarredNotes">
|
||||||
<div class="folderHeader">
|
<div class="folderHeader">
|
||||||
<i class="fa fa-star-o fa-left"></i>
|
<i class="fa fa-star-o fa-left"></i>
|
||||||
<span>
|
<span>
|
||||||
@@ -346,14 +346,19 @@ function log(o) {
|
|||||||
<i class="fa fa-upload"></i>
|
<i class="fa fa-upload"></i>
|
||||||
<span>Choose Files</span>
|
<span>Choose Files</span>
|
||||||
</a>
|
</a>
|
||||||
|
<!--
|
||||||
<a class="btn btn-default" id="downloadAllBtn">
|
<a class="btn btn-default" id="downloadAllBtn">
|
||||||
<i class="fa fa-download"></i>
|
<i class="fa fa-download"></i>
|
||||||
<span>Download All</span>
|
<span>Download All</span>
|
||||||
</a>
|
</a>
|
||||||
|
-->
|
||||||
|
<!--
|
||||||
|
因为noteId与serverNoteId的原因, 暂不支持
|
||||||
<a class="btn btn-default" id="linkAllBtn">
|
<a class="btn btn-default" id="linkAllBtn">
|
||||||
<i class="fa fa-link"></i>
|
<i class="fa fa-link"></i>
|
||||||
<span>Link All</span>
|
<span>Link All</span>
|
||||||
</a>
|
</a>
|
||||||
|
-->
|
||||||
</div>
|
</div>
|
||||||
<div id="attachUploadMsg">
|
<div id="attachUploadMsg">
|
||||||
</div>
|
</div>
|
||||||
|
@@ -6,8 +6,8 @@
|
|||||||
"window": {
|
"window": {
|
||||||
"toolbar": true,
|
"toolbar": true,
|
||||||
|
|
||||||
"frame": false,
|
"frame": true,
|
||||||
"transparent": true,
|
"transparent": false,
|
||||||
|
|
||||||
"min_width": 400,
|
"min_width": 400,
|
||||||
"min_height": 200,
|
"min_height": 200,
|
||||||
|
@@ -201,8 +201,32 @@ Note.renderNotesAndFirstOneContent = function(ret) {
|
|||||||
Note.changeNoteForPjax(ret[0].NoteId, true, false);
|
Note.changeNoteForPjax(ret[0].NoteId, true, false);
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 渲染并定位到特定的
|
||||||
|
Note.renderNotesAndTargetNote = function(ret, noteId) {
|
||||||
|
// 错误的ret是一个Object
|
||||||
|
if(!isArray(ret)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// note 导航
|
||||||
|
Note.renderNotes(ret);
|
||||||
|
// 渲染特定的
|
||||||
|
if(!isEmpty(ret[0])) {
|
||||||
|
if(noteId) {
|
||||||
|
// Note.changeNoteForPjax(noteId, true, false);
|
||||||
|
Note.changeNoteForPjax(noteId, true, false);
|
||||||
|
if(!Note.directToNote(noteId)) {
|
||||||
|
// 找不到啊
|
||||||
|
Note.changeNoteForPjax(ret[0].NoteId, true, false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Note.changeNoteForPjax(ret[0].NoteId, true, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 当前的note是否改变过了?
|
// 当前的note是否改变过了?
|
||||||
// 返回已改变的信息
|
// 返回已改变的信息
|
||||||
// force bool true表示content比较是比较HTML, 否则比较text, 默认为true
|
// force bool true表示content比较是比较HTML, 否则比较text, 默认为true
|
||||||
@@ -428,7 +452,7 @@ Note.curChangedSaveIt = function(force, callback) {
|
|||||||
Note.setNoteCache(hasChanged, false);
|
Note.setNoteCache(hasChanged, false);
|
||||||
|
|
||||||
// 设置更新时间
|
// 设置更新时间
|
||||||
Note.setNoteCache({"NoteId": hasChanged.NoteId, "UpdatedTime": (new Date()).format("yyyy-MM-ddThh:mm:ss.S")}, false);
|
Note.setNoteCache({"NoteId": hasChanged.NoteId, "UpdatedTime": new Date()}, false);
|
||||||
|
|
||||||
// 表示有未完成的保存
|
// 表示有未完成的保存
|
||||||
/*
|
/*
|
||||||
@@ -445,7 +469,7 @@ Note.curChangedSaveIt = function(force, callback) {
|
|||||||
|
|
||||||
me.saveInProcess[hasChanged.NoteId] = true;
|
me.saveInProcess[hasChanged.NoteId] = true;
|
||||||
|
|
||||||
console.error('保存当前的笔记: ' + hasChanged.NoteId);
|
// console.error('保存当前的笔记: ' + hasChanged.NoteId);
|
||||||
|
|
||||||
NoteService.updateNoteOrContent(hasChanged, function(ret) {
|
NoteService.updateNoteOrContent(hasChanged, function(ret) {
|
||||||
me.saveInProcess[hasChanged.NoteId] = false;
|
me.saveInProcess[hasChanged.NoteId] = false;
|
||||||
@@ -524,13 +548,19 @@ Note.hideContentLoading = function() {
|
|||||||
$("#noteMaskForLoading").css("z-index", -1);
|
$("#noteMaskForLoading").css("z-index", -1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 定位到笔记
|
||||||
Note.directToNote = function(noteId) {
|
Note.directToNote = function(noteId) {
|
||||||
var $p = $("#noteItemList");
|
var $p = $("#noteItemList");
|
||||||
var pHeight = $p.height();
|
var pHeight = $p.height();
|
||||||
// 相对于父亲的位置
|
// 相对于父亲的位置
|
||||||
var pTop = $("[noteId='" + noteId + "']").position().top;
|
var $t = $("[noteId='" + noteId + "']");
|
||||||
|
if($t.length == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// position方法返回的是元素的在页面内的绝对位置信息,top和left
|
||||||
|
var pTop = $t.position().top;
|
||||||
var scrollTop = $p.scrollTop();
|
var scrollTop = $p.scrollTop();
|
||||||
pTop += scrollTop;
|
pTop += scrollTop + 66; // 66是上面的title, search
|
||||||
/*
|
/*
|
||||||
log("..");
|
log("..");
|
||||||
log(noteId);
|
log(noteId);
|
||||||
@@ -539,16 +569,13 @@ Note.directToNote = function(noteId) {
|
|||||||
|
|
||||||
// 当前的可视范围的元素位置是[scrollTop, pHeight + scrollTop]
|
// 当前的可视范围的元素位置是[scrollTop, pHeight + scrollTop]
|
||||||
if(pTop >= scrollTop && pTop <= pHeight + scrollTop) {
|
if(pTop >= scrollTop && pTop <= pHeight + scrollTop) {
|
||||||
|
// alert(pTop + ' ' + scrollTop + ' ' + pHeight)
|
||||||
} else {
|
} else {
|
||||||
var top = pTop;
|
var top = pTop;
|
||||||
log("定位到特定note, 在可视范围内");
|
console.log("定位到特定note, 在可视范围内");
|
||||||
// 手机不用slimScroll
|
$("#noteItemList").scrollTop(top - 66);
|
||||||
if(!LEA.isMobile && !Mobile.isMobile()) {
|
|
||||||
$("#noteItemList").scrollTop(top);
|
|
||||||
// $("#noteItemList").slimScroll({ scrollTo: top + 'px', height: "100%", onlyScrollBar: true});
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// mustPush表示是否将状态push到state中, 默认为true
|
// mustPush表示是否将状态push到state中, 默认为true
|
||||||
@@ -997,7 +1024,16 @@ Note.newNote = function(notebookId, isShare, fromUserId, isMarkdown) {
|
|||||||
// 保存当前的笔记
|
// 保存当前的笔记
|
||||||
Note.curChangedSaveIt();
|
Note.curChangedSaveIt();
|
||||||
|
|
||||||
var note = {NoteId: getObjectId(), Title: "", Tags:[], Content:"", NotebookId: notebookId, IsNew: true, FromUserId: fromUserId, IsMarkdown: isMarkdown}; // 是新的
|
var note = {NoteId: getObjectId(),
|
||||||
|
Title: "H",
|
||||||
|
Tags:[], Content:"",
|
||||||
|
NotebookId: notebookId,
|
||||||
|
IsNew: true,
|
||||||
|
FromUserId: fromUserId,
|
||||||
|
IsMarkdown: isMarkdown,
|
||||||
|
CreatedTime: new Date(),
|
||||||
|
UpdatedTime: new Date()}; // 是新的
|
||||||
|
|
||||||
// 添加到缓存中
|
// 添加到缓存中
|
||||||
Note.addNoteCache(note);
|
Note.addNoteCache(note);
|
||||||
|
|
||||||
@@ -1429,6 +1465,29 @@ Note.isSameSearch = function(key) {
|
|||||||
|
|
||||||
// 搜索笔记
|
// 搜索笔记
|
||||||
Note.searchSeq = 0;
|
Note.searchSeq = 0;
|
||||||
|
|
||||||
|
// for recoverState
|
||||||
|
Note.searchNoteSys = function(val, noteId) {
|
||||||
|
$("#searchNoteInput").val(val);
|
||||||
|
var me = this;
|
||||||
|
NoteService.searchNote(val, function(notes) {
|
||||||
|
if(notes) {
|
||||||
|
Note.searchKey = val;
|
||||||
|
Notebook.changeCurNotebookTitle('Search results', false, notes.length, false, true);
|
||||||
|
Note.renderNotes(notes);
|
||||||
|
// markdown一旦setContent就focus, 导致搜索失去焦点
|
||||||
|
setTimeout(function() {
|
||||||
|
$("#searchNoteInput").focus();
|
||||||
|
})
|
||||||
|
if(!isEmpty(notes)) {
|
||||||
|
Note.renderNotesAndTargetNote(notes, noteId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// abort的
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Note.searchNote = function() {
|
Note.searchNote = function() {
|
||||||
var val = $("#searchNoteInput").val();
|
var val = $("#searchNoteInput").val();
|
||||||
if(!val) {
|
if(!val) {
|
||||||
@@ -1462,7 +1521,8 @@ Note.searchNote = function() {
|
|||||||
NoteService.searchNote(val, function(notes) {
|
NoteService.searchNote(val, function(notes) {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
if(t == Note.searchSeq && notes) {
|
if(t == Note.searchSeq && notes) {
|
||||||
Notebook.changeCurNotebookTitle('Search results', false, notes.length);
|
Note.searchKey = val;
|
||||||
|
Notebook.changeCurNotebookTitle('Search results', false, notes.length, false, true);
|
||||||
Note.renderNotes(notes);
|
Note.renderNotes(notes);
|
||||||
// markdown一旦setContent就focus, 导致搜索失去焦点
|
// markdown一旦setContent就focus, 导致搜索失去焦点
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@@ -2158,6 +2218,8 @@ var Attach = {
|
|||||||
var attachId = $(this).closest('li').data("id");
|
var attachId = $(this).closest('li').data("id");
|
||||||
var attach = self.attachsMap[attachId];
|
var attach = self.attachsMap[attachId];
|
||||||
var src = EvtService.getAttachLocalUrl(attachId); // + "/attach/download?attachId=" + attachId;
|
var src = EvtService.getAttachLocalUrl(attachId); // + "/attach/download?attachId=" + attachId;
|
||||||
|
// http://leanote.com/attach/download?attachId=54f7481638f4112ff000170f
|
||||||
|
|
||||||
if(LEA.isMarkdownEditor() && MD) {
|
if(LEA.isMarkdownEditor() && MD) {
|
||||||
MD.insertLink(src, attach.Title);
|
MD.insertLink(src, attach.Title);
|
||||||
} else {
|
} else {
|
||||||
@@ -2167,12 +2229,15 @@ var Attach = {
|
|||||||
|
|
||||||
// make all link
|
// make all link
|
||||||
self.linkAllBtnO.on("click",function(e) {
|
self.linkAllBtnO.on("click",function(e) {
|
||||||
|
// 暂不支持
|
||||||
|
return;
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
var note = Note.getCurNote();
|
var note = Note.getCurNote();
|
||||||
if(!note) {
|
if(!note) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var src = UrlPrefix + "/attach/downloadAll?noteId=" + Note.curNoteId
|
var src = EvtService.getAllAttachLocalUrl(note.NoteId); // UrlPrefix + "/attach/downloadAll?noteId=" + Note.curNoteId
|
||||||
|
// src = 'http://leanote.com/attach/downloadAll?noteId=' + note.NoteId;
|
||||||
var title = note.Title ? note.Title + ".tar.gz" : "all.tar.gz";
|
var title = note.Title ? note.Title + ".tar.gz" : "all.tar.gz";
|
||||||
|
|
||||||
if(LEA.isMarkdownEditor() && MD) {
|
if(LEA.isMarkdownEditor() && MD) {
|
||||||
|
@@ -638,7 +638,7 @@ Notebook.curActiveNotebookIsAll = function() {
|
|||||||
// 3. 使用Note.RederNotes()
|
// 3. 使用Note.RederNotes()
|
||||||
// callback Pjax, 当popstate时调用
|
// callback Pjax, 当popstate时调用
|
||||||
Notebook.changeNotebookSeq = 1;
|
Notebook.changeNotebookSeq = 1;
|
||||||
Notebook.changeNotebook = function(notebookId, callback) {
|
Notebook.changeNotebook = function(notebookId, callback, needRendNoteId) {
|
||||||
var me = this;
|
var me = this;
|
||||||
Notebook.changeNotebookNav(notebookId);
|
Notebook.changeNotebookNav(notebookId);
|
||||||
|
|
||||||
@@ -666,7 +666,7 @@ Notebook.changeNotebook = function(notebookId, callback) {
|
|||||||
if(callback) {
|
if(callback) {
|
||||||
callback(cacheNotes);
|
callback(cacheNotes);
|
||||||
} else {
|
} else {
|
||||||
Note.renderNotesAndFirstOneContent(cacheNotes);
|
Note.renderNotesAndTargetNote(cacheNotes, needRendNoteId);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -680,7 +680,7 @@ Notebook.changeNotebook = function(notebookId, callback) {
|
|||||||
if(callback) {
|
if(callback) {
|
||||||
callback(cacheNotes);
|
callback(cacheNotes);
|
||||||
} else {
|
} else {
|
||||||
Note.renderNotesAndFirstOneContent(cacheNotes);
|
Note.renderNotesAndTargetNote(cacheNotes, needRendNoteId);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@@ -705,7 +705,7 @@ Notebook.changeNotebook = function(notebookId, callback) {
|
|||||||
if(callback) {
|
if(callback) {
|
||||||
callback(cacheNotes);
|
callback(cacheNotes);
|
||||||
} else {
|
} else {
|
||||||
Note.renderNotesAndFirstOneContent(cacheNotes);
|
Note.renderNotesAndTargetNote(cacheNotes, needRendNoteId);
|
||||||
}
|
}
|
||||||
me.hideNoteAndEditorLoading();
|
me.hideNoteAndEditorLoading();
|
||||||
};
|
};
|
||||||
@@ -719,10 +719,12 @@ Notebook.changeNotebook = function(notebookId, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 改变标签, isStarred是否是星笔记本
|
// 改变标签, isStarred是否是星笔记本
|
||||||
Notebook.changeCurNotebookTitle = function(title, isStarred, subTitle) {
|
Notebook.changeCurNotebookTitle = function(title, isStarred, subTitle, isTag, isSearch) {
|
||||||
var me = this;
|
var me = this;
|
||||||
$("#curNotebookForListNote").html(title);
|
$("#curNotebookForListNote").html(title);
|
||||||
me.isStarred = isStarred;
|
me.isStarred = isStarred;
|
||||||
|
me.isTag = isTag;
|
||||||
|
me.isSearch = isSearch;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 笔记列表与编辑器的mask loading
|
// 笔记列表与编辑器的mask loading
|
||||||
|
@@ -1315,19 +1315,120 @@ function incrSync() {
|
|||||||
SyncService.incrSync();
|
SyncService.incrSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 历史, 恢复原貌
|
||||||
|
var State = {
|
||||||
|
// 保存当前状态
|
||||||
|
// 什么时候调用? 关闭程序, 改变note时
|
||||||
|
saveCurState: function(callback) {
|
||||||
|
// 左侧, 开闭状态
|
||||||
|
var StarredOpened = false;
|
||||||
|
var NotebookOpened = false;
|
||||||
|
var TagOpened = false;
|
||||||
|
var $leftOpen = $('.folderNote.opened');
|
||||||
|
if($leftOpen.length == 1) {
|
||||||
|
var id = $leftOpen.attr('id');
|
||||||
|
if(id == 'myStarredNotes') {
|
||||||
|
StarredOpened = true;
|
||||||
|
} else if(id == 'myNotebooks') {
|
||||||
|
NotebookOpened = true;
|
||||||
|
} else if(id == 'myTag') {
|
||||||
|
TagOpened = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 当前笔记
|
||||||
|
var CurNoteId = Note.curNoteId; // 当前打开的笔记
|
||||||
|
var CurIsStarred = false; // 当前是在星下
|
||||||
|
var CurNotebookId = ''; // 定位到某个笔记本
|
||||||
|
var CurTag = ''; // 搜索tag
|
||||||
|
if(Notebook.isSearch) {
|
||||||
|
var CurSearchKey = Note.searchKey;
|
||||||
|
}
|
||||||
|
if(Notebook.isStarred) {
|
||||||
|
CurIsStarred = true;
|
||||||
|
} else if(Notebook.isTag) {
|
||||||
|
CurTag = Tag.curTag;
|
||||||
|
}
|
||||||
|
CurNotebookId = Notebook.curNotebookId;
|
||||||
|
|
||||||
|
var state = {
|
||||||
|
StarredOpened: StarredOpened,
|
||||||
|
NotebookOpened: NotebookOpened,
|
||||||
|
TagOpened: TagOpened,
|
||||||
|
|
||||||
|
CurNoteId: CurNoteId,
|
||||||
|
CurIsStarred: CurIsStarred,
|
||||||
|
CurNotebookId: CurNotebookId,
|
||||||
|
CurTag: CurTag,
|
||||||
|
CurSearchKey: CurSearchKey
|
||||||
|
};
|
||||||
|
console.log(state);
|
||||||
|
UserService.saveCurState(state, callback);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 恢复状态
|
||||||
|
recoverState: function(state) {
|
||||||
|
console.log(state);
|
||||||
|
// 1. 左侧哪个open
|
||||||
|
if(!state.NotebookOpened) {
|
||||||
|
$('.folderNote.opened').removeClass('opened').addClass('closed');
|
||||||
|
if(state.StarredOpened) {
|
||||||
|
$('#myStarredNotes').removeClass('closed').addClass('opened');
|
||||||
|
} else if(state.TagOpened) {
|
||||||
|
$('#myTag').removeClass('closed').addClass('opened');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 2.
|
||||||
|
// 当前是starred notes
|
||||||
|
var notebookId = state.CurNotebookId;
|
||||||
|
if(state.CurIsStarred) {
|
||||||
|
Note.renderStarNote($('#myStarredNotes li[data-id="' + state.CurNoteId + '"]'));
|
||||||
|
}
|
||||||
|
// 搜索标签
|
||||||
|
else if(state.CurTag) {
|
||||||
|
Tag.searchTag(state.CurTag, state.CurNoteId);
|
||||||
|
}
|
||||||
|
// 搜索笔记
|
||||||
|
else if(state.CurSearchKey) {
|
||||||
|
Note.searchNoteSys(state.CurSearchKey, state.CurNoteId);
|
||||||
|
}
|
||||||
|
// 笔记本了
|
||||||
|
else {
|
||||||
|
Notebook.expandNotebookTo(notebookId);
|
||||||
|
Notebook.changeNotebook(notebookId, false, state.CurNoteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// note.html调用
|
// note.html调用
|
||||||
// 实始化页面
|
// 实始化页面
|
||||||
// 判断是否登录
|
// 判断是否登录
|
||||||
function initPage() {
|
function initPage() {
|
||||||
|
win.on('close', function() {
|
||||||
|
State.saveCurState(function() {
|
||||||
|
win.close(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// 注入前端变量#
|
// 注入前端变量#
|
||||||
WebService.set(Notebook, Note, Attach, Tag);
|
WebService.set(Notebook, Note, Attach, Tag);
|
||||||
|
|
||||||
|
// 在显示notebooks, stars, tags后才recoverState
|
||||||
|
var i = 0;
|
||||||
|
function ok() {
|
||||||
|
i++;
|
||||||
|
if(i == 3) {
|
||||||
|
State.recoverState(UserInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function _init() {
|
function _init() {
|
||||||
$(function() {
|
$(function() {
|
||||||
// 获取笔记本
|
// 获取笔记本
|
||||||
Service.notebookService.getNotebooks(function(notebooks) {
|
Service.notebookService.getNotebooks(function(notebooks) {
|
||||||
log(notebooks);
|
log(notebooks);
|
||||||
Notebook.renderNotebooks(notebooks);
|
Notebook.renderNotebooks(notebooks);
|
||||||
|
ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 获得笔记
|
// 获得笔记
|
||||||
@@ -1340,6 +1441,7 @@ function initPage() {
|
|||||||
// 获取star笔记
|
// 获取star笔记
|
||||||
NoteService.getStarNotes(function(notes) {
|
NoteService.getStarNotes(function(notes) {
|
||||||
Note.renderStars(notes);
|
Note.renderStars(notes);
|
||||||
|
ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 指定笔记, 也要保存最新笔记
|
// 指定笔记, 也要保存最新笔记
|
||||||
@@ -1352,6 +1454,7 @@ function initPage() {
|
|||||||
// 标签
|
// 标签
|
||||||
TagService.getTags(function(tags) {
|
TagService.getTags(function(tags) {
|
||||||
Tag.renderTagNav(tags);
|
Tag.renderTagNav(tags);
|
||||||
|
ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
// init notebook后才调用
|
// init notebook后才调用
|
||||||
@@ -1506,6 +1609,7 @@ function userMenu() {
|
|||||||
changeTheme(UserInfo.Theme);
|
changeTheme(UserInfo.Theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
initUploadImage();
|
initUploadImage();
|
||||||
userMenu();
|
userMenu();
|
||||||
|
@@ -79,10 +79,7 @@ $(function() {
|
|||||||
|
|
||||||
// bind close event
|
// bind close event
|
||||||
// 保存当前打开的笔记
|
// 保存当前打开的笔记
|
||||||
win.on('close', function() {
|
|
||||||
// TODO
|
|
||||||
win.close(true);
|
|
||||||
});
|
|
||||||
win.on('focus', function() {
|
win.on('focus', function() {
|
||||||
console.log('window is focused ');
|
console.log('window is focused ');
|
||||||
});
|
});
|
||||||
|
@@ -281,6 +281,40 @@ Tag.addTagNav = function(newTag) {
|
|||||||
me.renderTagNav(me.tags);
|
me.renderTagNav(me.tags);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Tag.searchTag = function(tag, noteId) {
|
||||||
|
// var $li = $(this).closest('li');
|
||||||
|
// var tag = $.trim($li.data("tag"));
|
||||||
|
// tag = Tag.mapCn2En[tag] || tag;
|
||||||
|
|
||||||
|
// 学习changeNotebook
|
||||||
|
|
||||||
|
// 1
|
||||||
|
Note.curChangedSaveIt();
|
||||||
|
|
||||||
|
// 2 先清空所有
|
||||||
|
// 也会把curNoteId清空
|
||||||
|
Note.clearAll();
|
||||||
|
|
||||||
|
// $("#tagSearch").html($li.html()).show();
|
||||||
|
|
||||||
|
Notebook.changeCurNotebookTitle(tag, false, '', true);
|
||||||
|
Tag.curTag = tag;
|
||||||
|
// $('#curNotebookForListNote').find('i, em').remove();
|
||||||
|
// $("#tagSearch .tag-delete").remove();
|
||||||
|
|
||||||
|
NoteService.searchNoteByTag(tag, function(notes) {
|
||||||
|
hideLoading();
|
||||||
|
if(notes) {
|
||||||
|
// 和note搜索一样
|
||||||
|
// 设空, 防止发生上述情况
|
||||||
|
// Note.curNoteId = "";
|
||||||
|
Note.renderNotes(notes);
|
||||||
|
Note.renderNotesAndTargetNote(notes, noteId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// 事件
|
// 事件
|
||||||
$(function() {
|
$(function() {
|
||||||
// tag
|
// tag
|
||||||
@@ -365,6 +399,10 @@ $(function() {
|
|||||||
function searchTag() {
|
function searchTag() {
|
||||||
var $li = $(this).closest('li');
|
var $li = $(this).closest('li');
|
||||||
var tag = $.trim($li.data("tag"));
|
var tag = $.trim($li.data("tag"));
|
||||||
|
|
||||||
|
Tag.searchTag(tag);
|
||||||
|
/*
|
||||||
|
|
||||||
// tag = Tag.mapCn2En[tag] || tag;
|
// tag = Tag.mapCn2En[tag] || tag;
|
||||||
|
|
||||||
// 学习changeNotebook
|
// 学习changeNotebook
|
||||||
@@ -379,7 +417,8 @@ $(function() {
|
|||||||
// $("#tagSearch").html($li.html()).show();
|
// $("#tagSearch").html($li.html()).show();
|
||||||
|
|
||||||
var h = $li.html();
|
var h = $li.html();
|
||||||
Notebook.changeCurNotebookTitle(h);
|
Notebook.changeCurNotebookTitle(h, false, '', true);
|
||||||
|
Tag.curTag = h;
|
||||||
$('#curNotebookForListNote').find('i, em').remove();
|
$('#curNotebookForListNote').find('i, em').remove();
|
||||||
// $("#tagSearch .tag-delete").remove();
|
// $("#tagSearch .tag-delete").remove();
|
||||||
|
|
||||||
@@ -396,7 +435,9 @@ $(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
$("#myTag .folderBody").on("click", "li .label", searchTag);
|
$("#myTag .folderBody").on("click", "li .label", searchTag);
|
||||||
// $("#minTagNav").on("click", "li", searchTag);
|
// $("#minTagNav").on("click", "li", searchTag);
|
||||||
|
|
||||||
|
15
test.js
15
test.js
@@ -6,6 +6,7 @@ var Api = require('api');
|
|||||||
var User = require('user');
|
var User = require('user');
|
||||||
var Server = require('server');
|
var Server = require('server');
|
||||||
var Evt = require('evt');
|
var Evt = require('evt');
|
||||||
|
var Common = require('common');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Notebook.addNotebook("1", "life");
|
Notebook.addNotebook("1", "life");
|
||||||
@@ -20,7 +21,7 @@ Api.addNotebook({
|
|||||||
// Api.uploadImage();
|
// Api.uploadImage();
|
||||||
User.userId = '54bdc65599c37b0da9000002';
|
User.userId = '54bdc65599c37b0da9000002';
|
||||||
User.userId = '54d7620d99c37b030600002c';
|
User.userId = '54d7620d99c37b030600002c';
|
||||||
User.userId = '54f08a1699c37b877b0001ee';
|
User.userId = '54f6e72899c37b6e20000044';
|
||||||
|
|
||||||
// 54d7624205fcd105da00005
|
// 54d7624205fcd105da00005
|
||||||
|
|
||||||
@@ -37,12 +38,11 @@ User.init(function() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
Note.getNoteByServerNoteId('54f1a1f899c37b4faf000001', function(note) {
|
// Note.getNoteByServerNoteId('54f1a1f899c37b4faf000001', function(note) {
|
||||||
console.log(note);
|
// console.log(note);
|
||||||
});
|
// });
|
||||||
|
|
||||||
Note.getDirtyNotes(function(ret) {
|
Note.getNotes('', function(ret) {
|
||||||
console.log('getDirtyNotes: ');
|
|
||||||
console.log(ret);
|
console.log(ret);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -112,5 +112,6 @@ console.log(reg);
|
|||||||
while(s = reg.exec(a)) {
|
while(s = reg.exec(a)) {
|
||||||
console.log(s);
|
console.log(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
console.log(Common.goNowToDate('2014-01-06T18:29:48.802+08:00'));
|
Reference in New Issue
Block a user