Index: /main/waeup.sirp/trunk/src/waeup/sirp/browser/tables.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/browser/tables.py	(revision 5008)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/browser/tables.py	(revision 5008)
@@ -0,0 +1,111 @@
+"""Datatables and related components used in different contexts.
+
+The tables defined here are javascript-powered output. In contrast to
+regular HTML tables they allow client-side sorting and batching of
+results.
+"""
+import grok
+from zope.security.management import checkPermission
+from waeup.sirp.browser.interfaces import (
+    IFacultyContainer, IFaculty, IDepartment, ICourseContainer)
+from waeup.sirp.tables import CodeAndTitleTableProvider, Col, Table
+from waeup.sirp.widgets.interfaces import ITableProvider
+
+class DepartmentTableProvider(CodeAndTitleTableProvider):
+    grok.context(IFaculty)
+    grok.provides(ITableProvider)
+    title = 'Departments'
+
+class FacultyTableProvider(CodeAndTitleTableProvider):
+    grok.context(IFacultyContainer)
+    grok.provides(ITableProvider)
+    title = 'Faculties'
+
+class CourseTableProvider(CodeAndTitleTableProvider):
+    grok.context(IDepartment)
+    grok.provides(ITableProvider)
+    title = 'Courses'
+
+    def prepare(self):
+        self.data_source = self.context.courses
+        
+    def getTables(self, view=None):
+        data = self.data_source
+        context_url = ''
+        if view:
+            context_url = view.url(self.context) + '/'
+
+        # Create a courses table...
+        cols = (
+            Col(
+                header='Code', sortable=True,
+                data = tuple([self.getItemURL(view, data[x].code)
+                              for x in data])),
+            Col(
+                header='Title', sortable=True,
+                data = tuple([data[x].title for x in data])),
+            )
+        delcol = Col(header='', sortable=False,
+                     data = [
+                '<form method="post">'
+                '<input type="submit" name="delcourse" value="Delete" />'
+                '<input type="hidden" name="code" value="%s" />'
+                '</form>' % (data[x].code)
+                for x in data])
+
+        if checkPermission('waeup.manageUniversity', self.context.courses):
+            cols = list(cols)
+            cols.append(delcol)
+            cols = tuple(cols)
+        self.coursetable = Table('Courses', cols=cols)
+
+        # Create a certificates table...
+        self.data_source = self.context.certificates
+        data = self.data_source
+        certcols =(
+            Col(
+                header='Code', sortable=True,
+                data = tuple([self.getItemURL(view, data[x].code)
+                              for x in data])),
+            Col(
+                header='Title', sortable=True,
+                data = tuple([data[x].title for x in data])),
+            )
+
+        delcol = Col(header='', sortable=False,
+                     data = [
+                '<form method="post">'
+                '<input type="submit" name="delcert" value="Delete" />'
+                '<input type="hidden" name="code" value="%s" />'
+                '</form>' % (data[x].code)
+                for x in data])
+
+        if checkPermission('waeup.manageUniversity', self.context.certificates):
+            certcols = list(certcols)
+            certcols.append(delcol)
+            certcols = tuple(certcols)
+
+        self.certtable = Table('Certificates', cols=certcols)
+        return (self.coursetable, self.certtable)
+
+class CourseContainerCourseTableProvider(CodeAndTitleTableProvider):
+    grok.context(ICourseContainer)
+    grok.provides(ITableProvider)
+    title = 'Courses'
+
+    def getTables(self, view=None):
+        data = self.data_source
+        context_url = ''
+        if view:
+            context_url = view.url(self.context) + '/'
+        cols = (
+            Col(
+                header='Code', sortable=True,
+                data = tuple([self.getItemURL(view, data[x].code)
+                              for x in data])),
+            Col(
+                header='Title', sortable=True,
+                data = tuple([data[x].title for x in data])),
+            )
+        self.table = Table(self.title, cols=cols)
+        return (self.table,)
