A custom deleter dialog for hosts has been added to provide an option
whether to remove the hosts from DNS.

Ticket #1470

--
Endi S. Dewata
From 68010a0e620b7c1220e617c5f5fcf2f0db59352e Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Tue, 19 Jul 2011 13:46:09 -0500
Subject: [PATCH] Added checkbox to remove hosts from DNS.

A custom deleter dialog for hosts has been added to provide an option
whether to remove the hosts from DNS.

Ticket #1470
---
 install/ui/dialog.js |    4 +-
 install/ui/entity.js |    7 +++
 install/ui/host.js   |   41 ++++++++++++++++
 install/ui/search.js |  131 +++++++++++++++++++++++++++++---------------------
 4 files changed, 127 insertions(+), 56 deletions(-)

diff --git a/install/ui/dialog.js b/install/ui/dialog.js
index 9d22da7f19acb6f1d798f5a8fcbbf217b625b6c8..5245ba92ce766269b8d84dceac7aab68ab302cb7 100644
--- a/install/ui/dialog.js
+++ b/install/ui/dialog.js
@@ -631,7 +631,7 @@ IPA.deleter_dialog =  function (spec) {
     };
 
     that.set_values = function(values) {
-        that.values = that.values.concat(values);
+        that.values = values;
     };
 
     that.create = function() {
@@ -678,5 +678,7 @@ IPA.deleter_dialog =  function (spec) {
         that.dialog_open(container);
     };
 
+    that.deleter_dialog_create = that.create;
+
     return that;
 };
diff --git a/install/ui/entity.js b/install/ui/entity.js
index ec0317897b9f94d4e278c55c1aced4d25de8ff2a..0940c7d17e5bf8c523d575b0c4533e99012bb58f 100644
--- a/install/ui/entity.js
+++ b/install/ui/entity.js
@@ -974,6 +974,13 @@ IPA.entity_builder = function(){
         return that.dialog(spec);
     };
 
+    that.deleter_dialog = function(spec) {
+        spec.factory = spec.factory || IPA.search_deleter_dialog;
+        spec.name = spec.name || 'remove';
+
+        return that.dialog(spec);
+    };
+
     that.build = function(){
         var item = entity;
         entity = null;
diff --git a/install/ui/host.js b/install/ui/host.js
index 9994abf31407c6be82ce186713995187620290ab..bbac4edd77c7528f4be97e5d50e24385e8bd5549 100644
--- a/install/ui/host.js
+++ b/install/ui/host.js
@@ -122,9 +122,50 @@ IPA.entity_factories.host = function () {
                 }
             ]
         }).
+        deleter_dialog({
+            factory: IPA.host_deleter_dialog
+        }).
         build();
 };
 
