1 |
{% extends "layout.html" %} |
2 |
{% block body %} |
3 |
<script type="text/javascript"> |
4 |
function deletePost(post_id) { |
5 |
if(confirm("Do you really want to delete this post?")) { |
6 |
$.post( |
7 |
'/posts/delete/', |
8 |
{'post_id': post_id}, |
9 |
function() { |
10 |
alert("The post has been deleted!!"); |
11 |
window.location.href = '/'; |
12 |
}); |
13 |
} |
14 |
return false; |
15 |
} |
16 |
function editPost(entry) { |
17 |
t = _.template($("#editTemplate").html()); |
18 |
$(".modal-body").append(t(items=entry)); |
19 |
$("input").each(function(item) { |
20 |
$(this).val(entry[$(this).attr('for')]); |
21 |
|
22 |
}, this); |
23 |
$("#editModal").modal(); |
24 |
} |
25 |
</script> |
26 |
<ul class="entries"> |
27 |
{% for entry in entries %} |
28 |
<li> |
29 |
@<b>{{ entry.who }}</b> |
30 |
<b>#{{ entry.what }}</b> /{{ entry.where }} {{ entry.how|safe }} |
31 |
{% if session.logged_in %} |
32 |
{% if session.isAdmin or session.username == entry.who %} |
33 |
<button class="right btn btn-sm btn-default" onclick='editPost({{entry.how|tojson|safe}})'> |
34 |
<i class="glyphicon glyphicon-edit"></i> |
35 |
</button> |
36 |
<a class="pull-right" href="#" onclick='deletePost({{entry.id|string|tojson|safe}})'> |
37 |
<i class="glyphicon glyphicon-trash"></i> |
38 |
</a> |
39 |
{% endif %} |
40 |
{% endif %} |
41 |
</li> |
42 |
{% endfor %} |
43 |
</ul> |
44 |
|
45 |
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true"> |
46 |
<div class="modal-dialog modal-lg"> |
47 |
<div class="modal-content"> |
48 |
<div class="modal-header"> |
49 |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
50 |
<h4 class="modal-title">Edit SWeeT</h4> |
51 |
</div> |
52 |
<div class="modal-body row"> |
53 |
|
54 |
</div> |
55 |
<div class="modal-footer"> |
56 |
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> |
57 |
</div> |
58 |
</div><!-- /.modal-content --> |
59 |
</div><!-- /.modal-dialog --> |
60 |
</div><!-- /.modal --> |
61 |
|
62 |
<script type="text/template" id="editTemplate"> |
63 |
<form action="" method="post"> |
64 |
<% _.each(items, function(item, key) { %> |
65 |
<div class="input-group col-md-12"> |
66 |
<label> <%= key %> </label> |
67 |
<input name=<%= key %> for=<%= key %> class="form-control" type="text"> </input> |
68 |
</div> |
69 |
</br> |
70 |
<% }) %> |
71 |
<button class="btn btn-default" type="submit">Save</button> |
72 |
</form> |
73 |
</script> |
74 |
{% endblock %} |