moksha/api/widgets/containers/dashboardcontainer.py | 2
moksha/api/widgets/containers/tabbedcontainer.py | 12 +-
moksha/api/widgets/containers/templates/dashboardcontainer.mak | 3
moksha/api/widgets/containers/templates/layout_applist.mak | 2
moksha/lib/helpers.py | 50 ++++++----
moksha/public/javascript/ui/moksha.ui.tabs.js | 9 +
6 files changed, 52 insertions(+), 26 deletions(-)
New commits:
commit ffd12a181a2f11f25b8ed10dda11a5e7d2d9f297
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Wed Feb 11 19:57:27 2009 -0500
make passing dynamic parameters to apps possible
diff --git a/moksha/api/widgets/containers/dashboardcontainer.py b/moksha/api/widgets/containers/dashboardcontainer.py
index 6892d6f..0dde052 100644
--- a/moksha/api/widgets/containers/dashboardcontainer.py
+++ b/moksha/api/widgets/containers/dashboardcontainer.py
@@ -43,7 +43,7 @@ class DashboardContainer(Widget):
# Filter out any None's in the layout which signify apps which are
# not allowed to run with the current session's authorization level
- l = ConfigWrapper.process_wrappers(layout)
+ l = ConfigWrapper.process_wrappers(layout, d)
d['layout'] = l
d['applist_widget'] = applist_widget
diff --git a/moksha/api/widgets/containers/tabbedcontainer.py b/moksha/api/widgets/containers/tabbedcontainer.py
index fc5577b..67d0b39 100644
--- a/moksha/api/widgets/containers/tabbedcontainer.py
+++ b/moksha/api/widgets/containers/tabbedcontainer.py
@@ -50,9 +50,10 @@ class TabbedContainer(FormField):
tabs = ()
javascript = [moksha_ui_tabs_js
]
- params = ["tabdefault"]
+ params = ["tabdefault", "passPathRemainder"]
tabdefault__doc="0-based index of the tab to be selected on page load"
- tabdefault='#my_profile'
+ tabdefault=0
+ passPathRemainder=False
# include_dynamic_js_calls = True #????
def update_params(self, d):
super(TabbedContainer, self).update_params(d)
@@ -60,8 +61,9 @@ class TabbedContainer(FormField):
raise ValueError, "JQueryUITabs is supposed to have id"
o = {
- 'tabdefault': d.get('tabdefault', 0)
- }
+ 'tabdefault': d.get('tabdefault', 0),
+ 'passPathRemainder': d.get('passPathRemainder', False)
+ }
self.add_call(jQuery("#%s" % d.id).mokshatabs(o))
tabs = eval_app_config(config.get(self.config_key, "None"))
@@ -73,7 +75,7 @@ class TabbedContainer(FormField):
# Filter out any None's in the list which signify apps which are
# not allowed to run with the current session's authorization level
- tabs = ConfigWrapper.process_wrappers(tabs)
+ tabs = ConfigWrapper.process_wrappers(tabs, d)
d['tabs'] = tabs
d['tabwidget'] = tabwidget
d['panewidget'] = panewidget
diff --git a/moksha/api/widgets/containers/templates/dashboardcontainer.mak b/moksha/api/widgets/containers/templates/dashboardcontainer.mak
index dd4e57d..a9042da 100644
--- a/moksha/api/widgets/containers/templates/dashboardcontainer.mak
+++ b/moksha/api/widgets/containers/templates/dashboardcontainer.mak
@@ -1,8 +1,7 @@
<div>
- Sample Template - you should subclass and create your own layout
<div id="container">
% for c in layout:
- ${applist_widget(category = c)}
+ ${applist_widget(category=c)}
% endfor
</div>
diff --git a/moksha/api/widgets/containers/templates/layout_applist.mak b/moksha/api/widgets/containers/templates/layout_applist.mak
index af2021a..8dc1fa6 100644
--- a/moksha/api/widgets/containers/templates/layout_applist.mak
+++ b/moksha/api/widgets/containers/templates/layout_applist.mak
@@ -12,7 +12,7 @@
% if not app.has_key('widget'):
<script type="text/javascript">
- $("#${app['id']}").load("${app['url']}");
+ $("#${app['id']}").load("${app['url']}", ${app['params']});
</script>
% endif
diff --git a/moksha/lib/helpers.py b/moksha/lib/helpers.py
index fa891e2..f3c4586 100644
--- a/moksha/lib/helpers.py
+++ b/moksha/lib/helpers.py
@@ -7,6 +7,7 @@ from repoze.what.predicates import (Not, Predicate, All, Any, has_all_permissio
import urllib
import uuid
+import simplejson as json
import re
from decorator import decorator
@@ -14,6 +15,23 @@ import moksha
scrub_filter = re.compile('[^_a-zA-Z0-9-]')
+def _update_params(params, d):
+ p = {}
+ if params:
+ for k in params.iterkeys():
+
+ if d and (k in d):
+ p[k] = d[k]
+ else:
+ p[k] = params[k]
+
+ if isinstance(p[k], dict) or isinstance(p[k], list):
+ p[k] = json.dumps(p[k])
+
+ return p
+
+ return params
+
class ConfigWrapper(object):
""" Base class for container configuration wrappers
@@ -34,7 +52,7 @@ class ConfigWrapper(object):
"""
@staticmethod
- def process_wrappers(wrappers):
+ def process_wrappers(wrappers, dict):
""" Helper method for evlauating a list of wrappers
:returns: a list of hashes for each of the application
@@ -43,18 +61,18 @@ class ConfigWrapper(object):
result = []
if isinstance(wrappers, ConfigWrapper):
- w = wrappers.process()
+ w = wrappers.process(dict)
if w:
result.append(w)
else:
for item in wrappers:
- w = item.process()
+ w = item.process(dict)
if w:
result.append(w)
return result
- def process(self):
+ def process(self, dict=None):
"""Override this in derived classes to return a hash representing
the configuration option
"""
@@ -96,7 +114,7 @@ class Category(ConfigWrapper):
self.css_class = css_class
- def process(self):
+ def process(self, dict=None):
"""Check the predicates and construct the dict
:returns: a dict with all the configuration data for this category
@@ -107,7 +125,7 @@ class Category(ConfigWrapper):
id = uuid.uuid4()
- apps = self.process_wrappers(self.apps)
+ apps = self.process_wrappers(self.apps, dict)
return {'label': self.label, 'apps': apps, 'id': id, 'css_class': self.css_class}
class App(ConfigWrapper):
@@ -146,7 +164,7 @@ class App(ConfigWrapper):
if self.label and not self.content_id:
self.content_id = scrub_filter.sub('_', self.label.lower())
- def process(self):
+ def process(self, dict=None):
"""Check the predicates and construct the dict
:returns: a dict with all the configuration data for this application
@@ -154,13 +172,11 @@ class App(ConfigWrapper):
if not check_predicates(self.auth):
return None
- query_str = ""
- if self.params:
- query_str = "?" + urllib.urlencode(self.params)
-
id = 'uuid' + str(uuid.uuid4())
- return {'label': self.label, 'url': self.url + query_str, 'id': id,
+ return {'label': self.label, 'url': self.url,
+ 'params': _update_params(self.params, dict),
+ 'id': id,
'content_id': self.content_id + '-' + id}
class MokshaApp(App):
@@ -204,14 +220,14 @@ class MokshaApp(App):
content_id,
params, auth)
- def process(self):
+ def process(self, dict=None):
# We return a placeholder if the app is not registered
if not moksha.apps.has_key(self.app):
return MokshaWidget(self.label, 'placeholder',
self.content_id,
- {'appname':self.app}, self.auth).process()
+ {'appname':self.app}, self.auth).process(dict)
- return super(MokshaApp, self).process()
+ return super(MokshaApp, self).process(dict)
class Widget(ConfigWrapper):
"""A configuration wrapper class that displays a ToscaWidget. Use this
@@ -258,14 +274,14 @@ class Widget(ConfigWrapper):
self.content_id += '-' + self.id
- def process(self):
+ def process(self, dict):
if not check_predicates(self.auth):
return None
url = '#' + self.content_id
return {'label': self.label, 'url': url,'widget': self.widget ,
- 'params':self.params, 'id': self.id, 'content_id': self.content_id}
+ 'params':_update_params(self.params, dict), 'id': self.id, 'content_id': self.content_id}
class MokshaWidget(Widget):
"""A configuration wrapper class that displays a ToscaWidget registered
diff --git a/moksha/public/javascript/ui/moksha.ui.tabs.js b/moksha/public/javascript/ui/moksha.ui.tabs.js
index d09c6f7..5208344 100644
--- a/moksha/public/javascript/ui/moksha.ui.tabs.js
+++ b/moksha/public/javascript/ui/moksha.ui.tabs.js
@@ -59,6 +59,7 @@ $.widget("ui.mokshatabs", {
var self = this, o = this.options;
+ self.path_remainder = '';
self.options.hash_level = _moksha_hash_consumer_level;
this.$tabs.each(function(i, a) {
// inline tab
@@ -464,6 +465,10 @@ $.widget("ui.mokshatabs", {
var id = "#" + hash[level + offset];
+ var remainder = level + offset + 1;
+ if (this.options.passPathRemainder && hash.length > remainder)
+ this.path_remainder = '/' + hash.splice(level + offset + 1).join('/');
+
return this.idToIndex(id);
},
idToIndex: function(id) {
@@ -520,6 +525,9 @@ $.widget("ui.mokshatabs", {
.find('em').data('label.tabs', label).html(o.spinner);
}
+ if (o.passPathRemainder)
+ url += self.path_remainder;
+
var ajaxOptions = $.extend({}, o.ajaxOptions, {
url: url,
success: function(r, s) {
@@ -601,6 +609,7 @@ $.ui.mokshatabs.defaults = {
cache: false,
idPrefix: 'ui-tabs-',
ajaxOptions: {},
+ passPathRemainder:false,
// animations
fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }