diff options
Diffstat (limited to 'install/ui')
-rw-r--r-- | install/ui/association.js | 67 | ||||
-rw-r--r-- | install/ui/dialog.js | 68 | ||||
-rw-r--r-- | install/ui/sudo.js | 23 |
3 files changed, 67 insertions, 91 deletions
diff --git a/install/ui/association.js b/install/ui/association.js index a9a2b50a0..664c80e21 100644 --- a/install/ui/association.js +++ b/install/ui/association.js @@ -144,17 +144,9 @@ IPA.bulk_associator = function(spec) { /** * This dialog is used for adding associations between two entities. */ -IPA.association_adder_dialog = function (spec) { +IPA.association_adder_dialog = function(spec) { spec = spec || {}; - /* - TODO: columns map in IPA.adder_dialog should be removed and add_column() - should be modified to add the column directly into the available_table - and selected_table. This way IPA.association_adder_dialog can call - create_column() from the initialization area, no need to modify the - parameters. - */ - default_columns(spec); var that = IPA.adder_dialog(spec); @@ -162,17 +154,35 @@ IPA.association_adder_dialog = function (spec) { that.pkey = spec.pkey; that.other_entity = spec.other_entity; that.attribute_member = spec.attribute_member; + that.exclude = spec.exclude || []; + + var init = function() { + if (!that.get_columns().length) { + var pkey_name = IPA.metadata.objects[spec.other_entity].primary_key; + that.create_column({ + entity: that.entity, + name: pkey_name, + label: IPA.metadata.objects[spec.other_entity].label, + primary_key: true, + width: '600px' + }); + } + }; that.search = function() { function on_success(data, text_status, xhr) { - var results = data.result; + that.clear_available_values(); - var pkey_attr = that.entity.metadata.primary_key; + var other_entity = IPA.get_entity(that.other_entity); + var pkey_attr = other_entity.metadata.primary_key; - for (var i=0; i<results.count; i++){ + var results = data.result; + for (var i=0; i<results.count; i++) { var result = results.result[i]; - if (result[pkey_attr] != spec.pkey){ + var pkey = result[pkey_attr][0]; + + if (that.exclude.indexOf(pkey) < 0) { that.add_available_value(result); } } @@ -207,18 +217,7 @@ IPA.association_adder_dialog = function (spec) { }).execute(); }; - /*initialization*/ - function default_columns(spec){ - if (!spec.columns) { - var pkey_name = IPA.metadata.objects[spec.other_entity].primary_key; - spec.columns = [{ - name: pkey_name, - label: IPA.metadata.objects[spec.other_entity].label, - primary_key: true, - width: '600px' - }]; - } - } + init(); return that; }; @@ -526,7 +525,8 @@ IPA.association_table_widget = function (spec) { pkey: pkey, other_entity: that.other_entity, attribute_member: that.attribute_member, - method: that.add_method + method: that.add_method, + exclude: that.values }); }; @@ -963,12 +963,15 @@ IPA.association_facet = function (spec) { title = title.replace('${primary_key}', pkey); title = title.replace('${other_entity}', label); + var pkeys = that.data[that.get_attribute_name()]; + var dialog = IPA.association_adder_dialog({ - 'title': title, - 'entity': that.entity, - 'pkey': pkey, - 'other_entity': that.other_entity, - 'attribute_member': that.attribute_member + title: title, + entity: that.entity, + pkey: pkey, + other_entity: that.other_entity, + attribute_member: that.attribute_member, + exclude: pkeys }); var adder_columns = that.adder_columns.values; @@ -1165,7 +1168,7 @@ IPA.association_facet = function (spec) { if (that.remove_button) that.remove_button.css('display', 'none'); } - var pkey = IPA.get_entity(that.entity.name).get_primary_key(); + var pkey = that.entity.get_primary_key(); var command = IPA.command({ entity: that.entity.name, diff --git a/install/ui/dialog.js b/install/ui/dialog.js index 86aefeffc..eb1bbd1d9 100644 --- a/install/ui/dialog.js +++ b/install/ui/dialog.js @@ -307,7 +307,7 @@ IPA.dialog = function(spec) { * This dialog provides an interface for searching and selecting * values from the available results. */ -IPA.adder_dialog = function (spec) { +IPA.adder_dialog = function(spec) { spec = spec || {}; @@ -316,7 +316,7 @@ IPA.adder_dialog = function (spec) { that.width = spec.width || 600; that.height = spec.height || 360; - if (!that.entity){ + if (!that.entity) { var except = { expected: false, message:'Adder dialog created without entity.' @@ -324,15 +324,37 @@ IPA.adder_dialog = function (spec) { throw except; } - that.columns = $.ordered_map(); + var init = function() { + that.available_table = IPA.table_widget({ + entity: that.entity, + name: 'available', + scrollable: true + }); + that.selected_table = IPA.table_widget({ + entity: that.entity, + name: 'selected', + scrollable: true + }); + + if (spec.columns) { + for (var i=0; i<spec.columns.length; i++) { + that.create_column(spec.columns[i]); + } + } + }; that.get_column = function(name) { - return that.columns.get(name); + return that.available_table.get_column(name); + }; + + that.get_columns = function() { + return that.available_table.get_columns(); }; that.add_column = function(column) { - that.columns.put(column.name, column); + that.available_table.add_column(column); + that.selected_table.add_column(column); }; that.set_columns = function(columns) { @@ -343,7 +365,8 @@ IPA.adder_dialog = function (spec) { }; that.clear_columns = function() { - that.columns.empty(); + that.available_table.clear_columns(); + that.selected_table.clear_columns(); }; that.create_column = function(spec) { @@ -353,32 +376,8 @@ IPA.adder_dialog = function (spec) { return column; }; - function initialize_table(){ - that.available_table = IPA.table_widget({ - entity: that.entity, - name: 'available', - scrollable: true - }); - - var columns = that.columns.values; - that.available_table.set_columns(columns); - - that.selected_table = IPA.table_widget({ - entity: that.entity, - name: 'selected', - scrollable: true - }); - - that.selected_table.set_columns(columns); - } that.create = function() { - /*TODO: move this earlier - The table initialization should be done earlier. However, - the adder columns are not added until after initialization is over, - and thus we have to dleay the creation of the table.*/ - initialize_table(); - // do not call that.dialog_create(); var container = $('<div/>', { @@ -528,7 +527,6 @@ IPA.adder_dialog = function (spec) { that.search(); }; - that.open = function(container) { that.buttons[IPA.messages.buttons.enroll] = that.execute; @@ -571,13 +569,7 @@ IPA.adder_dialog = function (spec) { return that.selected_table.save(); }; - /*dialog initialization */ - if (spec.columns){ - for (var i =0; i < spec.columns.length; i +=1){ - that.create_column(spec.columns[i]); - } - } - + init(); that.adder_dialog_create = that.create; diff --git a/install/ui/sudo.js b/install/ui/sudo.js index cdd5e50af..23e5f7a24 100644 --- a/install/ui/sudo.js +++ b/install/ui/sudo.js @@ -1076,7 +1076,8 @@ IPA.sudorule_association_table_widget = function(spec) { other_entity: that.other_entity, attribute_member: that.attribute_member, entity: that.entity, - external: that.external + external: that.external, + exclude: that.values }); }; @@ -1102,24 +1103,6 @@ IPA.sudo.rule_association_adder_dialog = function(spec) { that.external = spec.external; - - function setup_table(){ - if (!that.columns.length) { - var pkey_name = IPA.metadata.objects[that.other_entity].primary_key; - that.create_column({ - entity: that.entity, - name: pkey_name, - label: IPA.metadata.objects[that.other_entity].label, - primary_key: true, - width: '200px' - }); - } - } - - that.create = function() { - that.adder_dialog_create(); - }; - that.add = function() { var rows = that.available_table.remove_selected_rows(); that.selected_table.add_rows(rows); @@ -1136,7 +1119,5 @@ IPA.sudo.rule_association_adder_dialog = function(spec) { } }; - setup_table(); - return that; }; |