moksha/api/widgets/__init__.py | 1 moksha/api/widgets/containers/templates/layout_applist.mak | 4 moksha/api/widgets/selectable/__init__.py | 1 moksha/api/widgets/selectable/selectable.py | 20 +++ moksha/api/widgets/selectable/templates/selectable.mak | 25 ++++ moksha/connector/connector.py | 36 ++--- moksha/public/javascript/ui/moksha.ui.grid.js | 38 +++++- moksha/public/javascript/ui/moksha.ui.selectable.js | 81 +++++++++++++ 8 files changed, 182 insertions(+), 24 deletions(-)
New commits: commit 0b8807b56817607bbc05b10d8be4b88e9599cdd5 Author: John (J5) Palmieri johnp@redhat.com Date: Mon Mar 16 18:43:51 2009 -0400
fix the grid and connectors for better querying
* connector's query interface had incorrect indenting causing no data to be returned when a sort_row was passed to the the method * the grid can now update its filters to load new data
diff --git a/moksha/api/widgets/__init__.py b/moksha/api/widgets/__init__.py index 6449275..95410ec 100644 --- a/moksha/api/widgets/__init__.py +++ b/moksha/api/widgets/__init__.py @@ -2,4 +2,5 @@ from live import LiveWidget from util import * from grid import Grid from placeholder import Placeholder +from selectable import Selectable
diff --git a/moksha/api/widgets/containers/templates/layout_applist.mak b/moksha/api/widgets/containers/templates/layout_applist.mak index 797abeb..0c7cfd9 100644 --- a/moksha/api/widgets/containers/templates/layout_applist.mak +++ b/moksha/api/widgets/containers/templates/layout_applist.mak @@ -1,11 +1,11 @@ <div id="${category['id']}" class="ui-sortable ${category['css_class']}"> % for app in category['apps']: - <span class="sort"> + <span class="sort ${app['css_class']}"> % if app['label']: <h3>${app['label']}</h3> % endif
- <div id="${app['id']}" class="${app['css_class']}"> + <div id="${app['id']}"> % if app.has_key('widget'): ${app['widget'](**app['params'])} % endif diff --git a/moksha/connector/connector.py b/moksha/connector/connector.py index c93c3af..11f2dff 100644 --- a/moksha/connector/connector.py +++ b/moksha/connector/connector.py @@ -281,24 +281,24 @@ class IQuery(object): if not sort_col: sort_col = self.get_default_sort_col(resource_path)
- if params == None: - params = {} - - query_func = self.query_model(resource_path).get_query() - (total_rows, rows) = query_func(self, - offset = offset, - limit = num_rows, - order = sort_order, - sort_col = sort_col, - filters = filters, - **params) - r['total_rows'] = total_rows - r['row_count'] = len(rows) - if offset: - r['offset'] = offset - r['rows'] = rows - - results = r + if params == None: + params = {} + + query_func = self.query_model(resource_path).get_query() + (total_rows, rows) = query_func(self, + offset = offset, + limit = num_rows, + order = sort_order, + sort_col = sort_col, + filters = filters, + **params) + r['total_rows'] = total_rows + r['row_count'] = len(rows) + if offset: + r['offset'] = offset + r['rows'] = rows + + results = r
return results
diff --git a/moksha/public/javascript/ui/moksha.ui.grid.js b/moksha/public/javascript/ui/moksha.ui.grid.js index 2986f96..cf88fc2 100644 --- a/moksha/public/javascript/ui/moksha.ui.grid.js +++ b/moksha/public/javascript/ui/moksha.ui.grid.js @@ -132,6 +132,29 @@ self.refresh_data(event, search_criteria); },
+ request_update: function(search_criteria) { + var self = this; + + var sc = search_criteria; + + if (typeof(sc.rows_requested) != 'undefined') + self.options.rows_per_page =sc.rows_requested; + + if (typeof(sc.page_num) != 'undefined') + self.options.page_num = sc.page_num; + + if (typeof(sc.filters) != 'undefined') + self.options.filters = sc.filters; + + if (typeof(sc.sort_key) != 'undefined') + self.options.sort_key = sc.sort_key; + + if (typeof(sc.sort_order) != 'undefined') + self.options.sort_order = sc.sort_order; + + self.request_data_refresh(); + }, + refresh_data: function(event, search_criteria) { var self = this; var o = self.options; @@ -146,12 +169,19 @@ } }
+ var dispatch_data = {} + var filters = search_criteria.filters + if (typeof(filters) != 'undefined') + dispatch_data['filters'] = filters + + var numrows = search_criteria.numrows + if (typeof(numrows) != 'undefined') + dispatch_data['filters'] = filters
- var dispatch_data = {offset: search_criteria.start_row, - num_rows: search_criteria.rows_requested, - filters: filters - } + var offset = search_criteria.start_row + if (typeof(offset) != 'undefined') + dispatch_data['offset'] = offset
if (search_criteria.sort_key) { dispatch_data["sort_col"] = search_criteria.sort_key;
commit f5cb299c0a833038524815a155c3de613a9b0618 Author: John (J5) Palmieri johnp@redhat.com Date: Mon Mar 16 18:41:34 2009 -0400
add a new selectable widget which makes it easy to have highlighted selection
diff --git a/moksha/api/widgets/selectable/__init__.py b/moksha/api/widgets/selectable/__init__.py new file mode 100644 index 0000000..a40f1bd --- /dev/null +++ b/moksha/api/widgets/selectable/__init__.py @@ -0,0 +1 @@ +from selectable import Selectable \ No newline at end of file diff --git a/moksha/api/widgets/selectable/selectable.py b/moksha/api/widgets/selectable/selectable.py new file mode 100644 index 0000000..6366982 --- /dev/null +++ b/moksha/api/widgets/selectable/selectable.py @@ -0,0 +1,20 @@ +from tw.api import JSLink, Widget +from tw.jquery.ui_core import jquery_ui_core_js +from tw.jquery import jQuery, jquery_js +from uuid import uuid4 + + +moksha_ui_selectable_js = JSLink(modname='moksha', filename='public/javascript/ui/moksha.ui.selectable.js', + javascript=[jquery_ui_core_js]) + +class Selectable(Widget): + template = 'mako:moksha.api.widgets.selectable.templates.selectable' + javascript = [moksha_ui_selectable_js] + + def update_params(self, d): + super(Selectable, self).update_params(d) + content_id = d.id + '-uuid' + str(uuid4()) + d['content_id'] = content_id + + self.add_call(jQuery("#%s" % d.content_id).moksha_selectable()) + diff --git a/moksha/api/widgets/selectable/templates/__init__.py b/moksha/api/widgets/selectable/templates/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/moksha/api/widgets/selectable/templates/selectable.mak b/moksha/api/widgets/selectable/templates/selectable.mak new file mode 100644 index 0000000..ec87647 --- /dev/null +++ b/moksha/api/widgets/selectable/templates/selectable.mak @@ -0,0 +1,25 @@ +<div class="links" id="${content_id}"> + % for c in categories: + <h4> + ${c['label']} + </h4> + <ul> + % for c, item in enumerate(c['items']): + <li> + <a id="${content_id}_${c}" href="${item['link']}" >${item['label']}</a> + % if 'data' in item: + <script type="text/javascript"> + <% + data = item['data'] + label = item['label'] + if 'label' not in data: + data['label'] = label + %> + $("#${content_id}_${c}").data('.moksha_selectable_data', ${item['data']}) + </script> + % endif + </li> + % endfor + </ul> + % endfor +</div> \ No newline at end of file diff --git a/moksha/public/javascript/ui/moksha.ui.selectable.js b/moksha/public/javascript/ui/moksha.ui.selectable.js new file mode 100644 index 0000000..c176af5 --- /dev/null +++ b/moksha/public/javascript/ui/moksha.ui.selectable.js @@ -0,0 +1,81 @@ +/* + * Moksha UI Selectable - manages a group of links so that when one is clicked + * it fires off an event and adds a selected class to + * the link (and removes the class from other + * links) + * + * Copyright (c) 2009 Red Hat, Inc. + * Dual licensed under the MIT + * and GPLv2 licenses. + * + * + * Depends: + * jQuery - ui.core.js + */ +(function ($) { +$.widget("ui.moksha_selectable", { + + _init: function() { + // create selectable + this._createselectable(); + + }, + + destroy: function() { + + }, + + select: function(i) { + var o = this.options; + if (i < this.$links.length) { + if (o.selected != i) + if (o.selected < this.$links.length) + $(this.$links[o.selected]).removeClass(o.selectedClass) + + $(this.$links[i]).addClass(o.selectedClass) + } + }, + + + _createselectable: function() { + var o = this.options; + var $e = this.element; + + this.hover_timer = null; + + this.$links = jQuery('a', $e); + + var self = this; + + this.$links.unbind('.moksha_selectable').bind('click.moksha_selectable', + function () { + + var i=-1; + for (i in self.$links) { + if (self.$links[i] === this) { + self.select(i); + break; + } + } + + if (i >= 0) + $(self.element).triggerHandler('selected', {index: i, + element: this}); + }); + + this.select(o.selected); + + + } +}) +$.extend($.ui.moksha_selectable, { + version: '@VERSION', + defaults: { + popupClass: 'ui-moksha-selectable', + selectedClass: 'selected', + selected: 0 + } +}); + + +})(jQuery);
moksha-commits@lists.fedorahosted.org