def topmenu_items (current,request=None):
result=deepcopy(standard_topmenu_items)
for d in result:
- if d['label'].lower().find(current)>=0: d['active']=True
+ if d['label'].lower().find(current)>=0: d['is_active']=True
if not request: return result
has_user=request.user.is_authenticated()
# result.append (login_out_items [ has_user] )
<table class='display' id='hazelnut-{{ domid }}'>
<thead><tr> {% for subject_field in subject_fields %}
-<th>{{ subject_field }}</th>{% endfor %}
+<th>{{ subject_field }}</th>{% endfor %} {% if checkboxes %}<th>+/-</th>{% endif %}
</tr></thead>
<tbody>
</tbody>
class Hazelnut (Plugin):
- def __init__ (self, query, **settings):
+ def __init__ (self, query, checkboxes=False, **settings):
Plugin.__init__ (self, **settings)
self.query=query
+ self.checkboxes=checkboxes
def template_file (self):
return "hazelnut.html"
-{# could try to set class='active' on the one we want to highlight #}
<ul class="nav nav-tabs" id='tab-{{ domid }}'>
{% for son in sons %}
-<li{% if son.active %} class='active'{% endif %}> <a href="#{{ son.domid }}" data-toggle="tab">{{ son.title }}</a> </li>
+<li{% if son.is_active %} class='active'{% endif %}> <a href="#{{ son.domid }}" data-toggle="tab">{{ son.title }}</a> </li>
{% endfor %}
</ul><!--nav-tabs-->
<div class="tab-content">
{% for son in sons %}
-<div class="tab-pane fade in{% if son.active %} active{% endif %}" id="{{ son.domid }}">
+<div class="tab-pane fade in{% if son.is_active %} active{% endif %}" id="{{ son.domid }}">
{{ son.rendered }}
</div><!--tab-pane-->
{% endfor %}
def template_file (self):
return "tabs.html"
+ # see Composite.py for the details of template_env, that exposes global
+ # 'sons' as a list of sons with each a set of a few attributes
toggled=False),
Tabs (page=page,
title='Sample Tabs',
+ domid='test-tabs',
# *** we select this one to be the active tab ***
- active='raw2',
+ active_domid='son2',
sons = [ Raw (page=page,
- title='a raw plugin',domid='raw1',
+ title='a raw plugin',
+ domid='son0',
togglable=False,
- html= 3*lorem_p),
+ html= 3*lorem_p,
+ ),
StaticList(page=page,
title='a slice list',
+ domid='son1',
togglable=False,
header="static list but not togglable",
- list=hard_wired_slice_names),
+ list=hard_wired_slice_names,
+ ),
Raw (page=page,
- title='raw title',domid='raw2',
- togglable=False,html=lorem) ]),
+ title='raw title',
+ domid='son2',
+ togglable=False,
+ html=lorem) ]),
StaticList (page=page,
title='SimpleList with slice names',
list=hard_wired_slice_names,
def tab_view (request):
prelude=Prelude( js_files='js/bootstrap.js', css_files='css/bootstrap.css')
prelude_env = prelude.prelude_env()
+
tab_env = {'title':'Page for playing with Tabs',
'topmenu_items': topmenu_items('tab',request),
'username':the_user (request),
'lorem': lorem,
}
tab_env.update (prelude_env)
-
return render_to_response ('view-tab.html', tab_env,
context_instance=RequestContext(request))
from manifold.manifoldquery import ManifoldQuery
from plugins.stack.stack import Stack
+from plugins.tabs.tabs import Tabs
from plugins.hazelnut.hazelnut import Hazelnut
from plugins.lists.slicelist import SliceList
from plugins.querycode.querycode import QueryCode
main_plugin = Stack (
page=page,
title="global container",
- sons=[
- Hazelnut ( # setting visible attributes first
+ togglable=False,
+ sons=[Tabs (
page=page,
- title='a sample and simple hazelnut',
- # this is the query at the core of the slice list
- query=main_query,
- ),
- QueryCode (
+ title="different angles",
+ active_domid='with-checkboxes',
+ sons=[
+ Hazelnut (
+ page=page,
+ title='a sample and simple hazelnut',
+ togglable=False,
+ # this is the query at the core of the slice list
+ query=main_query,
+ ),
+ Hazelnut (
+ page=page,
+ title='with checkboxes',
+ domid='with-checkboxes',
+ togglable=False,
+ checkboxes=True,
+ # this is the query at the core of the slice list
+ query=main_query,
+ ),
+ ]),
+ QueryCode (
page=page,
title='xmlrpc code',
query=main_query,
toggled=False,
),
- ])
+ ])
# variables that will get passed to the view-plugin.html template
template_env = {}
# more general variables expected in the template
template_env [ 'title' ] = 'Test view for hazelnut'
# the menu items on the top
- template_env [ 'topmenu_items' ] = topmenu_items('hazelnut', request)
+ template_env [ 'topmenu_items' ] = topmenu_items('slice', request)
# so we can sho who is logged
template_env [ 'username' ] = the_user (request)
{% insert_str prelude "css/sample.css" %}
{% insert prelude_js %}
-$(function(){console.log('hey!');$('#tooltipid').tooltip({'selector':'','placement':'bottom'});});
+$(function(){$('#tooltipid').tooltip({'selector':'','placement':'bottom'});});
{% endinsert %}
<div id=sample-tabs>
Let us now try to attach <button id='mylougout' class='btn btn-danger' data='mydata'>a click function to a button</button>
<script>
-function foo() {alert ('foo' + $(this).attr('data'));}
+function foo() {alert ('foo ' + $(this).attr('data'));}
$(function() {$('#mylougout').click(foo);})
</script>
from unfold.plugin import Plugin
+# this is a simple base class for plugins that contain/arrange a set of other plugins
+# sons is expected to be a list of the contained plugins, and
+# active_domid is the domid for the one son that should be displayed as active
+# some subclasses of Composite, like e.g. Tabs, will not behave as expected
+# if a valid active_domid is not be provided
+
class Composite (Plugin):
- def __init__ (self, sons=[], active=None, *args, **kwds):
+ def __init__ (self, sons=[], active_domid=None, *args, **kwds):
Plugin.__init__ (self, *args, **kwds)
self.sons=sons
- self.active=active
+ self.active_domid=active_domid
+ # make sure this is valid, unset otherwise, so we always have exactly one active
+ self.check_active_domid()
+
+ def check_active_domid(self):
+ matches= [ son for son in self.sons if son.domid==self.active_domid ]
+ if len(matches)!=1:
+ print "WARNING: %s has %d valid son(s) for being active - expecting 1, resetting"%\
+ (self,len(matches))
+ self.active_domid=None
def insert (self, plugin):
self.sons.append(plugin)
- # xxx currently there is no guarantee that exactly one son will be active
def template_env (self, request):
# this is designed so as to support a template like
# {% for son in sons %} {{ son.rendered }} ...
- def is_active (son):
-# print 'comparing >%s< and >%s<'%(son.domid,self.active)
- return son.domid==self.active
+ def is_active (son,rank):
+ # if active_domid is not specified, make the first one active
+ if not self.active_domid: return rank==0
+ return son.domid==self.active_domid
ranks=range(len(self.sons))
env = { 'sons':
[ { 'rendered': son.render(request),
'rank': rank,
- 'active': is_active(son),
+ 'is_active': is_active(son,rank),
'title': son.title,
'domid': son.domid,
'classname': son.classname,
# do this only once the structure is fine
self.page.record_plugin(self)
+ def __repr__ (self):
+ return "[%s]:%s"%(self.classname,self.domid)
+
def _py_classname (self):
try: return self.__class__.__name__
except: return 'Plugin'
<div class="nav-collapse topmenu">
<ul class="nav nav-pills" id='menu_ul'>
{% for d in topmenu_items %}
- {% if d.active %}
+ {% if d.is_active %}
<li class='active'> <a href="{{ d.href }}"> {{ d.label }} </a> </li>
{% else %}
<li class='other'> <a href="{{ d.href }}"> {{ d.label }} </a> </li>