summaryrefslogtreecommitdiffstats
path: root/install/ui/dialog.js
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2011-05-16 22:23:20 -0500
committerAdam Young <ayoung@redhat.com>2011-05-20 12:11:47 -0400
commit46137fdf898690836ae61e54b1cb2711492287f3 (patch)
treeb64b936fca3f738bdd19862113d8005b72e4eb82 /install/ui/dialog.js
parent00abd47de4d3238295cbe5dc30210b913c0f07a1 (diff)
downloadfreeipa-46137fdf898690836ae61e54b1cb2711492287f3.tar.gz
freeipa-46137fdf898690836ae61e54b1cb2711492287f3.tar.xz
freeipa-46137fdf898690836ae61e54b1cb2711492287f3.zip
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
Diffstat (limited to 'install/ui/dialog.js')
-rw-r--r--install/ui/dialog.js59
1 files changed, 31 insertions, 28 deletions
diff --git a/install/ui/dialog.js b/install/ui/dialog.js
index 2c9fdb0e2..9cba47fdd 100644
--- a/install/ui/dialog.js
+++ b/install/ui/dialog.js
@@ -40,8 +40,7 @@ IPA.dialog = function(spec) {
that.buttons = {};
- that.fields = [];
- that.fields_by_name = {};
+ that.fields = $.ordered_map();
that.sections = [];
@@ -52,8 +51,9 @@ IPA.dialog = function(spec) {
that.__defineSetter__("entity_name", function(entity_name){
that._entity_name = entity_name;
- for (var i=0; i<that.fields.length; i++) {
- that.fields[i].entity_name = entity_name;
+ var fields = that.fields.values;
+ for (var i=0; i<fields.length; i++) {
+ fields[i].entity_name = entity_name;
}
for (var j=0; j<that.sections.length; j++) {
@@ -66,12 +66,11 @@ IPA.dialog = function(spec) {
};
that.get_field = function(name) {
- return that.fields_by_name[name];
+ return that.fields.get(name);
};
that.add_field = function(field) {
- that.fields.push(field);
- that.fields_by_name[field.name] = field;
+ that.fields.put(field.name, field);
};
that.field = function(field) {
@@ -80,8 +79,9 @@ IPA.dialog = function(spec) {
};
that.is_valid = function() {
- for (var i=0; i<that.fields.length; i++) {
- var field = that.fields[i];
+ var fields = that.fields.values;
+ for (var i=0; i<fields.length; i++) {
+ var field = fields[i];
if (!field.valid) return false;
}
return true;
@@ -116,8 +116,9 @@ IPA.dialog = function(spec) {
that.entity = IPA.get_entity(that.entity_name);
- for (var i=0; i<that.fields.length; i++) {
- var field = that.fields[i];
+ var fields = that.fields.values;
+ for (var i=0; i<fields.length; i++) {
+ var field = fields[i];
field.entity_name = that.entity_name;
field.init();
}
@@ -136,8 +137,9 @@ IPA.dialog = function(spec) {
var table = $('<table/>').appendTo(that.container);
- for (var i=0; i<that.fields.length; i++) {
- var field = that.fields[i];
+ var fields = that.fields.values;
+ for (var i=0; i<fields.length; i++) {
+ var field = fields[i];
if (field.hidden) continue;
var tr = $('<tr/>').appendTo(table);
@@ -172,8 +174,9 @@ IPA.dialog = function(spec) {
* Setup behavior
*/
that.setup = function() {
- for (var i=0; i<that.fields.length; i++) {
- var field = that.fields[i];
+ var fields = that.fields.values;
+ for (var i=0; i<fields.length; i++) {
+ var field = fields[i];
var span = $('span[name="'+field.name+'"]', that.container);
field.setup(span);
@@ -241,8 +244,9 @@ IPA.dialog = function(spec) {
};
that.save = function(record) {
- for (var i=0; i<that.fields.length; i++) {
- var field = that.fields[i];
+ var fields = that.fields.values;
+ for (var i=0; i<fields.length; i++) {
+ var field = fields[i];
var values = field.save();
record[field.name] = values.join(',');
}
@@ -262,8 +266,9 @@ IPA.dialog = function(spec) {
};
that.reset = function() {
- for (var i=0; i<that.fields.length; i++) {
- var field = that.fields[i];
+ var fields = that.fields.values;
+ for (var i=0; i<fields.length; i++) {
+ var field = fields[i];
field.reset();
}
for (var j=0; j<that.sections.length; j++) {
@@ -318,16 +323,14 @@ IPA.adder_dialog = function (spec) {
that.width = spec.width || '600px';
- that.columns = [];
- that.columns_by_name = {};
+ that.columns = $.ordered_map();
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) {
@@ -338,8 +341,7 @@ IPA.adder_dialog = function (spec) {
};
that.clear_columns = function() {
- that.columns = [];
- that.columns_by_name = {};
+ that.columns.empty();
};
that.create_column = function(spec) {
@@ -355,7 +357,8 @@ IPA.adder_dialog = function (spec) {
height: '151px'
});
- that.available_table.set_columns(that.columns);
+ var columns = that.columns.values;
+ that.available_table.set_columns(columns);
that.available_table.init();
@@ -365,7 +368,7 @@ IPA.adder_dialog = function (spec) {
height: '151px'
});
- that.selected_table.set_columns(that.columns);
+ that.selected_table.set_columns(columns);
that.selected_table.init();