From 0a813aebd424059f27e3bda9dee150577b756174 Mon Sep 17 00:00:00 2001
From: Andreas Valder <andreasv@fsmpi.rwth-aachen.de>
Date: Thu, 1 Sep 2016 18:38:12 +0200
Subject: [PATCH] added a delete function to the backend and the courses

---
 server.py             |  7 ++++---
 static/moderator.js   | 14 ++++++++++++--
 templates/macros.html | 10 +++++++++-
 3 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/server.py b/server.py
index 82f2616..81d40c2 100755
--- a/server.py
+++ b/server.py
@@ -149,11 +149,11 @@ def edit():
 	tabs = {
 		'courses': ('courses_data', 'id', ['visible', 'listed', 'title', 'short',
 				'handle', 'organizer', 'subject', 'semester', 'downloadable',
-				'internal', 'responsible']),
+				'internal', 'responsible','deleted']),
 		'lectures': ('lectures_data', 'id', ['visible', 'title', 'comment',
-				'internal', 'speaker', 'place', 'time', 'duration', 'jumplist']),
+				'internal', 'speaker', 'place', 'time', 'duration', 'jumplist','deleted']),
 		'site_texts': ('site_texts', 'key', ['value']),
-		'videos': ('videos_data', 'id', ['visible'])
+		'videos': ('videos_data', 'id', ['visible','deleted'])
 	}
 	query('BEGIN')
 	if request.is_json:
@@ -171,6 +171,7 @@ def edit():
 	query('COMMIT')
 	return "OK", 200
 
+
 @app.route('/auth')
 def auth(): # For use with nginx auth_request
 	if 'X-Original-Uri' not in request.headers:
diff --git a/static/moderator.js b/static/moderator.js
index 4fb25a4..745d1c3 100644
--- a/static/moderator.js
+++ b/static/moderator.js
@@ -48,7 +48,7 @@ var moderatorinterface = {
 		var path = $(src).data('path');
 		moderatorinterface.set(path,value ? 1 : 0);
 	},
-	set: function(path,value) {
+	set: function(path,value,reload=false) {
 		var req = {};
 		req[path] = value;
 		$.ajax({
@@ -56,8 +56,18 @@ var moderatorinterface = {
 			url: "/edit",
 			dataType: "text",
 			contentType: "application/json",
-			data: JSON.stringify(req)
+			data: JSON.stringify(req),
+			success: function () {
+				if (reload) {
+					window.location.reload();
+				}
+			}
 		})
+	},
+	delete: function(src) {
+		if (confirm('Realy delete this?')) { 
+			moderatorinterface.set($(src).data('path'),1,true); 
+		}
 	}
 };
 
diff --git a/templates/macros.html b/templates/macros.html
index 1921aad..629a8d9 100644
--- a/templates/macros.html
+++ b/templates/macros.html
@@ -1,5 +1,4 @@
 {% macro preview(lecture) %}
-
 <li class="list-group-item">
 	<a class="hidden-xs" href="{{url_for('play', id=lecture['id'])}}" title="{{ lecture['coursetitle'] }}">
 		<div class="row">
@@ -154,6 +153,7 @@ $('#embedcodebtn').popover(
 					<span class="glyphicon glyphicon-play"></span>
 					Play
 				</a>
+				{{ valuedeletebtn(['lectures',lecture.id,'deleted']) }}
 			</span>
 		</span>
 	</div>
@@ -173,3 +173,11 @@ $('#embedcodebtn').popover(
 	<input type="checkbox" data-path="{{path|join('.')}}" {% if value %} checked {% endif %} onchange="moderatorinterface.change(this)"/>
 	{% endif %}
 {% endmacro %}
+
+{% macro valuedeletebtn (path) %}
+	{% if ismod() %}
+	<button data-path="{{path|join('.')}}" onclick="moderatorinterface.delete(this)">
+			<span class="glyphicon glyphicon-trash"></span>
+		</button>
+	{% endif %}
+{% endmacro %}
-- 
GitLab