This depends on my patch number 25! It should apply without it, but deleting entries won't work properly.

Ticket #206

Pavel
>From 1b99aa86c0faddfa8253c97745a090410313269b Mon Sep 17 00:00:00 2001
From: Pavel Zuna <pz...@redhat.com>
Date: Fri, 1 Oct 2010 12:40:30 -0400
Subject: [PATCH 3/3] Add Delete capabilities to Search facet in the WebUI.

Ticket #206
---
 install/static/search.js   |  103 +++++++++++++++++++++++++++++++++++++++++++-
 ipalib/plugins/internal.py |    8 +++-
 2 files changed, 107 insertions(+), 4 deletions(-)

diff --git a/install/static/search.js b/install/static/search.js
index 59caf71..e97632b 100644
--- a/install/static/search.js
+++ b/install/static/search.js
@@ -34,6 +34,52 @@ function search_create(obj_name, scl, container)
         $.bbq.pushState(state);
     };
 
+    function delete_on_click() {
+        var delete_list = [];
+        var delete_dialog = $('<div></div>', {
+            title: ipa_messages.button.delete,
+            'class': 'search-dialog-delete',
+        });
+
+        function delete_on_click() {
+            ipa_cmd('del', delete_list, {}, delete_on_win, null, obj_name);
+            delete_dialog.dialog('close');
+        };
+
+        function delete_on_win() {
+            for (var i = 0; i < delete_list.length; ++i) {
+                var chk = container.find(
+                    '.search-selector[title=' + delete_list[i] + ']'
+                );
+                if (chk)
+                    chk.closest('tr').remove();
+            }
+        };
+
+        function cancel_on_click() {
+            delete_dialog.dialog('close');
+        };
+
+        container.find('.search-selector').each(function () {
+            var jobj = $(this);
+            if (jobj.attr('checked'))
+                delete_list.push(jobj.attr('title'));
+        });
+
+        if (delete_list.length == 0)
+            return;
+
+        delete_dialog.text(ipa_messages.search.delete_confirm);
+
+        delete_dialog.dialog({
+            modal: true,
+            buttons: {
+                'Delete': delete_on_click,
+                'Cancel': cancel_on_click,
+            },
+        });
+    };
+
     if (!container) {
         alert('ERROR: search_create: Second argument "container" missing!');
         return;
@@ -50,6 +96,8 @@ function search_create(obj_name, scl, container)
     jobj.children().last().attr('name', 'search-' + obj_name + '-filter')
     jobj.append('<input type="submit" value="'+ipa_messages.button.find+ '" />');
     jobj.children().last().click(find_on_click);
+    jobj.append('<input type="submit" value="'+ipa_messages.button.delete+ '" />');
+    jobj.children().last().click(delete_on_click);
     div.append('<span class="search-buttons"></span>');
 
     var search_results = $('<div/>', {
@@ -65,12 +113,45 @@ function search_create(obj_name, scl, container)
     search_table.append('<tfoot></tfoot>');
 
     var tr = search_table.find('tr');
+    search_insert_checkbox_th(tr);
     for (var i = 0; i < scl.length; ++i) {
         var c = scl[i];
         search_insert_th(tr, obj_name, c[0], c[1], c[2]);
     }
 }
 
+function search_insert_checkbox_th(jobj)
+{
+    function select_all_on_click() {
+        var jobj = $(this);
+
+        var checked = null;
+        if (jobj.attr('checked')) {
+            checked = true;
+            jobj.attr('title', 'Unselect All');
+        } else {
+            checked = false;
+            jobj.attr('title', 'Select All');
+        }
+        jobj.attr('checked', checked);
+
+        var chks = jobj.closest('.search-container').find('.search-selector');
+        for (var i = 0; i < chks.length; ++i)
+            chks[i].checked = checked;
+    };
+
+    var checkbox = $('<input />', {
+        type: 'checkbox',
+        title: 'Select All',
+    });
+    checkbox.click(select_all_on_click);
+
+    var th = $('<th></th>');
+    th.append(checkbox);
+
+    jobj.append(th);
+}
+
 var _search_th_template = '<th abbr="A" title="C">N</th>';
 
 function search_insert_th(jobj, obj_name, attr, name, render_call)
@@ -119,11 +200,16 @@ function search_load(jobj, criteria, on_win, on_fail)
 
 function search_generate_tr(thead, tbody, entry_attrs)
 {
+    var obj_name = tbody.closest('.search-container').attr('title');
+    var pkey = ipa_objs[obj_name].primary_key;
+    var pkey_value = entry_attrs[pkey];
+
     tbody.append('<tr></tr>');
     var tr = tbody.children().last();
+    search_generate_checkbox_td(tr, pkey_value);
 
     var ths = thead.find('th');
-    for (var i = 0; i < ths.length; ++i) {
+    for (var i = 1; i < ths.length; ++i) {
         var jobj = $(ths[i]);
         var attr = jobj.attr('abbr');
         var value = entry_attrs[attr];
@@ -137,7 +223,6 @@ function search_generate_tr(thead, tbody, entry_attrs)
 
     tbody.find('.search-a-pkey').click(function () {
         var jobj = $(this);
-        var obj_name = tbody.closest('.search-container').attr('title');
 
         var state = {};
         state[obj_name + '-facet'] = 'details';
@@ -148,6 +233,20 @@ function search_generate_tr(thead, tbody, entry_attrs)
     });
 }
 
+function search_generate_checkbox_td(tr, pkey)
+{
+    var checkbox = $('<input />', {
+        name: pkey,
+        title: pkey,
+        type: 'checkbox',
+        'class': 'search-selector',
+    });
+    var td = $('<td></td>');
+
+    td.append(checkbox);
+    tr.append(td);
+}
+
 var _search_td_template = '<td title="A">V</td>';
 var _search_a_pkey_template = '<a href="jslink" class="search-a-pkey">V</a>';
 
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index a777055..096da18 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -42,10 +42,14 @@ class json_metadata(Command):
             "find": _("Find"),
             "reset":_("Reset"),
             "update":_("Update"),
-            "enroll":_("Enroll")
+            "enroll":_("Enroll"),
+            "delete":_("Delete"),
             },
         "search":{
-            "quick_links":_("Quick Links")
+            "quick_links":_("Quick Links"),
+            "select_all":_("Select All"),
+            "unselect_all":_("Unselect All"),
+            "delete_confirm":_("Do you really want to delete the selected entries?"),
             },
         "details":{
             "identity":_("Identity Details"),
-- 
1.7.1.1

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

Reply via email to