From 69e77212ea428f79742b9ff0452ef19d74cc76d4 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Thu, 2 Dec 2010 22:12:59 -0600 Subject: [PATCH] HBAC Service Groups adjustments The association facet for HBAC Service Groups has been removed and replaced with an association table in the details page. The ipa_association_table_widget has been modified to support multiple columns in the table itself and in the adder dialog. The ipa_association_adder_dialog and ipa_association_facet have been refactored. The ipa_sudorule_association_widget and ipa_rule_association_widget has been removed because their functionalities have been merged into ipa_association_table_widget. --- install/static/associate.js | 505 ++++++++++++++++++++++++--------- install/static/details.js | 1 + install/static/entity.js | 2 +- install/static/hbac.js | 11 +- install/static/hbacsvcgroup.js | 30 +- install/static/host.js | 2 +- install/static/ipa.js | 4 +- install/static/rule.js | 167 ----------- install/static/service.js | 2 +- install/static/sudocmdgroup.js | 2 +- install/static/sudorule.js | 60 +--- install/static/widget.js | 8 +- 12 files changed, 410 insertions(+), 384 deletions(-) diff --git a/install/static/associate.js b/install/static/associate.js index 04fc37598..1a96362f5 100644 --- a/install/static/associate.js +++ b/install/static/associate.js @@ -141,12 +141,6 @@ function ipa_association_adder_dialog(spec) { that.pkey = spec.pkey; that.other_entity = spec.other_entity; - that.associator = spec.associator; - that.method = spec.method || 'add_member'; - - that.on_success = spec.on_success; - that.on_error = spec.on_error; - that.init = function() { if (!that.columns.length) { var pkey_name = IPA.metadata[that.other_entity].primary_key; @@ -165,7 +159,7 @@ function ipa_association_adder_dialog(spec) { that.search = function() { execute_search(that.get_filter()); - } + }; function execute_search(filter){ function on_success(data, text_status, xhr) { @@ -179,22 +173,7 @@ function ipa_association_adder_dialog(spec) { } ipa_cmd('find', [filter], {'all': true}, on_success, null, that.other_entity); - }; - - that.add = function() { - - var associator = that.associator({ - 'entity_name': that.entity_name, - 'pkey': that.pkey, - 'other_entity': that.other_entity, - 'values': that.get_selected_values(), - 'method': that.method, - 'on_success': that.on_success, - 'on_error': that.on_error - }); - - associator.execute(); - }; + } return that; } @@ -246,7 +225,7 @@ function ipa_association_config(spec) { that.name = spec.name; that.associator = spec.associator; that.add_method = spec.add_method; - that.delete_method = spec.delete_method; + that.remove_method = spec.remove_method; return that; } @@ -257,87 +236,98 @@ function ipa_association_table_widget(spec) { var that = ipa_table_widget(spec); - that.facet = spec.facet; that.other_entity = spec.other_entity; - that.add = spec.add; - that.remove = spec.remove; + that.associator = spec.associator || bulk_associator; + that.add_method = spec.add_method || 'add_member'; + that.remove_method = spec.remove_method || 'remove_member'; + + that.adder_columns = []; + that.adder_columns_by_name = {}; + + that.get_adder_column = function(name) { + return that.adder_columns_by_name[name]; + }; + + that.add_adder_column = function(column) { + column.entity_name = that.entity_name; + that.adder_columns.push(column); + that.adder_columns_by_name[column.name] = column; + }; + + that.create_adder_column = function(spec) { + var column = ipa_column(spec); + that.add_adder_column(column); + return column; + }; + + that.init = function() { + + var entity = IPA.get_entity(that.entity_name); + var association = entity.get_association(that.other_entity); + + if (association) { + if (association.associator) { + that.associator = association.associator == 'serial' ? serial_associator : bulk_associator; + } + + if (association.add_method) that.add_method = association.add_method; + if (association.remove_method) that.remove_method = association.remove_method; + } + + // create a column if none defined + if (!that.columns.length) { + that.create_column({ + 'name': that.name, + 'label': IPA.metadata[that.other_entity].label, + 'primary_key': true + }); + } + + that.table_init(); + }; that.create = function(container) { - if (!that.columns.length) { - var pkey_name = IPA.metadata[that.other_entity].primary_key; - - var column = that.create_column({ - name: pkey_name, - label: IPA.metadata[that.other_entity].label, - primary_key: true - }); - - column.setup = function(container, record) { - container.empty(); - - var value = record[column.name]; - value = value ? value.toString() : ''; - - $('', { - 'href': '#'+value, - 'html': value, - 'click': function (value) { - return function() { - var state = IPA.tab_state(that.other_entity); - state[that.other_entity + '-facet'] = 'details'; - state[that.other_entity + '-pkey'] = value; - $.bbq.pushState(state); - return false; - } - }(value) - }).appendTo(container); - }; - } - that.table_create(container); - var action_panel = that.facet.get_action_panel(); - var li = $('.action-controls', action_panel); + var buttons = $('span[name=buttons]', container); - // creating generic buttons for layout $('', { 'type': 'button', 'name': 'remove', - 'value': IPA.messages.button.remove - }).appendTo(li); + 'value': 'Remove '+that.label + }).appendTo(buttons); $('', { 'type': 'button', 'name': 'add', - 'value': IPA.messages.button.enroll - }).appendTo(li); + 'value': 'Add '+that.label + }).appendTo(buttons); }; that.setup = function(container) { that.table_setup(container); - // replacing generic buttons with ipa_button and setting click handler - var action_panel = that.facet.get_action_panel(); - - var button = $('input[name=remove]', action_panel); + var button = $('input[name=remove]', container); button.replaceWith(ipa_button({ 'label': button.val(), 'icon': 'ui-icon-trash', - 'click': function() { that.remove(); } + 'click': function() { that.show_remove_dialog(); } })); - button = $('input[name=add]', action_panel); + button = $('input[name=add]', container); button.replaceWith(ipa_button({ 'label': button.val(), 'icon': 'ui-icon-plus', - 'click': function() { that.add() } + 'click': function() { that.show_add_dialog() } })); }; - that.get_records = function(pkeys, on_success, on_error) { + that.get_records = function(on_success, on_error) { + + if (!that.values.length) return; var batch = ipa_batch_command({ 'name': that.entity_name+'_'+that.name, @@ -345,12 +335,12 @@ function ipa_association_table_widget(spec) { 'on_error': on_error }); - for (var i=0; iError: '+error_thrown.name+'

'); - summary.append('

'+error_thrown.title+'

'); - summary.append('

'+error_thrown.message+'

'); + dialog.add = function() { + that.add( + dialog.get_selected_values(), + function() { + that.refresh(); + dialog.close(); + }, + function() { + that.refresh(); + dialog.close(); + } + ); + }; + + dialog.init(); + + dialog.open(that.container); + }; + + that.add = function(values, on_success, on_error) { + + var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; + + var command = ipa_command({ + 'method': that.entity_name+'_'+that.add_method, + 'args': [pkey], + 'on_success': on_success, + 'on_error': on_error + }); + command.set_option(that.other_entity, values.join(',')); + + command.execute(); + }; + + that.show_remove_dialog = function() { + + var selected_values = that.get_selected_values(); + + if (!selected_values.length) { + alert('Select '+that.label+' to be removed.'); + return; } var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; - ipa_cmd('show', [pkey], {'rights': true}, on_success, on_error, that.entity_name); + var label = IPA.metadata[that.other_entity].label; + var title = 'Remove '+label+' from '+that.entity_name+' '+pkey; + + var dialog = ipa_association_deleter_dialog({ + 'title': title, + 'entity_name': that.entity_name, + 'pkey': pkey, + 'other_entity': that.other_entity, + 'values': selected_values + }); + + dialog.remove = function() { + that.remove( + selected_values, + function() { + that.refresh(); + dialog.close(); + }, + function() { + that.refresh(); + dialog.close(); + } + ); + }; + + dialog.init(); + + dialog.open(that.container); }; + that.remove = function(values, on_success, on_error) { + + var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; + + var command = ipa_command({ + 'method': that.entity_name+'_'+that.remove_method, + 'args': [pkey], + 'on_success': on_success, + 'on_error': on_error + }); + + command.set_option(that.other_entity, values.join(',')); + + command.execute(); + }; + + that.save = function() { + return null; + }; + + // methods that should be invoked by subclasses + that.association_table_widget_init = that.init; + return that; } @@ -418,7 +510,7 @@ function ipa_association_facet(spec) { that.associator = spec.associator || bulk_associator; that.add_method = spec.add_method || 'add_member'; - that.delete_method = spec.delete_method || 'remove_member'; + that.remove_method = spec.remove_method || 'remove_member'; that.columns = []; that.columns_by_name = {}; @@ -458,11 +550,6 @@ function ipa_association_facet(spec) { return column; }; - that.is_dirty = function() { - var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; - return pkey != that.pkey || other_entity != that.other_entity; - }; - that.init = function() { var entity = IPA.get_entity(that.entity_name); @@ -474,30 +561,61 @@ function ipa_association_facet(spec) { } if (association.add_method) that.add_method = association.add_method; - if (association.delete_method) that.delete_method = association.delete_method; + if (association.remove_method) that.remove_method = association.remove_method; } var label = IPA.metadata[that.other_entity] ? IPA.metadata[that.other_entity].label : that.other_entity; + var pkey_name = IPA.metadata[that.other_entity].primary_key; - that.table = ipa_association_table_widget({ + that.table = ipa_table_widget({ 'id': that.entity_name+'-'+that.other_entity, - 'name': that.name, + 'name': pkey_name, 'label': label, 'entity_name': that.entity_name, - 'other_entity': that.other_entity, - 'facet': that + 'other_entity': that.other_entity }); if (that.columns.length) { that.table.set_columns(that.columns); + + } else { + + var column = that.table.create_column({ + name: that.table.name, + label: IPA.metadata[that.other_entity].label, + primary_key: true + }); + + column.setup = function(container, record) { + container.empty(); + + var value = record[column.name]; + value = value ? value.toString() : ''; + + $('
', { + 'href': '#'+value, + 'html': value, + 'click': function (value) { + return function() { + var state = IPA.tab_state(that.other_entity); + state[that.other_entity + '-facet'] = 'details'; + state[that.other_entity + '-pkey'] = value; + $.bbq.pushState(state); + return false; + } + }(value) + }).appendTo(container); + }; } - that.table.add = function() { that.add(); }; - that.table.remove = function() { that.remove() }; - that.facet_init(); }; + that.is_dirty = function() { + var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; + return pkey != that.pkey; + }; + that.create = function(container) { that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; @@ -514,6 +632,23 @@ function ipa_association_facet(spec) { var span = $('', { 'name': 'association' }).appendTo(container); that.table.create(span); + + var action_panel = that.get_action_panel(); + var li = $('.action-controls', action_panel); + + // creating generic buttons for layout + $('', { + 'type': 'button', + 'name': 'remove', + 'value': IPA.messages.button.remove + }).appendTo(li); + + $('', { + 'type': 'button', + 'name': 'add', + 'value': IPA.messages.button.enroll + }).appendTo(li); + }; that.setup = function(container) { @@ -523,9 +658,26 @@ function ipa_association_facet(spec) { var span = $('span[name=association]', that.container); that.table.setup(span); + + // replacing generic buttons with ipa_button and setting click handler + var action_panel = that.get_action_panel(); + + var button = $('input[name=remove]', action_panel); + button.replaceWith(ipa_button({ + 'label': button.val(), + 'icon': 'ui-icon-trash', + 'click': function() { that.show_remove_dialog(); } + })); + + button = $('input[name=add]', action_panel); + button.replaceWith(ipa_button({ + 'label': button.val(), + 'icon': 'ui-icon-plus', + 'click': function() { that.show_add_dialog() } + })); }; - that.add = function() { + that.show_add_dialog = function() { var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; var label = IPA.metadata[that.other_entity] ? IPA.metadata[that.other_entity].label : that.other_entity; @@ -535,29 +687,42 @@ function ipa_association_facet(spec) { 'title': title, 'entity_name': that.entity_name, 'pkey': pkey, - 'other_entity': that.other_entity, - 'associator': that.associator, - 'method': that.add_method, - 'on_success': function() { - that.refresh(); - dialog.close(); - }, - 'on_error': function() { - that.refresh(); - dialog.close(); - } + 'other_entity': that.other_entity }); if (that.adder_columns.length) { dialog.set_columns(that.adder_columns); } + dialog.add = function() { + + var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; + + var associator = that.associator({ + 'entity_name': that.entity_name, + 'pkey': pkey, + 'other_entity': that.other_entity, + 'values': dialog.get_selected_values(), + 'method': that.add_method, + 'on_success': function() { + that.refresh(); + dialog.close(); + }, + 'on_error': function() { + that.refresh(); + dialog.close(); + } + }); + + associator.execute(); + }; + dialog.init(); dialog.open(that.container); }; - that.remove = function() { + that.show_remove_dialog = function() { var label = IPA.metadata[that.other_entity] ? IPA.metadata[that.other_entity].label : that.other_entity; var values = that.table.get_selected_values(); @@ -577,7 +742,7 @@ function ipa_association_facet(spec) { 'other_entity': that.other_entity, 'values': values, 'associator': that.associator, - 'method': that.delete_method, + 'method': that.remove_method, 'on_success': function() { that.refresh(); dialog.close(); @@ -593,8 +758,74 @@ function ipa_association_facet(spec) { dialog.open(that.container); }; - that.refresh = function(){ - that.table.refresh(); + that.get_records = function(pkeys, on_success, on_error) { + + if (!pkeys.length) return; + + var batch = ipa_batch_command({ + 'name': that.entity_name+'_'+that.name, + 'on_success': on_success, + 'on_error': on_error + }); + + for (var i=0; iError: '+error_thrown.name+'

'); + summary.append('

'+error_thrown.title+'

'); + summary.append('

'+error_thrown.message+'

'); + } + + var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; + ipa_cmd('show', [pkey], {'rights': true}, on_success, on_error, that.entity_name); }; that.association_facet_init = that.init; diff --git a/install/static/details.js b/install/static/details.js index 5e3cd8d62..f0e24ac08 100644 --- a/install/static/details.js +++ b/install/static/details.js @@ -272,6 +272,7 @@ function ipa_details_section(spec){ }; // methods that should be invoked by subclasses + that.section_init = that.init; that.section_create = that.create; that.section_setup = that.setup; that.section_load = that.load; diff --git a/install/static/entity.js b/install/static/entity.js index 548623e2d..dcb7e6f82 100644 --- a/install/static/entity.js +++ b/install/static/entity.js @@ -330,7 +330,7 @@ function ipa_entity_set_association_definition(entity_name, data) { 'name': other_entity, 'associator': config.associator, 'add_method': config.add_method, - 'delete_method': config.delete_method + 'remove_method': config.remove_method }); } } diff --git a/install/static/hbac.js b/install/static/hbac.js index a85a89a51..f0f2f96d7 100755 --- a/install/static/hbac.js +++ b/install/static/hbac.js @@ -553,8 +553,7 @@ function ipa_hbac_details_general_section(spec){ 'style': 'width: 100%;' }).appendTo(container); - var tr = $('', { - }).appendTo(table); + var tr = $('').appendTo(table); var td = $('', { 'style': 'width: 100px; text-align: right;', @@ -613,8 +612,7 @@ function ipa_hbac_details_general_section(spec){ 'html': 'undo' }).appendTo(span); - tr = $('', { - }).appendTo(table); + tr = $('').appendTo(table); td = $('', { 'style': 'text-align: right; vertical-align: top;', @@ -642,8 +640,7 @@ function ipa_hbac_details_general_section(spec){ 'html': 'undo' }).appendTo(span); - tr = $('', { - }).appendTo(table); + tr = $('').appendTo(table); td = $('', { 'style': 'text-align: right; vertical-align: top;', @@ -689,7 +686,7 @@ function ipa_hbac_association_widget(spec) { spec = spec || {}; - var that = ipa_rule_association_widget(spec); + var that = ipa_association_table_widget(spec); that.category = spec.category; diff --git a/install/static/hbacsvcgroup.js b/install/static/hbacsvcgroup.js index 94a79c026..1972e6c56 100755 --- a/install/static/hbacsvcgroup.js +++ b/install/static/hbacsvcgroup.js @@ -31,7 +31,7 @@ function ipa_hbacsvcgroup() { that.create_association({ 'name': 'hbacsvc', 'add_method': 'add_member', - 'delete_method': 'remove_member' + 'remove_method': 'remove_member' }); var dialog = ipa_hbacsvcgroup_add_dialog({ @@ -53,13 +53,6 @@ function ipa_hbacsvcgroup() { }); that.add_facet(facet); - facet = ipa_hbacsvcgroup_member_hbacsvc_facet({ - 'name': 'member_hbacsvc', - 'label': IPA.metadata['hbacsvc'].label+' '+IPA.messages.association.members, - 'other_entity': 'hbacsvc' - }); - that.add_facet(facet); - that.entity_init(); }; @@ -152,17 +145,30 @@ function ipa_hbacsvcgroup_details_facet(spec) { section.create_field({ 'name': 'cn', 'label': 'Name' }); section.create_field({ 'name': 'description', 'label': 'Description' }); + section = ipa_details_section({ + 'name': 'services', + 'label': 'Services' + }); + that.add_section(section); + + var field = ipa_hbacsvcgroup_member_hbacsvc_table_widget({ + 'name': 'member_hbacsvc', + 'label': 'Services', + 'other_entity': 'hbacsvc' + }); + section.add_field(field); + that.details_facet_init(); }; return that; } -function ipa_hbacsvcgroup_member_hbacsvc_facet(spec) { +function ipa_hbacsvcgroup_member_hbacsvc_table_widget(spec) { spec = spec || {}; - var that = ipa_association_facet(spec); + var that = ipa_association_table_widget(spec); that.init = function() { @@ -197,7 +203,7 @@ function ipa_hbacsvcgroup_member_hbacsvc_facet(spec) { that.create_column({ name: 'description', label: 'Description', - width: '150px' + width: '350px' }); that.create_adder_column({ @@ -213,7 +219,7 @@ function ipa_hbacsvcgroup_member_hbacsvc_facet(spec) { width: '100px' }); - that.association_facet_init(); + that.association_table_widget_init(); }; return that; diff --git a/install/static/host.js b/install/static/host.js index 4a60bbccd..d9a2dfe03 100644 --- a/install/static/host.js +++ b/install/static/host.js @@ -420,7 +420,7 @@ function ipa_host_managedby_host_facet(spec) { var that = ipa_association_facet(spec); that.add_method = 'add_managedby'; - that.delete_method = 'remove_managedby'; + that.remove_method = 'remove_managedby'; that.init = function() { diff --git a/install/static/ipa.js b/install/static/ipa.js index 6f44e358c..10993af85 100644 --- a/install/static/ipa.js +++ b/install/static/ipa.js @@ -57,8 +57,8 @@ var IPA = ( function () { that.layouts_dir = 'layouts'; that.get_template = function(path) { - if (!that.layout) return path; - return that.layouts_dir+'/'+that.layout+'/'+path; + var layout = that.layout || 'default'; + return that.layouts_dir+'/'+layout+'/'+path; }; /* initialize the IPA JSON-RPC helper diff --git a/install/static/rule.js b/install/static/rule.js index b73fb56a7..ec1eb72ce 100755 --- a/install/static/rule.js +++ b/install/static/rule.js @@ -77,170 +77,3 @@ function ipa_rule_details_section(spec){ return that; } - -function ipa_rule_association_widget(spec) { - - spec = spec || {}; - - var that = ipa_table_widget(spec); - - that.other_entity = spec.other_entity; - - that.add_method = spec.add_method; - that.remove_method = spec.remove_method; - - that.init = function() { - // create a column if none defined - if (!that.columns.length) { - that.create_column({ - 'name': that.name, - 'label': IPA.metadata[that.other_entity].label, - 'primary_key': true - }); - } - - that.table_init(); - }; - - that.create = function(container) { - - that.table_create(container); - - var buttons = $('span[name=buttons]', container); - - $('', { - 'type': 'button', - 'name': 'remove', - 'value': 'Remove '+that.label - }).appendTo(buttons); - - $('', { - 'type': 'button', - 'name': 'add', - 'value': 'Add '+that.label - }).appendTo(buttons); - }; - - that.setup = function(container) { - - that.table_setup(container); - - var button = $('input[name=remove]', that.table); - button.replaceWith(ipa_button({ - 'label': button.val(), - 'icon': 'ui-icon-trash', - 'click': function() { that.show_remove_dialog(); } - })); - - button = $('input[name=add]', that.table); - button.replaceWith(ipa_button({ - 'label': button.val(), - 'icon': 'ui-icon-plus', - 'click': function() { that.show_add_dialog() } - })); - - var entity = IPA.get_entity(that.entity_name); - var association = entity.get_association(that.other_entity); - - if (association && association.associator == 'serial') { - that.associator = serial_associator; - } else { - that.associator = bulk_associator; - } - }; - - that.load = function(result) { - that.values = result[that.name] || []; - that.reset(); - }; - - that.set_values = function(values) { - - that.tbody.empty(); - for (var i=0; values && i