Patch Description:
Paging in DNS record search facet was disabled because there was a mismatch between primary keys sent by server and values displayed in the facet.

The facet was modified to enable paging. To preserve amount of information which was displayed before, current rows have variable height - they can contain more that one line depending on number of values in the record. Each record has a checkbox and indsname in its first line to distinguish one record from others. Because there is only one checkbox for record, delete command is called with --del-all option which causes that entire record is removed. Individual values can be deleted in record's details facet.

https://fedorahosted.org/freeipa/ticket/2094
--
Petr Vobornik
From a5317698136c44523bfeb979ead256268610cd3d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20Voborn=C3=ADk?= <pvobo...@redhat.com>
Date: Tue, 24 Jan 2012 15:31:18 +0100
Subject: [PATCH] Added paging to DNS record search facet

Paging in DNS record search facet was disabled because there was a mismatch between primary keys sent by server and values displayed in the facet.

The facet was modified to enable paging. To preserve amount of information which was displayed before, current rows have variable height - they can contain more that one line depending on number of values in the record. Each record has a checkbox and indsname in its first line to distinguish one record from others. Because there is only one checkbox for record, delete command is called with --rem-all option which causes that entire record is removed. Individual values can be deleted in record's details facet.

https://fedorahosted.org/freeipa/ticket/2094
---
 install/ui/dns.js    |  127 +++++++++++++++++++++++++++++---------------------
 install/ui/search.js |    4 +-
 2 files changed, 77 insertions(+), 54 deletions(-)

diff --git a/install/ui/dns.js b/install/ui/dns.js
index b50f13f97122b5b6c9a4e6fc7633935c86bcb2e2..a34cbd9b101ff125b62482a1bb6da98ed7ede04c 100644
--- a/install/ui/dns.js
+++ b/install/ui/dns.js
@@ -105,7 +105,7 @@ IPA.dns.zone_entity = function(spec) {
             facet_group: 'dnsrecord',
             nested_entity : 'dnsrecord',
             name: 'records',
-            pagination: false,
+            deleter_dialog: IPA.dns.record_search_deleter_dialog,
             title: IPA.metadata.objects.dnszone.label_singular,
             label: IPA.metadata.objects.dnsrecord.label,
             columns: [
@@ -468,80 +468,101 @@ IPA.dns.record_search_facet = function(spec) {
 
     var that = IPA.nested_search_facet(spec);
 
-    that.load_all = function(data) {
+    that.get_records = function(pkeys, on_success, on_error) {
+
+        var batch = IPA.batch_command({
+            name: that.get_records_command_name(),
+            on_success: on_success,
+            on_error: on_error
+        });
+
+        var zone = IPA.nav.get_state('dnszone-pkey');
+
+        for (var i=0; i<pkeys.length; i++) {
+            var pkey = pkeys[i];
+
+            var command = IPA.command({
+                entity: that.table.entity.name,
+                method: 'show',
+                args: [zone, pkey],
+                options: { all: true }
+            });
+
+            batch.add_command(command);
+        }
+
+        batch.execute();
+    };
+
+
+    that.load_records = function(records) {
+        that.table.empty();
 
         var types = IPA.dns_record_types();
 
-        var result = data.result.result;
-        var records = [];
+        for (var i=0; i<records.length; i++) {
 
-        for (var i=0; i<result.length; i++) {
-            var record = result[i];
+            var original = records[i];
+            var record = {
+                idnsname: original.idnsname,
+                values: []
+            };
 
             for (var j=0; j<types.length; j++) {
                 var type = types[j];
-                if (!record[type.value]) continue;
+                if (!original[type.value]) continue;
 
-                var values = record[type.value];
+                var values = original[type.value];
                 for (var k=0; k<values.length; k++) {
-                    records.push({
-                        idnsname: record.idnsname,
+                    record.values.push({
                         type: type.label,
                         data: values[k]
                     });
                 }
             }
+
+            that.add_record(record);
         }
+        that.table.set_values(that.selected_values);
+    };
+
+    that.add_record = function(record) {
+
+        for (var i=0; i<record.values.length; i++) {
+
+            var value = record.values[i];
+
+            if (i === 0) {
+                value.idnsname = record.idnsname;
+            }
 
-        that.load_records(records);
+            var tr = that.table.add_record(value);
 
-        if (data.result.truncated) {
-            var message = IPA.messages.search.truncated;
-            message = message.replace('${counter}', data.result.count);
-            that.table.summary.text(message);
-        } else {
-            that.table.summary.text(data.result.summary);
+            if (i > 0) {
+                $('input[name="'+that.table.name+'"]', tr).remove();
+            }
         }
     };
 
-    that.get_selected_values = function() {
-
-        var values = [];
-
-        var records = {};
-        var value;
-        var record_type;
-
-        $('input[name="idnsname"]:checked', that.table.tbody).each(function() {
-            $('div', $(this).parent().parent()).each(function() {
-                var div = $(this);
-                var name = div.attr('name');
-                var text = div.text();
-
-                if (name === 'idnsname') {
-                    value = records[text];
-                    if (!value) {
-                        value = { pkey: text };
-                        records[text] = value;
-                    }
-                } else if (name === 'type') {
-                    record_type = text.toLowerCase()+'record';
-
-                } else if (name === 'data') {
-                    if (!value[record_type]) {
-                        value[record_type] = text;
-                    } else {
-                         value[record_type] += ',' + text;
-                    }
-                }
-            });
-        });
-
-        for (var key in records) {
-            values.push(records[key]);
+    return that;
+};
+
+IPA.dns.record_search_deleter_dialog = function(spec) {
+
+    spec = spec || {};
+
+    var that = IPA.search_deleter_dialog(spec);
+
+    that.create_command = function() {
+
+        var batch = that.search_deleter_dialog_create_command();
+
+        for (var i=0; i<batch.commands.length; i++) {
+            var command = batch.commands[i];
+            command.set_option('del_all', true);
         }
 
-        return values;
+        return batch;
     };
 
     return that;
diff --git a/install/ui/search.js b/install/ui/search.js
index a7074e2200e8a5adedf659cb47eddca6c495227e..76a1f3af370d3ea22a2d9d416f7420b988f37d74 100644
--- a/install/ui/search.js
+++ b/install/ui/search.js
@@ -38,6 +38,8 @@ IPA.search_facet = function(spec) {
 
     var that = IPA.table_facet(spec);
 
+    that.deleter_dialog = spec.deleter_dialog || IPA.search_deleter_dialog;
+
     var init = function() {
 
         that.init_table(that.managed_entity);
@@ -133,7 +135,7 @@ IPA.search_facet = function(spec) {
         var dialog = that.managed_entity.get_dialog('remove');
 
         if (!dialog) {
-            dialog = IPA.search_deleter_dialog();
+            dialog = that.deleter_dialog();
         }
 
         dialog.entity_name = that.managed_entity.name;
-- 
1.7.7.5

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

Reply via email to