From b01220cc38b2bcaeb35931bda1dc9a258ff3850b Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Fri, 27 May 2011 16:30:41 -0500 Subject: Added pagination for associations. The association facet has been modified to support pagination. The UI will show 20 members per page. There are buttons to go to a previous or next page. There is also an input text to jump directly to a certain page. Ticket #1011 --- install/ui/associate.js | 146 +++++++++++++++++++++++++++++++----------------- install/ui/ipa.css | 19 ++++++- install/ui/sudo.js | 9 ++- install/ui/widget.js | 131 +++++++++++++++++++++++++++++-------------- 4 files changed, 210 insertions(+), 95 deletions(-) (limited to 'install') diff --git a/install/ui/associate.js b/install/ui/associate.js index 5eb84260..ad2da521 100644 --- a/install/ui/associate.js +++ b/install/ui/associate.js @@ -468,19 +468,20 @@ IPA.association_table_widget = function (spec) { that.get_records = function(on_success, on_error) { - if (!that.values.length) return; + var length = that.values.length; + if (!length) return; + + if (length > 100) { + length = 100; + } var batch = IPA.batch_command({ 'name': that.entity_name+'_'+that.name, 'on_success': on_success, 'on_error': on_error }); - var length = that.values.length; - if (length > 100){ - length = 100; - } - for (var i=0; i< length; i++) { + for (var i=0; i total ? total : end; - var command = IPA.command({ - entity: that.other_entity, - method: 'find', - args: args, - options: options, - on_success: on_success, - on_error: on_error + var summary = 'Showing '+start+' to '+end+' of '+total+' entries.'; + that.table.summary.text(summary); + + var list = pkeys.slice(start-1, end); + + var columns = that.table.columns.values; + if (columns.length == 1) { // show pkey only + var name = columns[0].name; + that.table.empty(); + for (var i=0; iError: '+error_thrown.name+'

'); + summary.append('

'+error_thrown.message+'

'); + } + ); + } + }; + + that.get_records = function(pkeys, on_success, on_error) { + + var length = pkeys.length; + if (!length) return; + + var batch = IPA.batch_command({ + 'name': that.entity_name+'_'+that.name, + 'on_success': on_success, + 'on_error': on_error }); - command.execute(); + for (var i=0; i 100) { + length = 100; + } + if (!that.values.length) return; var batch = IPA.batch_command({ @@ -168,7 +175,7 @@ IPA.sudocmd_member_sudocmdgroup_table_widget = function (spec) { 'on_error': on_error }); - for (var i=0; i', { + that.table = $('', { 'class': 'search-table' }).appendTo(container); - that.table = table; if (that.scrollable) { - table.addClass('scrollable'); + that.table.addClass('scrollable'); } - var thead = $('').appendTo(table); - that.thead = thead; + that.thead = $('').appendTo(that.table); - var tr = $('').appendTo(thead); + var tr = $('').appendTo(that.thead); var th = $('').appendTo(that.table); if (that.height) { - tbody.css('height', that.height); + that.tbody.css('height', that.height); } - tr = $('').appendTo(tbody); + that.row = $(''); var td = $('').appendTo(table); - that.tfoot = tfoot; + that.tfoot = $('').appendTo(that.table); - tr = $('').appendTo(tfoot); + tr = $('').appendTo(that.tfoot); td = $('
', { 'style': 'width: 22px;' }).appendTo(tr); - $('', { - 'type': 'checkbox', - 'name': 'select' + var select_all_checkbox = $('', { + type: 'checkbox', + name: 'select', + title: IPA.messages.search.select_all }).appendTo(th); + select_all_checkbox.change(function() { + var checked = select_all_checkbox.is(':checked'); + select_all_checkbox.attr('title', checked ? IPA.messages.search.unselect_all : IPA.messages.search.select_all); + var checkboxes = $('input[name=select]', that.tbody).get(); + for (var i=0; i').appendTo(table); - that.tbody = tbody; + that.tbody = $('
', { 'style': 'width: 22px;' - }).appendTo(tr); + }).appendTo(that.row); $('', { 'type': 'checkbox', @@ -1176,7 +1189,7 @@ IPA.table_widget = function (spec) { for (/* var */ i=0; i').appendTo(tr); + td = $('').appendTo(that.row); if (column.width) { td.css('width', column.width); } @@ -1186,16 +1199,74 @@ IPA.table_widget = function (spec) { }).appendTo(td); } - var tfoot = $('
', { colspan: columns.length+1 }).appendTo(tr); - $('', { + that.summary = $('', { 'name': 'summary' }).appendTo(td); + + that.pagination = $('', { + 'name': 'pagination' + }).appendTo(td); + + if (that.page_length) { + + $('', { + text: 'Prev', + name: 'prev_page', + click: function() { + if (that.current_page > 1) { + that.current_page--; + that.refresh(); + } + return false; + } + }).appendTo(that.pagination); + + that.pagination.append(' '); + + $('', { + text: 'Next', + name: 'next_page', + click: function() { + if (that.current_page < that.total_pages) { + that.current_page++; + that.refresh(); + } + return false; + } + }).appendTo(that.pagination); + + that.pagination.append(' Page: '); + + that.current_page_input = $('', { + type: 'text', + name: 'current_page', + keypress: function(e) { + if (e.which == 13) { + var page = parseInt($(this).val(), 10); + if (page < 1) { + page = 1; + } else if (page > that.total_pages) { + page = that.total_pages; + } + that.current_page = page; + $(this).val(page); + that.refresh(); + } + } + }).appendTo(that.pagination); + + that.pagination.append(' / '); + + that.total_pages_span = $('', { + name: 'total_pages' + }).appendTo(that.pagination); + } }; that.select_changed = function(){ @@ -1204,28 +1275,6 @@ IPA.table_widget = function (spec) { that.setup = function(container) { that.widget_setup(container); - -// that.table = $('table', that.container); -// that.thead = $('thead', that.table); -// that.tbody = $('tbody', that.table); -// that.tfoot = $('tfoot', that.table); - - var select_all_checkbox = $('input[name=select]', that.thead); - select_all_checkbox.attr('title', IPA.messages.search.select_all); - - select_all_checkbox.change(function() { - var checked = select_all_checkbox.is(':checked'); - select_all_checkbox.attr('title', checked ? IPA.messages.search.unselect_all : IPA.messages.search.select_all); - var checkboxes = $('input[name=select]', that.tbody).get(); - for (var i=0; i