From: Thierry Parmentelat Date: Wed, 12 Dec 2012 12:23:04 +0000 (+0100) Subject: simplelist can be datatabled with need_datatables=True X-Git-Tag: myslice-django-0.1-1~142 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=ee4bff70dd38e334edb0216b3c27a90facfc6244;p=unfold.git simplelist can be datatabled with need_datatables=True fix plugin hide.show engine with multiple plugins --- diff --git a/engine/views.py b/engine/views.py index d5020a90..a6f741a7 100644 --- a/engine/views.py +++ b/engine/views.py @@ -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 plugins.simplelist.py") + hard_wired_list.append("which in turn relies on") + hard_wired_list.append("template widget-template.html") + 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)) diff --git a/plugins/simplelist.py b/plugins/simplelist.py index 2e06f4e1..19abe28a 100644 --- a/plugins/simplelist.py +++ b/plugins/simplelist.py @@ -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 index 00000000..3ff4bc6f --- /dev/null +++ b/static/css/simplelist.css @@ -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 index 00000000..ad1664b0 --- /dev/null +++ b/static/js/need-datatables.js @@ -0,0 +1,2 @@ +/* elements with class 'need-datatables' are set to use datatables */ +$(document).ready(function() {$('.need-datatables').each(function() { $(this).dataTable() } ) } ) diff --git a/static/js/plugin.js b/static/js/plugin.js index cb04cfc6..4d8346db 100644 --- a/static/js/plugin.js +++ b/static/js/plugin.js @@ -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();}); }) - }) - - + }) diff --git a/templates/view-plugin.html b/templates/view-plugin.html index 8413732c..134cc3ce 100644 --- a/templates/view-plugin.html +++ b/templates/view-plugin.html @@ -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 %} diff --git a/templates/view-slice.html b/templates/view-slice.html index 9bf68b15..f38c1021 100644 --- a/templates/view-slice.html +++ b/templates/view-slice.html @@ -1,3 +1,4 @@ +{# -*-django-html-mumamo-mode-*- #} {% extends 'layout-myslice.html' %} {% block content_main %} @@ -13,12 +14,4 @@ $(document).ready(function () { $('#datatable').dataTable() } ) {% endinsert %} - - - - {% for slicename in slices %} - - {% endfor %} - -
slice
{{ slicename }}
{% endblock content_related %} diff --git a/templates/widget-plugin.html b/templates/widget-plugin.html index 64c117ee..fe9dcbaa 100644 --- a/templates/widget-plugin.html +++ b/templates/widget-plugin.html @@ -11,7 +11,7 @@ {% endif %} {% endif %} -
+
{{ plugin_content|safe }}
diff --git a/templates/widget-simplelist.html b/templates/widget-simplelist.html index 40ad0c14..fb5812ef 100644 --- a/templates/widget-simplelist.html +++ b/templates/widget-simplelist.html @@ -1,16 +1,10 @@ - + +{% if header %} + +{% endif %} + +{% for item in list %} + +{% endfor %} + +
{{ header }}
{{ item }}