-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcouchever.js
167 lines (147 loc) · 3.82 KB
/
couchever.js
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
$db = $.couch.db("couchever");
function refreshNoteList() {
$("ul#NoteList").empty();
$db.view("couchever/allnotes", {
success: function(data) {
for (r in data.rows) {
v= data.rows[r].value
docid = v._id;
doctit = v.Title;
html = '<li><a href="" value="'+docid+'">' +doctit+ '</a></li>';
$("ul#NoteList").append(html);
}
$("#NoteList li a").click( function(e) {
e.preventDefault;
showNote($(this).attr('value'));
return false;
});
} ,
error: function(status) {
alert("Cannot retrieve Notes");
},
reduce: false
});
}
function refreshTagList() {
$("ul#TagList").empty();
$db.view("couchever/tags", {
success: function(data) {
for (r in data.rows) {
v= data.rows[r]
docid = v.key;
doctnbr = v.value;
html = '<li><a href="#" value="'+docid+'">'+docid+'</a></li>';
$("ul#TagList").append(html);
}
$("#TagList li a").click( function(e) {
e.preventDefault;
//showNote($(this).attr('value'));
return false;
});
} ,
error: function(status) {
alert("Cannot retrieve Tags");
},
group: true
});
}
function setDefaultActions() {
$("#BtAddNote").click( function(e) {
e.preventDefault;
NewNote();
return false;
});
$("#BtEditNote").click( function(e) {
e.preventDefault;
EditNote($("span#noteid").text());
return false;
});
$("#BtDelNote").click( function(e) {
e.preventDefault;
DelNote($("span#noteid").text());
return false;
});
}
function init() {
setDefaultActions();
refreshTagList();
refreshNoteList();
}
function setmsg(msg){
$("span#msg").empty();
$("span#msg").append(msg);
}
function showNote(searchid) {
$("div#ct").empty();
$db.openDoc(searchid, {
success: function(data) {
html = Mustache.to_html(Tpl_ShowDoc, data);
$("div#ct").append(html);
} ,
error: function(status) {
setmsg("ERROR: Cannot retrieve Document");
}
});
}
function submitNewDoc(){
var formData = form2js('NewDoc', '.', true,
function(node)
{
if (node.name && node.name =="Tags")
{
return { name: node.name, value: node.value.split(" ") };
}
});
$db.saveDoc(formData, {
success: function(data) {
setmsg("Document saved");
$("div#ct").empty();
refreshTagList();
refreshNoteList();
} ,
error: function(status) {
setmsg("ERROR: Cannot retrieve Document");
}
});
}
function NewNote() {
$("div#ct").empty();
data=[];
html = Mustache.to_html(Tpl_NewDoc, data);
$("div#ct").append(html);
}
function EditNote(searchid) {
$("div#ct").empty();
$db.openDoc(searchid, {
success: function(data) {
html = Mustache.to_html(Tpl_EditDoc, data);
$("div#ct").append(html);
} ,
error: function(status) {
setmsg("ERROR: Cannot retrieve Document");
}
});
}
function DelNote(searchid) {
if (confirm("Delete this note ?")) {
alert("Delete this note?");
$db.openDoc(searchid, {
success: function(data) {
$db.removeDoc(data, {
success: function() {
$("div#ct").empty();
setmsg("Document removed");
refreshTagList();
refreshNoteList();
} ,
error: function(status) {
setmsg("ERROR: Cannot remove Document");
}
});
} ,
error: function(status) {
setmsg("ERROR: Cannot retrieve Document");
}
});
}
}