From 319bd17d8224d026199c2830d57b7a9dc672b591 Mon Sep 17 00:00:00 2001
From: Christian Dresen <c.dresen@fh-muenster.de>
Date: Tue, 11 Oct 2016 20:03:54 +0200
Subject: [PATCH] [WarpFood] Added function to delete food orders. Closed #27

---
 www/web/warpfood/templates/warpfood/view.html | 16 ++++++++++++++--
 www/web/warpfood/views.py                     | 12 ++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/www/web/warpfood/templates/warpfood/view.html b/www/web/warpfood/templates/warpfood/view.html
index 9a6b6a4..3f9c929 100644
--- a/www/web/warpfood/templates/warpfood/view.html
+++ b/www/web/warpfood/templates/warpfood/view.html
@@ -31,7 +31,7 @@
                             {% if sheet.order_time %}
                                 <a href="/pizza/sheet_ordered/{{ sheet.id }}" class="btn btn-success disabled">{% trans "ordered" %}</a>
                             {% else %}
-                                <a href="/pizza/sheet_ordered/{{ sheet.id }}" class="btn btn-danger" id="confirm">{% trans "confirm" %}</a>
+                                <a href="/pizza/sheet_ordered/{{ sheet.id }}" class="btn btn-danger" id="confirm_order">{% trans "confirm" %}</a>
                             {% endif %}
                             <!-- <a href="/pizza/export_sheet/{{ sheet.id }}" class="btn btn-info">Print order</a> -->
                         {% endif %}
@@ -77,6 +77,7 @@
     <table class="table table-striped table-hover">
         <thead>
             <tr>
+                <th>&nbsp;&nbsp;<span class="glyphicon glyphicon-trash"></span></th>
                 <th>{% trans "username" %}</th>
                 <th>{% trans "article" %}</th>
                 <th>{% trans "size" %}</th>
@@ -88,6 +89,7 @@
         <tbody>
             {% for order in orders %}
                 <tr>
+                    <td>&nbsp;&nbsp;<a href="#" data-order-id="{{order.id}}" class="confirm_order_delete"><span class="glyphicon glyphicon-minus text-danger"></span></a></td>
                     <td>{{ order.user }}</td>
                     <td>{{ order.article }}</td>
                     <td>{{ order.size }}</td>
@@ -157,7 +159,7 @@
     </div>
     
     <script>
-        $('#confirm').click(function (e) {
+        $('#confirm_order').click(function (e) {
             e.preventDefault();
             bootbox.confirm("{% trans "are_you_sure" %}", function (result) {
                 if(result)
@@ -166,6 +168,16 @@
                 }
             });
         });
+        $('.confirm_order_delete').click(function (e) {
+            e.preventDefault();
+            id = $(this).data('order-id')
+            bootbox.confirm("{% trans "are_you_sure" %}", function (result) {
+                if(result)
+                {
+                   window.location = "/pizza/delete_order/"+id;
+                }
+            });
+        });
     </script>
 {% endblock %}
 
diff --git a/www/web/warpfood/views.py b/www/web/warpfood/views.py
index 15d3a02..034dc9c 100644
--- a/www/web/warpfood/views.py
+++ b/www/web/warpfood/views.py
@@ -128,3 +128,15 @@ def sheet_ordered(request, sheet_id=0):
         sheet.save()
 
     return redirect("/pizza/view/%s" % sheet_id)
+
+def delete_order(request, order_id=0):
+    if order_id != 0:
+        try:
+            order = FoodOrder.objects.get(id=order_id)
+            sheet_id = order.sheet_id
+            order.delete()
+            return redirect("/pizza/view/%s" % sheet_id)
+        except:
+            pass
+
+    return redirect("/")
-- 
GitLab