moksha/api
by Luke Macken
moksha/api/widgets/grid.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
New commits:
commit cd9d0341a52190e8c29e4fb2e396a5d0fb577128
Author: Luke Macken <lmacken(a)redhat.com>
Date: Tue May 5 10:46:33 2009 -0400
Remove the mutable filters dict from the Grid base class
diff --git a/moksha/api/widgets/grid.py b/moksha/api/widgets/grid.py
index 28286b8..29f7c09 100644
--- a/moksha/api/widgets/grid.py
+++ b/moksha/api/widgets/grid.py
@@ -48,7 +48,7 @@ class Grid(FormField):
rows_per_page = 10
page_num = 1
total_rows = 0
- filters = {}
+ filters = None
unique_key = None
sort_key = None
sort_order = -1
@@ -65,6 +65,9 @@ class Grid(FormField):
if not getattr(d,"id",None):
raise ValueError, "Moksha Grid is supposed to have id"
+ if not d.filters:
+ d.filters = {}
+
grid_d = {}
for p in self.params:
v = d.get(p)
15 years, 1 month
2 commits - moksha/lib
by Luke Macken
moksha/lib/helpers.py | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
New commits:
commit d5e13ffc2c709f54726716a0a109b8f3523373eb
Merge: b0a2b0d... ad42a78...
Author: Luke Macken <lmacken(a)redhat.com>
Date: Tue May 5 10:34:42 2009 -0400
Merge branch 'master' of git+ssh://git.fedorahosted.org/git/moksha
commit b0a2b0df2bdf43cd8c4893bc6f66b9eb51f5f2ae
Author: Luke Macken <lmacken(a)redhat.com>
Date: Tue May 5 10:33:57 2009 -0400
Generate uuid's in the ConfigWrapper.process instead of __init__.
This was causing clashes in the updates application.
diff --git a/moksha/lib/helpers.py b/moksha/lib/helpers.py
index eaab91f..18ddb2f 100644
--- a/moksha/lib/helpers.py
+++ b/moksha/lib/helpers.py
@@ -84,9 +84,6 @@ class ConfigWrapper(object):
Derive from this class to create new configuration syntax
"""
- def __init__(self):
- super(ConfigWrapper, self).__init__()
- self.uuid = 'uuid' + str(uuid.uuid4())
def _update_nested_dicts(self, dest, source):
"""Recursive helper which updates nested dicts"""
@@ -135,8 +132,8 @@ class ConfigWrapper(object):
the configuration option
"""
default_values = dict(query_string='',
- id = self.uuid,
- type = self.__class__.__name__)
+ id='uuid' + str(uuid.uuid4()),
+ type=self.__class__.__name__)
return default_values
15 years, 1 month
3 commits - moksha/public
by John (J5) Palmieri
moksha/public/javascript/moksha.js | 9 +++---
moksha/public/javascript/ui/moksha.ui.grid.js | 34 ++++++++++++++++++++++++--
2 files changed, 37 insertions(+), 6 deletions(-)
New commits:
commit ad42a78f5dc95009e8e8589eb2ed7135c815b227
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Mon May 4 17:20:31 2009 -0400
remove debugging alert statement
diff --git a/moksha/public/javascript/ui/moksha.ui.grid.js b/moksha/public/javascript/ui/moksha.ui.grid.js
index 4a349a0..077379a 100644
--- a/moksha/public/javascript/ui/moksha.ui.grid.js
+++ b/moksha/public/javascript/ui/moksha.ui.grid.js
@@ -536,7 +536,6 @@
// set the defaults
$.each(filters, function (i, f) {
- alert (f.name + '=' + f.value);
o.filters[f.name] = f.value;
});
},
commit 6c411fdd19d9bfae7e7e3a606a93db247193b3c3
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Mon May 4 17:20:16 2009 -0400
fix selector
diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js
index 3e045bd..e381146 100644
--- a/moksha/public/javascript/moksha.js
+++ b/moksha/public/javascript/moksha.js
@@ -147,9 +147,8 @@ moksha = {
// run over all the toplevel arguments and add them to the list
// if they match
var $filtered_fragment = fragment.filter('a[moksha_url]');
- $a_list.extend($filtered_fragment);
- if (!$a_list.length)
+ if (!($a_list.length + $filtered_fragment.length))
return fragment;
var _goto = function(e) {
@@ -159,7 +158,7 @@ moksha = {
return false;
}
- $.each($a_list, function(i, e) {
+ var transform = function(i, e) {
var $e = $(e)
var href = $e.attr('href');
var moksha_url = $e.attr('moksha_url');
@@ -172,7 +171,9 @@ moksha = {
href = moksha.url(href);
e.href = href;
}
- );
+
+ $.each($a_list, transform);
+ $.each($filtered_fragment, transform);
return fragment;
},
commit 68113281b3a4344b7fc6e48b389d929220edff69
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Mon May 4 17:05:06 2009 -0400
add a filter plugin to the grid
diff --git a/moksha/public/javascript/ui/moksha.ui.grid.js b/moksha/public/javascript/ui/moksha.ui.grid.js
index cdd4240..4a349a0 100644
--- a/moksha/public/javascript/ui/moksha.ui.grid.js
+++ b/moksha/public/javascript/ui/moksha.ui.grid.js
@@ -36,6 +36,8 @@
self.$rowplaceholder = jQuery('<span />').addClass('moksha_rowplaceholder');
self.$rowplaceholder.hide();
+ self._init_controls();
+
if (!self.element.is('table')) {
var t = self._generate_table();
@@ -44,8 +46,6 @@
self._setup_template();
}
- self._init_controls();
-
self.clear();
},
@@ -521,6 +521,37 @@
}
});
+ $.ui.mokshagrid.prototype.controls.filter = {
+ _init: function($grid, $el) {
+ var filters = this.getFilters($el);
+ var self = this;
+ var o = $grid.options;
+
+ var onChange = function() {
+ o.filters[this.name] = this.value;
+ $grid.request_data_refresh();
+ }
+
+ filters.change(onChange);
+
+ // set the defaults
+ $.each(filters, function (i, f) {
+ alert (f.name + '=' + f.value);
+ o.filters[f.name] = f.value;
+ });
+ },
+
+ getFilters: function($el) {
+ var filters = $el.find('select,input');
+
+ return filters;
+ },
+
+ processElement: function($el) {
+ // we don't do anything here as it is all handled by the event handler
+ },
+ }
+
$.ui.mokshagrid.prototype.controls.info_display = {
_init: function($grid, $el) {
var template_html = '<span>' + unescape($el.html()) + '<span>';
15 years, 1 month
moksha/public
by Luke Macken
moksha/public/javascript/moksha.js | 16 ----------------
1 file changed, 16 deletions(-)
New commits:
commit b28320628af87a5460945bac8e39c781ee801a1d
Author: Luke Macken <lmacken(a)redhat.com>
Date: Mon May 4 10:19:43 2009 -0400
Remove duplicate license header...
diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js
index cc63d9e..3e045bd 100644
--- a/moksha/public/javascript/moksha.js
+++ b/moksha/public/javascript/moksha.js
@@ -1,19 +1,3 @@
-// This file is part of Moksha.
-// Copyright (C) 2008-2009 Red Hat, Inc.
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as
-// published by the Free Software Foundation, either version 3 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
/*
* Moksha javascript library
*
15 years, 1 month
moksha/api moksha/public
by John (J5) Palmieri
moksha/api/widgets/grid.py | 10
moksha/public/javascript/moksha.js | 32 +
moksha/public/javascript/ui/moksha.ui.grid.js | 442 +++++++++++++++++---------
3 files changed, 330 insertions(+), 154 deletions(-)
New commits:
commit 0d6b1dfbf8bd2da7ec6a98c1ace803f5d51d46b3
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Mon May 4 13:29:13 2009 -0400
add a new plugin system for adding controls to the grid (e.g. pagers)
* this gives us much more control as a designer can add templates
to change the look and feel and a developer can add plugins
to add more functionality
diff --git a/moksha/api/widgets/grid.py b/moksha/api/widgets/grid.py
index de43532..28286b8 100644
--- a/moksha/api/widgets/grid.py
+++ b/moksha/api/widgets/grid.py
@@ -1,16 +1,16 @@
# This file is part of Moksha.
# Copyright (C) 2008-2009 Red Hat, Inc.
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
-#
+#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -41,7 +41,8 @@ class Grid(FormField):
params= ['rows_per_page', 'page_num', 'total_rows',
'filters', 'unique_key', 'sort_key', 'sort_order',
'row_template', 'resource', 'resource_path',
- 'loading_throbber', 'uid', 'more_link', 'alphaPager']
+ 'loading_throbber', 'uid', 'more_link', 'alphaPager',
+ 'numericPager']
hidden = True # hide from the moksha main menu
rows_per_page = 10
@@ -57,6 +58,7 @@ class Grid(FormField):
loading_throbber = None
more_link = None
alphaPager = False
+ numericPager = False
def update_params(self, d):
super(Grid, self).update_params(d)
diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js
index 5262f89..cc63d9e 100644
--- a/moksha/public/javascript/moksha.js
+++ b/moksha/public/javascript/moksha.js
@@ -1,5 +1,21 @@
-/* This file is part of Moksha.
- * Copyright (C) 2008-2009 Red Hat, Inc.
+// This file is part of Moksha.
+// Copyright (C) 2008-2009 Red Hat, Inc.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+/*
+ * Moksha javascript library
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -143,6 +159,12 @@ moksha = {
// get all anchors with a moksha_url attr but not inside a rowtemplate
var $a_list = $('a[moksha_url]:not(.rowtemplate *):not(.template *)', fragment);
+
+ // run over all the toplevel arguments and add them to the list
+ // if they match
+ var $filtered_fragment = fragment.filter('a[moksha_url]');
+ $a_list.extend($filtered_fragment);
+
if (!$a_list.length)
return fragment;
@@ -511,6 +533,12 @@ moksha = {
moksha.debug(msg);
},
+ warn: function(msg) {
+ // TODO: Make this do something to indicate it is different from a
+ // error or info message
+ moksha.debug(msg);
+ },
+
log: function(msg) {
moksha.debug(msg);
},
diff --git a/moksha/public/javascript/ui/moksha.ui.grid.js b/moksha/public/javascript/ui/moksha.ui.grid.js
index e5d03bd..cdd4240 100644
--- a/moksha/public/javascript/ui/moksha.ui.grid.js
+++ b/moksha/public/javascript/ui/moksha.ui.grid.js
@@ -1,21 +1,22 @@
// This file is part of Moksha.
// Copyright (C) 2008-2009 Red Hat, Inc.
-//
+//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
-//
+//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
-//
+//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
(function($) {
$.widget("ui.mokshagrid",{
+ controls: function(){},
/* methods */
_init: function() {
@@ -43,6 +44,8 @@
self._setup_template();
}
+ self._init_controls();
+
self.clear();
},
@@ -219,6 +222,53 @@
self.request_data_refresh();
},
+ _foreach_controls: function(callback) {
+ var self = this;
+
+ // get our controls
+ var $controls = $('#grid-controls', this.element.parent());
+
+ // iterate through all of our control plugins
+ // and get any id that matches
+ for(var key in self.controls) {
+ var $matched_controls = $("#" + key, $controls);
+ $.each($matched_controls, function(i, c) {
+ callback(self.controls[key], i, c);
+ });
+ }
+ },
+
+ _init_controls: function() {
+ var self = this;
+ var f = function(plugin, i, c) {
+ // for each matched control call the
+ // _init method of the plugin if it has one
+
+ $(c).data('grid.moksha_grid', self);
+ if (plugin._init)
+ plugin._init.call(plugin,
+ self,
+ $(c));
+ }
+
+ this._foreach_controls(f);
+ },
+
+ _process_controls: function() {
+ var self = this;
+ var f = function(plugin, i, c) {
+ // for each matched control call the
+ // processElement method of the plugin
+ results = plugin.processElement.call(plugin,
+ $(c));
+
+ // place the results inside the element
+ $(c).html(results);
+ }
+
+ this._foreach_controls(f);
+ },
+
refresh_data: function(event, search_criteria) {
var self = this;
var o = self.options;
@@ -233,13 +283,18 @@
self.append_row(json.rows[i]);
}
- var tr = json.total_rows;
+
+ // reset based on returned values
+ o.total_rows = json.total_rows;
+ o.start_row = json.start_row;
+ o.rows_per_pager = json.rows_per_page;
+
+ self._process_controls();
+
var vr = self.visible_row_count();
- var sr = json.start_row;
- var rpp = json.rows_per_page;
+ /* msg block
var msg = '';
- var pager = '';
var show_range = vr.toString();
// show an actual range if we are not starting from 0
@@ -252,21 +307,7 @@
$('.message', self.$pager_bottom_placeholder).html(msg);
- var pager;
- if (o.more_link)
- pager = self._generate_more_link(o.more_link,
- search_criteria.filters);
- else
- pager = self._generate_numerical_pager(tr, sr, rpp);
-
- $('.pager', self.$pager_bottom_placeholder).html(pager);
- self.$pager_bottom_placeholder.show();
-
- if (o.alphaPager) {
- pager = self._generate_alpha_pager();
- $('.pager', self.$pager_top_placeholder).html(pager);
- self.$pager_top_placeholder.show();
- }
+ */
}
var dispatch_data = {}
@@ -309,8 +350,10 @@
var $rows = $('.' + o.rowClass, $ph.parent());
for (i=$rows.length; i > 0; i--) {
- if (!$($rows[i-1]).hasClass(o.blankRowClass))
+ if (!$($rows[i-1]).hasClass(o.blankRowClass)) {
+ o.visible_rows = i + 1;
return i;
+ }
}
return 0;
@@ -397,128 +440,6 @@
self.request_data_refresh();
},
- _generate_more_link: function (more_link, filters) {
- var go = moksha.csrf_rewrite_url(more_link, filters);
- var pager = $('<a>View more ></a>').attr('href',
- 'javascript:moksha.goto("' + go + '")');
-
- return pager;
- },
-
- _generate_alpha_pager: function () {
- var self = this;
- var o = self.options;
- var curr_alpha = o.filters.prefix;
- if (typeof(curr_alpha) == 'undefined')
- current_alpha = '';
-
- var pager = $('<ul />');
- var goto_page = function() {
- var page_jump = $(this).data('alpha_page.moksha_grid');
- self.goto_alpha_page(page_jump);
- }
-
- var alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- for (i in alph) {
- var a = alph[i];
-
- var page = $('<li />').html(a).addClass('page-button').addClass('current-page');
- if (a!=curr_alpha) {
- page.removeClass('current-page');
-
- var page_link = $('<a href="javascript:void(0)"></a>').html(a);
- page_link.data('alpha_page.moksha_grid', a);
- page_link.click(goto_page);
-
- page.html(page_link);
- }
-
- pager.append(page);
- }
-
- var page = $('<li>All</li>').addClass('page-button').addClass('current-button');
- if (curr_alpha != '') {
- var page_link = $('<a href="javascript:void(0)"></a>').html('All');
-
- page_link.data('alpha_page.moksha_grid', '');
- page_link.click(goto_page);
-
- page.html(page_link);
- }
-
- pager.append(page);
-
- return pager;
- },
-
- _generate_numerical_pager: function (total_rows, start_row, rows_per_page) {
- var self = this;
- var o = self.options;
- var total_pages = parseInt(total_rows / rows_per_page);
- if (total_rows != total_pages * rows_per_page)
- total_pages += 1;
-
- var curr_page = parseInt((start_row + 0.5) / rows_per_page) + 1;
-
- var next_page = curr_page + 1;
-
- var pager = $('<ul />');
- var goto_page = function() {
- var page_jump = $(this).data('page.moksha_grid');
- self.goto_page(page_jump);
- }
-
- var show_prev = parseInt((o.pagerPageLimit + 0.5) / 2) + 1;
- var show_next = o.pagerPageLimit - show_prev;
- var num_next_left = total_pages - curr_page;
- if (num_next_left < show_next)
- show_prev += (show_next - num_next_left)
-
- var page_list = [];
- var i, j;
- for (i = curr_page, j = 0; i > 0 && j < show_prev ; i--, j++) {
- page_list.push(i);
- }
-
- page_list.reverse();
- if (page_list.length < show_prev)
- show_next += (show_prev - page_list.length)
-
- for (i = curr_page + 1, j = 0; i <= total_pages && j < show_next ; i++, j++) {
- page_list.push(i);
- }
-
- for (i in page_list) {
- var page_num = page_list[i];
- var page = $('<li></li>').html(page_num).addClass('page-button').addClass('current-page');
- if (page_num != curr_page) {
- page.removeClass('current-page');
- var page_link = $('<a href="javascript:void(0)"></a>').html(page_num);
-
- page_link.data('page.moksha_grid', page_num);
- page_link.click(goto_page);
-
- page.html(page_link);
- }
-
- pager.append(page);
- }
-
- var page = $("<li>Next</li>").addClass('page-button').addClass('next-page');
-
- if (curr_page < total_pages) {
- var page_link = $('<a href="javascript:void(0)"></a>').html('Next');
-
- page_link.data('page.moksha_grid', next_page);
- page_link.click(goto_page);
- page.html(page_link);
- }
-
- pager.append(page);
-
- return(pager);
- },
-
_generate_table: function() {
var self = this;
var t = $('<table />');
@@ -578,6 +499,7 @@
rows_per_page: 10,
page_num: 1,
total_rows: 0,
+ visible_rows: 0,
filters: {},
unique_key: undefined,
sort_key: undefined,
@@ -587,11 +509,10 @@
resource_path: null,
blankRowClass: 'moksha-grid-blank-row',
rowClass: 'moksha-grid-row',
- moreClass: 'moksha-grid-more',
- pagerTopClass: 'moksha-grid-pager-top',
- pagerBottomClass: 'moksha-grid-pager-bottom',
pagerPageLimit: 10,
alphaPager: false,
+ numericPager: false,
+ filterControls: false,
more_link: null,
loading_throbber: ["Loading", // list of img urls or text
"Loading.",
@@ -600,6 +521,231 @@
}
});
+ $.ui.mokshagrid.prototype.controls.info_display = {
+ _init: function($grid, $el) {
+ var template_html = '<span>' + unescape($el.html()) + '<span>';
+ var $template = jQuery.template(template_html, {regx:'moksha'});
+
+ // place in a data slot inside the element
+ $el.data('info_display_template.moksha_grid', $template);
+
+ $el.html(this.processElement($el));
+
+ // remove the template marker from the element
+ $el.removeClass('template');
+ },
+
+ processElement: function($el) {
+ var $grid = $el.data('grid.moksha_grid');
+
+ var $template = $el.data('info_display_template.moksha_grid');
+ return this._generate_info_display($template, $grid.options);
+ },
+
+ _generate_info_display: function($template, o) {
+ var $display = jQuery($template.apply(o));
+ moksha.update_marked_anchors($display);
+
+ return $display;
+ }
+ }
+
+ $.ui.mokshagrid.prototype.controls.pager = {
+ pager_types: {},
+ _init: function($grid, $el) {
+ var type = $el.attr('type');
+
+ var pager_obj = this.pager_types[type];
+ if (!pager_obj) {
+ moksha.warn('Pager type ' + type + ' requested but does not have a plugin');
+ return '';
+ }
+
+
+ if (typeof(pager_obj._init) == "function") {
+ pager_obj._init.call(pager_obj,
+ $grid,
+ $el);
+ }
+ },
+
+ processElement: function($el) {
+ var type = $el.attr('type');
+
+ var pager_obj = this.pager_types[type];
+
+ if (!pager_obj) {
+ moksha.warn('Pager type ' + type + ' requested but does not have a plugin');
+ return '';
+ }
+
+ return pager_obj.processElement.call(this.pager_types[type],
+ $el);
+ },
+ };
+
+ $.ui.mokshagrid.prototype.controls.pager.pager_types.more_link = {
+
+ _init: function($grid, $el) {
+ var template_html = unescape($el.html());
+ var $template = jQuery.template(template_html, {regx:'moksha'});
+
+ // place in a data slot inside the element
+ $el.data('more_link_template.moksha_grid', $template);
+
+ // remove the template marker from the element
+ $el.removeClass('template');
+
+ $el.html(this.processElement($el));
+ },
+
+ processElement: function($el) {
+ var $grid = $el.data('grid.moksha_grid');
+ if (!$grid.options.more_link)
+ return "";
+
+ var $template = $el.data('more_link_template.moksha_grid');
+ return this._generate_more_pager($template, $grid.options);
+ },
+
+ _generate_more_pager: function($template, o) {
+ var $pager = jQuery($template.apply(o));
+ moksha.update_marked_anchors($pager);
+
+ return $pager;
+ }
+ }
+
+ $.ui.mokshagrid.prototype.controls.pager.pager_types.alpha = {
+ processElement: function($el) {
+ var $grid = $el.data('grid.moksha_grid');
+
+ if (!$grid.options.alphaPager)
+ return "";
+
+ return this._generate_alpha_pager($grid);
+ },
+
+ _generate_alpha_pager: function ($grid) {
+ var o = $grid.options;
+ var curr_alpha = o.filters.prefix;
+ if (typeof(curr_alpha) == 'undefined')
+ current_alpha = '';
+
+ var pager = $('<ul />');
+ var goto_page = function() {
+ var page_jump = $(this).data('alpha_page.moksha_grid');
+ $grid.goto_alpha_page(page_jump);
+ }
+
+ var alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ for (i in alph) {
+ var a = alph[i];
+
+ var page = $('<li />').html(a).addClass('page-button').addClass('current-page');
+ if (a!=curr_alpha) {
+ page.removeClass('current-page');
+
+ var page_link = $('<a href="javascript:void(0)"></a>').html(a);
+ page_link.data('alpha_page.moksha_grid', a);
+ page_link.click(goto_page);
+
+ page.html(page_link);
+ }
+
+ pager.append(page);
+ }
+
+ var page = $('<li>All</li>').addClass('page-button').addClass('current-button');
+ if (curr_alpha != '') {
+ var page_link = $('<a href="javascript:void(0)"></a>').html('All');
+
+ page_link.data('alpha_page.moksha_grid', '');
+ page_link.click(goto_page);
+
+ page.html(page_link);
+ }
+
+ pager.append(page);
+
+ return pager;
+ }
+ };
+
+ $.ui.mokshagrid.prototype.controls.pager.pager_types.numeric = {
+ processElement: function($el) {
+ var $grid = $el.data('grid.moksha_grid');
+ var o = $grid.options;
+ if (!o.numericPager)
+ return ""
+
+ return this._generate_numerical_pager($grid,
+ o.total_rows,
+ o.start_row,
+ o.rows_per_page);
+ },
+
+ _generate_numerical_pager: function ($grid, total_rows, start_row, rows_per_page) {
+ var o = $grid.options;
+ var total_pages = parseInt(total_rows / rows_per_page);
+ if (total_rows != total_pages * rows_per_page)
+ total_pages += 1;
+
+ var curr_page = parseInt((start_row + 0.5) / rows_per_page) + 1;
+ var next_page = curr_page + 1;
+ var pager = $('<ul />');
+
+ var goto_page = function() {
+ var page_jump = $(this).data('page.moksha_grid');
+ $grid.goto_page(page_jump);
+ }
+
+ var show_prev = parseInt((o.pagerPageLimit + 0.5) / 2) + 1;
+ var show_next = o.pagerPageLimit - show_prev;
+ var num_next_left = total_pages - curr_page;
+ if (num_next_left < show_next)
+ show_prev += (show_next - num_next_left)
+
+ var page_list = [];
+ var i, j;
+ for (i = curr_page, j = 0; i > 0 && j < show_prev; i--, j++)
+ page_list.push(i);
+
+ page_list.reverse();
+ if (page_list.length < show_prev)
+ show_next += (show_prev - page_list.length)
+
+ for (i = curr_page + 1, j = 0; i <= total_pages && j < show_next; i++, j++)
+ page_list.push(i);
+
+ for (i in page_list) {
+ var page_num = page_list[i];
+ var page = $('<li></li>').html(page_num).addClass('page-button').addClass('current-page');
+ if (page_num != curr_page) {
+ page.removeClass('current-page');
+ var page_link = $('<a href="javascript:void(0)"></a>').html(page_num);
+
+ page_link.data('page.moksha_grid', page_num);
+ page_link.click(goto_page);
+ page.html(page_link);
+ }
+
+ pager.append(page);
+ }
+
+ var page = $("<li>Next</li>").addClass('page-button').addClass('next-page');
+ if (curr_page < total_pages) {
+ var page_link = $('<a href="javascript:void(0)"></a>').html('Next');
+ page_link.data('page.moksha_grid', next_page);
+ page_link.click(goto_page);
+ page.html(page_link);
+ }
+
+ pager.append(page);
+ return(pager);
+ }
+ };
+
$.extend( $.template.regx , {
moksha:/\@\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g
}
15 years, 1 month
moksha/public
by Luke Macken
moksha/public/javascript/moksha.js | 34 +++++++++++++---------------------
1 file changed, 13 insertions(+), 21 deletions(-)
New commits:
commit d6821f33726b5a03758fd3e0447834fcaefd8169
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sun May 3 20:27:20 2009 -0400
Update the moksha.js header
diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js
index 0d4f3f3..5262f89 100644
--- a/moksha/public/javascript/moksha.js
+++ b/moksha/public/javascript/moksha.js
@@ -1,31 +1,23 @@
-// This file is part of Moksha.
-// Copyright (C) 2008-2009 Red Hat, Inc.
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as
-// published by the Free Software Foundation, either version 3 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-/*
- * Moksha javascript library
+/* This file is part of Moksha.
+ * Copyright (C) 2008-2009 Red Hat, Inc.
*
- * Copyright (c) 2008 Red Hat, Inc.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
*
- * GPLv2+ license.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Depends:
* jquery.js
*/
-
(function(){
True = true
15 years, 1 month