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

--
Endi S. Dewata
From 4b8e273447cb3c82ea8668dece54adc5146e831c Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Fri, 4 Nov 2011 20:43:39 -0500
Subject: [PATCH] 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/aci.js         |    2 +
 install/ui/add.js         |    6 +-
 install/ui/association.js |  221 ++++---------------------------------------
 install/ui/automount.js   |    1 +
 install/ui/dns.js         |   57 +++++++-----
 install/ui/facet.js       |  227 ++++++++++++++++++++++++++++++++++++++++++++-
 install/ui/search.js      |  131 +++++++++-----------------
 install/ui/widget.js      |   14 ++--
 8 files changed, 335 insertions(+), 324 deletions(-)

diff --git a/install/ui/aci.js b/install/ui/aci.js
index 92c5dcf02db36dfe48be4b80f0d6d0656c72de61..5d66bfb2bb2542dc57e2a2ac8fe0547948c57ed2 100644
--- a/install/ui/aci.js
+++ b/install/ui/aci.js
@@ -200,6 +200,7 @@ IPA.aci.selfservice_entity = function(spec) {
     that.init = function(params) {
 
         params.builder.search_facet({
+            pagination: false,
             columns:['aciname']}).
         details_facet({
             sections:[{
@@ -232,6 +233,7 @@ IPA.aci.delegation_entity = function(spec) {
     that.init = function(params) {
 
         params.builder.search_facet({
+            pagination: false,
             columns:['aciname']}).
         details_facet({sections:[
             {
diff --git a/install/ui/add.js b/install/ui/add.js
index 621861fd6736fe8c34a2e926f8ed76773737ad96..c9d5e46bb44bafd087fe214be06adb0ecf3d180b 100644
--- a/install/ui/add.js
+++ b/install/ui/add.js
@@ -46,8 +46,7 @@ IPA.entity_adder_dialog = function(spec) {
                 that.add(
                     function(data, text_status, xhr) {
                         var facet = IPA.current_entity.get_facet();
-                        var table = facet.table;
-                        table.refresh();
+                        facet.refresh();
                         that.close();
                     },
                     that.on_error);
@@ -67,8 +66,7 @@ IPA.entity_adder_dialog = function(spec) {
                         that.show_message(message);
 
                         var facet = IPA.current_entity.get_facet();
-                        var table = facet.table;
-                        table.refresh();
+                        facet.refresh();
                         that.reset();
                     },
                     that.on_error);
diff --git a/install/ui/association.js b/install/ui/association.js
index 6ef73dafe445af5c68fb506c2450fa67724efd84..553966eb93c12c92a8b592bd1054ea7615b153a3 100644
--- a/install/ui/association.js
+++ b/install/ui/association.js
@@ -457,9 +457,9 @@ IPA.association_table_widget = function (spec) {
         }
 
         var batch = IPA.batch_command({
-            'name': that.entity.name+'_'+that.name,
-            'on_success': on_success,
-            'on_error': on_error
+            name: that.entity.name+'_'+that.name,
+            on_success: on_success,
+            on_error: on_error
         });
 
         for (var i=0; i<length; i++) {
@@ -701,7 +701,6 @@ IPA.association_facet = function (spec) {
 
     var that = IPA.table_facet(spec);
 
-    that.entity = spec.entity;
     that.attribute_member = spec.attribute_member;
     that.indirect_attribute_member = spec.indirect_attribute_member;
 
@@ -721,8 +720,6 @@ IPA.association_facet = function (spec) {
 
     that.adder_columns = $.ordered_map();
 
-    that.page_length = spec.page_length === undefined ? 20 : spec.page_length;
-
     that.get_adder_column = function(name) {
         return that.adder_columns.get(name);
     };
@@ -748,10 +745,16 @@ IPA.association_facet = function (spec) {
         return column;
     };
 
-    function setup_columns(){
+    var init = function() {
+
         var column;
         var i;
 
+        var adder_columns = spec.adder_columns || [];
+        for (i=0; i<adder_columns.length; i++) {
+            that.create_adder_column(adder_columns[i]);
+        }
+
         var pkey_name;
         if (that.other_entity) {
             pkey_name = IPA.metadata.objects[that.other_entity].primary_key;
@@ -772,100 +775,19 @@ IPA.association_facet = function (spec) {
             });
         }
 
-        var label = IPA.metadata.objects[that.other_entity] ?
-            IPA.metadata.objects[that.other_entity].label : that.other_entity;
-
-        that.table = IPA.table_widget({
-            id: that.entity.name+'-'+that.other_entity,
-            'class': 'content-table',
-            name: pkey_name,
-            label: label,
-            entity: that.entity,
-            other_entity: that.other_entity,
-            page_length: that.page_length,
-            scrollable: true,
-            selectable: !that.read_only
-        });
-
-        var columns = that.columns.values;
-
-        that.table.set_columns(columns);
-
-        for (i=0; i<columns.length; i++) {
-            column = columns[i];
-            column.entity_name = that.other_entity;
-
-            if (column.link) {
-                column.link_handler = function(value) {
-                    IPA.nav.show_page(that.other_entity, 'default', value);
-                    return false;
-                };
-            }
-        }
-
-        var adder_columns = that.adder_columns.values;
+        adder_columns = that.adder_columns.values;
         for (i=0; i<adder_columns.length; i++) {
             column = adder_columns[i];
             column.entity_name = that.other_entity;
         }
 
-        that.table.prev_page = function() {
-            if (that.table.current_page > 1) {
-                var state = {};
-                state[that.entity_name+'-page'] = that.table.current_page - 1;
-                IPA.nav.push_state(state);
-            }
-        };
+        var other_entity = IPA.get_entity(that.other_entity);
+        that.init_table(other_entity);
+    };
 
-        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.refresh = function() {
-            var state = {};
-            var page = parseInt(IPA.nav.get_state(that.entity_name+'-page'), 10) || 1;
-            if (page < 1) {
-                state[that.entity_name+'-page'] = 1;
-                IPA.nav.push_state(state);
-                return;
-            } else if (page > that.table.total_pages) {
-                state[that.entity_name+'-page'] = that.table.total_pages;
-                IPA.nav.push_state(state);
-                return;
-            }
-            that.table.current_page = page;
-            that.table.current_page_input.val(page);
-            that.refresh_table();
-        };
-
-        that.table.select_changed = function() {
-
-            var values = that.table.get_selected_values();
-
-            if (that.remove_button) {
-                if (values.length === 0) {
-                    that.remove_button.addClass('action-button-disabled');
-                } else {
-                    that.remove_button.removeClass('action-button-disabled');
-                }
-            }
-        };
-    }
+    that.get_records_command_name = function() {
+        return that.entity.name+'_'+that.get_attribute_name();
+    };
 
     that.create_header = function(container) {
 
@@ -1070,105 +992,8 @@ IPA.association_facet = function (spec) {
         dialog.open(that.container);
     };
 
-    that.refresh_table = function() {
-
-        that.table.current_page_input.val(that.table.current_page);
-        that.table.total_pages_span.text(that.table.total_pages);
-
-        var pkeys = that.data[that.get_attribute_name()];
-        if (!pkeys || !pkeys.length) {
-            that.table.empty();
-            that.table.summary.text(IPA.messages.association.no_entries);
-            return;
-        }
-
-        pkeys.sort();
-        var total = 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);
-
-        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; i<list.length; i++) {
-                var entry = {};
-                entry[name] = list[i];
-                that.table.add_record(entry);
-            }
-
-        } else { // get and show additional fields
-            that.get_records(
-                list,
-                function(data, text_status, xhr) {
-                    var results = data.result.results;
-                    that.table.empty();
-                    for (var i=0; i<results.length; i++) {
-                        var record = results[i].result;
-                        that.table.add_record(record);
-                    }
-                },
-                function(xhr, text_status, error_thrown) {
-                    that.table.empty();
-                    var summary = that.table.summary.empty();
-                    summary.append(error_thrown.name+': '+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.get_attribute_name(),
-            'on_success': on_success,
-            'on_error': on_error
-        });
-
-        for (var i=0; i<length; i++) {
-            var pkey = pkeys[i];
-
-            var command = IPA.command({
-                entity: that.other_entity,
-                method: 'show',
-                args: [pkey],
-                options: { all: true }
-            });
-
-            batch.add_command(command);
-        }
-
-        batch.execute();
-    };
-
-    that.load = function(data) {
-        that.facet_load(data);
-
-        var pkeys = that.data[that.get_attribute_name()];
-        if (pkeys) {
-            that.table.total_pages =
-                Math.ceil(pkeys.length / that.table.page_length);
-        } else {
-            that.table.total_pages = 1;
-        }
-
-        delete that.table.current_page;
-
-        that.table.refresh();
-        that.table.unselect_all();
+    that.load_pkeys = function(result) {
+        that.pkeys = that.data[that.get_attribute_name()] || [];
     };
 
     that.refresh = function() {
@@ -1217,11 +1042,7 @@ IPA.association_facet = function (spec) {
         return false;
     };
 
-    /*initialization*/
-    var adder_columns = spec.adder_columns || [];
-    for (var i=0; i<adder_columns.length; i++) {
-        that.create_adder_column(adder_columns[i]);
-    }
-    setup_columns();
+    init();
+
     return that;
 };
diff --git a/install/ui/automount.js b/install/ui/automount.js
index 054d2aee414254d600d5319371e1e301b65c98cb..9c0152ae9aa99307ef47bfe0df00bd45adfe7cd0 100644
--- a/install/ui/automount.js
+++ b/install/ui/automount.js
@@ -71,6 +71,7 @@ IPA.automount.map_entity = function(spec) {
         nested_search_facet({
             facet_group: 'automountkey',
             nested_entity: 'automountkey',
+            pagination: false,
             label: IPA.metadata.objects.automountkey.label,
             name: 'keys',
             get_values: IPA.get_option_values,
diff --git a/install/ui/dns.js b/install/ui/dns.js
index 2cf5cd4a9f02442731aefd7298127c0d1fa7ae69..933366c05e5b035cf4e199405ea0879a7ecea542 100644
--- a/install/ui/dns.js
+++ b/install/ui/dns.js
@@ -88,12 +88,13 @@ IPA.dns.zone_entity = function(spec) {
             }]
         }).
         nested_search_facet({
+            factory: IPA.dns.record_search_facet,
             facet_group: 'dnsrecord',
             nested_entity : 'dnsrecord',
             name: 'records',
+            pagination: false,
             title: IPA.metadata.objects.dnszone.label_singular,
             label: IPA.metadata.objects.dnsrecord.label,
-            load: IPA.dns_record_search_load,
             get_values: IPA.dnsrecord_get_delete_values,
             columns: [
                 {
@@ -407,31 +408,41 @@ IPA.dnszone_adder_dialog = function(spec) {
     return that;
 };
 
-IPA.dns_record_search_load = function (result) {
-    this.table.empty();
-    var normalized_record;
-    var dns_record_types = IPA.dns_record_types();
-    for (var i = 0; i<result.length; i++) {
-        var record = result[i];
-        for (var j =0; j < dns_record_types.length; j += 1){
-            var record_type = dns_record_types[j].value;
-            if (record[record_type]){
-                var record_of_type = record[record_type];
-                for (var k =0;
-                     k < record_of_type.length;
-                     k+=1)
-                {
-                    normalized_record = {
-                        idnsname:record.idnsname,
-                        type:record_type,
-                        data:record_of_type[k]
-                    };
-                    this.table.add_record(normalized_record);
+IPA.dns.record_search_facet = function(spec) {
 
+    var that = IPA.nested_search_facet(spec);
+
+    var init = function() {
+
+        that.table.load = function(result) {
+
+            that.table.empty();
+
+            var types = IPA.dns_record_types();
+
+            for (var i=0; i<result.length; i++) {
+                var record = result[i];
+
+                for (var j=0; j<types.length; j++) {
+                    var type = types[j].value;
+                    if (!record[type]) continue;
+
+                    var data = record[type];
+                    for (var k=0; k<data.length; k++) {
+                        that.table.add_record({
+                            idnsname: record.idnsname,
+                            type: type,
+                            data: data[k]
+                        });
+                    }
                 }
             }
-        }
-    }
+        };
+    };
+
+    init();
+
+    return that;
 };
 
 IPA.dns.record_entity = function(spec) {
diff --git a/install/ui/facet.js b/install/ui/facet.js
index 5b6d964df54ffb22175b70b8aa9b65ce8bc22408..e4377151bcd5bf13adc39da4ceb6ca4f5221bc86 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<columns.length; i++) {
+            that.create_column(columns[i]);
+        }
+    };
+
     that.get_columns = function() {
         return that.columns.values;
     };
@@ -428,10 +440,217 @@ IPA.table_facet = function(spec) {
         return that;
     };
 
-    var columns = spec.columns || [];
-    for (var i=0; i<columns.length; i++) {
-        that.create_column(columns[i]);
-    }
+    that.load = function(result) {
+        that.facet_load(result);
+
+        that.table.current_page = 1;
+        that.table.total_pages = 1;
+
+        if (that.pagination) {
+            that.table.load_page(result);
+        } else {
+            that.table.load(result);
+        }
+
+        that.table.current_page_input.val(that.table.current_page);
+        that.table.total_pages_span.text(that.table.total_pages);
+
+        that.table.unselect_all();
+    };
+
+    that.get_records_command_name = function() {
+        return that.entity.name+'_get_records';
+    };
+
+    that.get_records = function(on_success, on_error) {
+
+        var length = that.values.length;
+        if (!length) return;
+
+        var batch = IPA.batch_command({
+            name: that.get_records_command_name(),
+            on_success: on_success,
+            on_error: on_error
+        });
+
+        for (var i=0; i<length; i++) {
+            var pkey = that.values[i];
+
+            var command = IPA.command({
+                entity: that.table.entity.name,
+                method: 'show',
+                args: [pkey],
+                options: { all: true }
+            });
+
+            batch.add_command(command);
+        }
+
+        batch.execute();
+    };
+
+    that.select_changed = function() {
+
+        var values = that.table.get_selected_values();
+
+        if (that.remove_button) {
+            if (values.length === 0) {
+                that.remove_button.addClass('action-button-disabled');
+            } else {
+                that.remove_button.removeClass('action-button-disabled');
+            }
+        }
+    };
+
+    that.init_table = function(entity) {
+
+        that.table = IPA.table_widget({
+            'class': 'content-table',
+            name: entity.metadata.primary_key,
+            label: entity.metadata.label,
+            entity: entity,
+            page_length: that.page_length,
+            search_all: that.search_all,
+            scrollable: true,
+            selectable: that.selectable && !that.read_only
+        });
+
+        var columns = that.columns.values;
+        for (var i=0; i<columns.length; i++) {
+            var column = columns[i];
+
+            if (column.link) {
+                column.link_handler = function(value) {
+                    IPA.nav.show_page(entity.name, 'default', value);
+                    return false;
+                };
+            }
+
+            that.table.add_column(column);
+        }
+
+        that.table.select_changed = function() {
+            that.select_changed();
+        };
+
+        that.table.prev_page = function() {
+            if (that.table.current_page > 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<result.length; i++) {
+                var record = that.table.get_record(result[i], 0);
+                that.table.add_record(record);
+            }
+
+            that.table.unselect_all();
+        };
+
+        that.table.load_page = function(result) {
+
+            that.load_pkeys(result);
+
+            if (that.pkeys.length) {
+                that.table.total_pages =
+                    Math.ceil(that.pkeys.length / that.table.page_length);
+            } else {
+                that.table.total_pages = 1;
+            }
+
+            delete that.table.current_page;
+
+            var state = {};
+            var page = parseInt(IPA.nav.get_state(that.entity_name+'-page'), 10) || 1;
+            if (page < 1) {
+                state[that.entity_name+'-page'] = 1;
+                IPA.nav.push_state(state);
+                return;
+            } else if (page > 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<that.values.length; i++) {
+                    var entry = {};
+                    entry[name] = that.values[i];
+                    that.table.add_record(entry);
+                }
+                return;
+            }
+
+            // get and show additional fields
+            that.get_records(
+                function(data, text_status, xhr) {
+                    var results = data.result.results;
+                    that.table.empty();
+                    for (var i=0; i<results.length; i++) {
+                        var record = results[i].result;
+                        that.table.add_record(record);
+                    }
+                },
+                function(xhr, text_status, error_thrown) {
+                    that.table.empty();
+                    var summary = that.table.summary.empty();
+                    summary.append(error_thrown.name+': '+error_thrown.message);
+                }
+            );
+        };
+    };
+
+    init();
 
     return that;
 };
diff --git a/install/ui/search.js b/install/ui/search.js
index a8f897ab597c2dd38208351e5768029133ad7085..493edb7f5a6197107e96e7530ca3e48a8df89e2c 100644
--- a/install/ui/search.js
+++ b/install/ui/search.js
@@ -38,66 +38,27 @@ IPA.search_facet = function(spec) {
 
     var that = IPA.table_facet(spec);
 
-    that.search_all = spec.search_all || false;
-    that.selectable = spec.selectable;
-
     function get_values() {
         return that.table.get_selected_values();
     }
 
     that.get_values = spec.get_values || get_values;
 
-    function initialize_table_columns(){
+    var init = function() {
+
         that.managed_entity = IPA.get_entity(that.managed_entity_name);
-        var entity = that.managed_entity;
-
-        that.table = IPA.table_widget({
-            'class': 'content-table',
-            name: 'search',
-            label: entity.metadata.label,
-            entity: entity,
-            search_all: that.search_all,
-            scrollable: true,
-            selectable: that.selectable
-        });
 
         var columns = that.columns.values;
         for (var i=0; i<columns.length; i++) {
             var column = columns[i];
-            column.entity = entity;
-            var metadata = IPA.get_entity_param(entity.name, column.name);
+
+            var metadata = IPA.get_entity_param(that.managed_entity_name, column.name);
             column.primary_key = metadata && metadata.primary_key;
             column.link = column.primary_key;
-
-            if (column.link) {
-                column.link_handler = function(value) {
-                    IPA.nav.show_page(entity.name, 'default', value);
-                    return false;
-                };
-            }
-
-            that.table.add_column(column);
         }
 
-        that.table.select_changed = function() {
-            that.select_changed();
-        };
-
-        that.table.refresh = function() {
-            that.refresh();
-        };
-
-        that.table.load = function(result) {
-            that.table.empty();
-
-            for (var i = 0; i<result.length; i++) {
-                var record = that.table.get_record(result[i], 0);
-                that.table.add_record(record);
-            }
-
-            that.table.unselect_all();
-        };
-    }
+        that.init_table(that.managed_entity);
+    };
 
     that.create_content = function(container) {
         that.table.create(container);
@@ -144,7 +105,7 @@ IPA.search_facet = function(spec) {
             icon: 'remove-icon',
             click: function() {
                 if (!that.remove_button.hasClass('action-button-disabled')) {
-                    that.remove();
+                    that.show_remove_dialog();
                 }
                 return false;
             }
@@ -155,7 +116,9 @@ IPA.search_facet = function(spec) {
             label: IPA.messages.buttons.add,
             icon: 'add-icon',
             click: function() {
-                that.add();
+                if (!that.add_button.hasClass('action-button-disabled')) {
+                    that.show_add_dialog();
+                }
                 return false;
             }
         }).appendTo(that.controls);
@@ -173,29 +136,12 @@ IPA.search_facet = function(spec) {
         }
     };
 
-    that.select_changed = function() {
-
-        var values = that.table.get_selected_values();
-
-        if (that.remove_button) {
-            if (values.length === 0) {
-                that.remove_button.addClass('action-button-disabled');
-            } else {
-                that.remove_button.removeClass('action-button-disabled');
-            }
-        }
-    };
-
-    that.add = function() {
+    that.show_add_dialog = function() {
         var dialog = that.managed_entity.get_dialog('add');
         dialog.open(that.container);
     };
 
-    that.remove = function() {
-        that.remove_instances(that.managed_entity);
-    };
-
-    that.remove_instances = function(entity) {
+    that.show_remove_dialog = function() {
 
         var values = that.get_values();
 
@@ -212,12 +158,12 @@ IPA.search_facet = function(spec) {
             dialog = IPA.search_deleter_dialog();
         }
 
-        dialog.entity_name = entity.name;
-        dialog.entity = entity;
+        dialog.entity_name = that.managed_entity.name;
+        dialog.entity = that.managed_entity;
         dialog.facet = that;
 
         title = IPA.messages.dialogs.remove_title;
-        var label = entity.metadata.label;
+        var label = that.managed_entity.metadata.label;
         dialog.title = title.replace('${entity}', label);
 
         dialog.set_values(values);
@@ -232,21 +178,25 @@ IPA.search_facet = function(spec) {
         IPA.nav.push_state(state);
     };
 
-    function load(result) {
-        that.table.load(result);
-    }
-
-    that.load = spec.load || load;
-
-    that.refresh = function() {
-        that.search_refresh(that.entity);
+    that.load_pkeys = function(result) {
+        that.pkeys = [];
+        for (var i=0; i<result.length; i++) {
+            var record = result[i];
+            var values = record[that.managed_entity.metadata.primary_key];
+            that.pkeys.push(values[0]);
+        }
+        return that.pkeys;
     };
 
     that.on_error = function(xhr, text_status, error_thrown) {
         that.report_error(error_thrown);
     };
 
-    that.search_refresh = function(entity){
+    that.get_search_command_name = function() {
+        return that.managed_entity.name + '_find' + (that.pagination ? "_pkeys" : "");
+    };
+
+    that.refresh = function() {
 
         function on_success(data, text_status, xhr) {
 
@@ -260,12 +210,15 @@ IPA.search_facet = function(spec) {
                 that.table.summary.text(data.result.summary);
             }
 
+            that.table.current_page_input.val(that.table.current_page);
+            that.table.total_pages_span.text(that.table.total_pages);
+
             that.filter.focus();
             that.select_changed();
         }
 
         var filter = [];
-        var current_entity = entity;
+        var current_entity = that.managed_entity;
         filter.unshift(IPA.nav.get_state(current_entity.name+'-filter'));
         current_entity = current_entity.get_containing_entity();
         while (current_entity !== null) {
@@ -274,7 +227,8 @@ IPA.search_facet = function(spec) {
         }
 
         var command = IPA.command({
-            entity: entity.name,
+            name: that.get_search_command_name(),
+            entity: that.managed_entity.name,
             method: 'find',
             args: filter,
             options: {
@@ -284,11 +238,16 @@ IPA.search_facet = function(spec) {
             on_error: that.on_error
         });
 
+        if (that.pagination) {
+            command.set_option('pkey_only', true);
+            command.set_option('sizelimit', 0);
+        }
+
         command.execute();
     };
 
     that.clear = function() {
-        if(that.needs_clear()) {
+        if (that.needs_clear()) {
             that.table.clear();
         }
     };
@@ -298,11 +257,11 @@ IPA.search_facet = function(spec) {
         return that.old_filter !== '' || that.old_filter !== filter;
     };
 
+    init();
+
     // methods that should be invoked by subclasses
     that.search_facet_create_content = that.create_content;
-
-    //initialization
-    initialize_table_columns();
+    that.search_facet_refresh = that.refresh;
 
     return that;
 };
@@ -398,7 +357,7 @@ IPA.nested_search_facet = function(spec) {
         }
     };
 
-    that.refresh = function(){
+    that.refresh = function() {
 
         var pkey = IPA.nav.get_state(that.entity.name+'-pkey');
 
@@ -407,7 +366,7 @@ IPA.nested_search_facet = function(spec) {
             return;
         }
 
-        that.search_refresh(that.managed_entity);
+        that.search_facet_refresh();
     };
 
     return that;
diff --git a/install/ui/widget.js b/install/ui/widget.js
index c3260659377def163242a78c514f912b79b89781..2a3b952b05ad3e7ea33f3bc03db0f0f1876feb86 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -1305,6 +1305,7 @@ IPA.table_widget = function (spec) {
     };
 
     that.add_column = function(column) {
+        column.entity = that.entity;
         that.columns.put(column.name, column);
     };
 
@@ -1566,13 +1567,12 @@ IPA.table_widget = function (spec) {
 
         that.empty();
 
-        that.values = result[that.name];
-        if (that.values) {
-            for (var i=0; i<that.values.length; i++) {
-                var record = that.get_record(result, i);
-                that.add_record(record);
-            }
+        that.values = result[that.name] || [];
+        for (var i=0; i<that.values.length; i++) {
+            var record = that.get_record(result, i);
+            that.add_record(record);
         }
+
         that.unselect_all();
     };
 
@@ -1617,7 +1617,7 @@ IPA.table_widget = function (spec) {
 
             if (values instanceof Array){
                 record[name] = values[index];
-            }else{
+            } else {
                 record[name] = values;
             }
         }
-- 
1.7.5.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to