-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.html
214 lines (196 loc) · 6.84 KB
/
admin.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Admin Page</title>
<script src="js/jquery-2.0.3.min.js"></script>
</head>
<body>
<h3>Welcome </h3>
<div id="main" onload="mainMenu()">
</div>
<a id="logout" href="#">Logout</a>
</body>
<script>
function getPosts() {
$.ajax({
url: "controller.php?action=post&postaction=show",
beforeSend: function (xhr) {
xhr.overrideMimeType("applcation/json; charset=utf8");
}
}).done(function (data) {
if (data['status'] === "OK") {
for (var i = 0; i < data['posts'].length; i++) {
var id = data['posts'][i]['id'];
var title = data['posts'][i]['title'];
var postDate = data['posts'][i]['postDate'];
var author = data['posts'][i]['author'];
var post = data['posts'][i]['post'];
$("body").append("<p><form id='"+id+"' class='posts' method='post'>\
<input type='text' class='title' disabled value='"+title+"'/>\
<label>"+postDate+"</label>\
<label>"+author+"</label>\
<textarea class='post' disabled>"+post+"</textarea>\
<button class='edit'>Edit</button> <button class='delete'>Delete</button>\
</form></p>");
}
}
});
}
$(document).ready(function(){
$("a#logout").click(function(e){
e.preventDefault();
$.ajax({
url: "controller.php?action=logout",
beforeSend: function (xhr) {
xhr.overrideMimeType("application/json; charset=utf8");
}
}).done(function (data){
if (data['logout'])
{
localStorage.removeItem("session");
window.location.href = "login.html";
}
});
});
$("div#main").on("click", "a#menu", function(e) {
$("div#main").html("<form id='imageupload' method='post' 'enctype='multipart/form-data'><label for='menuform'>Menu: </label><input type='file' name='foodmenu' /><input type='submit' value='Υποβολή'/></form><a id='back' href='#'>Επιστροφή</a>");
});
$("div#main").on("click", "a#schedule", function(e) {
$("div#main").html("<form id='imageupload' method='post' enctype='multipart/form-data'><label for='scheduleform'>Menu: </label><input type='file' name='buschedule' /><input type='submit' value='Υποβολή'/></form><a id='back' href='#'>Επιστροφή</a>");
});
$("div#main").on("click", "a#announcements", function(e) {
$("div#main").html("<form id='announce' method='post'><label for='post'>Title: </label><input type='text' id='title' name='title' size='25'/><br/><label>Post: </label><textarea name='post'></textarea><input type='submit'/></form><a id='back' href='#'>Επιστροφή</a>");
});
});
$("div#main").on("submit", "#imageupload", function(e) {
e.preventDefault();
var formData = new FormData($("form")[0]);
$.ajax({
url: 'controller.php?action=fileupload',
type: 'POST',
data: formData,
cache: false,
contentType: false,
processData: false
}).done(function (data){
alert(data);
});
});
$("div#main").on("submit", "#announce", function(e) {
e.preventDefault();
var formData = new FormData($("form")[0]);
$.ajax({
url: 'controller.php?action=post&postaction=create',
type: 'POST',
data: formData,
dataType: 'json',
cache: false,
contentType: false,
processData: false
}).done(function (data){
if (data['created']) {
alert("Successfully Posted!");
$("form.posts").remove();
getPosts(); //I know noob move :P
}
else {
alert("A problem was occurred!");
}
});
});
$("div#main").on("DOMNodeInserted", "#announce", function(e) {
getPosts();
});
$("body").on("click", ".edit", function(e) {
e.preventDefault();
$(this).siblings(".title").attr("disabled", false);
$(this).siblings(".post").attr("disabled", false);
$(this).text('Save');
$(this).attr('class', 'save');
});
$("body").on("click", ".save", function(e) {
e.preventDefault();
var id = $(this).parent().attr('id');
var title = $(this).siblings(".title").val();
var post = $(this).siblings(".post").val();
var data = new FormData();
data.append('id', id);
data.append('title', title);
data.append('post', post);
$.ajax({
url: 'controller.php?action=post&postaction=edit',
type: 'POST',
data: data,
dataType: 'json',
cache: false,
contentType: false,
processData: false
}).done(function (data) {
if (data['updated']) {
alert("Successfully Edited!");
}
else {
alert("Problem occurred!");
}
});
$("form.posts").remove();
getPosts();
});
$("body").on("click", ".delete", function(e) {
e.preventDefault();
var id = $(this).parent().attr('id');
var data = new FormData();
data.append('id', id);
$.ajax({
url: 'controller.php?action=post&postaction=delete',
type: 'POST',
data: data,
dataType: 'json',
cache: false,
contentType: false,
processData: false
}).done(function (data) {
if (data['deleted']) {
alert("Successfully deleted!");
}
else {
alert("Problem occurred!");
}
});
$("form.posts").remove();
getPosts();
});
$("div#main").on("click", "a#back", function (e) {
$("form.posts").remove();
$("div#main").html(mainMenu);
});
$(document).ready(function(e) {
$.ajax({
url: "controller.php?action=checklogin",
beforeSend: function (xhr) {
xhr.overrideMimeType("application/json; charset=utf8");
}
}).done(function (data){
if (!data['loggedin'])
{
localStorage.removeItem("session");
window.location.href = "login.html";
}
else
{
$("div#main").html(mainMenu);
}
});
});
var mainMenu = "<table>\
<tr>\
<td><a id='menu' href='#'>Menu Λέσχης</a></td>\
<td><a id='schedule' href='#'>Δρομολόγια</a></td>\
</tr>\
<tr>\
<td colspan='2'><a id='announcements' href='#'>Ανακοινώσεις Σπουδαστικού</a></td>\
</tr>\
</table>";
</script>
</html>