simplelist can be datatabled with need_datatables=True
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 12 Dec 2012 12:23:04 +0000 (13:23 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 12 Dec 2012 12:23:04 +0000 (13:23 +0100)
fix plugin hide.show engine with multiple plugins

engine/views.py
plugins/simplelist.py
static/css/simplelist.css [new file with mode: 0644]
static/js/need-datatables.js [new file with mode: 0644]
static/js/plugin.js
templates/view-plugin.html
templates/view-slice.html
templates/widget-plugin.html
templates/widget-simplelist.html

index d5020a9..a6f741a 100644 (file)
@@ -7,21 +7,42 @@ from django.shortcuts import render_to_response
 
 from plugins.simplelist import SimpleList
 
-from myslice.viewutils import menu_items, the_user
+from myslice.viewutils import menu_items, the_user, hard_wired_slice_names
 
 def test_plugin_view (request):
     
-    test_plugin = SimpleList (visible=True, hidable=True)
-    plugin_content = test_plugin.render (request)
+    hard_wired_list=[]
+    hard_wired_list.append("this hard-wired list")
+    hard_wired_list.append("is defined")
+    hard_wired_list.append("in <code>plugins.simplelist.py</code>")
+    hard_wired_list.append("which in turn relies on")
+    hard_wired_list.append("template <code>widget-template.html</code>")
+    hard_wired_list.append("while it should of course")
+    hard_wired_list.append("instead issue a query")
+    hard_wired_list.append("and fill the DOM in js from there")
+    hard_wired_list.append("it would however maybe make sense")
+    hard_wired_list.append("to offer the option to 'datatablify'")
+    hard_wired_list.append("the list from the python code")
+    hard_wired_list.append("just like a standard plugin can be set as visible or not")
+    hard_wired_list.append("")    
+    hard_wired_list.append("OTOH and IMHO, there should be two separate and explicit subclasses of SimpleList for slices or testbeds")
 
-    print '--------------------'
-    print plugin_content
-    print '--------------------'
+    plugin_main = SimpleList (visible=True, hidable=True, list=hard_wired_list, header='Hard wired')
+    content_main = plugin_main.render (request)
+
+    # lacks a/href to /slice/%s
+    plugin_related = SimpleList (visible=True, hidable=True,
+                                 need_datatables='yes', 
+                                 list=hard_wired_slice_names, header='Slices' )
+    content_related = plugin_related.render (request)
+
+    
 
     return render_to_response ('view-plugin.html',
                                {'title': 'Test Plugin View',
                                 'menu_items': menu_items('plugin', request),
-                                'content_main' : plugin_content,
+                                'content_main' : content_main,
+                                'content_related' : content_related,
                                 'username' : the_user (request),
                                 },
                                context_instance=RequestContext(request))
index 2e06f4e..19abe28 100644 (file)
@@ -5,4 +5,5 @@ from engine.plugin import Plugin
 class SimpleList (Plugin) :
     
     def render_content (self, request):
-        return render_to_string ("widget-simplelist.html",{})
+        return render_to_string ("widget-simplelist.html",
+                                 self._settings)
diff --git a/static/css/simplelist.css b/static/css/simplelist.css
new file mode 100644 (file)
index 0000000..3ff4bc6
--- /dev/null
@@ -0,0 +1,3 @@
+select { 
+    width: auto;
+}
diff --git a/static/js/need-datatables.js b/static/js/need-datatables.js
new file mode 100644 (file)
index 0000000..ad1664b
--- /dev/null
@@ -0,0 +1,2 @@
+/* elements with class 'need-datatables' are set to use datatables */
+$(document).ready(function() {$('.need-datatables').each(function() { $(this).dataTable() } ) } )
index cb04cfc..4d8346d 100644 (file)
@@ -7,20 +7,21 @@
  * }; 
  */
 
