From 46137fdf898690836ae61e54b1cb2711492287f3 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Mon, 16 May 2011 22:23:20 -0500 Subject: jQuery ordered map. The ordered map is a jQuery extension for creating a collection which can be accessed both as an ordered list and as a map. This collection can be used to store various objects including entities, fields, columns, and dialogs. A test suite for this class has been added as well. Ticket #1232 --- install/ui/widget.js | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'install/ui/widget.js') diff --git a/install/ui/widget.js b/install/ui/widget.js index dd228888..85980ace 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -1078,20 +1078,18 @@ IPA.table_widget = function (spec) { that.scrollable = spec.scrollable; that.save_values = typeof spec.save_values == 'undefined' ? true : spec.save_values; - that.columns = []; - that.columns_by_name = {}; + that.columns = $.ordered_map(); that.get_columns = function() { - return that.columns; + return that.columns.values; }; that.get_column = function(name) { - return that.columns_by_name[name]; + return that.columns.get(name); }; that.add_column = function(column) { - that.columns.push(column); - that.columns_by_name[column.name] = column; + that.columns.put(column.name, column); }; that.set_columns = function(columns) { @@ -1102,8 +1100,7 @@ IPA.table_widget = function (spec) { }; that.clear_columns = function() { - that.columns = []; - that.columns_by_name = {}; + that.columns.empty(); }; that.create_column = function(spec) { @@ -1115,8 +1112,9 @@ IPA.table_widget = function (spec) { that.init = function() { that.widget_init(); - for (var i=0; i').appendTo(tr); - if (that.scrollable && (i == that.columns.length-1)) { + if (that.scrollable && (i == columns.length-1)) { if (column.width) { var width = parseInt(column.width.substring(0, column.width.length-2),10); width += 16; @@ -1168,7 +1167,7 @@ IPA.table_widget = function (spec) { 'html': label }).appendTo(th); - if (i == that.columns.length-1) { + if (i == columns.length-1) { $('', { 'name': 'buttons', 'style': 'float: right;' @@ -1194,8 +1193,8 @@ IPA.table_widget = function (spec) { 'value': 'user' }).appendTo(td); - for (/* var */ i=0; i').appendTo(tr); if (column.width) { @@ -1211,7 +1210,7 @@ IPA.table_widget = function (spec) { tr = $('').appendTo(tfoot); - td = $('', { colspan: that.columns.length+1 }).appendTo(tr); + td = $('', { colspan: columns.length+1 }).appendTo(tr); $('', { 'name': 'summary' @@ -1295,17 +1294,22 @@ IPA.table_widget = function (spec) { }; that.get_record = function(result, index) { + var record = {}; - for (var i=0; i