Provide Interface for Booking Deletion 29/52129/4
authorSawyer Bergeron <sbergeron@iol.unh.edu>
Tue, 13 Feb 2018 22:53:56 +0000 (17:53 -0500)
committerSawyer Bergeron <sbergeron@iol.unh.edu>
Mon, 19 Feb 2018 21:16:25 +0000 (21:16 +0000)
Jira: PHAROS-355

User can now delete their own booking by going to the detail view of their booking
and clicking 'delete'

Change-Id: I279da364c2a5dfd03b877d1236c610d0fef563bc
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
dashboard/src/booking/urls.py
dashboard/src/booking/views.py
dashboard/src/templates/booking/booking_calendar.html
dashboard/src/templates/booking/booking_delete.html [new file with mode: 0644]
dashboard/src/templates/booking/booking_detail.html

index 403e32f..ed3b1d4 100644 (file)
@@ -30,11 +30,17 @@ from booking.views import *
 urlpatterns = [
     url(r'^(?P<resource_id>[0-9]+)/$', BookingFormView.as_view(), name='create'),
     url(r'^(?P<resource_id>[0-9]+)/edit/(?P<booking_id>[0-9]+)/$', BookingEditFormView.as_view(), name='edit'),
+
     url(r'^(?P<resource_id>[0-9]+)/bookings_json/$', ResourceBookingsJSON.as_view(),
         name='bookings_json'),
 
     url(r'^detail/$', BookingView.as_view(), name='detail_prefix'),
     url(r'^detail/(?P<booking_id>[0-9]+)/$', BookingView.as_view(), name='detail'),
 
+    url(r'^delete/$', BookingDeleteView.as_view(), name='delete_prefix'),
+    url(r'^delete/(?P<booking_id>[0-9]+)/$', BookingDeleteView.as_view(), name='delete'),
+
+    url(r'^delete/(?P<booking_id>[0-9]+)/confirm/$', bookingDelete, name='delete_booking'),
+
     url(r'^list/$', BookingListView.as_view(), name='list')
-]
+]
\ No newline at end of file
index ab3a04e..7e35af2 100644 (file)
@@ -18,6 +18,7 @@ from django.views import View
 from django.views.generic import FormView
 from django.views.generic import TemplateView
 from jira import JIRAError
+from django.shortcuts import redirect
 
 from account.jira_util import get_jira
 from booking.forms import BookingForm, BookingEditForm
@@ -163,6 +164,7 @@ class BookingEditFormView(FormView):
 class BookingView(TemplateView):
     template_name = "booking/booking_detail.html"
 
+
     def get_context_data(self, **kwargs):
         booking = get_object_or_404(Booking, id=self.kwargs['booking_id'])
         title = 'Booking Details'
@@ -170,6 +172,21 @@ class BookingView(TemplateView):
         context.update({'title': title, 'booking': booking})
         return context
 
+class BookingDeleteView(TemplateView):
+    template_name = "booking/booking_delete.html"
+
+    def get_context_data(self, **kwargs):
+        booking = get_object_or_404(Booking, id=self.kwargs['booking_id'])
+        title = 'Delete Booking'
+        context = super(BookingDeleteView, self).get_context_data(**kwargs)
+        context.update({'title': title, 'booking': booking})
+        return context
+
+def bookingDelete(request, booking_id):
+    booking = get_object_or_404(Booking, id=booking_id)
+    booking.delete()
+    messages.add_message(request, messages.SUCCESS, 'Booking deleted')
+    return redirect('../../../../')
 
 class BookingListView(TemplateView):
     template_name = "booking/booking_list.html"
@@ -188,4 +205,4 @@ class ResourceBookingsJSON(View):
         bookings = resource.booking_set.get_queryset().values('id', 'start', 'end', 'purpose',
                                                               'jira_issue_status', 'opsys__name',
                                                               'installer__name', 'scenario__name')
-        return JsonResponse({'bookings': list(bookings)})
+        return JsonResponse({'bookings': list(bookings)})
\ No newline at end of file
index 52193d5..2e3f970 100644 (file)
     <script type="text/javascript">
         var bookings_url = "{% url 'booking:bookings_json' resource_id=resource.id %}";
         var booking_detail_prefix = "{% url 'booking:detail_prefix' %}";
+        var booking_delete_prefix = "{% url 'booking:delete_prefix' %}";
         var user_timezone = "{{ request.user.userprofile.timezone }}"
     </script>
 
     <script src={% static "js/fullcalendar-options.js" %}></script>
     <script src={% static "js/datetimepicker-options.js" %}></script>
     <script src={% static "js/booking-calendar.js" %}></script>
-{% endblock extrajs %}
+{% endblock extrajs %}
\ No newline at end of file
diff --git a/dashboard/src/templates/booking/booking_delete.html b/dashboard/src/templates/booking/booking_delete.html
new file mode 100644 (file)
index 0000000..76a5634
--- /dev/null
@@ -0,0 +1,11 @@
+{% load jira_filters %}
+{% load bootstrap3 %}
+
+<p>
+    Really delete Booking from {{ booking.start}} to {{ booking.end }}?
+</p>
+<p>
+    <div id="booking_delete_form_div">
+        <a href="{% url 'booking:delete_booking' booking_id=booking.id %}" class="btn btn btn-danger">Delete Booking</a>
+    </div>
+</p>
\ No newline at end of file
index dd0bf03..c88cd84 100644 (file)
@@ -1,5 +1,22 @@
 {% load jira_filters %}
 
+<script type="text/javascript">
+    function deleteClick(id) {
+        var booking_delete_url = booking_delete_prefix + id
+        $.ajax({
+            url: booking_delete_url,
+            type: 'get',
+            success: function (data) {
+                $('#booking_delete_content').html(data);
+            },
+            failure: function (data) {
+                alert('Error finding that booking');
+            }
+        });
+        $('#booking_delete_modal').modal('show');
+    }
+</script>
+
 <p>
     <b>Resource: </b>
     <a href="{{ booking.resource.url }}">
     <a href="{% url 'booking:edit' booking_id=booking.id resource_id=booking.resource.id  %}" class="btn btn btn-success">
         Edit Booking
     </a>
+    <a href="javascript:deleteClick({{ booking.id }})" class="btn btn btn-danger">
+        Delete Booking
+    </a>
+    <div id="booking_delete_modal" class="modal fade" role="dialog">
+        <div class="modal-dialog">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <button type="button" class="close" data-dismiss="modal">&times;</button>
+                    <h4 class="modal-title">Delete Booking</h4>
+                </div>
+                <div class="modal-body" id="booking_delete_content">
+                </div>
+            </div>
+        </div>
+    </div>
 </p>
 {% endif %}
-{% endif %}
+{% endif %}
\ No newline at end of file