delete associations

    Uses code very similar to the search code for deleting associations
Only uses the serial means of deletion. While this works for all deletes,
    it is slower than bulk.

From 8620779c9bbfe7f39653da03aeeb20ae0ff5be45 Mon Sep 17 00:00:00 2001
From: Adam Young <ayo...@redhat.com>
Date: Thu, 28 Oct 2010 17:20:12 -0400
Subject: [PATCH] delete associations

Uses code very similar to the search code for deleting associations
Only uses the serial means of dletion.  While this works for all deletes,
it is slower than bulk.
---
 install/static/associate.js |  116 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 109 insertions(+), 7 deletions(-)

diff --git a/install/static/associate.js b/install/static/associate.js
index 7daa0cf..7b4960e 100644
--- a/install/static/associate.js
+++ b/install/static/associate.js
@@ -59,6 +59,41 @@ function SerialAssociator(form, manyObjPkeys, on_success)
     }
 }
 
+
+function serial_delete(delete_method, one_entity, one_entity_pkey, many_entity,
+                       many_entity_pkeys, on_success){
+    that = {};
+    that.one_entity = one_entity;
+    that.on_success = on_success;
+    that.many_entity_pkeys = many_entity_pkeys;
+    that.delete_next = function(){
+        var  many_entity_pkey =  this.many_entity_pkeys.shift();
+        if (many_entity_pkey){
+            var options = {};
+            options[one_entity] = one_entity_pkey;
+            var args = [many_entity_pkey];
+            ipa_cmd( delete_method,args, options ,
+                     function(data, text_status, xhr) {
+                         if (data.error){
+                             alert("error deleting member: "
+                                   +data.error.message);
+                         }else{
+                             that.delete_next();
+                         }
+                     },
+                     function(xhr, text_status, error_thrown) {
+                         alert("associateFailure");
+                     },
+                     many_entity );
+        }else{
+            this.on_success();
+        }
+    }
+
+    that.delete_next();
+}
+
+
 /**
 *This associator is for the common case where all the asociations can be sent
 in a single rpc
@@ -221,6 +256,11 @@ function ipa_association_config(spec) {
     return that;
 }
 
+
+
+
+
+
 function ipa_association_facet(spec) {
 
     spec = spec || {};
@@ -284,15 +324,21 @@ function ipa_association_facet(spec) {
         container.find('.search-filter').css('display', 'none');
         container.find('.search-buttons').html('');
 
-        $('<input/>', {
-            type:  'button',
-            value: 'enroll',
-            click: function() {
+        var ctrls = container.find('.search-buttons');
+
+        ipa_make_button( 'ui-icon-plus',IPA.messages.button.enroll).
+            click(function() {
                 that.show_enrollment_dialog();
-            }
-        }).appendTo(container.find('.search-buttons'));
+            }).appendTo(ctrls);
 
-        var header = $('<tr></tr>').appendTo(container.find('.search-table thead:last'));
+        ipa_make_button('ui-icon-trash',IPA.messages.button.delete).
+            click(function(){
+                that.delete_on_click(container);
+            }).appendTo(ctrls);
+
+
+
+        var header = container.find('.search-table thead:last').find("tr");;
         for (var i =0 ; i != that.columns.length ;i++){
             $('<th></th>',{
                 html: that.columns[i].title
@@ -301,14 +347,70 @@ function ipa_association_facet(spec) {
         that.refresh(container);
     };
 
+    that.delete_on_click = function(container) {
+        var delete_list = [];
+        var delete_dialog = $('<div></div>', {
+            title: IPA.messages.button.delete,
+            'class': 'search-dialog-delete'
+        });
+
+        function delete_on_click() {
+            serial_delete('remove_member', that.entity_name,
+                          that.pkey, that.other_entity, delete_list,
+                          function(){ that.refresh(container)});
+            delete_dialog.dialog('close');
+        }
+        function delete_on_win() {
+            delete_dialog.dialog('close');
+        }
+        function cancel_on_click() {
+            delete_dialog.dialog('close');
+        }
+        var confirm_list = $('<ul/>');
+        var delete_list = [];
+        container.find('.search-selector').each(function () {
+            if (this.checked){
+                delete_list.push(this.title);
+                confirm_list.append($('<li/>',{text: this.title}));
+            }
+        });
+        if (delete_list.length == 0){
+            return;
+        }
+        delete_dialog.append(confirm_list);
+        delete_dialog.append(
+            $('<p/>',
+              {text:IPA.messages.search.delete_confirm}));
+
+
+        delete_dialog.dialog({
+            modal: true,
+            buttons: {
+                'Delete': delete_on_click,
+                'Cancel': cancel_on_click
+            }
+        });
+    }
+
     that.refresh = function(container) {
 
         function refresh_on_success(data, text_status, xhr) {
             var tbody = container.find('.search-table tbody');
             tbody.empty();
             var associationList = data.result.result[that.columns[0].column];
+            //TODO, this is masking an error where the wrong
+            //direction association is presented upon page reload.
+            //if the associationList is unset, it is because
+            //form.associationColumns[0] doesn't exist in the results
+            if (!associationList) return;
+
+
             for (var j = 0; j < associationList.length; j++){
+                var association = associationList[j];
                 var row  = $('<tr/>').appendTo(tbody);
+                search_generate_checkbox_td(row, association);
+
+
                 for (var k = 0; k < that.columns.length ;k++){
                     var column = that.columns[k].column;
                     $('<td></td>',{
-- 
1.7.1

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

Reply via email to