use SliceList rather than SimpleList
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 11 Mar 2013 14:54:45 +0000 (15:54 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 11 Mar 2013 14:54:45 +0000 (15:54 +0100)
engine/plugin.py
engine/templates/plugin-setenv.js
plugins/simplelist.py
plugins/slicelist.py
plugins/static/js/simplelist.js
trash/dashboard.py

index 00b37b7..92bbe6c 100644 (file)
@@ -61,7 +61,8 @@ class Plugin:
         self.title=title
         if not domid: domid=Plugin.newdomid()
         self.domid=domid
-        self.classname=self._classname()
+        self.classname=self._py_classname()
+        self.plugin_classname=self._js_classname()
         self.visible=visible
         self.togglable=togglable
         self.toggled=toggled
@@ -77,10 +78,14 @@ class Plugin:
         # do this only once the structure is fine
         self.pluginset.record_plugin(self)
 
-    def _classname (self): 
+    def _py_classname (self): 
         try:    return self.__class__.__name__
         except: return 'Plugin'
 
+    def _js_classname (self): 
+        try:    return self.plugin_classname ()
+        except: return self._py_classname()
+
     ##########
     def need_debug (self):
         if not DEBUG:           return False
@@ -221,3 +226,5 @@ class Plugin:
     # also 'query_uuid' gets replaced with query.uuid
     def json_settings_list (self): return ['json_settings_list-must-be-redefined']
 
+    # might also define this one; see e.g. slicelist.py that piggybacks simplelist js code
+    # def plugin_classname (self):
index f6c27fa..0d44075 100644 (file)
@@ -1 +1 @@
-$(document).ready(function() { jQuery('#{{ domid }}').{{ classname }}({{ settings_json|safe }}); });
+$(document).ready(function() { jQuery('#{{ domid }}').{{ plugin_classname }}({{ settings_json|safe }}); });
index d4cefb1..371e5d6 100644 (file)
@@ -3,9 +3,10 @@ from engine.plugin import Plugin
 class SimpleList (Plugin) :
 
     # only deal with our own stuff here and let Plugin handle the rest
-    def __init__ (self, list=[], with_datatables=False, **settings):
+    def __init__ (self, key, value, with_datatables=False, **settings):
         Plugin.__init__ (self, **settings)
-        self.list=list
+        self.key=key
+        self.value=value
         self.with_datatables = with_datatables
 
     # SimpleList is useless per se anyways
index c980423..92673f2 100644 (file)
@@ -1,17 +1,12 @@
 from plugins.simplelist import SimpleList
 
+# the SimpleList plugin requires 'key' and 'value' that are used 
+# on the results of the query for rendering
 class SliceList (SimpleList):
     
-    def __init__ (self, list=[], **settings):
-        SimpleList.__init__(self, **settings)
-        self.list = [ "<a href='/slice/%s/' class='slicelist'>%s</a>"%(x,x) for x in list ]
+    def __init__ (self, **settings):
+        SimpleList.__init__(self, key='slice_hrn', value='slice_hrn', **settings)
 
-#    def requirements (self):
-#        reqs=SimpleList.requirements(self)
-#        reqs['js_files'].append('slice.js')
-#        reqs['js_files'].append('slice2.js')
-#        reqs['css_files'].append('slice.css')
-#        reqs['css_files'].append('slice2.css')
-#        reqs['js_chunks']=['js chunk1','js chunk2']
-#        reqs['css_chunks']=['css chunk1','css chunk2']
-#        return reqs
+    # writing a js plugin for that would be overkill, just use SimpleList
+    def plugin_classname (self):
+        return 'SimpleList'
index 120c6f9..c49456b 100644 (file)
@@ -64,6 +64,7 @@ simplelist_debug=false;
         }
         var options = e.data.data().SimpleList.options;
         var is_cached = options.query.timestamp != 'now' ? true : false;
+       // here is where we use 'key' and 'value' from the SimpleList (python) constructor
        html_code=myslice_html_ul(rows, options.key, options.value, is_cached)+"<br/>";
         e.data.html(html_code);
        var $elt = e.data;
index 35eeb33..8dc2dbe 100644 (file)
@@ -10,7 +10,7 @@ from django.contrib.auth.decorators import login_required
 from engine.pluginset import PluginSet
 from engine.manifoldquery import ManifoldQuery
 
-from plugins.simplelist import SimpleList
+from plugins.slicelist import SliceList
 
 # 
 from myslice.viewutils import topmenu_items, the_user
@@ -28,19 +28,20 @@ def dashboard_view (request):
                                   # xxx filter : should filter on the slices the logged user can see
                                   # we don't have the user's hrn yet
                                   # in addition this currently returns all slices anyways
+                                  # filter = ...
                                   sort='slice_hrn',)
     pluginset.enqueue_query (slices_query)
 
-    main_plugin = SimpleList ( # setting visible attributes first
+    main_plugin = SliceList ( # setting visible attributes first
         pluginset=pluginset,
-        title='Asynchroneous SimpleList',
+        title='Asynchroneous SliceList',
         header='slices list', 
         with_datatables=True,
         toggled=True,
         # this is required for the javascript code
         query=slices_query,
-        key='slice_hrn',
-        value='slice_hrn',
+#        key='slice_hrn',
+#        value='slice_hrn',
         )
 
     # variables that will get passed to the view-plugin.html template