A selectable option has been added to the table widget to show/hide
the checkbox column for selecting table rows. By default it's set
to true. The indirect association facet has been modified to hide
the column because it is non-editable.

--
Endi S. Dewata
From a5b4c76264704670ead3e00d5531d29210ea754e Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Tue, 7 Jun 2011 12:58:51 -0500
Subject: [PATCH] Added selectable option for table widget.

A selectable option has been added to the table widget to show/hide
the checkbox column for selecting table rows. By default it's set
to true. The indirect association facet has been modified to hide
the column because it is non-editable.
---
 install/ui/associate.js |    3 +-
 install/ui/widget.js    |   73 +++++++++++++++++++++++++++-------------------
 2 files changed, 45 insertions(+), 31 deletions(-)

diff --git a/install/ui/associate.js b/install/ui/associate.js
index c1e0b429f12bd499bf0a4fb7b1fb30d8f49c67e2..657839f29a497df24fd0f262dec9258a9661f440 100644
--- a/install/ui/associate.js
+++ b/install/ui/associate.js
@@ -771,7 +771,8 @@ IPA.association_facet = function (spec) {
             entity_name: that.entity_name,
             other_entity: that.other_entity,
             page_length: that.page_length,
-            scrollable: true
+            scrollable: true,
+            selectable: !that.read_only
         });
 
         var columns = that.columns.values;
diff --git a/install/ui/widget.js b/install/ui/widget.js
index fc73e85b125f0a1770f3077d478df69fb8fcd366..6e70cc0a120e487d2dba0cb5b884a2334f781d1c 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -883,6 +883,7 @@ IPA.select_widget = function(spec) {
             that.create_undo(container);
         }
     };
+
     that.setup = function(container) {
         that.widget_setup(container);
 
@@ -1056,12 +1057,14 @@ IPA.table_widget = function (spec) {
     var that = IPA.widget(spec);
 
     that.scrollable = spec.scrollable;
-    that.save_values = typeof spec.save_values == 'undefined' ? true : spec.save_values;
+    that.selectable = spec.selectable === undefined ? true : spec.selectable;
+    that.save_values = spec.save_values === undefined ? true : spec.save_values;
     that['class'] = spec['class'];
 
     that.current_page = 1;
     that.total_pages = 1;
     that.page_length = spec.page_length;
+
     that.columns = $.ordered_map();
 
     that.get_columns = function() {
@@ -1121,26 +1124,30 @@ IPA.table_widget = function (spec) {
 
         var tr = $('<tr/>').appendTo(that.thead);
 
-        var th = $('<th/>', {
-            'style': 'width: 22px;'
-        }).appendTo(tr);
+        var th;
 
-        var select_all_checkbox = $('<input/>', {
-            type: 'checkbox',
-            name: 'select',
-            title: IPA.messages.search.select_all
-        }).appendTo(th);
+        if (that.selectable) {
+            th = $('<th/>', {
+                'style': 'width: 22px;'
+            }).appendTo(tr);
 
-        select_all_checkbox.change(function() {
-            var checked = select_all_checkbox.is(':checked');
-            select_all_checkbox.attr('title', checked ? IPA.messages.search.unselect_all : IPA.messages.search.select_all);
-            var checkboxes = $('input[name=select]', that.tbody).get();
-            for (var i=0; i<checkboxes.length; i++) {
-                checkboxes[i].checked = checked;
-            }
-            that.select_changed();
-            return false;
-        });
+            var select_all_checkbox = $('<input/>', {
+                type: 'checkbox',
+                name: 'select',
+                title: IPA.messages.search.select_all
+            }).appendTo(th);
+
+            select_all_checkbox.change(function() {
+                var checked = select_all_checkbox.is(':checked');
+                select_all_checkbox.attr('title', checked ? IPA.messages.search.unselect_all : IPA.messages.search.select_all);
+                var checkboxes = $('input[name=select]', that.tbody).get();
+                for (var i=0; i<checkboxes.length; i++) {
+                    checkboxes[i].checked = checked;
+                }
+                that.select_changed();
+                return false;
+            });
+        }
 
         var columns = that.columns.values;
         for (var i=0; i<columns.length; i++) {
@@ -1158,8 +1165,8 @@ IPA.table_widget = function (spec) {
                     /* don't use the checkbox column as part of the overall
                        calculation for column widths.  It is so small
                        that it throws off the average. */
-                    width = (that.table.width() - IPA.checkbox_column_width) /
-                        (columns.length);
+                    width = (that.table.width() - (that.selectable ? IPA.checkbox_column_width : 0)) /
+                        columns.length;
                 }
                 width += 'px';
                 th.css('width', width);
@@ -1196,15 +1203,19 @@ IPA.table_widget = function (spec) {
 
         that.row = $('<tr/>');
 
-        var td = $('<td/>', {
-            'style': 'width: '+ IPA.checkbox_column_width +'px;'
-        }).appendTo(that.row);
+        var td;
 
-        $('<input/>', {
-            'type': 'checkbox',
-            'name': 'select',
-            'value': 'user'
-        }).appendTo(td);
+        if (that.selectable) {
+            td = $('<td/>', {
+                'style': 'width: '+ IPA.checkbox_column_width +'px;'
+            }).appendTo(that.row);
+
+            $('<input/>', {
+                'type': 'checkbox',
+                'name': 'select',
+                'value': 'user'
+            }).appendTo(td);
+        }
 
         for (/* var */ i=0; i<columns.length; i++) {
             /* var */ column = columns[i];
@@ -1223,7 +1234,9 @@ IPA.table_widget = function (spec) {
 
         tr = $('<tr/>').appendTo(that.tfoot);
 
-        td = $('<td/>', { colspan: columns.length+1 }).appendTo(tr);
+        td = $('<td/>', {
+            colspan: columns.length + (that.selectable ? 1 : 0)
+        }).appendTo(tr);
 
         that.summary = $('<span/>', {
             'name': 'summary'
-- 
1.7.4

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

Reply via email to