544de4f by Anon Ray at 2013-06-27 | 1 | {% extends "layout.html" %} |
2 | {% block body %} |
|
347ae26 by Arvind at 2013-01-08 | 3 | <script type="text/javascript"> |
544de4f by Anon Ray at 2013-06-27 | 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 | } |
|
5185b44 by Arvind Khadri at 2014-04-04 | 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 | } |
|
347ae26 by Arvind at 2013-01-08 | 25 | </script> |
544de4f by Anon Ray at 2013-06-27 | 26 | <ul class="entries"> |
31f43d5 by Arvind at 2013-01-07 | 27 | {% for entry in entries %} |
544de4f by Anon Ray at 2013-06-27 | 28 | <li> |
29 | @<b>{{ entry.who }}</b> |
|
30 | <b>#{{ entry.what }}</b> /{{ entry.where }} {{ entry.how|safe }} |
|
31 | {% if session.logged_in %} |
|
5185b44 by Arvind Khadri at 2014-04-04 | 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> |
|
544de4f by Anon Ray at 2013-06-27 | 36 | <a class="pull-right" href="#" onclick='deletePost({{entry.id|string|tojson|safe}})'> |
5185b44 by Arvind Khadri at 2014-04-04 | 37 | <i class="glyphicon glyphicon-trash"></i> |
544de4f by Anon Ray at 2013-06-27 | 38 | </a> |
39 | {% endif %} |
|
5185b44 by Arvind Khadri at 2014-04-04 | 40 | {% endif %} |
544de4f by Anon Ray at 2013-06-27 | 41 | </li> |
1a7990c by Arvind at 2013-04-26 | 42 | {% endfor %} |
31f43d5 by Arvind at 2013-01-07 | 43 | </ul> |
5185b44 by Arvind Khadri at 2014-04-04 | 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> |
|
544de4f by Anon Ray at 2013-06-27 | 74 | {% endblock %} |