Commit f7b7edeb by Czémán Arnold

dashboard: add delete view for Endpoint

parent 764d9bf6
......@@ -29,17 +29,24 @@ $(function () {
return false;
});
$('.group-create, .node-create, .tx-tpl-ownership, .group-delete, .node-delete, .disk-remove, .template-delete, .delete-from-group, .lease-delete').click(function(e) {
$('.group-create, .node-create, .tx-tpl-ownership, .group-delete, .node-delete, .disk-remove, .template-delete, .delete-from-group, .lease-delete, .endpoint-delete').click(function(e) {
$.ajax({
type: 'GET',
url: $(this).prop('href'),
success: function(data) {
$('body').append(data);
var modal = $('#confirmation-modal');
modal.modal('show');
modal.on('hidden.bs.modal', function() {
modal.remove();
});
success: function(data, _, xhr) {
var ctype = xhr.getResponseHeader("content-type") || "";
if(ctype.indexOf("html") > -1) {
$('body').append(data);
var modal = $('#confirmation-modal');
modal.modal('show');
modal.on('hidden.bs.modal', function() {
modal.remove();
});
}
else if(ctype.indexOf("json") > -1) {
if(data.error !== null && data.error !== undefined)
addMessage(data.error, "warning");
}
},
error: function(xhr, textStatus, error) {
if(xhr.status === 403) {
......
......@@ -348,6 +348,9 @@ a.hover-black {
width: 100px;
}
.endpoint-list-table-thin {
width: 70px;
}
.nojs-dropdown-menu
{
......
......@@ -430,6 +430,13 @@ class EndpointListTable(Table):
attrs={'th': {'data-sort': "string"}}
)
actions = TemplateColumn(
verbose_name=_("Actions"),
template_name="dashboard/endpoint-list/column-endpoint-actions.html",
attrs={'th': {'class': 'endpoint-list-table-thin'}},
orderable=False,
)
class Meta:
model = DataStore
attrs = {'class': ('table table-bordered table-striped table-hover'
......
......@@ -41,4 +41,14 @@
</div><!-- .panel-body -->
</div>
<div class="panel panel-default">
<div class="panel-heading">
<a href="{% url "dashboard.views.storage-endpoint-delete" pk=object.pk %}"
class="btn btn-xs btn-danger pull-right endpoint-delete">
{% trans "Delete" %}
</a>
<h4 class="no-margin"><i class="fa fa-times"></i> {% trans "Delete endpoint" %}</h4>
</div>
</div>
{% endblock %}
{% load i18n %}
<a href="{% url "dashboard.views.storage-endpoint-edit" pk=record.pk%}" id="endpoint-list-edit-button" class="btn btn-default btn-xs" title="{% trans "Edit" %}">
<i class="fa fa-edit"></i>
</a>
<a href="{% url "dashboard.views.storage-endpoint-delete" pk=record.pk %}" class="btn btn-danger btn-xs endpoint-delete" title="{% trans "Delete" %}">
<i class="fa fa-times"></i>
</a>
......@@ -54,7 +54,7 @@ from .views import (
NodeActivityView,
UserList,
StorageDetail, StorageList, StorageChoose, StorageCreate, DiskDetail,
EndpointCreate, EndpointList, EndpointEdit,
EndpointCreate, EndpointList, EndpointEdit, EndpointDelete,
MessageList, MessageDetail, MessageCreate, MessageDelete,
)
from .views.vm import vm_ops, vm_mass_ops
......@@ -251,6 +251,8 @@ urlpatterns = patterns(
name="dashboard.views.storage-endpoint-list"),
url(r'^storage/endpoint/(?P<pk>\d+)/$', EndpointEdit.as_view(),
name='dashboard.views.storage-endpoint-edit'),
url(r"^storage/endpoint/delete/(?P<pk>\d+)/$", EndpointDelete.as_view(),
name="dashboard.views.storage-endpoint-delete"),
url(r'^disk/(?P<pk>\d+)/$', DiskDetail.as_view(),
name="dashboard.views.disk-detail"),
......
......@@ -21,12 +21,16 @@ import logging
from django.contrib import messages
from django.core.urlresolvers import reverse, reverse_lazy
from django.db.models import Q
from django.utils.translation import ugettext_lazy as _
from django.views.generic import UpdateView, TemplateView, CreateView
from django.utils.translation import ugettext_lazy as _, ugettext
from django.views.generic import (
UpdateView, TemplateView, CreateView, DeleteView
)
from django.contrib.messages.views import SuccessMessageMixin
from django.shortcuts import redirect
from django_tables2 import SingleTableView
from django.http import Http404, HttpResponse
from django.http import (
Http404, HttpResponse, HttpResponseRedirect, JsonResponse
)
from django.core.exceptions import PermissionDenied
from braces.views import SuperuserRequiredMixin
......@@ -389,5 +393,53 @@ class EndpointEdit(SuperuserRequiredMixin, UpdateView):
def get_success_url(self):
ds = self.get_object()
return reverse("dashboard.views.storage-endpoint-edit",
kwargs={"pk": ds.id})
return reverse_lazy("dashboard.views.storage-endpoint-edit",
kwargs={"pk": ds.id})
class EndpointDelete(SuperuserRequiredMixin, DeleteView):
model = Endpoint
success_message = _("Endpoint successfully deleted.")
def get_template_names(self):
if self.request.is_ajax():
return ['dashboard/confirm/ajax-delete.html']
else:
return ['dashboard/confirm/base-delete.html']
def check_reference(self):
object = self.get_object()
if object.datastore_set.count() != 0:
raise PermissionDenied()
def get(self, request, *args, **kwargs):
try:
self.check_reference()
except PermissionDenied:
message = ugettext("Another object references"
" to the selected object.")
if request.is_ajax():
return JsonResponse({"error": message})
else:
messages.warning(request, message)
return redirect(self.get_success_url())
return super(EndpointDelete, self).get(request, *args, **kwargs)
def get_success_url(self):
return reverse_lazy("dashboard.views.storage-endpoint-list")
def delete_obj(self, request, *args, **kwargs):
self.get_object().delete()
def delete(self, request, *args, **kwargs):
self.check_reference()
self.delete_obj(request, *args, **kwargs)
if request.is_ajax():
return HttpResponse(
json.dumps({'message': self.success_message}),
content_type="application/json",
)
else:
messages.success(request, self.success_message)
return HttpResponseRedirect(self.get_success_url())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment