From 9405e1a9db11294a11efa24a7a3c36ea76a42f31 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Fri, 4 Nov 2011 20:43:39 -0500 Subject: Added paging on search facet. The search facet has been modified to support paging on most entities using the --pkey-only option to get the primary keys and a batch command to get the complete records. Paging on DNS records is not supported because a record may appear as multiple rows. The following entities do not have --pkey-only option: Automount Key, Self-Service Permissions, Delegation. The search and association facet have been refactored to reuse the common code from the table facet base class. Ticket #981 --- install/ui/facet.js | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 223 insertions(+), 4 deletions(-) (limited to 'install/ui/facet.js') diff --git a/install/ui/facet.js b/install/ui/facet.js index 5b6d964d..e4377151 100644 --- a/install/ui/facet.js +++ b/install/ui/facet.js @@ -391,9 +391,21 @@ IPA.table_facet = function(spec) { var that = IPA.facet(spec); that.managed_entity_name = spec.managed_entity_name || that.entity.name; + that.page_length = spec.page_length === undefined ? 20 : spec.page_length; + + that.pagination = spec.pagination === undefined ? true : spec.pagination; + that.search_all = spec.search_all; + that.selectable = spec.selectable === undefined ? true : spec.selectable; that.columns = $.ordered_map(); + var init = function() { + var columns = spec.columns || []; + for (var i=0; i 1) { + var state = {}; + state[that.entity_name+'-page'] = that.table.current_page - 1; + IPA.nav.push_state(state); + } + }; + + that.table.next_page = function() { + if (that.table.current_page < that.table.total_pages) { + var state = {}; + state[that.entity_name+'-page'] = that.table.current_page + 1; + IPA.nav.push_state(state); + } + }; + + that.table.set_page = function(page) { + if (page < 1) { + page = 1; + } else if (page > that.total_pages) { + page = that.total_pages; + } + var state = {}; + state[that.entity_name+'-page'] = page; + IPA.nav.push_state(state); + }; + + that.table.load = function(result) { + + that.table.empty(); + + for (var i=0; i that.table.total_pages) { + state[that.entity_name+'-page'] = that.table.total_pages; + IPA.nav.push_state(state); + return; + } + that.table.current_page = page; + + if (!that.pkeys || !that.pkeys.length) { + that.table.empty(); + that.table.summary.text(IPA.messages.association.no_entries); + return; + } + + that.pkeys.sort(); + var total = that.pkeys.length; + + var start = (that.table.current_page - 1) * that.table.page_length + 1; + var end = that.table.current_page * that.table.page_length; + end = end > total ? total : end; + + var summary = IPA.messages.association.paging; + summary = summary.replace('${start}', start); + summary = summary.replace('${end}', end); + summary = summary.replace('${total}', total); + that.table.summary.text(summary); + + that.values = that.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; i