-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmynotes.php
More file actions
143 lines (137 loc) · 4.42 KB
/
mynotes.php
File metadata and controls
143 lines (137 loc) · 4.42 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
<?php
include_once './template/header.php';
?>
<div class="container-fluid">
<div id="login-notification">
<h2>Please log in.</h2>
</div>
<div id="notes">
<div id="new-note" class="col-sm-offset-4 col-sm-4">
<div id="output" class="alert alert-success" role="alert"></div>
<input type="text" class="form-control" placeholder="Title">
<textarea class="form-control" rows="1" placeholder="Add note"></textarea>
<button class="btn btn-primary">Add</button>
<button class="btn btn-default">Cancel</button>
</div>
<div id="display-notes" class="col-sm-offset-2 col-sm-9">
<h2><p class="text-info">All notes of <b><?php echo $_SESSION['name']; ?></b></p></h2>
<div class="col-sm-4" id="div1">
</div>
<div class="col-sm-4" id="div2">
</div>
<div class="col-sm-4" id="div3">
</div>
</div>
</div>
<script>
makeActive(1);
$(function () {
<?php
if(!empty($_SESSION['name'])){
?>
showNotes();
<?php
}else{
?>
showLoginNotification();
<?php
}
?>
});
var list = $('#grid');
var title = $('#new-note input');
var output = $('#output');
output.hide();
title.hide();
var addnote_btn = $('#new-note button').first().hide();
var cancelnote_btn = $('#new-note button').last().hide();
var content = $('#new-note textarea');
showAllNotes();
content.on('click', function (event) {
event.stopPropagation();
showNewNote();
});
title.on('click', function (event) {
event.stopPropagation();
});
cancelnote_btn.on('click', function () {
clearNewNote();
});
addnote_btn.on('click', function () {
addNote(title.val(), content.val());
});
$(document.body).on('click', function () {
clearNewNote();
});
function showNote(note, index) {
//console.log(index+"|"+note.title);
var newrow = '<div class="panel panel-primary"><div class="panel-heading"><h3 class="panel-title">' + note.title + '</h3></div><div class="panel-body">' + note.content + '</div><div class="panel-footer">' + note.created_at + '</div></div>';
var id = "#div" + (index + 1);
$(id).append(newrow);
//console.log(id+"|"+note.title);
}
function showAllNotes() {
removeList();
$.post('./core/api/shownotes.php', function (data) {
var json_obj = $.parseJSON(data);
for (var j in json_obj) {
var i = json_obj.length - j - 1;
showNote(json_obj[i], j%3);
}
});
}
function removeList() {
$('.panel').remove();
}
function addNote(t, c) {
var request = $.ajax({
type: 'POST',
data: {title: title.val(), content: content.val()},
url: './core/api/addnote.php'
});
request.done(function () {
output.text('Well Done! You successfully add a note.');
clearNewNote();
output.show();
showAllNotes();
});
}
function showNewNote() {
content.attr('rows', 3);
title.show();
addnote_btn.show();
cancelnote_btn.show();
output.hide();
}
function clearNewNote() {
content.attr('rows', 1);
content.val('');
title.val('');
title.hide();
output.hide();
addnote_btn.hide();
cancelnote_btn.hide();
}
function showLoginNotification() {
$('#login-notification').show();
$('#notes').hide();
}
function showNotes() {
$('#login-notification').hide();
$('#notes').show();
$('#display-notes').show();
}
</script>
<style>
body {
padding-top: 70px;
}
textarea {
resize: none;
}
#grid li {
}
</style>
<?php
include_once './template/footer.php';
?>