This repository was archived by the owner on May 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforum.html
302 lines (237 loc) · 10 KB
/
forum.html
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
<!DOCTYPE html>
<html>
<head>
<title>List Contacts form Mongodb</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy"
crossorigin="anonymous">
<link rel="stylesheet" href="dashboard.css">
<link href='https://fonts.googleapis.com/css?family=Advent Pro' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css?family=Bubbler One' rel='stylesheet'>
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<link rel="icon" href="images/favicon.ico" type="image/x-icon">
<style>
body {
font-family: 'Advent Pro';font-size: 22px;
background-image: url("images/bg_.gif");
}
#msg{
margin: 25px;
padding: 25px;
background-color: rgb(122, 184, 219);
border-radius: 20px;
}
#contact-form{
margin: 25px;
padding: 25px;
background-color: rgb(219, 101, 71);
border-radius: 20px;
}
header{
font-family: 'Bubbler One';
font-size: 50px;
display: block;
text-align: center;
}
</style>
</head>
<body>
<header>
Welcome to the live chat! Interact with the other users of Destination!
</header>
<div class="table-responsive">
<table id="contacts-table" class="table table-striped">
<!--<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Email</th>
<th>Msg</th>
<th>Actions</th>
</tr>
</thead>-->
<tbody id="contacts-body">
</tbody>
</table>
</div>
<div class="container" id=msg-board>
<form id="contact-form">
<div class="form-group">
<label for="user-name">Username</label>
<input type="text" class="form-control" id="user-name" placeholder="Name" required>
</div>
<div class="form-group">
<label for="user-question"></label>
<textarea class="form-control" id="user-question" placeholder="Join the conversation!" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</main>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4"
crossorigin="anonymous"></script>
<script>
$(document).ready(function () {
var apiKey = "5e284c034327326cf1c91aba";
var myDB = "destination-298c";
var myCollection = "destination";
$(document).on("click",".delete", function (event) {
event.preventDefault();
event.stopPropagation();
console.log("click event");
var id = $(this).data("id");
console.log("id... " + id);
deleteContact(id);
});
//create listener for submit
var contact = {
ans: "",
}
$("#submit-btn").on("click",function (event) {
console.log("submitting form details");
event.preventDefault();
event.stopPropagation();
listAns();
//retrieve form values
contact.ans = $("#answer").val();
//set contact format json data
let contactDocument = {
ans: contact.ans,
};
var settings = {
"async": true,
"crossDomain": true,
"url": "https://"+ myDB +".restdb.io/rest/" + myCollection +"",
"method": "POST",
"headers": {
"content-type": "application/json",
"x-apikey": apiKey,
"cache-control": "no-cache"
},
"processData": false,
"data": JSON.stringify(contactDocument)
}
$.ajax(settings).done(function (response) {
console.log(response);
});
});
function deleteContact(id){
var settings = {
"async": true,
"crossDomain": true,
"url": "https://"+ myDB +".restdb.io/rest/" + myCollection + "/" + id,
"method": "DELETE",
"headers": {
"content-type": "application/json",
"x-apikey": apiKey,
"cache-control": "no-cache"
}
}
$.ajax(settings).done(function (response) {
console.log("delete entry:" + id);
//animate before removing from DOM
//tap on data id
$('tr[data-row="' + id +'"]').fadeOut(300, function(){ $(this).remove();});
});
}
var i = 0
$("#like-btn").on("click", function(event){
i++
console.log(i)
$("#like-btn").text(`${i} likes`)
})
function listContacts() {
console.log("start of listing contacts");
var settings = {
"async": true,
"crossDomain": true,
"url": "https://"+ myDB +".restdb.io/rest/" + myCollection +"",
"method": "GET",
"headers": {
"content-type": "application/json",
"x-apikey": apiKey,
"cache-control": "no-cache"
}
}
$.ajax(settings).done(function (data) {
console.log("successfully log into db");
console.log(data);
var numContacts = data.length;
console.log("number of contacts" + numContacts);
$("#num-contacts").html(numContacts);
//do a jquery loop of json objects based on their keys(indexes)
$.each(data, function (key, value) {
console.log(key + "value");
console.log("Name" + data[key].name);
console.log("title" + data[key].title);
console.log("qns" + data[key].qns);
console.log("id" + data[key]._id);
var contactDocument = {
name: data[key].name,
title: data[key].title,
qns: data[key].qns,
id: data[key]._id
}
$("#msg-board").append(
//`<tr data-row="${contactDocument.id}"><td>${contactDocument.id}</td><td>${contactDocument.name}</td><td>${contactDocument.title}</td><td>${contactDocument.qns}</td>
//<td><a href="x" class="btn btn-danger delete" id="delete-${contactDocument.id}" data-id="${contactDocument.id}">Delete</a>
//<button class="btn btn-info edit" id="edit-${contactDocument.id}" data-id="${contactDocument.id}">Edit</button></td></tr>
//`
`<section id="msg">
<h3>${contactDocument.name}</h3>
<h4>${contactDocument.qns}</h4>
<a href="x" class="btn btn-danger delete" id="delete-${contactDocument.id}" data-id="${contactDocument.id}">Delete</a>
</section>
`
);
}); //end each loop
});
} //end listContacts
listContacts();
}); //end doc ready
var apiKey = "5e284c034327326cf1c91aba";
var myDB = "destination-298c";
var myCollection = "destination";
//create listener for submit
var contact = {
name: "",
title: "",
qns: ""
}
$("#contact-form").submit(function (e) {
console.log("submitting form details");
event.preventDefault();
//retrieve form values
contact.name = $("#user-name").val();
contact.title = $("#qns-title").val();
contact.qns = $("#user-question").val();
//set contact format json data
let contactDocument = {
name: contact.name,
title: contact.title,
qns: contact.qns,
};
var settings = {
"async": true,
"crossDomain": true,
"url": "https://"+ myDB +".restdb.io/rest/" + myCollection +"",
"method": "POST",
"headers": {
"content-type": "application/json",
"x-apikey": apiKey,
"cache-control": "no-cache"
},
"processData": false,
"data": JSON.stringify(contactDocument)
}
$.ajax(settings).done(function (response) {
console.log(response);
});
});
</script>
</body>
</html>