Repository navigation
Expand file tree
/
Copy pathnote.js
More file actions
474 lines (458 loc) · 12.7 KB
/
Copy pathnote.js
File metadata and controls
474 lines (458 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
function loadNotes(){
//显示区域
$("#pc_part_1").show();
$("#pc_part_2").show();
$("#pc_part_3").show();
//隐藏区域
$("#pc_part_5").hide();
$("#pc_part_6").hide();
$("#pc_part_4").hide();
$("#pc_part_7").hide();
$("#pc_part_8").hide();
//点击笔记本加载列表(给现有的或者未来的元素匹配)
//动态绑定事件处理
$("#book_list li a").removeClass("checked");
$(this).find("a").addClass("checked");
//获取noteBookId
var noteIds = $(this).data("noteIds");
//发送ajax请求
$.ajax({
url:basePath+"/note/loadnotes.do",
type:"post",
data:{"noteId":noteIds},
dataType:"json",
success:function(result){
$("#note_list").empty();
if(result.status==0){
var datas = result.data;
for (var index = 0; index < datas.length; index++) {
var note_Title = datas[index].cn_note_title;
var note_Id = datas[index].cn_note_id;
var li_s =
"<li class='online'>"+
"<a>"+
"<i class='fa fa-file-text-o' title='online' rel='tooltip-bottom'>"+
"</i>"+note_Title+
"<button type='button' class='btn btn-default btn-xs btn_position btn_slide_down'>"+
"<i class='fa fa-chevron-dow'></i>"+
"</button>"+
"</a>"+
"<div class='note_menu' tabindex='-1'>"+
"<dl>"+
"<dt><button type='button' class='btn btn-default btn-xs btn_move' title='移动至...'><i class='fa fa-random'></i></button></dt>"+
"<dt><button type='button' class='btn btn-default btn-xs btn_share' title='分享'><i class='fa fa-sitemap'></i></button></dt>"+
"<dt><button type='button' class='btn btn-default btn-xs btn_delete' title='删除'><i class='fa fa-times'></i></button></dt>"+
"</dl>"+
"</div>"+
"</li>";
//创建节点
var $lis = $(li_s);
//藏值
$lis.data("note_Id",note_Id);
//拼接节点
$("#note_list").append($lis);
}
}
},
error:function(){
alert("网络繁忙,请稍后再试!");
}
});
}
//添加笔记
function addNotes(){
//获取笔记内容
var noteTitle = $("#input_note").val().trim();
//获取笔记本的Id
var $li_s_a = $("#book_list li a.checked").parent();
var bookIds = $li_s_a.data("noteIds");
var ok = true;
//检测用户是否选择笔记本
if(bookIds==undefined){
$("#modalBasicLabel_2").html("请选择笔记本").css("color","red");
return;
}
//检测用户笔记本是否为空
if(noteTitle==""){
$("#modalBasicLabel_2").html("笔记内容不能为空").css("color","red");
ok=false;
}
if(ok){
$.ajax({
url:basePath+"note/addnote.do?",
type:"post",
data:{"noteTitle":noteTitle,"bookId":bookIds,"userId":uId},
dataType:"json",
success:function(result){
if(result.status==0){
//关闭窗口
closeWindow();
//获取笔记ID
var noteId = result.data;
var li_s =
"<li class='online'>"+
"<a>"+
"<i class='fa fa-file-text-o' title='online' rel='tooltip-bottom'>"+
"</i>"+noteTitle+
"<button type='button' class='btn btn-default btn-xs btn_position btn_slide_down'>"+
"<i class='fa fa-chevron-dow'></i>"+
"</button>"+
"</a>"+
"<div class='note_menu' tabindex='-1'>"+
"<dl>"+
"<dt><button type='button' class='btn btn-default btn-xs btn_move' title='移动至...'><i class='fa fa-random'></i></button></dt>"+
"<dt><button type='button' class='btn btn-default btn-xs btn_share' title='分享'><i class='fa fa-sitemap'></i></button></dt>"+
"<dt><button type='button' class='btn btn-default btn-xs btn_delete' title='删除'><i class='fa fa-times'></i></button></dt>"+
"</dl>"+
"</div>"+
"</li>";
//创建节点
var $lis = $(li_s);
//藏值笔记ID
$lis.data("noteId",noteId);
$("#note_list").prepend($lis);
setTimeout("flushPage()", 0);
}
},
error:function(){
alert("网络异常,请稍后再试!");
}
});
}
}
function showNote(){
$("#note_list li a").removeClass("checked");
$(this).find("a").addClass("checked");
//获取笔记ID
var noteId = $(this).data("note_Id");
//发送ajax请求
$.ajax({
url:basePath+"note/findnote.do",
type:"post",
data:{"noteId":noteId},
dataType:"json",
success:function(result){
if(result.status==0){
var note = result.data;
//获取标题
var noteTitleName = note.cn_note_title;
//获取笔记内容
var noteBody = note.cn_note_body;
//设置标题
$("#input_note_title").val(noteTitleName);
//设置笔记内容
um.setContent(noteBody);
}
},
error:function(){
alert("网络繁忙,请稍后再试!");
}
});
}
//编辑笔记
function upateNotes(){
//获取标题
var noteTitle = $("#input_note_title").val();
//获取笔记内容
var noteBody = um.getContent();
//获取笔记ID
var $noteli = $("#note_list li a.checked").parent();
var noteId = $noteli.data("note_Id");
//发送ajax请求
$.ajax({
url:basePath+"/note/updateNote.do",
type : "post",
data : {"noteTitle":noteTitle,"noteBody":noteBody,"noteId":noteId},
dataType : "json",
success : function(result){
if(result.status==0){
//如果标题改变,修改列表标题
var newTitle = $("#note_list a.checked").text().trim();
if(newTitle!=noteTitle){
var news = "<i class='fa fa-file-text-o' title='online' rel='tooltip-bottom'>"+
"</i>"+noteTitle+
"<button type='button' class='btn btn-default btn-xs btn_position btn_slide_down'>"+
"<i class='fa fa-chevron-dow'></i>"+
"</button>";
$("#note_list a.checked").html(news);
}
alert("保存成功!");
}
},
error : function(){
alert("操作失败");
}
});
}
function resysle(){
//显示背景颜色
$(".opacity_bg").show();
//触发对话框
$("#can").load("alert/alert_delete_note.html");
//点击删除触发函数
$("#can").on("click","#recycle_note",recycleNote);
}
//进入回收站
function recycleNote(){
//获取笔记ID
var $lis = $("#note_list li a.checked").parent();
//var $lis = $(this).parents("li");
var noteId = $lis.data("note_Id");
//发送ajax请求
$.ajax({
url: basePath+"note/noteStatus.do",
type : "post",
data : {"noteId":noteId},
dataType : "json",
success : function(result){
if(result.status==0){
//删除列表
$lis.remove();
//清空编辑区和标题
um.setContent("");
$("#input_note_title").val("");
//提示删除
//删除成功自动触发关闭按钮
}
alert("删除成功!");
},
error : function(){
alert("删除失败!")
}
});
}
//分享笔记
function shareNote(){
//获取ID
var $lis = $("#note_list li a.checked").parent();
var noteId = $lis.data("note_Id");
//发送ajax请求
$.ajax({
url : basePath+"note/sharenote.do",
type : "post",
data :{"noteId":noteId},
dataType : "json",
success : function(result){
if(result.status==0){
alert(result.msg);
}else{
alert(result.msg);
}
},
error : function(){
alert("分享失败");
}
});
}
//搜索回收站分享笔记
function searchRecycle(){
$("#search_recycle li a").removeClass("checked");
$(this).find("a").addClass("checked");
var key = event.keyCode;
//用户按下之后开始检索
if(key==13){
$("#search_recycle").empty();
//获取用户输入的搜索内容
var keyText =
$("#search_note").val().trim();
//开始ajax请求
$.ajax({
url : basePath+"note/searchnote.do",
type : "post",
data : {"keyNote":keyText},
dataType : "json",
success : function(result){
if(result.status==0){
var noteData
= result.data;
for (var index = 0; index < noteData.length; index++) {
var noteShareTitle = noteData[index].cn_share_title;
var shareId = noteData[index].cn_share_id;
var li_s =
"<li class='online'>"+
"<a>"+
"<i class='fa fa-file-text-o' title='online' rel='tooltip-bottom'>"+
"</i>"+noteShareTitle+
"<button type='button' class='btn btn-default btn-xs btn_position btn_slide_down'>"+
"<i class='fa fa-chevron-dow'></i>"+
"</button>"+
"</a>"+
"</li>";
//创建节点
var $lis = $(li_s);
//藏值
$lis.data("shareId",shareId);
//拼接节点
$("#search_recycle").append($lis);
}
//隐藏全部笔记
$("#pc_part_1").show();
$("#pc_part_6").show();
$("#pc_part_5").show();
$("#pc_part_2").hide();
$("#pc_part_3").hide();
//展示搜索笔记
$("#pc_part_4").hide();
$("#pc_part_7").hide();
$("#pc_part_8").hide();
}
},
error : function(){
alert("网络繁忙,请稍后再试!");
}
});
}
}
function showShareNote(){
//获取检索笔记Id
var shareId = $(this).data("shareId");
//发送ajax请求
$.ajax({
url : basePath+"note/shareshow.do",
type : "post",
data : {"shareId":shareId},
dataType : "json",
success : function(result){
if(result.status==0){
var shareData = result.data;
$("#noput_note_title").text(shareData.cn_share_title);
$("#noput_note_body").text(shareData.cn_share_body);
}
//显示区域
$("#pc_part_5").show();
$("#pc_part_6").show();
//隐藏区域
$("#pc_part_3").hide();
$("#pc_part_2").hide();
},
error : function(){
alert("网络繁忙,请稍后再试!");
}
});
}
//展示回收站笔记
function recycleShowNote(){
$("#pc_part_4").show();
$("#pc_part_2").hide();
$("#pc_part_6").hide();
$("#pc_part_7").hide();
$("#pc_part_8").hide();
$("#replayNoteInput").empty();
$.ajax({
url : basePath+"note/recycleNote.do",
type : "post",
data : {"userId":uId},
dataType : "json",
success : function(result){
if(result.status==0){
var noteData = result.data;
for (var index = 0; index < noteData.length; index++) {
var noteTitle = noteData[index].cn_note_title;
var noteId = noteData[index].cn_note_id;
//节点初始化
var lis =
"<li class='disable'>"+
"<a>"+
"<i class='fa fa-file-text-o' title='online' rel='tooltip-bottom'>"+
"</i>"+noteTitle+""+
"<button type='button' class='btn btn-default btn-xs btn_position btn_delete'>"+
"<i class='fa fa-times'></i>"+
"</button>"+
"<button type='button' class='btn btn-default btn-xs btn_position_2 btn_replay' id ='show_replay'>"+
"<i class='fa fa-reply'></i>"+
"</button>"+
"</a>"+
"</li>";
//创建节点
var $li_s = $(lis);
//藏值
$li_s.data("noteId",noteId);
//拼接节点
$("#replayNoteInput").append($li_s);
}
}
},
error : function(){
alert("网络繁忙,请稍后再试!");
}
});
}
//打开笔记恢复按钮
function replayNoteInput(){
//获取笔记Id
var $li = $(this).parent().parent("li");
var noteId = $li.data("noteId");
$(".opacity_bg").show();
$("#can").load("alert/alert_replay.html",function(){
$.ajax({
url:basePath+"notebook/loadbooks.do",
type:"post",
data:{"userId":uId},
dataType:"json",
success : function(result){
if(result.status==0){
var dataNote = result.data;
for (var index = 0; index < dataNote.length; index++) {
var noteTitle = dataNote[index].cn_notebook_name;
var noteData = dataNote[index].cn_notebook_id;
var options ='<option value = '+noteData+'>'+noteTitle+'</option>' ;
var $option = $(options);
//
$option.data("booknoteId",noteData);
//将获取的笔记Id放于恢复按钮中
$("#sure_replay").data("noteId",noteId);
$("#replaySelect").append($option);
}
}
},
error : function(){
alert("网络繁忙,请稍后再试!");
}
});
});
}
//恢复笔记
function replayNote(){
//获取笔记Id
var noteId = $("#sure_replay").data("noteId");
//获取笔记本Id
var bookNoteId = $("#replaySelect option:checked").val();
//将回收站恢复的笔记删除
//发送ajax请求
$.ajax({
url : basePath+"note/replayNote.do",
type : "post",
data : {"noteId":noteId,"bookNoteId":bookNoteId},
dataType : "json",
success : function(result){
if(result.status==0){
//关闭恢复窗口
closeNoteWindows();
alert("操作成功!");
//再次点击页面.自动触发一次请求
setTimeout(function(){
$("#rollback_button").trigger("click");
}, 0);
}
},
error : function(){
alert("网络繁忙,请稍后再试!");
}
});
}
//获取回收站的noteId
function getRecycleNoteId(){
}
//打开笔记窗口
function showNoteWindows(){
$("#can").load("alert/alert_note.html");
$(".opacity_bg").show();
}
//关闭笔记窗口
function closeNoteWindows(){
$("#can").empty();
$(".opacity_bg").hide();
}
function flushPage(){
window.location.reload(true);
}