Add "create new" button to table of existing rotations
This commit is contained in:
@@ -200,3 +200,4 @@ class ImageUploadForm(forms.Form):
|
||||
'''
|
||||
name = forms.CharField()
|
||||
image = forms.ImageField()
|
||||
|
||||
|
||||
@@ -29,7 +29,12 @@
|
||||
<td>{{r.name}}</td>
|
||||
<td><input type="button" class="btn btn-info" ng-click="selectRotation(r.id)" value="select"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<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>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>Rotation: {{selected_rot.name}}</h2>
|
||||
<div>Instances in currently selected rotation:</div>
|
||||
<table class="table table-striped">
|
||||
@@ -38,7 +43,6 @@
|
||||
<td>{{i.item.name}}</td><td>{{i.duration}}s</td>
|
||||
<td><input type="button" ng-click="deleteInstance(i.id);" value="delete" class="btn btn-danger"></input><td>
|
||||
</tr>
|
||||
</table
|
||||
</div>
|
||||
|
||||
</div
|
||||
|
||||
@@ -38,6 +38,12 @@ app.service("InstanceList", ["$http", function($http){
|
||||
}
|
||||
});
|
||||
}
|
||||
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);
|
||||
@@ -67,7 +73,7 @@ app.service("ItemList", ["$http",'InstanceList', function($http, InstanceList){
|
||||
};
|
||||
}]);
|
||||
|
||||
app.controller('infoadmin_ctrl', function($scope, $http, ItemList, InstanceList){
|
||||
app.controller('infoadmin_ctrl', function($scope, $http, $window, ItemList, InstanceList){
|
||||
// init items
|
||||
$scope.rotations = [];
|
||||
$scope.infoitems = [];
|
||||
@@ -75,6 +81,15 @@ app.controller('infoadmin_ctrl', function($scope, $http, ItemList, InstanceList)
|
||||
// helpers
|
||||
$scope.deleteItem = ItemList.deleteItem;
|
||||
$scope.selectRotation = InstanceList.getRotation;
|
||||
|
||||
/* Create a new rotation from with the user-provided name
|
||||
* We also want to reload the page afterwards to refresh the table
|
||||
* If the table were implemented with ng-table we could just refresh that but at the moment
|
||||
* it's not so we just fullblast the whole thing */
|
||||
$scope.createRotation = function(name) {
|
||||
InstanceList.createRotation(name);
|
||||
$window.location.reload();
|
||||
};
|
||||
$scope.createInstance = InstanceList.createInstance;
|
||||
$scope.deleteInstance = InstanceList.deleteInstance;
|
||||
// fetch data
|
||||
|
||||
@@ -12,6 +12,7 @@ from infoscreen.models import ImageUploadForm
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
import json
|
||||
import logging
|
||||
|
||||
def index(request,idx, *args, **kwargs):
|
||||
return render(request, 'infoscreen_index.html',{'rotation':idx})
|
||||
@@ -135,6 +136,25 @@ def createImageItem(request, *args, **kwargs):
|
||||
ImageInfoItem.objects.create(img=img, name=name)
|
||||
return HttpResponse('{"status":"success"}')
|
||||
|
||||
@require_http_methods(["POST"])
|
||||
@ensure_csrf_cookie
|
||||
@permission_required('infoscreen.add_rotation', login_url='/login')
|
||||
def createRotation(request, *args, **kwargs):
|
||||
try:
|
||||
data = json.loads(request.body.decode("utf-8"))
|
||||
except:
|
||||
return HttpResponse('{"error": "bad post body!"}', status=400)
|
||||
|
||||
try:
|
||||
name = data["name"]
|
||||
Rotation.objects.create(name=name)
|
||||
resp = HttpResponse(status=200)
|
||||
except:
|
||||
resp = HttpResponse('{"error" : "could not create rotation!"}', status=400)
|
||||
|
||||
return resp
|
||||
|
||||
|
||||
createInstance = itemCreator(InfoInstance)
|
||||
deleteInstance = itemDeletor(InfoInstance)
|
||||
createABBItem = itemCreator(ABBInfoItem)
|
||||
|
||||
@@ -44,6 +44,7 @@ from infoscreen.views import createExternalImageInfoItem
|
||||
from infoscreen.views import createImageItem
|
||||
from infoscreen.views import createABBItem
|
||||
from infoscreen.views import createSossoItem
|
||||
from infoscreen.views import createRotation
|
||||
from infoscreen.views import admin as infoscreen_admin
|
||||
#application
|
||||
from members.views import applicationindex
|
||||
@@ -82,6 +83,7 @@ urlpatterns = [
|
||||
url(r'^infoscreen/create_abbitem$', createABBItem),
|
||||
url(r'^infoscreen/create_sossoitem$', createSossoItem),
|
||||
url(r'^infoscreen/admin$', infoscreen_admin),
|
||||
url(r'^infoscreen/create_rotation$', createRotation),
|
||||
#application
|
||||
url(r'^application/$', applicationindex),
|
||||
url(r'^application/success$', applicationSuccessIndex),
|
||||
|
||||
Reference in New Issue
Block a user