+IPA.host_deleter_dialog = function(spec) {
+
+    spec = spec || {};
+
+    var that = IPA.search_deleter_dialog(spec);
+
+    that.create = function() {
+
+        that.deleter_dialog_create();
+
+        var metadata = IPA.get_method_option('host_del', 'updatedns');
+
+        that.updatedns = $('<input/>', {
+            type: 'checkbox',
+            name: 'updatedns',
+            title: metadata.doc
+        }).appendTo(that.container);
+
+        that.container.append(' ');
+
+        that.container.append(metadata.doc);
+    };
+
+    that.create_command = function() {
+        var batch = that.search_deleter_dialog_create_command();
+        var updatedns = that.updatedns.is(':checked');
+
+        for (var i=0; i<batch.commands.length; i++) {
+            var command = batch.commands[i];
+            command.set_option('updatedns', updatedns);
+        }
+
+        return batch;
+    };
+
+    return that;
+};
+
 IPA.dnszone_select_widget = function(spec) {
 
     spec = spec || {};
diff --git a/install/ui/search.js b/install/ui/search.js
index 1b07908b8c735e54adbd8cd5c85c4fcfd389d8bd..fec394deaae2d390c14828024d200dde42251a8a 100644
--- a/install/ui/search.js
+++ b/install/ui/search.js
@@ -182,16 +182,13 @@ IPA.search_facet = function(spec) {
         dialog.open(that.container);
     };
 
-
     that.remove = function() {
         that.remove_instances(that.managed_entity);
     };
 
-
     that.remove_instances = function(entity) {
 
         var values = that.get_values();
-        var label = entity.metadata.label;
 
         var title;
         if (!values.length) {
@@ -200,60 +197,21 @@ IPA.search_facet = function(spec) {
             return;
         }
 
+        var dialog = that.managed_entity.get_dialog('remove');
+
+        if (!dialog) {
+            dialog = IPA.search_deleter_dialog();
+        }
+
+        dialog.entity_name = entity.name;
+        dialog.entity = entity;
+        dialog.facet = that;
+
         title = IPA.messages.dialogs.remove_title;
-        title = title.replace('${entity}', label);
+        var label = entity.metadata.label;
+        dialog.title = title.replace('${entity}', label);
 
-        var dialog = IPA.deleter_dialog({
-            'title': title,
-            'parent': that.container,
-            'values': values,
-            entity_name: entity.name
-        });
-
-        dialog.execute = function() {
-
-            var batch = IPA.batch_command({
-                'on_success': function() {
-                    that.refresh();
-                    dialog.close();
-                },
-                'on_error': function() {
-                    that.refresh();
-                    dialog.close();
-                }
-            });
-
-            var pkeys =
-                entity.get_primary_key_prefix();
-
-            for (var i=0; i<values.length; i++) {
-                var command = IPA.command({
-                    entity: entity.name,
-                    method: 'del'
-                });
-
-                for (var k=0; k<pkeys.length; k++) {
-                    command.add_arg(pkeys[k]);
-                }
-                var value = values[i];
-                if (value instanceof Object){
-                    for (var key in value){
-                        if (value.hasOwnProperty(key)){
-                            if (key === 'pkey'){
-                                command.add_arg(value[key]);
-                            }else{
-                                command.set_option(key, value[key]);
-                            }
-                        }
-                    }
-                }else{
-                    command.add_arg(value);
-                }
-                batch.add_command(command);
-            }
-
-            batch.execute();
-        };
+        dialog.set_values(values);
 
         dialog.init();
 
@@ -339,6 +297,69 @@ IPA.search_facet = function(spec) {
     return that;
 };
 
+IPA.search_deleter_dialog = function(spec) {
+
+    spec = spec || {};
+
+    var that = IPA.deleter_dialog(spec);
+
+    that.create_command = function() {
+        var batch = IPA.batch_command();
+
+        var pkeys = that.entity.get_primary_key_prefix();
+
+        for (var i=0; i<that.values.length; i++) {
+            var command = IPA.command({
+                entity: that.entity.name,
+                method: 'del'
+            });
+
+            for (var j=0; j<pkeys.length; j++) {
+                command.add_arg(pkeys[j]);
+            }
+
+            var value = that.values[i];
+            if (value instanceof Object) {
+                for (var key in value) {
+                    if (value.hasOwnProperty(key)) {
+                        if (key === 'pkey'){
+                            command.add_arg(value[key]);
+                        } else {
+                            command.set_option(key, value[key]);
+                        }
+                    }
+                }
+            } else {
+                command.add_arg(value);
+            }
+
+            batch.add_command(command);
+        }
+
+        return batch;
+    };
+
+    that.execute = function() {
+
+        var batch = that.create_command();
+
+        batch.on_success = function() {
+            that.facet.refresh();
+            that.close();
+        };
+
+        batch.on_error = function() {
+            that.facet.refresh();
+            that.close();
+        };
+
+        batch.execute();
+    };
+
+    that.search_deleter_dialog_create_command = that.create_command;
+
+    return that;
+};
 
 /*TODO.  this has much copied code from above.  Refactor the search_facet
 To either be nested or not nested. */
-- 
1.7.5.1

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

Reply via email to