From b36df6e9b9c1104d37fe14782a7e21e57097a7c0 Mon Sep 17 00:00:00 2001 From: Adam Young Date: Mon, 25 Jul 2011 12:15:14 -0400 Subject: removing setters setup and init change widget and widget unit tests to hold on to entity, not entity name. Replacing entity_name with entity.name in most places. The one exception is columns for table_widget. Widgets that refer to other entities have to have late resolution of the entity object, due to circular dependencies. cleanup entity assignment. removed template and layout, merged setup into create adder dialogs adjust height for external removed init from widget, isection, association, facet, host and service Make unit tests use factory. fix functional tests to click find link correctly. tweak to activation test, but still broken. moved initialization code to the end use --all for hbacrule find, so the type shows up now fixed dns exception code and exception handling for get_entity replace metadata look up with value from entity. fixed author lines removed duplicate columns in managed by facets. tweak to nav fix in order to initialize tab. more defensive code update metadata for true false one line init for entity_name in widget move init code to end of constructor functions moved constants to start of function for adder_dialog external fields for dialogs initialized at dialog creation sudo sections: move add fields and columns to widget definition. The parameter validation in IPA.column ...This is precondition checking. Note that it merely throws an exception if the entity_name is not set. I want this stuff at the top of the function so that it is obvious to people looking to use them what is required. I added a comment to make this clear, but I'd like to keep precondition checking at the top of the function. decreased the scope of the pkey_name and moved the initiailzation fof columns into the setup_column function for association_tables return false at the end of click handler removed blank labels in sudo command section fix radio buttons for sudo category fixed table side for adder dialogs with external fields comments for future direction with add_columns https://fedorahosted.org/freeipa/ticket/1451 https://fedorahosted.org/freeipa/ticket/1462 https://fedorahosted.org/freeipa/ticket/1493 https://fedorahosted.org/freeipa/ticket/1497 https://fedorahosted.org/freeipa/ticket/1532 https://fedorahosted.org/freeipa/ticket/1534 --- install/ui/aci.js | 47 ++- install/ui/add.js | 111 +++-- install/ui/association.js | 275 ++++++------ install/ui/automount.js | 32 +- install/ui/certificate.js | 9 - install/ui/details.js | 149 +------ install/ui/dialog.js | 168 ++++---- install/ui/dns.js | 100 +---- install/ui/entitle.js | 3 - install/ui/entity.js | 93 ++--- install/ui/hbac.js | 461 ++++++++------------- install/ui/host.js | 80 ++-- install/ui/ipa.js | 20 +- install/ui/jquery.ordered-map.js | 9 +- install/ui/navigation.js | 15 +- install/ui/rule.js | 89 ++-- install/ui/search.js | 42 +- install/ui/service.js | 70 ++-- install/ui/sudo.js | 783 ++++++++++++----------------------- install/ui/test/aci_tests.js | 19 +- install/ui/test/association_tests.js | 11 +- install/ui/test/data/ipa_init.json | 101 ++--- install/ui/test/details_tests.js | 30 +- install/ui/test/entity_tests.js | 3 +- install/ui/test/navigation_tests.js | 6 +- install/ui/test/widget_tests.js | 133 +++--- install/ui/user.js | 11 +- install/ui/widget.js | 197 +++++---- ipalib/plugins/internal.py | 2 + 29 files changed, 1191 insertions(+), 1878 deletions(-) diff --git a/install/ui/aci.js b/install/ui/aci.js index 54050c79c..9c1188afb 100644 --- a/install/ui/aci.js +++ b/install/ui/aci.js @@ -222,9 +222,6 @@ IPA.attributes_widget = function(spec) { var id = spec.name; - that.setup = function() { - }; - that.create = function(container) { that.container = container; @@ -366,31 +363,26 @@ IPA.rights_widget = function(spec) { var that = IPA.checkboxes_widget(spec); that.rights = ['write', 'add', 'delete']; - - that.init = function() { - - that.widget_init(); - - for (var i=0; i', { name: 'attrs', diff --git a/install/ui/add.js b/install/ui/add.js index 614a20905..988ea8ff1 100644 --- a/install/ui/add.js +++ b/install/ui/add.js @@ -32,82 +32,30 @@ IPA.add_dialog = function (spec) { that.method = spec.method || 'add'; that.pre_execute_hook = spec.pre_execute_hook; - function show_edit_page(entity_name,result){ - var pkey_name = IPA.metadata.objects[entity_name].primary_key; + function show_edit_page(entity,result){ + var pkey_name = entity.metadata.primary_key; var pkey = result[pkey_name]; if (pkey instanceof Array) { pkey = pkey[0]; } - IPA.nav.show_page(that.entity_name, 'default', pkey); + IPA.nav.show_entity_page(that.entity, 'default', pkey); } that.show_edit_page = spec.show_edit_page || show_edit_page; - that.init = function() { - that.add_button(IPA.messages.buttons.add, function() { - var record = {}; - that.save(record); - that.add( - record, - function(data, text_status, xhr) { - var facet = IPA.current_entity.get_facet(); - var table = facet.table; - table.refresh(); - that.close(); - } - ); - }); - - - that.add_button(IPA.messages.buttons.add_and_add_another, function() { - var record = {}; - that.save(record); - that.add( - record, - function(data, text_status, xhr) { - var facet = IPA.current_entity.get_facet(); - var table = facet.table; - table.refresh(); - that.reset(); - } - ); - }); - - that.add_button(IPA.messages.buttons.add_and_edit, function() { - var record = {}; - that.save(record); - that.add( - record, - function(data, text_status, xhr) { - that.close(); - - var entity_name = that.entity_name; - var result = data.result.result; - that.show_edit_page(entity_name,result); - } - ); - }); - - that.add_button(IPA.messages.buttons.cancel, function() { - that.close(); - }); - - that.dialog_init(); - }; - that.add = function(record, on_success, on_error) { var field, value, pkey_prefix; - var pkey_name = IPA.metadata.objects[that.entity_name].primary_key; + var pkey_name = that.entity.metadata.primary_key; var command = IPA.command({ - entity: that.entity_name, + entity: that.entity.name, method: that.method, on_success: on_success, on_error: on_error }); - pkey_prefix = IPA.get_entity(that.entity_name).get_primary_key_prefix(); + pkey_prefix = that.entity.get_primary_key_prefix(); for (var h=0; h', { name: field.name, 'class': 'details-field' @@ -116,18 +97,6 @@ IPA.details_section = function(spec) { } }; - that.setup = function(container) { - - that.container = container; - - var fields = that.fields.values; - for (var i=0; i', { - id: spec.id, - name: spec.name, - href: spec.href || '#' + (spec.name || 'button'), - title: spec.title || spec.label, - 'class': 'ui-state-default ui-corner-all input_link', - style: spec.style, - click: spec.click, - blur: spec.blur - }); - - if (spec['class']) button.addClass(spec['class']); - - if (spec.icon) { - $('', { - 'class': 'icon '+spec.icon - }).appendTo(button); - } - - if (spec.label) { - $('', { - 'class': 'button-label', - html: spec.label - }).appendTo(button); - } - - return button; -}; diff --git a/install/ui/dialog.js b/install/ui/dialog.js index 513a5b9f2..f4a8293bc 100644 --- a/install/ui/dialog.js +++ b/install/ui/dialog.js @@ -30,10 +30,9 @@ IPA.dialog = function(spec) { var that = {}; + that.entity = spec.entity; that.name = spec.name; that.title = spec.title; - that._entity_name = spec.entity_name; - that.width = spec.width || 400; that.height = spec.height; @@ -67,24 +66,6 @@ IPA.dialog = function(spec) { } }; - that.__defineGetter__("entity_name", function(){ - return that._entity_name; - }); - - that.__defineSetter__("entity_name", function(entity_name){ - that._entity_name = entity_name; - - var fields = that.fields.values; - for (var i=0; i',{id: field.name+'-label', - text:field.label+': '})); + text: label_text})); td = $('', { style: 'vertical-align: top;' @@ -217,44 +185,21 @@ IPA.dialog = function(spec) { section.create(div); } - }; - - /** - * Setup behavior - */ - that.setup = function() { - var fields = that.fields.values; - for (var i=0; i'); - if (container) { container.append(that.container); } that.create(); - that.setup(); that.container.dialog({ 'title': that.title, @@ -308,9 +253,7 @@ IPA.dialog = function(spec) { } }; - that.dialog_init = that.init; that.dialog_create = that.create; - that.dialog_setup = that.setup; that.dialog_open = that.open; var fields = spec.fields || []; @@ -320,6 +263,7 @@ IPA.dialog = function(spec) { if (field_spec instanceof Object) { var factory = field_spec.factory || IPA.text_widget; + field_spec.entity = that.entity; field = factory(field_spec); /* This is a bit of a hack, and is here to support ACI @@ -335,7 +279,10 @@ IPA.dialog = function(spec) { } } else { - field = IPA.text_widget({ name: field_spec, undo: false }); + field = IPA.text_widget({ + name: field_spec, + entity:that.entity, + undo: false }); that.add_field(field); } } @@ -348,16 +295,27 @@ IPA.dialog = function(spec) { * values from the available results. */ IPA.adder_dialog = function (spec) { + var NORMAL_HEIGHT = '151px'; + var EXTERNAL_HEIGHT = '119px'; spec = spec || {}; var that = IPA.dialog(spec); - + that.external = spec.external; that.width = spec.width || 600; that.height = spec.height || 360; + if (!that.entity){ + var except = { + expected: false, + message:'Adder dialog created without entity.' + }; + throw except; + } + that.columns = $.ordered_map(); + that.get_column = function(name) { return that.columns.get(name); }; @@ -378,38 +336,40 @@ IPA.adder_dialog = function (spec) { }; that.create_column = function(spec) { + spec.entity = that.entity; var column = IPA.column(spec); that.add_column(column); return column; }; - that.init = function() { + function initialize_table(){ + var table_height = NORMAL_HEIGHT; + if (that.external){ + table_height = EXTERNAL_HEIGHT; + } + that.available_table = IPA.table_widget({ + entity: that.entity, name: 'available', scrollable: true, - height: '151px' + height: table_height }); var columns = that.columns.values; that.available_table.set_columns(columns); - that.available_table.init(); - that.selected_table = IPA.table_widget({ + entity: that.entity, name: 'selected', scrollable: true, - height: '151px' + height: NORMAL_HEIGHT }); that.selected_table.set_columns(columns); - - that.selected_table.init(); - - that.dialog_init(); - }; - + } that.create = function() { + // do not call that.dialog_create(); var search_panel = $('
', { @@ -465,6 +425,7 @@ IPA.adder_dialog = function (spec) { that.available_table.create(available_panel); + var buttons_panel = $('
', { name: 'buttons', 'class': 'adder-dialog-buttons' @@ -495,17 +456,6 @@ IPA.adder_dialog = function (spec) { }).appendTo(selected_panel); that.selected_table.create(selected_panel); - }; - - that.setup = function() { - - // do not call that.dialog_setup(); - - var available_panel = $('div[name=available]', that.container); - that.available_table.setup(available_panel); - - var selected_panel = $('div[name=selected]', that.container); - that.selected_table.setup(selected_panel); that.filter_field = $('input[name=filter]', that.container); @@ -513,7 +463,10 @@ IPA.adder_dialog = function (spec) { that.find_button = IPA.button({ name: 'find', 'label': button.val(), - 'click': function() { that.search(); } + 'click': function() { + that.search(); + return false; + } }); button.replaceWith(that.find_button); @@ -539,9 +492,29 @@ IPA.adder_dialog = function (spec) { }); button.replaceWith(that.add_button); + if (that.external) { + var external_panel = $('
', { + name: 'external', + 'class': 'adder-dialog-external' + }).appendTo(results_panel); + + $('
', { + html: IPA.messages.objects.sudorule.external, + 'class': 'ui-widget-header' + }).appendTo(external_panel); + + that.external_field = $('', { + type: 'text', + name: 'external', + style: 'width: 244px' + }).appendTo(external_panel); + + } + that.search(); }; + that.open = function(container) { that.buttons[IPA.messages.buttons.enroll] = that.execute; @@ -584,9 +557,16 @@ IPA.adder_dialog = function (spec) { return that.selected_table.save(); }; - that.adder_dialog_init = that.init; + /*dialog initialization */ + if (spec.columns){ + for (var i =0; i < spec.columns.length; i +=1){ + that.create_column(spec.columns[i]); + } + } + + initialize_table(); + that.adder_dialog_create = that.create; - that.adder_dialog_setup = that.setup; return that; }; diff --git a/install/ui/dns.js b/install/ui/dns.js index 7cef5ae72..da96ee107 100644 --- a/install/ui/dns.js +++ b/install/ui/dns.js @@ -27,7 +27,10 @@ IPA.entity_factories.dnszone = function() { if (!IPA.dns_enabled) { - throw "DNS not enabled on server"; + var except = { + expected: true + }; + throw except; } return IPA.entity_builder(). @@ -106,93 +109,6 @@ IPA.dnszone_adder_dialog = function(spec) { var that = IPA.add_dialog(spec); - that.create = function() { - - var table = $('').appendTo(that.container); - - var field = that.fields.get('idnsname'); - var tr = $('').appendTo(table); - - var td = $('').appendTo(table); - - td = $('').appendTo(table); - - td = $('
', { - style: 'vertical-align: top;', - title: field.label - }).appendTo(tr); - - td.append($('', { - style: 'vertical-align: top;' - }).appendTo(tr); - - var span = $('', { - name: field.name - }).appendTo(td); - - field.create(span); - field.field_span = span; - - field = that.fields.get('name_from_ip'); - tr = $('
', { - style: 'vertical-align: top;', - title: field.label - }).appendTo(tr); - - td = $('', { - style: 'vertical-align: top;' - }).appendTo(tr); - - span = $('', { - name: field.name - }).appendTo(td); - - td.append($('
', { - colspan: 2, - html: ' ' - }).appendTo(tr); - - var fields = that.fields.values; - for (var i=0; i').appendTo(table); - - td = $('', { - style: 'vertical-align: top;', - title: field.label - }).appendTo(tr); - - td.append($('', { - style: 'vertical-align: top;' - }).appendTo(tr); - - span = $('', { - name: field.name - }).appendTo(td); - - field.create(span); - field.field_span = span; - } - }; - that.save = function(record) { var idnsname; @@ -259,7 +175,10 @@ IPA.dns_record_search_load = function (result) { IPA.entity_factories.dnsrecord = function() { if (!IPA.dns_enabled) { - throw "DNS not enabled on server"; + var except = { + expected: true + }; + throw except; } return IPA.entity_builder(). @@ -459,8 +378,7 @@ IPA.dnsrecord_redirection_dialog = function(spec) { IPA.dnsrecord_host_link_widget = function(spec){ var that = IPA.entity_link_widget(spec); that.other_pkeys = function(){ - var entity = IPA.get_entity(that.entity_name); - var pkey = entity.get_primary_key(); + var pkey = that.entity.get_primary_key(); return [pkey[0]+'.'+pkey[1]]; }; return that; diff --git a/install/ui/entitle.js b/install/ui/entitle.js index 54c633641..15fbf2358 100644 --- a/install/ui/entitle.js +++ b/install/ui/entitle.js @@ -526,7 +526,6 @@ IPA.entitle.certificate_column = function(spec) { certificate: certificate, add_pem_delimiters: false }); - dialog.init(); dialog.open(); return false; } @@ -706,8 +705,6 @@ IPA.entitle.download_widget = function(spec) { certificate: userpkcs12[0].__base64__, add_pem_delimiters: false }); - - dialog.init(); dialog.open(); } ); diff --git a/install/ui/entity.js b/install/ui/entity.js index a2386b816..599cde65b 100644 --- a/install/ui/entity.js +++ b/install/ui/entity.js @@ -3,7 +3,7 @@ /* Authors: * Pavel Zuna - * Endi S. Dewata + * Endi Sukma Dewata * Adam Young * * Copyright (C) 2010-2011 Red Hat @@ -31,6 +31,8 @@ IPA.facet = function (spec) { var that = {}; + that.entity = spec.entity; + that.name = spec.name; that.label = spec.label; that.title = spec.title || that.label; @@ -41,7 +43,7 @@ IPA.facet = function (spec) { that.header = spec.header || IPA.facet_header({ facet: that }); - that._entity_name = spec.entity_name; + that.entity_name = spec.entity_name; that.dialogs = $.ordered_map(); @@ -50,14 +52,6 @@ IPA.facet = function (spec) { that.state = {}; - that.__defineGetter__('entity_name', function() { - return that._entity_name; - }); - - that.__defineSetter__('entity_name', function(entity_name) { - that._entity_name = entity_name; - }); - that.get_dialog = function(name) { return that.dialogs.get(name); }; @@ -67,16 +61,6 @@ IPA.facet = function (spec) { return that; }; - that.init = function() { - - var dialogs = that.dialogs.values; - for (var i=0; i + * Adam Young * * Copyright (C) 2010 Red Hat * see file 'COPYING' for use and warranty information @@ -26,6 +27,7 @@ IPA.entity_factories.hbacrule = function() { return IPA.entity_builder(). entity('hbacrule'). search_facet({ + search_all:true, columns:['cn', { factory: IPA.column, @@ -47,20 +49,7 @@ IPA.entity_factories.hbacrule = function() { factory: IPA.hbacrule_details_facet }). adder_dialog({ - fields:[ - 'cn', - { - factory: IPA.radio_widget, - 'name': 'accessruletype', - 'options': [ - { 'value': 'allow', - 'label': IPA.messages.objects.hbacrule.allow - }, - { 'value': 'deny', - 'label': IPA.messages.objects.hbacrule.deny - }], - 'undo': false - }] + fields:['cn'] }). build(); }; @@ -115,33 +104,32 @@ IPA.hbacsvcgroup_member_hbacsvc_table_widget = function(spec) { var that = IPA.association_table_widget(spec); - that.init = function() { - var column = that.create_column({ - name: 'cn', - primary_key: true, - width: '150px', - link: true - }); + var column = that.create_column({ + name: 'cn', + primary_key: true, + width: '150px', + entity:that.entity, + link: true + }); - that.create_column({ - name: 'description', - width: '350px' - }); + that.create_column({ + name: 'description', + entity:that.entity, - that.create_adder_column({ - name: 'cn', - primary_key: true, - width: '100px' - }); + width: '350px' + }); - that.create_adder_column({ - name: 'description', - width: '100px' - }); + that.create_adder_column({ + name: 'cn', + primary_key: true, + width: '100px' + }); - that.association_table_widget_init(); - }; + that.create_adder_column({ + name: 'description', + width: '100px' + }); return that; }; @@ -154,157 +142,193 @@ IPA.hbacrule_details_facet = function(spec) { var that = IPA.details_facet(spec); - that.init = function() { - - var section = IPA.hbacrule_details_general_section({ - 'name': 'general', - 'label': IPA.messages.details.general + function general_section(){ + var section = IPA.details_list_section({ + name: 'general', + entity:that.entity, + label: IPA.messages.details.general }); - that.add_section(section); section.text({name: 'cn', read_only: true}); - section.radio({name: 'accessruletype'}); + section.text({ + name: 'accessruletype', + read_only:true + }); section.textarea({name: 'description'}); - section.radio({name: 'ipaenabledflag'}); + section.radio({ + name: 'ipaenabledflag', + options:[ + {'value': 'TRUE',label: IPA.messages['true']}, + {'value': 'FALSE',label:IPA.messages['false']} + ] + }); + return section; + } + + function user_category_section(){ var param_info = IPA.get_entity_param('hbacrule', 'usercategory'); - section = IPA.rule_details_section({ - 'name': 'user', - 'label': IPA.messages.objects.hbacrule.user, - 'text': param_info.doc+':', - 'field_name': 'usercategory', - 'options': [ - { 'value': 'all', 'label': IPA.messages.objects.hbacrule.anyone }, - { 'value': '', 'label': IPA.messages.objects.hbacrule.specified_users } + var section = IPA.rule_details_section({ + name: 'user', + entity:that.entity, + + label: IPA.messages.objects.hbacrule.user, + text: param_info.doc+':', + field_name: 'usercategory', + options: [ + { value: 'all', label: IPA.messages.objects.hbacrule.anyone }, + { value: '', + label: IPA.messages.objects.hbacrule.specified_users } ], - 'tables': [ - { 'field_name': 'memberuser_user' }, - { 'field_name': 'memberuser_group' } + tables: [ + { field_name: 'memberuser_user' }, + { field_name: 'memberuser_group' } ] }); - that.add_section(section); var category = section.add_field(IPA.radio_widget({ name: 'usercategory' })); section.add_field(IPA.rule_association_table_widget({ - 'id': that.entity_name+'-memberuser_user', - 'name': 'memberuser_user', 'category': category, - 'other_entity': 'user', 'add_method': 'add_user', 'remove_method': 'remove_user' + id: that.entity.name+'-memberuser_user', + name: 'memberuser_user', category: category, + other_entity: 'user', add_method: 'add_user', + remove_method: 'remove_user' })); section.add_field(IPA.rule_association_table_widget({ - 'id': that.entity_name+'-memberuser_group', - 'name': 'memberuser_group', 'category': category, - 'other_entity': 'group', 'add_method': 'add_user', 'remove_method': 'remove_user' + id: that.entity.name+'-memberuser_group', + name: 'memberuser_group', category: category, + other_entity: 'group', add_method: 'add_user', + remove_method: 'remove_user' })); + return section; + } - param_info = IPA.get_entity_param('hbacrule', 'hostcategory'); - - section = IPA.rule_details_section({ - 'name': 'host', - 'label': IPA.messages.objects.hbacrule.host, - 'text': param_info.doc+':', - 'field_name': 'hostcategory', - 'options': [ - { 'value': 'all', 'label': IPA.messages.objects.hbacrule.any_host }, - { 'value': '', 'label': IPA.messages.objects.hbacrule.specified_hosts } + function hostcategory_section(){ + var param_info = IPA.get_entity_param('hbacrule', 'hostcategory'); + + var section = IPA.rule_details_section({ + name: 'host', + label: IPA.messages.objects.hbacrule.host, + entity:that.entity, + text: param_info.doc+':', + field_name: 'hostcategory', + options: [ + { value: 'all', label: IPA.messages.objects.hbacrule.any_host }, + { value: '', + label: IPA.messages.objects.hbacrule.specified_hosts } ], - 'tables': [ - { 'field_name': 'memberhost_host' }, - { 'field_name': 'memberhost_hostgroup' } - ] + tables: [ + { field_name: 'memberhost_host' }, + { field_name: 'memberhost_hostgroup' } + ] }); - that.add_section(section); - category = section.add_field(IPA.radio_widget({ + var category = section.add_field(IPA.radio_widget({ name: 'hostcategory' })); section.add_field(IPA.rule_association_table_widget({ - 'id': that.entity_name+'-memberhost_host', - 'name': 'memberhost_host', 'category': category, - 'other_entity': 'host', 'add_method': 'add_host', 'remove_method': 'remove_host' + id: that.entity.name+'-memberhost_host', + name: 'memberhost_host', category: category, + other_entity: 'host', add_method: 'add_host', + remove_method: 'remove_host' })); section.add_field(IPA.rule_association_table_widget({ - 'id': that.entity_name+'-memberhost_hostgroup', - 'name': 'memberhost_hostgroup', 'category': category, - 'other_entity': 'hostgroup', 'add_method': 'add_host', 'remove_method': 'remove_host' + id: that.entity.name+'-memberhost_hostgroup', + name: 'memberhost_hostgroup', category: category, + other_entity: 'hostgroup', add_method: 'add_host', + remove_method: 'remove_host' })); + return section; + } - param_info = IPA.get_entity_param('hbacrule', 'servicecategory'); - - section = IPA.rule_details_section({ - 'name': 'service', - 'label': IPA.messages.objects.hbacrule.service, - 'text': param_info.doc+':', - 'field_name': 'servicecategory', - 'options': [ - { 'value': 'all', 'label': IPA.messages.objects.hbacrule.any_service }, - { 'value': '', 'label': IPA.messages.objects.hbacrule.specified_services } + function servicecategory_section(){ + var param_info = IPA.get_entity_param('hbacrule', 'servicecategory'); + + var section = IPA.rule_details_section({ + name: 'service', + entity:that.entity, + label: IPA.messages.objects.hbacrule.service, + text: param_info.doc+':', + field_name: 'servicecategory', + options: [ + { value: 'all', + label: IPA.messages.objects.hbacrule.any_service }, + { value: '', + label: IPA.messages.objects.hbacrule.specified_services } ], 'tables': [ - { 'field_name': 'memberservice_hbacsvc' }, - { 'field_name': 'memberservice_hbacsvcgroup' } + { field_name: 'memberservice_hbacsvc' }, + { field_name: 'memberservice_hbacsvcgroup' } ] }); - that.add_section(section); - category = section.add_field(IPA.radio_widget({ + var category = section.add_field(IPA.radio_widget({ name: 'servicecategory' })); section.add_field(IPA.rule_association_table_widget({ - 'id': that.entity_name+'-memberservice_hbacsvc', - 'name': 'memberservice_hbacsvc', 'category': category, - 'other_entity': 'hbacsvc', 'add_method': 'add_service', 'remove_method': 'remove_service' + id: that.entity.name+'-memberservice_hbacsvc', + name: 'memberservice_hbacsvc', category: category, + other_entity: 'hbacsvc', add_method: 'add_service', + remove_method: 'remove_service' })); section.add_field(IPA.rule_association_table_widget({ - 'id': that.entity_name+'-memberservice_hbacsvcgroup', - 'name': 'memberservice_hbacsvcgroup', 'category': category, - 'other_entity': 'hbacsvcgroup', 'add_method': 'add_service', 'remove_method': 'remove_service' + id: that.entity.name+'-memberservice_hbacsvcgroup', + name: 'memberservice_hbacsvcgroup', category: category, + other_entity: 'hbacsvcgroup', add_method: 'add_service', + remove_method: 'remove_service' })); + return section; + } - param_info = IPA.get_entity_param('hbacrule', 'sourcehostcategory'); + function sourcehostcategory_section(){ - section = IPA.rule_details_section({ - 'name': 'sourcehost', - 'label': IPA.messages.objects.hbacrule.sourcehost, - 'text': param_info.doc+':', - 'field_name': 'sourcehostcategory', - 'options': [ - { 'value': 'all', 'label': IPA.messages.objects.hbacrule.any_host }, - { 'value': '', 'label': IPA.messages.objects.hbacrule.specified_hosts } + var param_info = IPA.get_entity_param('hbacrule', 'sourcehostcategory'); + + var section = IPA.rule_details_section({ + name: 'sourcehost', + entity:that.entity, + label: IPA.messages.objects.hbacrule.sourcehost, + text: param_info.doc+':', + field_name: 'sourcehostcategory', + options: [ + { value: 'all', label: IPA.messages.objects.hbacrule.any_host }, + { value: '', + label: IPA.messages.objects.hbacrule.specified_hosts } ], - 'tables': [ - { 'field_name': 'sourcehost_host' }, - { 'field_name': 'sourcehost_hostgroup' } + tables: [ + { field_name: 'sourcehost_host' }, + { field_name: 'sourcehost_hostgroup' } ] }); - that.add_section(section); - category = section.add_field(IPA.radio_widget({ + var category = section.add_field(IPA.radio_widget({ name: 'sourcehostcategory' })); section.add_field(IPA.rule_association_table_widget({ - 'id': that.entity_name+'-sourcehost_host', - 'name': 'sourcehost_host', 'category': category, - 'other_entity': 'host', 'add_method': 'add_sourcehost', 'remove_method': 'remove_sourcehost' + id: that.entity.name+'-sourcehost_host', + name: 'sourcehost_host', category: category, + other_entity: 'host', add_method: 'add_sourcehost', + remove_method: 'remove_sourcehost' })); section.add_field(IPA.rule_association_table_widget({ - 'id': that.entity_name+'-sourcehost_hostgroup', - 'name': 'sourcehost_hostgroup', 'category': category, - 'other_entity': 'hostgroup', 'add_method': 'add_sourcehost', 'remove_method': 'remove_sourcehost' + id: that.entity.name+'-sourcehost_hostgroup', + name: 'sourcehost_hostgroup', category: category, + other_entity: 'hostgroup', add_method: 'add_sourcehost', + remove_method: 'remove_sourcehost' })); - that.details_facet_init(); - }; + return section; + } that.update = function(on_success, on_error) { - var pkey = IPA.nav.get_state(that.entity_name+'-pkey'); + var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var modify_operation = { 'execute': false, 'command': IPA.command({ - entity: that.entity_name, + entity: that.entity.name, method: 'mod', args: [pkey], options: {all: true, rights: true} @@ -331,7 +355,7 @@ IPA.hbacrule_details_facet = function(spec) { 'category': 'usercategory', 'has_values': false, 'command': IPA.command({ - entity: that.entity_name, + entity: that.entity.name, method: 'remove_user', args: [pkey], options: {all: true, rights: true} @@ -341,7 +365,7 @@ IPA.hbacrule_details_facet = function(spec) { 'category': 'hostcategory', 'has_values': false, 'command': IPA.command({ - entity: that.entity_name, + entity: that.entity.name, method: 'remove_host', args: [pkey], options: {all: true, rights: true} @@ -351,7 +375,7 @@ IPA.hbacrule_details_facet = function(spec) { 'category': 'servicecategory', 'has_values': false, 'command': IPA.command({ - entity: that.entity_name, + entity: that.entity.name, method: 'remove_service', args: [pkey], options: {all: true, rights: true} @@ -361,7 +385,7 @@ IPA.hbacrule_details_facet = function(spec) { 'category': 'sourcehostcategory', 'has_values': false, 'command': IPA.command({ - entity: that.entity_name, + entity: that.entity.name, method: 'remove_sourcehost', args: [pkey], options: {all: true, rights: true} @@ -372,7 +396,7 @@ IPA.hbacrule_details_facet = function(spec) { var enable_operation = { 'execute': false, 'command': IPA.command({ - entity: that.entity_name, + entity: that.entity.name, method: 'enable', args: [pkey], options: {all: true, rights: true} @@ -391,7 +415,7 @@ IPA.hbacrule_details_facet = function(spec) { var values = field.save(); if (!values) continue; - var param_info = IPA.get_entity_param(that.entity_name, field.name); + var param_info = IPA.get_entity_param(that.entity.name, field.name); // skip primary key if (param_info && param_info['primary_key']) continue; @@ -469,6 +493,7 @@ IPA.hbacrule_details_facet = function(spec) { } } + if (modify_operation.execute) batch.add_command(modify_operation.command); if (enable_operation.execute) batch.add_command(enable_operation.command); @@ -480,170 +505,18 @@ IPA.hbacrule_details_facet = function(spec) { batch.execute(); }; - return that; -}; - - -IPA.hbacrule_details_general_section = function(spec) { - - spec = spec || {}; - - var that = IPA.details_section(spec); - - that.create = function(container) { - - var table = $('', { - 'style': 'width: 100%;' - }).appendTo(container); - - var tr = $('').appendTo(table); - - var td = $('').appendTo(table); - - td = $('
', { - 'style': 'width: 100px; text-align: right;' - }).appendTo(tr); + /*initialization*/ + that.add_section(general_section()); + that.add_section(user_category_section()); + that.add_section(hostcategory_section()); + that.add_section(servicecategory_section()); + that.add_section(sourcehostcategory_section()); - var param_info = IPA.get_entity_param('hbacrule', 'cn'); - td.append(param_info.label+':'); - - td = $('').appendTo(tr); - - var field = that.get_field('cn'); - var span = $('', { - name: 'cn', - 'class': 'details-field' - }).appendTo(td); - - $('', { - 'style': 'text-align: right;' - }).appendTo(tr); - - param_info = IPA.get_entity_param('hbacrule', 'accessruletype'); - td.append(param_info.label+':'); - - field = that.get_field('accessruletype'); - span = $('', { - name: 'accessruletype', - 'class': 'details-field' - }).appendTo(td); - - $('', { - 'type': 'radio', - 'name': 'accessruletype', - 'value': 'allow' - }).appendTo(span); - - span.append(' '); - - span.append(IPA.messages.objects.hbacrule.allow); - - span.append(' '); - - $('', { - 'type': 'radio', - 'name': 'accessruletype', - 'value': 'deny' - }).appendTo(span); - - span.append(' '); - - span.append(IPA.messages.objects.hbacrule.deny); - - span.append(' '); - - field.create_undo(span); - - tr = $('
', { - 'style': 'text-align: right; vertical-align: top;' - }).appendTo(tr); - - param_info = IPA.get_entity_param('hbacrule', 'description'); - td.append(param_info.label+':'); - - td = $('', { - 'colspan': 2 - }).appendTo(tr); - - field = that.get_field('description'); - span = $('', { - name: 'description', - 'class': 'details-field' - }).appendTo(td); - - $('