-$(document).ready(
-    function() {
-       $('.plugin-hide').each(function(p) {
-           plugin='#'+$(this).attr('id').replace('hide-','plugin-');
-           show='#'+$(this).attr('id').replace('hide-','show-');
-           type=$(this).attr('plugin-type');
-           $(this).click(function () { jQuery(plugin).hide(); jQuery(show).show(); $(this).hide();})
+$(document).ready(function() {
+    $('.plugin-hide').each(function() {
+       window.console.log ('@load: id='+$(this).attr('id'));
+       $(this).click(function () { 
+           var plugin='#'+$(this).attr('id').replace('hide-','plugin-'); 
+           var show='#'+$(this).attr('id').replace('hide-','show-'); 
+           window.console.log ("Hiding:"+$(this).attr('id')+' plugin='+plugin+' show='+show);
+           jQuery(plugin).hide(); jQuery(show).show(); $(this).hide();});
        })
-       $('.plugin-show').each(function(p) {
-           plugin='#'+$(this).attr('id').replace('show-','plugin-');
-           hide='#'+$(this).attr('id').replace('show-','hide-');
-           type=$(this).attr('plugin-type');
-           $(this).click(function () { jQuery(plugin).show(); jQuery(hide).show(); $(this).hide();})
+    $('.plugin-show').each(function() {
+       window.console.log ('@load: id='+$(this).attr('id'));
+       $(this).click(function () { 
+           var plugin='#'+$(this).attr('id').replace('show-','plugin-'); 
+           var hide='#'+$(this).attr('id').replace('show-','hide-'); 
+           window.console.log ("Showing:"+$(this).attr('id')+' plugin='+plugin+' hide='+hide);
+           jQuery(plugin).show(); jQuery(hide).show(); $(this).hide();});
        })
-           })
-
-
+    })
index 8413732..134cc3c 100644 (file)
@@ -1,5 +1,13 @@
 {% extends 'layout-myslice.html' %}
 
 {% block content_main %}
-{{ content_main }}
+{{ content_main|safe }}
 {% endblock content_main %}
+
+{% block content_related %}
+{% insert_str prelude "datatables/js/dataTables.js" %}
+{% insert_str prelude "js/need-datatables.js" %}
+{% insert_str prelude "css/simplelist.css" %}
+
+{{ content_related|safe }}
+{% endblock content_related %}
index 9bf68b1..f38c102 100644 (file)
@@ -1,3 +1,4 @@
+{# -*-django-html-mumamo-mode-*- #}
 {% extends 'layout-myslice.html' %}
 
 {% block content_main %}
 $(document).ready(function () { $('#datatable').dataTable() } )
 {% endinsert %}
 
-<table id='datatable'>
-  <thead> <tr> <th>slice</th> </tr> </thead>
-  <tbody>
-    {% for slicename in slices %}
-    <tr><td> <a href="/slice/{{ slicename }}/">{{ slicename }}</a></td></tr>
-    {% endfor %}
-  </tbody>
-</table>
 {% endblock content_related %}
index 64c117e..fe9dcba 100644 (file)
@@ -11,7 +11,7 @@
 {% endif %}
 {% endif %}
 
-<div class='plugin {{ title }}' id='plugin-{{ uuid }}' plugin-type='{{ title }}'>
+<div class='plugin {{ title }}' id='plugin-{{ uuid }}'>
 {{ plugin_content|safe }}
 </div><!--plugin {{ title }}-->
 
index 40ad0c1..fb5812e 100644 (file)
@@ -1,16 +1,10 @@
-<ul>
-<li>this hard-wired list</li>
-<li>is defined</li>
-<li>in <code>plugins.simplelist.py</code></li>
-<li>which in turn relies on</li>
-<li>template <code>widget-template.html</code></li>
-<li>while it should of course</li>
-<li>instead issue a query</li>
-<li>and fill the DOM in js from there</li>
-<li>it would however maybe make sense</li>
-<li>to offer the option to 'datatablify'</li>
-<li>the list from the python code</li>
-<li>just like a standard plugin can be set as visible or not</li>
-<li />
-<li>OTOH and IMHO, there should be two separate and explicit subclasses of SimpleList for slices or testbeds</li>
-</ul>
+<table class='simplelist {%if need_datatables %}need-datatables{% endif %}'>
+{% if header %}
+<thead><tr><th>{{ header }}</th></tr></thead>
+{% endif %}
+<tbody>
+{% for item in list %}
+<tr><td>{{ item }}</td></tr>
+{% endfor %}
+</tbody>
+</table>