Add delete button for rotations in table

Resolves #21
This commit is contained in:
Jan Tuomi
2017-01-12 08:25:09 -05:00
parent 4f12c42c5f
commit 8048d69397
4 changed files with 34 additions and 4 deletions
+5 -1
View File
@@ -24,14 +24,18 @@
Select rotation to edit:
</div>
<table class="table table-striped">
<tr><th>Rotation</th><th>Select</th></tr>
<tr><th>Rotation</th>
<th>Select</th>
<th>Delete</th></tr>
<tr ng-repeat="r in rotations">
<td>{{r.name}}</td>
<td><input type="button" class="btn btn-info" ng-click="selectRotation(r.id)" value="select"></td>
<td><input type="button" class="btn btn-danger" ng-click="deleteRotation(r.id)" value="delete"></input></td>
</tr>
<tr>
<td><input type="text" ng-model="r.name" placeholder="Name"></input></td>
<td><input type="button" class="btn btn-success" ng-click="createRotation(r.name)" value="create new"></input></td>
<td></td>
</tr>
</table>
+12 -3
View File
@@ -38,15 +38,19 @@ app.service("InstanceList", ["$http", function($http){
}
});
}
this.deleteInstance = function(id){
$http.delete("/infoscreen/instance/"+id).then(function(response){
self.getRotation(self.selected_rot.id);
});
}
this.createRotation = function(name) {
data = {'name': name}
console.log(name)
$http.post("/infoscreen/create_rotation", data).then(function(response) {
});
}
this.deleteInstance = function(id){
$http.delete("/infoscreen/instance/"+id).then(function(response){
self.getRotation(self.selected_rot.id);
this.deleteRotation = function(id) {
$http.delete("/infoscreen/delete_rotation/" + id).then(function(response) {
});
}
}]);
@@ -90,6 +94,11 @@ app.controller('infoadmin_ctrl', function($scope, $http, $window, ItemList, Inst
InstanceList.createRotation(name);
$window.location.reload();
};
$scope.deleteRotation = function(id) {
InstanceList.deleteRotation(id);
$window.location.reload();
}
$scope.createInstance = InstanceList.createInstance;
$scope.deleteInstance = InstanceList.deleteInstance;
// fetch data
+15
View File
@@ -154,6 +154,21 @@ def createRotation(request, *args, **kwargs):
return resp
@require_http_methods(["DELETE"])
@ensure_csrf_cookie
@permission_required('infoscreen.delete_rotation', login_url='/login')
def deleteRotation(request, *args, **kwargs):
id = kwargs.pop("id", 0)
logging.warning("Deleting rotation with id={}".format(id))
try:
Rotation.objects.filter(id=id).delete()
resp = HttpResponse(status=200)
except:
resp = HttpResponse('{"error" : "could not delete rotation!"}', status=400)
return resp
createInstance = itemCreator(InfoInstance)
deleteInstance = itemDeletor(InfoInstance)
+2
View File
@@ -45,6 +45,7 @@ from infoscreen.views import createImageItem
from infoscreen.views import createABBItem
from infoscreen.views import createSossoItem
from infoscreen.views import createRotation
from infoscreen.views import deleteRotation
from infoscreen.views import admin as infoscreen_admin
#application
from members.views import applicationindex
@@ -84,6 +85,7 @@ urlpatterns = [
url(r'^infoscreen/create_sossoitem$', createSossoItem),
url(r'^infoscreen/admin$', infoscreen_admin),
url(r'^infoscreen/create_rotation$', createRotation),
url(r'^infoscreen/delete_rotation/(?P<id>\d+)$', deleteRotation),
#application
url(r'^application/$', applicationindex),
url(r'^application/success$', applicationSuccessIndex),