From 6f0c16e4289dd1a68bfd673da52a511087d84b9a Mon Sep 17 00:00:00 2001 From: Endi Sukma Dewata Date: Thu, 17 Nov 2011 11:25:09 -0600 Subject: Added support for radio buttons in table widget. The table widget has been modified to support single-valued attribute using radio buttons needed by some facets in HBAC Test. The widget now uses 'pagination' flag to determine whether to show the pagination control. The test data has also been updated. Ticket #388 --- install/ui/widget.js | 103 +++++++++++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 44 deletions(-) (limited to 'install/ui/widget.js') diff --git a/install/ui/widget.js b/install/ui/widget.js index 5b50d8f16..221adb0de 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -979,9 +979,12 @@ IPA.table_widget = function (spec) { that.save_values = spec.save_values === undefined ? true : spec.save_values; that['class'] = spec['class']; + that.pagination = spec.pagination; that.current_page = 1; that.total_pages = 1; - that.page_length = spec.page_length; + that.page_length = spec.page_length || 20; + + that.multivalued = spec.multivalued === undefined ? true : spec.multivalued; that.columns = $.ordered_map(); @@ -1043,20 +1046,22 @@ IPA.table_widget = function (spec) { 'style': 'width: 22px;' }).appendTo(tr); - var select_all_checkbox = $('', { - type: 'checkbox', - name: 'select', - title: IPA.messages.search.select_all - }).appendTo(th); + if (that.multivalued) { + var select_all_checkbox = $('', { + type: 'checkbox', + name: that.name, + title: IPA.messages.search.select_all + }).appendTo(th); - select_all_checkbox.change(function() { - if(select_all_checkbox.is(':checked')) { - that.select_all(); - } else { - that.unselect_all(); - } - return false; - }); + select_all_checkbox.change(function() { + if(select_all_checkbox.is(':checked')) { + that.select_all(); + } else { + that.unselect_all(); + } + return false; + }); + } } var columns = that.columns.values; @@ -1122,11 +1127,19 @@ IPA.table_widget = function (spec) { 'style': 'width: '+ IPA.checkbox_column_width +'px;' }).appendTo(that.row); - $('', { - 'type': 'checkbox', - 'name': 'select', - 'value': 'user' - }).appendTo(td); + if (that.multivalued) { + $('', { + type: 'checkbox', + name: that.name, + value: '' + }).appendTo(td); + } else { + $('', { + type: 'radio', + name: that.name, + value: '' + }).appendTo(td); + } } for (/* var */ i=0; i', { - 'name': 'pagination' + that.pagination_control = $('', { + 'class': 'pagination-control' }).appendTo(td); - if (that.page_length) { + if (that.pagination) { $('', { text: IPA.messages.widget.prev, @@ -1169,9 +1182,9 @@ IPA.table_widget = function (spec) { that.prev_page(); return false; } - }).appendTo(that.pagination); + }).appendTo(that.pagination_control); - that.pagination.append(' '); + that.pagination_control.append(' '); $('', { text: IPA.messages.widget.next, @@ -1180,11 +1193,11 @@ IPA.table_widget = function (spec) { that.next_page(); return false; } - }).appendTo(that.pagination); + }).appendTo(that.pagination_control); - that.pagination.append(' '); - that.pagination.append(IPA.messages.widget.page); - that.pagination.append(': '); + that.pagination_control.append(' '); + that.pagination_control.append(IPA.messages.widget.page); + that.pagination_control.append(': '); that.current_page_input = $('', { type: 'text', @@ -1195,13 +1208,13 @@ IPA.table_widget = function (spec) { that.set_page(page); } } - }).appendTo(that.pagination); + }).appendTo(that.pagination_control); - that.pagination.append(' / '); + that.pagination_control.append(' / '); that.total_pages_span = $('', { name: 'total_pages' - }).appendTo(that.pagination); + }).appendTo(that.pagination_control); } }; @@ -1234,16 +1247,16 @@ IPA.table_widget = function (spec) { }; that.select_all = function() { - $('input[name=select]', that.thead).attr('checked', true). + $('input[name="'+that.name+'"]', that.thead).attr('checked', true). attr('title', IPA.messages.search.unselect_all); - $('input[name=select]', that.tbody).attr('checked', true); + $('input[name="'+that.name+'"]', that.tbody).attr('checked', true); that.select_changed(); }; that.unselect_all = function() { - $('input[name=select]', that.thead).attr('checked', false). + $('input[name="'+that.name+'"]', that.thead).attr('checked', false). attr('title', IPA.messages.search.select_all); - $('input[name=select]', that.tbody).attr('checked', false); + $('input[name="'+that.name+'"]', that.tbody).attr('checked', false); that.select_changed(); }; @@ -1269,7 +1282,7 @@ IPA.table_widget = function (spec) { if (that.save_values) { var values = []; - $('input[name="select"]', that.tbody).each(function() { + $('input[name="'+that.name+'"]', that.tbody).each(function() { values.push($(this).val()); }); @@ -1283,7 +1296,7 @@ IPA.table_widget = function (spec) { that.get_selected_values = function() { var values = []; - $('input[name="select"]:checked', that.tbody).each(function() { + $('input[name="'+that.name+'"]:checked', that.tbody).each(function() { values.push($(this).val()); }); @@ -1291,7 +1304,7 @@ IPA.table_widget = function (spec) { }; that.get_selected_rows = function() { - return $('input[name="select"]:checked', that.tbody).closest('tr'); + return $('input[name="'+that.name+'"]:checked', that.tbody).closest('tr'); }; that.get_record = function(result, index) { @@ -1319,7 +1332,7 @@ IPA.table_widget = function (spec) { var tr = that.row.clone(); tr.appendTo(that.tbody); - $('input[name="select"]', tr).click(function(){ + $('input[name="'+that.name+'"]', tr).click(function(){ that.select_changed(); }); @@ -1332,7 +1345,7 @@ IPA.table_widget = function (spec) { value = value ? value.toString() : ''; if (column.primary_key) { - $('input[name="select"]', tr).val(value); + $('input[name="'+that.name+'"]', tr).val(value); } var span = $('span[name="'+column.name+'"]', tr); @@ -1343,7 +1356,9 @@ IPA.table_widget = function (spec) { that.add_rows = function(rows) { for (var i=0; i