Commit 2398cbad authored by Leonidas Poulopoulos's avatar Leonidas Poulopoulos
Browse files

Added delete functionality to Servers and Services

parent af9d484b
......@@ -357,6 +357,53 @@ def base_response(request):
}
@login_required
def del_server(request):
if request.method == 'GET':
user = request.user
req_data = request.GET.copy()
server_pk = req_data['server_pk']
profile = user.get_profile()
institution = profile.institution
resp = {}
try:
server = InstServer.objects.get(instid=institution, pk=server_pk)
except InstServer.DoesNotExist:
resp['error'] = "Could not get server or you have no rights to delete"
return HttpResponse(json.dumps(resp), mimetype='application/json')
try:
server.delete()
except:
resp['error'] = "Could not delete server"
return HttpResponse(json.dumps(resp), mimetype='application/json')
resp['success'] = "Server successfully deleted"
return HttpResponse(json.dumps(resp), mimetype='application/json')
@login_required
def del_service(request):
if request.method == 'GET':
user = request.user
req_data = request.GET.copy()
service_pk = req_data['service_pk']
profile = user.get_profile()
institution = profile.institution
resp = {}
try:
service = ServiceLoc.objects.get(institutionid=institution, pk=service_pk)
except ServiceLoc.DoesNotExist:
resp['error'] = "Could not get service or you have no rights to delete"
return HttpResponse(json.dumps(resp), mimetype='application/json')
try:
service.delete()
except:
resp['error'] = "Could not delete service"
return HttpResponse(json.dumps(resp), mimetype='application/json')
resp['success'] = "Service successfully deleted"
return HttpResponse(json.dumps(resp), mimetype='application/json')
def geolocate(request):
return render_to_response('front/geolocate.html',
context_instance=RequestContext(request))
......
......@@ -66,6 +66,37 @@ var oTable = $('#table').dataTable({
oTable.fnDraw();
$('[id^=del_server_]').click(function(){
server_id = (this.id).replace("del_server_", '');
name = this.getAttribute("data-servername");
$("#mymodalbody").html("You are about to delete server: <b>"+name+"</b><br>Press Delete to proceed or Cancel to cancel deletion");
$("#myModalLabel").html("Delete Server "+name);
$('#myModal').modal('show');
$(".modal-footer").show();
$("#server_name_del").html(name)
return false;
});
$("#delserverSubmit").click(function(){
$.ajax({
url:"{% url del-server %}/?server_pk="+server_id,
type: "GET",
success: function(data){
if (data.error){
$(".modal-footer").hide();
$("#mymodalbody").html("<font style='color:#B94A48'>"+data.error+"</font>");
}
if (data.success){
$(".modal-footer").hide();
$("#mymodalbody").html("Server "+name+" successfully deleted");
window.setTimeout('location.reload()', 1000);
}
}
});
});
{% endif %}
});
</script>
......@@ -111,7 +142,7 @@ oTable.fnDraw();
<td>{{server.retry}}</td>
<td>{{server.status_server}}</td>
<td>{{server.proto}}</td>
<td style="text-align: center;"><a href="{% url edit-servers server.pk %}" class="btn btn-small">edit</a> <a href="{% url edit-servers server.pk %}" class="btn btn-small btn-warning">delete</a></td>
<td style="text-align: center;"><a href="{% url edit-servers server.pk %}" class="btn btn-small">edit</a> <a href="#" id="del_server_{{server.pk}}" data-servername="{{server.name}}" class="btn btn-small btn-warning">delete</a></td>
</tr>
{% endfor %}
</tbody>
......@@ -119,6 +150,18 @@ oTable.fnDraw();
{% else %}
<div>No servers defined yet (<a href="{% url edit-servers %}">add</a>)</div>
{% endif %}
<div class="modal hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Delete Server</h3>
</div>
<div class="modal-body" id="mymodalbody">
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<a class="btn btn-warning" id="delserverSubmit" href="#">Delete</a>
</div>
</div>
{% endblock %}
......@@ -71,7 +71,35 @@ var oTable = $('#table').dataTable({
});
oTable.fnDraw();
$('[id^=del_service_]').click(function(){
server_id = (this.id).replace("del_service_", '');
name = this.getAttribute("data-servicename");
$("#mymodalbody").html("You are about to delete service: <b>"+name+"</b><br>Press Delete to proceed or Cancel to cancel deletion");
$("#myModalLabel").html("Delete Service "+name);
$('#myModal').modal('show');
$(".modal-footer").show();
$("#service_name_del").html(name)
return false;
});
$("#delserviceSubmit").click(function(){
$.ajax({
url:"{% url del-service %}/?service_pk="+server_id,
type: "GET",
success: function(data){
if (data.error){
$(".modal-footer").hide();
$("#mymodalbody").html("<font style='color:#B94A48'>"+data.error+"</font>");
}
if (data.success){
$(".modal-footer").hide();
$("#mymodalbody").html("Service "+name+" successfully deleted");
window.setTimeout('location.reload()', 1000);
}
}
});
});
{% endif %}
});
</script>
......@@ -114,7 +142,7 @@ oTable.fnDraw();
<td>{{service.IPv6}}</td>
<td>{{service.AP_no}}</td>
<td>{{service.wired}}</td>
<td style="text-align: center;"><a href="{% url edit-services service.pk %}" class="btn btn-small">edit</a> <a href="{% url edit-services service.pk %}" class="btn btn-small btn-warning">delete</a></td>
<td style="text-align: center;"><a href="{% url edit-services service.pk %}" class="btn btn-small">edit</a> <a href="#" id="del_service_{{service.pk}}" data-servicename="{% tolocale service LANGUAGE_CODE%}" class="btn btn-small btn-warning">delete</a></td>
</tr>
{% endfor %}
</tbody>
......@@ -122,5 +150,17 @@ oTable.fnDraw();
{% else %}
<div>No services defined yet (<a href="{% url edit-services %}">edit</a>)</div>
{% endif %}
<div class="modal hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Delete Service</h3>
</div>
<div class="modal-body" id="mymodalbody">
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<a class="btn btn-warning" id="delserviceSubmit" href="#">Delete</a>
</div>
</div>
{% endblock %}
\ No newline at end of file
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 to comment