diff --git a/install/static/add.js b/install/static/add.js index 671d11f96..9c68aea31 100644 --- a/install/static/add.js +++ b/install/static/add.js @@ -21,160 +21,80 @@ /* REQUIRES: ipa.js */ -var IPA_ADD_POPULATE = 1; -var IPA_ADD_UPDATE = 2; - -function ipa_add_field(spec) { - - spec = spec || {}; - - var that = {}; - that.name = spec.name; - that.label = spec.label; - that._entity_name = spec.entity_name; - - that.init = spec.init; - that.setup = spec.setup; - - that.__defineGetter__("entity_name", function(){ - return that._entity_name; - }); - - that.__defineSetter__("entity_name", function(entity_name){ - that._entity_name = entity_name; - }); - - return that; -} - function ipa_add_dialog(spec) { spec = spec || {}; - var that = {}; + var that = ipa_dialog(spec); + that.name = spec.name; that.title = spec.title; that._entity_name = spec.entity_name; - that.init = spec.init; + that.init = function() { - that.fields = []; - that.fields_by_name = {}; + that.add_button('Add', function() { + var record = that.get_record(); + that.add( + record, + function() { + var entity = IPA.get_entity(that.entity_name); + var facet = entity.get_facet('search'); + var table = facet.table; + table.refresh(that.container); + that.clear(that.container); + } + ); + }); - var dialog = $('
'); + that.add_button('Add and Edit', function() { + var record = that.get_record(); + that.add( + record, + function() { + that.close(); - that.__defineGetter__("entity_name", function(){ - return that._entity_name; - }); + var pkey_name = IPA.metadata[that.entity_name].primary_key; + var pkey = record[pkey_name]; - that.__defineSetter__("entity_name", function(entity_name){ - that._entity_name = entity_name; + var state = {}; + state[that.entity_name + '-facet'] = 'details'; + state[that.entity_name + '-pkey'] = pkey; + $.bbq.pushState(state); + }, + function() { that.close(); } + ); + }); - for (var i=0; i' + field.label + ''); - dialog.append(''); - dialog.append('
'); - } - } - - dialog.dialog({ - modal: true, - buttons: { - 'Add': that.add, - 'Add and edit': that.add_and_edit, - 'Cancel': that.cancel - } + that.add_button('Cancel', function() { + that.close(); }); }; - that.add = function(evt, called_from_add_and_edit) { - var pkey = []; - var options = {}; + that.add = function(record, on_success, on_error) { + var pkey_name = IPA.metadata[that.entity_name].primary_key; - function add_win(data, text_status, xhr) { - if (called_from_add_and_edit) { - var state = {}; - state[that.entity_name + '-facet'] = 'details'; - state[that.entity_name + '-pkey'] = pkey[0]; - $.bbq.pushState(state); - }else{ - dialog.find('input').each( function () { - $(this).val(''); - }); - } - } - for (var i = 0; i < that.fields.length; ++i) { + var args = []; + var options = {}; + + for (var i=0; iError: '+error_thrown.name+'

'); + div.append('

'+error_thrown.title+'

'); + div.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); }; return that; @@ -373,13 +406,15 @@ function ipa_association_facet(spec) { return pkey != that.pkey || other_entity != that.other_entity; }; + that.create = function(container) { + that.setup_views(container); + }; + that.setup = function(container, unspecified) { that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; that.other_entity = $.bbq.getState(that.entity_name + '-enroll', true) || ''; - that.setup_views(container); - //TODO I18N var header_message = that.other_entity + '(s) enrolled in ' + that.entity_name + ' ' + that.pkey; @@ -403,12 +438,6 @@ function ipa_association_facet(spec) { return that; } - -function association_list_create(obj_name, jobj) -{ - search_create(obj_name, [], jobj); -} - function ipa_deleter_dialog_setup() { var that = this; diff --git a/install/static/details.js b/install/static/details.js index 9301f3102..efb896a6c 100644 --- a/install/static/details.js +++ b/install/static/details.js @@ -31,23 +31,20 @@ IPA.is_field_writable = function(rights){ alert('no right'); } return rights.indexOf('w') > -1; -} +}; function ipa_details_field(spec) { spec = spec || {}; - spec.create = spec.create || create; - spec.setup = spec.setup || setup; - spec.load = spec.load || load; - spec.save = spec.save || save; - var that = ipa_widget(spec); - function create(container) { - } + that.create = spec.create || create; + that.setup = spec.setup || setup; + that.load = spec.load || load; + that.save = spec.save || save; - function setup(container) { + function create(container) { var dl = $('dl', container); @@ -65,6 +62,9 @@ function ipa_details_field(spec) { }).appendTo(dl); } + function setup(container) { + } + function load(container, result) { var multivalue = false; @@ -187,10 +187,6 @@ function ipa_details_section(spec){ } }); - that.get_fields = function() { - return that.fields; - }; - that.get_field = function(name) { return that.fields_by_name[name]; }; @@ -231,6 +227,13 @@ function ipa_details_section(spec){ return field; }; + that.init = function() { + for (var i=0; iError: '+error_thrown.name+'

'); - details.append('

'+error_thrown.title+'

'); - details.append('

'+error_thrown.message+'

'); - } - - var params = []; - if (facet.pkey) params.push(facet.pkey); - - ipa_cmd( - 'show', params, {all: true, rights: true}, on_success, on_failure, facet.entity_name - ); -} - -function ipa_details_create(container, result) +function ipa_details_create(container) { var facet = this; @@ -364,6 +339,8 @@ function ipa_details_create(container, result) var entity_name = container.attr('id'); container.attr('title', entity_name); + facet.setup_views(container); + var details = $('
', { 'class': 'details' }).appendTo(container); @@ -377,7 +354,7 @@ function ipa_details_create(container, result) 'icon': 'ui-icon-refresh', 'class': 'details-reset', 'click': function() { - ipa_details_reset(container); + facet.reset(container); return false; } })); @@ -389,7 +366,7 @@ function ipa_details_create(container, result) 'icon': 'ui-icon-check', 'class': 'details-update', 'click': function() { - ipa_details_update(container, ipa_details_cache[facet.entity_name][pkey_name][0]); + facet.update(container, ipa_details_cache[facet.entity_name][pkey_name][0]); return false; } })); @@ -410,52 +387,111 @@ function ipa_details_create(container, result) 'class': 'details-section' }).appendTo(details); - section.setup(div, result); + section.create(div); details.append('
'); } } +function ipa_details_setup(container, unspecified) { + var that = this; -function ipa_details_section_setup(container, result) { - var section = this; - var fields = section.get_fields(); + for (var i = 0; i < that.sections.length; ++i) { + var section = that.sections[i]; - if (section.template) { - var template = IPA.get_template(section.template); - container.load(template, function(data, text_status, xhr) { - for (var i = 0; i < fields.length; ++i) { - var field = fields[i]; - field.create(container); - field.setup(container); - field.load(container, result); - } - }); - return; + var div = $( + '#'+that.entity_name+'-'+that.name+'-'+section.name, + container + ); + + section.setup(div, unspecified); + } +} + +function ipa_details_load(container, unspecified) { + + var that = this; + + that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; + if (!that.pkey && !unspecified) return; + + function on_success(data, text_status, xhr) { + var result = data.result.result; + + ipa_details_cache[that.entity_name] = $.extend(true, {}, result); + for (var i = 0; i < that.sections.length; ++i) { + var section = that.sections[i]; + + var div = $( + '#'+that.entity_name+'-'+that.name+'-'+section.name, + container + ); + + section.load(div, result); + } } - section.create(container); + function on_failure(xhr, text_status, error_thrown) { + var details = $('.details', container).empty(); + details.append('

Error: '+error_thrown.name+'

'); + details.append('

'+error_thrown.title+'

'); + details.append('

'+error_thrown.message+'

'); + } + var params = []; + if (that.pkey) params.push(that.pkey); + + ipa_cmd( + 'show', params, {all: true, rights: true}, on_success, on_failure, that.entity_name + ); +} + +function ipa_details_section_create(container) { + + var that = this; + if (that.template) return; + + var dl = $('
', { + 'id': that.name, + 'class': 'entryattrs' + }).appendTo(container); + + var fields = that.fields; for (var i = 0; i < fields.length; ++i) { var field = fields[i]; field.create(container); - field.setup(container); - field.load(container, result); } } -function ipa_details_section_create(container, result) { - var section = this; +function ipa_details_section_setup(container, unspecified) { + var that = this; + if (that.template) return; - var dl = $('
', { - 'id': section.name, - 'class': 'entryattrs' - }).appendTo(container); + var fields = that.fields; + for (var i = 0; i < fields.length; ++i) { + var field = fields[i]; + field.setup(container); + } } function ipa_details_section_load(container, result) { - var section = this; - var fields = section.get_fields(); + var that = this; + var fields = that.fields; + + if (that.template) { + var template = IPA.get_template(that.template); + container.load( + template, + function(data, text_status, xhr) { + for (var i = 0; i < fields.length; ++i) { + var field = fields[i]; + field.setup(container); + field.load(container, result); + } + } + ); + return; + } for (var j=0; j tags i.e. all attribute values */ $('dd', container).remove(); /* go through all
tags and pair them with newly created
s */ - var facet = ipa_entity_get_details_facet(entity_name); - var sections = facet.get_sections(); - for (var i=0; i', {'class': 'entity-views'}).appendTo(container); var entity = IPA.get_entity(facet.entity_name); - var facets = entity.get_facets(); - for (var i=0; i").appendTo(tr); + var span = $('span[name="'+name+'"]', container); + span.empty(); $("", { - href: "#details", - title: "Details", + href: '#details', + title: 'Details', + text: 'Details', click: function() { var state = {}; state[obj_name+'-facet'] = 'details'; @@ -370,7 +389,7 @@ function ipa_entity_quick_links(tr, attr, value, entry_attrs) { nav_push_state(state); return false; } - }).appendTo(td); + }).appendTo(span); var attribute_members = IPA.metadata[obj_name].attribute_members; for (attr_name in attribute_members) { @@ -379,6 +398,8 @@ function ipa_entity_quick_links(tr, attr, value, entry_attrs) { var m = objs[i]; var label = IPA.metadata[m].label; + span.append(' | '); + $("", { href: '#'+m, title: label, @@ -393,7 +414,7 @@ function ipa_entity_quick_links(tr, attr, value, entry_attrs) { return false; } }(m) - }).append(' | ' ).appendTo(td); + }).appendTo(span); } } } diff --git a/install/static/group.js b/install/static/group.js index 1d1e9b5ce..97f498ae2 100644 --- a/install/static/group.js +++ b/install/static/group.js @@ -20,6 +20,52 @@ /* REQUIRES: ipa.js, details.js, search.js, add.js, entity.js */ +function ipa_group() { + + var that = ipa_entity({ + 'name': 'group' + }); + + that.super_init = that.super('init'); + + that.init = function() { + + var dialog = ipa_group_add_dialog({ + 'name': 'add', + 'title': 'Add New Group' + }); + that.add_dialog(dialog); + dialog.init(); + + that.super_init(); + }; + + return that; +} + +IPA.add_entity(ipa_group()); + +function ipa_group_add_dialog(spec) { + + spec = spec || {}; + + var that = ipa_add_dialog(spec); + + that.super_init = that.super('init'); + + that.init = function() { + + this.super_init(); + + this.add_field(ipa_text_widget({name:'cn', label:'Name'})); + this.add_field(ipa_text_widget({name:'description', label:'Description'})); + this.add_field(ipa_checkbox_widget({name:'posix', label:'Is this a POSIX group?'})); + this.add_field(ipa_text_widget({name:'gidnumber', label:'GID'})); + }; + + return that; +} + ipa_entity_set_search_definition('group', [ ['cn', 'Name', null], ['gidnumber', 'GID', null], @@ -27,15 +73,6 @@ ipa_entity_set_search_definition('group', [ ['quick_links', 'Quick Links', ipa_entity_quick_links] ]); -ipa_entity_set_add_definition('group', [ - 'dialog-add-group', 'Add New Group', [ - ['cn', 'Name', null], - ['description', 'Description', null], - ['posix', 'Is this a POSIX group?', f_posix], - ['gidnumber', 'GID', null] - ] -]); - ipa_entity_set_details_definition('group',[ ipa_stanza({name:'identity', label:'Group Details'}). input({name:'cn', label:'Group Name'}). @@ -48,24 +85,3 @@ ipa_entity_set_association_definition('group', { 'rolegroup': { associator: 'serial' }, 'taskgroup': { associator: 'serial' } }); - -function f_posix(dlg, mode) -{ - function checkbox_on_click() { - var jobj = $(this); - if (jobj.attr('checked')) - jobj.attr('checked', false); - else - jobj.attr('checked', true); - }; - - if (mode == IPA_ADD_POPULATE) { - dlg.append(''); - dlg.append(''); - dlg.children().last().click(checkbox_on_click); - } else { - if (dlg.find('input:checkbox[name=posix]').attr('checked')) - return (true); - return (false); - } -} diff --git a/install/static/hbac.js b/install/static/hbac.js index f81fe5d7d..fed645129 100755 --- a/install/static/hbac.js +++ b/install/static/hbac.js @@ -26,114 +26,144 @@ function ipa_hbac() { 'name': 'hbac' }); + that.super_init = that.super('init'); + that.init = function() { - that.create_add_dialog({ + var dialog = ipa_hbac_add_dialog({ 'name': 'add', - 'title': 'Add New Rule', - 'init': ipa_hbac_add_init + 'title': 'Add New Rule' }); + that.add_dialog(dialog); + dialog.init(); - that.create_search_facet({ + var facet = ipa_hbac_search_facet({ 'name': 'search', - 'label': 'Search', - 'init': ipa_hbac_search_init, - 'setup': ipa_hbac_search_setup + 'label': 'Search' }); + that.add_facet(facet); - that.create_details_facet({ + facet = ipa_hbac_details_facet({ 'name': 'details', - 'label': 'Details', - 'init': ipa_hbac_details_init + 'label': 'Details' }); - }; + that.add_facet(facet); - that.init(); + that.super_init(); + }; return that; } IPA.add_entity(ipa_hbac()); -function ipa_hbac_add_init() { - this.create_field({name:'cn', label:'Rule Name'}); - this.create_field({name:'accessruletype', label:'Rule type (allow/deny)'}); +function ipa_hbac_add_dialog(spec) { + + spec = spec || {}; + + var that = ipa_add_dialog(spec); + + that.super_init = that.super('init'); + + that.init = function() { + + that.super_init(); + + that.add_field(ipa_text_widget({ + 'name': 'cn', + 'label': 'Rule Name' + })); + + that.add_field(ipa_text_widget({ + 'name': 'accessruletype', + 'label': 'Rule type (allow/deny)' + })); + }; + + return that; } -function ipa_hbac_search_init() { +function ipa_hbac_search_facet(spec) { - this.create_column({name:'cn', label:'Rule Name'}); - this.create_column({name:'usercategory', label:'Who'}); - this.create_column({name:'hostcategory', label:'Accessing'}); - this.create_column({name:'servicecategory', label:'Via Service'}); - this.create_column({name:'sourcehostcategory', label:'From'}); - this.create_column({name:'ipaenabledflag', label:'Active'}); + spec = spec || {}; - this.create_column({ - name: 'quick_links', - label: 'Quick Links', - setup: ipa_hbac_quick_links - }); -} + var that = ipa_search_facet(spec); -function ipa_hbac_search_setup(container) { + that.super_init = that.super('init'); + that.super_create = that.super('create'); + that.super_setup = that.super('setup'); - var that = this; + that.init = function() { - that.filter = $.bbq.getState(that.entity_name + '-filter', true) || ''; + that.create_column({name:'cn', label:'Rule Name'}); + that.create_column({name:'usercategory', label:'Who'}); + that.create_column({name:'hostcategory', label:'Accessing'}); + that.create_column({name:'ipaenabledflag', label:'Active'}); + that.create_column({name:'servicecategory', label:'Via Service'}); + that.create_column({name:'sourcehostcategory', label:'From'}); + + that.create_column({ + name: 'quick_links', + label: 'Quick Links', + setup: ipa_hbac_quick_links + }); + + that.super_init(); + }; + + that.create = function(container) { + + var that = this; /* - // Not yet implemented + // Not yet implemented - var left_buttons = $('', { - 'style': 'float: left;' - }).appendTo(container); + var left_buttons = $('', { + 'style': 'float: left;' + }).appendTo(container); - left_buttons.append(ipa_button({ - 'label': 'Troubleshoot Rules' - })); + left_buttons.append(ipa_button({ + 'label': 'Troubleshoot Rules' + })); - left_buttons.append(ipa_button({ - 'label': 'Cull Disabled Rules' - })); - - var right_buttons = $('', { - 'style': 'float: right;' - }).appendTo(container); - - right_buttons.append(ipa_button({ - 'label': 'Login Services' - })); - - right_buttons.append(ipa_button({ - 'label': 'Login Svc Groups' - })); - - container.append('

'); + left_buttons.append(ipa_button({ + 'label': 'Cull Disabled Rules' + })); */ - search_create(that.entity_name, that.columns, container); + var right_buttons = $('', { + 'style': 'float: right;' + }).appendTo(container); - ipa_button({ - 'label': IPA.messages.button.add, - 'icon': 'ui-icon-plus', - 'click': function() { - var entity = IPA.get_entity(that.entity_name); - entity.add_dialog.open(); - return false; - } - }).appendTo($('.search-controls', container)); + right_buttons.append(ipa_button({ + 'label': 'HBAC Services', + 'click': function() { + var state = {}; + state['entity'] = 'hbacsvc'; + nav_push_state(state); + return false; + } + })); +/* + right_buttons.append(ipa_button({ + 'label': 'Login Svc Groups' + })); +*/ + container.append('

'); - search_load(container, that.filter); + that.super_create(container); + }; + + return that; } -function ipa_hbac_quick_links(tr, attr, value, entry_attrs) { +function ipa_hbac_quick_links(container, name, value, record) { var column = this; var facet = column.facet; var pkey = IPA.metadata[column.entity_name].primary_key; - var pkey_value = entry_attrs[pkey][0]; + var pkey_value = record[pkey]; - var td = $('').appendTo(tr); + var span = $('span[name='+name+']', container); $('
', { 'href': '#details', @@ -146,9 +176,9 @@ function ipa_hbac_quick_links(tr, attr, value, entry_attrs) { nav_push_state(state); return false; } - }).appendTo(td); + }).appendTo(span); - td.append(' | '); + span.append(' | '); $('', { 'href': '#test-rule', @@ -161,212 +191,224 @@ function ipa_hbac_quick_links(tr, attr, value, entry_attrs) { nav_push_state(state); return false; } - }).appendTo(td); + }).appendTo(span); } -function ipa_hbac_details_init() { +function ipa_hbac_details_facet(spec) { - var that = this; - var section; + spec = spec || {}; - if (IPA.layout) { - section = that.create_section({ - 'name': 'general', - 'label': 'General', - 'template': 'hbac-details-general.html #contents' - }); + var that = ipa_details_facet(spec); - } else { - section = ipa_hbac_details_general_section({ - 'name': 'general', - 'label': 'General' - }); - that.add_section(section); - } + that.super_init = that.super('init'); + that.super_create = that.super('create'); + that.super_setup = that.super('setup'); - section.create_text({ 'name': 'cn', 'label': 'Name' }); - section.create_radio({ 'name': 'accessruletype', 'label': 'Rule Type' }); - section.create_textarea({ 'name': 'description', 'label': 'Description' }); - section.create_radio({ 'name': 'ipaenabledflag', 'label': 'Enabled' }); + that.init = function() { - if (IPA.layout) { - section = that.create_section({ - 'name': 'user', - 'label': 'Who', - 'template': 'hbac-details-user.html #contents' - }); + var section; - } else { - section = ipa_hbac_details_tables_section({ - 'name': 'user', - 'label': 'Who', - 'text': 'Rule applies when access is requested by:', - 'field_name': 'usercategory', - 'options': [ - { 'value': 'all', 'label': 'Anyone' }, - { 'value': '', 'label': 'Specified Users and Groups' } - ], - 'tables': [ - { 'field_name': 'memberuser_user' }, - { 'field_name': 'memberuser_group' } - ] - }); - that.add_section(section); - } + if (IPA.layout) { + section = that.create_section({ + 'name': 'general', + 'label': 'General', + 'template': 'hbac-details-general.html #contents' + }); - section.create_radio({ name: 'usercategory', label: 'User category' }); - section.add_field(ipa_hbac_association_widget({ - 'id': that.entity_name+'-memberuser_user', - 'name': 'memberuser_user', 'label': 'Users', - 'other_entity': 'user', 'add_method': 'add_user', 'delete_method': 'remove_user' - })); - section.add_field(ipa_hbac_association_widget({ - 'id': that.entity_name+'-memberuser_group', - 'name': 'memberuser_group', 'label': 'Groups', - 'other_entity': 'group', 'add_method': 'add_user', 'delete_method': 'remove_user' - })); + } else { + section = ipa_hbac_details_general_section({ + 'name': 'general', + 'label': 'General' + }); + that.add_section(section); + } - if (IPA.layout) { - section = that.create_section({ - 'name': 'host', - 'label': 'Accessing', - 'template': 'hbac-details-host.html #contents' - }); + section.create_text({ 'name': 'cn', 'label': 'Name' }); + section.create_radio({ 'name': 'accessruletype', 'label': 'Rule Type' }); + section.create_textarea({ 'name': 'description', 'label': 'Description' }); + section.create_radio({ 'name': 'ipaenabledflag', 'label': 'Enabled' }); - } else { - section = ipa_hbac_details_tables_section({ - 'name': 'host', - 'label': 'Accessing', - 'text': 'Rule applies when access is requested to:', - 'field_name': 'hostcategory', - 'options': [ - { 'value': 'all', 'label': 'Any Host' }, - { 'value': '', 'label': 'Specified Hosts and Groups' } - ], - 'tables': [ - { 'field_name': 'memberhost_host' }, - { 'field_name': 'memberhost_hostgroup' } - ], - 'columns': [ - ] - }); - that.add_section(section); - } + if (IPA.layout) { + section = that.create_section({ + 'name': 'user', + 'label': 'Who', + 'template': 'hbac-details-user.html #contents' + }); - section.create_radio({ 'name': 'hostcategory', 'label': 'Host category' }); - section.add_field(ipa_hbac_association_widget({ - 'id': that.entity_name+'-memberhost_host', - 'name': 'memberhost_host', 'label': 'Hosts', - 'other_entity': 'host', 'add_method': 'add_host', 'delete_method': 'remove_host' - })); - section.add_field(ipa_hbac_association_widget({ - 'id': that.entity_name+'-memberhost_hostgroup', - 'name': 'memberhost_hostgroup', 'label': 'Host Groups', - 'other_entity': 'hostgroup', 'add_method': 'add_host', 'delete_method': 'remove_host' - })); + } else { + section = ipa_hbac_details_tables_section({ + 'name': 'user', + 'label': 'Who', + 'text': 'Rule applies when access is requested by:', + 'field_name': 'usercategory', + 'options': [ + { 'value': 'all', 'label': 'Anyone' }, + { 'value': '', 'label': 'Specified Users and Groups' } + ], + 'tables': [ + { 'field_name': 'memberuser_user' }, + { 'field_name': 'memberuser_group' } + ] + }); + that.add_section(section); + } - if (IPA.layout) { - section = that.create_section({ - 'name': 'service', - 'label': 'Via Service', - 'template': 'hbac-details-service.html #contents' - }); + section.create_radio({ name: 'usercategory', label: 'User category' }); + section.add_field(ipa_hbac_association_widget({ + 'id': that.entity_name+'-memberuser_user', + 'name': 'memberuser_user', 'label': 'Users', + 'other_entity': 'user', 'add_method': 'add_user', 'delete_method': 'remove_user' + })); + section.add_field(ipa_hbac_association_widget({ + 'id': that.entity_name+'-memberuser_group', + 'name': 'memberuser_group', 'label': 'Groups', + 'other_entity': 'group', 'add_method': 'add_user', 'delete_method': 'remove_user' + })); - } else { - section = ipa_hbac_details_tables_section({ - 'name': 'service', - 'label': 'Via Service', - 'text': 'Rule applies when access is requested via:', - 'field_name': 'servicecategory', - 'options': [ - { 'value': 'all', 'label': 'Any Service' }, - { 'value': '', 'label': 'Specified Services and Groups' } - ], - 'tables': [ - { 'field_name': 'memberservice_hbacsvc' }, - { 'field_name': 'memberservice_hbacsvcgroup' } - ] - }); - that.add_section(section); - } + if (IPA.layout) { + section = that.create_section({ + 'name': 'host', + 'label': 'Accessing', + 'template': 'hbac-details-host.html #contents' + }); - section.create_radio({ 'name': 'servicecategory', 'label': 'Service category' }); - section.add_field(ipa_hbac_association_widget({ - 'id': that.entity_name+'-memberservice_hbacsvc', - 'name': 'memberservice_hbacsvc', 'label': 'Services', - 'other_entity': 'hbacsvc', 'add_method': 'add_service', 'delete_method': 'remove_service' - })); - section.add_field(ipa_hbac_association_widget({ - 'id': that.entity_name+'-memberservice_hbacsvcgroup', - 'name': 'memberservice_hbacsvcgroup', 'label': 'Service Groups', - 'other_entity': 'hbacsvcgroup', 'add_method': 'add_service', 'delete_method': 'remove_service' - })); + } else { + section = ipa_hbac_details_tables_section({ + 'name': 'host', + 'label': 'Accessing', + 'text': 'Rule applies when access is requested to:', + 'field_name': 'hostcategory', + 'options': [ + { 'value': 'all', 'label': 'Any Host' }, + { 'value': '', 'label': 'Specified Hosts and Groups' } + ], + 'tables': [ + { 'field_name': 'memberhost_host' }, + { 'field_name': 'memberhost_hostgroup' } + ] + }); + that.add_section(section); + } - if (IPA.layout) { - section = that.create_section({ - 'name': 'sourcehost', - 'label': 'From', - 'template': 'hbac-details-sourcehost.html #contents' - }); + section.create_radio({ 'name': 'hostcategory', 'label': 'Host category' }); + section.add_field(ipa_hbac_association_widget({ + 'id': that.entity_name+'-memberhost_host', + 'name': 'memberhost_host', 'label': 'Hosts', + 'other_entity': 'host', 'add_method': 'add_host', 'delete_method': 'remove_host' + })); + section.add_field(ipa_hbac_association_widget({ + 'id': that.entity_name+'-memberhost_hostgroup', + 'name': 'memberhost_hostgroup', 'label': 'Host Groups', + 'other_entity': 'hostgroup', 'add_method': 'add_host', 'delete_method': 'remove_host' + })); - } else { - section = ipa_hbac_details_tables_section({ - 'name': 'sourcehost', - 'label': 'From', - 'text': 'Rule applies when access is being initiated from:', - 'field_name': 'sourcehostcategory', - 'options': [ - { 'value': 'all', 'label': 'Any Host' }, - { 'value': '', 'label': 'Specified Hosts and Groups' } - ], - 'tables': [ - { 'field_name': 'sourcehost_host' }, - { 'field_name': 'sourcehost_hostgroup' } - ] - }); - that.add_section(section); - } + if (IPA.layout) { + section = that.create_section({ + 'name': 'service', + 'label': 'Via Service', + 'template': 'hbac-details-service.html #contents' + }); - section.create_radio({ 'name': 'sourcehostcategory', 'label': 'Source host category' }); - section.add_field(ipa_hbac_association_widget({ - 'id': that.entity_name+'-sourcehost_host', - 'name': 'sourcehost_host', 'label': 'Host', - 'other_entity': 'host', 'add_method': 'add_sourcehost', 'delete_method': 'remove_sourcehost' - })); - section.add_field(ipa_hbac_association_widget({ - 'id': that.entity_name+'-sourcehost_hostgroup', - 'name': 'sourcehost_hostgroup', 'label': 'Host Groups', - 'other_entity': 'hostgroup', 'add_method': 'add_sourcehost', 'delete_method': 'remove_sourcehost' - })); + } else { + section = ipa_hbac_details_tables_section({ + 'name': 'service', + 'label': 'Via Service', + 'text': 'Rule applies when access is requested via:', + 'field_name': 'servicecategory', + 'options': [ + { 'value': 'all', 'label': 'Any Service' }, + { 'value': '', 'label': 'Specified Services and Groups' } + ], + 'tables': [ + { 'field_name': 'memberservice_hbacsvc' }, + { 'field_name': 'memberservice_hbacsvcgroup' } + ] + }); + that.add_section(section); + } - if (IPA.layout) { - section = that.create_section({ - 'name': 'accesstime', - 'label': 'When', - 'template': 'hbac-details-accesstime.html #contents' - }); + section.create_radio({ 'name': 'servicecategory', 'label': 'Service category' }); + section.add_field(ipa_hbac_association_widget({ + 'id': that.entity_name+'-memberservice_hbacsvc', + 'name': 'memberservice_hbacsvc', 'label': 'Services', + 'other_entity': 'hbacsvc', 'add_method': 'add_service', 'delete_method': 'remove_service' + })); + section.add_field(ipa_hbac_association_widget({ + 'id': that.entity_name+'-memberservice_hbacsvcgroup', + 'name': 'memberservice_hbacsvcgroup', 'label': 'Service Groups', + 'other_entity': 'hbacsvcgroup', 'add_method': 'add_service', 'delete_method': 'remove_service' + })); - } else { - section = ipa_hbac_details_tables_section({ - 'name': 'accesstime', - 'label': 'When', - 'text': 'Rule applies when access is being requested at:', - 'field_name': 'accesstime', - 'options': [ - { 'value': 'all', 'label': 'Any Time' }, - { 'value': '', 'label': 'Specified Times' } - ], - 'tables': [ - { 'field_name': 'accesstime' } - ] - }); - that.add_section(section); - } + if (IPA.layout) { + section = that.create_section({ + 'name': 'sourcehost', + 'label': 'From', + 'template': 'hbac-details-sourcehost.html #contents' + }); - section.add_field(ipa_hbac_accesstime_widget({ - 'id': that.entity_name+'-accesstime', - 'name': 'accesstime', 'label': 'Access Time' - })); + } else { + section = ipa_hbac_details_tables_section({ + 'name': 'sourcehost', + 'label': 'From', + 'text': 'Rule applies when access is being initiated from:', + 'field_name': 'sourcehostcategory', + 'options': [ + { 'value': 'all', 'label': 'Any Host' }, + { 'value': '', 'label': 'Specified Hosts and Groups' } + ], + 'tables': [ + { 'field_name': 'sourcehost_host' }, + { 'field_name': 'sourcehost_hostgroup' } + ] + }); + that.add_section(section); + } + + section.create_radio({ 'name': 'sourcehostcategory', 'label': 'Source host category' }); + section.add_field(ipa_hbac_association_widget({ + 'id': that.entity_name+'-sourcehost_host', + 'name': 'sourcehost_host', 'label': 'Host', + 'other_entity': 'host', 'add_method': 'add_sourcehost', 'delete_method': 'remove_sourcehost' + })); + section.add_field(ipa_hbac_association_widget({ + 'id': that.entity_name+'-sourcehost_hostgroup', + 'name': 'sourcehost_hostgroup', 'label': 'Host Groups', + 'other_entity': 'hostgroup', 'add_method': 'add_sourcehost', 'delete_method': 'remove_sourcehost' + })); + + if (IPA.layout) { + section = that.create_section({ + 'name': 'accesstime', + 'label': 'When', + 'template': 'hbac-details-accesstime.html #contents' + }); + + } else { + section = ipa_hbac_details_tables_section({ + 'name': 'accesstime', + 'label': 'When', + 'text': 'Rule applies when access is being requested at:', + 'field_name': 'accesstime', + 'options': [ + { 'value': 'all', 'label': 'Any Time' }, + { 'value': '', 'label': 'Specified Times' } + ], + 'tables': [ + { 'field_name': 'accesstime' } + ] + }); + that.add_section(section); + } + + section.add_field(ipa_hbac_accesstime_widget({ + 'id': that.entity_name+'-accesstime', + 'name': 'accesstime', 'label': 'Access Time' + })); + + that.super_init(); + }; + + return that; } function ipa_hbac_details_general_section(spec){ @@ -473,8 +515,6 @@ function ipa_hbac_details_tables_section(spec){ spec = spec || {}; - spec.create = create; - var that = ipa_details_section(spec); that.text = spec.text; @@ -485,7 +525,7 @@ function ipa_hbac_details_tables_section(spec){ that.super_setup = that.super('setup'); - function create(container) { + that.create = function(container) { if (that.template) return; @@ -512,7 +552,13 @@ function ipa_hbac_details_tables_section(spec){ 'id': that.entity_name+'-'+table.field_name }).appendTo(container); } - } + + var fields = that.fields; + for (var i = 0; i < fields.length; ++i) { + var field = fields[i]; + field.create(container); + } + }; return that; } @@ -528,30 +574,30 @@ function ipa_hbac_association_widget(spec) { that.add_method = spec.add_method; that.delete_method = spec.delete_method; + that.super_init = that.super('init'); that.super_create = that.super('create'); that.super_setup = that.super('setup'); - that.create = function(container) { - - // create a column when none defined + 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, - 'link': false + 'primary_key': true }); } + that.super_init(); + }; + + that.create = function(container) { + that.super_create(container); var div = $('#'+that.id, container); var buttons = $('span[name=buttons]', div); - if (buttons.children().length) { - // widget loaded from template - return; - } $('', { 'type': 'button', @@ -588,7 +634,6 @@ function ipa_hbac_association_widget(spec) { var dialog = ipa_association_adder_dialog({ 'title': title, - 'parent': container, 'entity_name': that.entity_name, 'pkey': pkey, 'other_entity': that.other_entity, @@ -604,7 +649,9 @@ function ipa_hbac_association_widget(spec) { } }); - dialog.open(); + dialog.init(); + + dialog.open(container); }; that.remove = function(container) { @@ -622,7 +669,6 @@ function ipa_hbac_association_widget(spec) { var dialog = ipa_association_deleter_dialog({ 'title': title, - 'parent': container, 'entity_name': that.entity_name, 'pkey': pkey, 'other_entity': that.other_entity, @@ -639,7 +685,40 @@ function ipa_hbac_association_widget(spec) { } }); - dialog.open(); + dialog.init(); + + dialog.open(container); + }; + + that.refresh = function(container) { + + function on_success(data, text_status, xhr) { + + that.tbody.empty(); + + var column_name = that.columns[0].name; + var values = data.result.result[column_name]; + //TODO, this is masking an error where the wrong + //direction association is presented upon page reload. + //if the values is unset, it is because + //form.associationColumns[0] doesn't exist in the results + if (!values) return; + + for (var i = 0; iError: '+error_thrown.name+'

'); + div.append('

'+error_thrown.title+'

'); + div.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.save = function(container) { @@ -655,30 +734,30 @@ function ipa_hbac_accesstime_widget(spec) { var that = ipa_table_widget(spec); + that.super_init = that.super('init'); that.super_create = that.super('create'); that.super_setup = that.super('setup'); - that.create = function(container) { - - // create a column when none defined + that.init = function() { + // create a column if none defined if (!that.columns.length) { that.create_column({ 'name': that.name, 'label': that.label, - 'primary_key': true, - 'link': false + 'primary_key': true }); } + that.super_init(); + }; + + that.create = function(container) { + that.super_create(container); var div = $('#'+that.id); var buttons = $('span[name=buttons]', div); - if (buttons.children().length) { - // widget loaded from template - return; - } $('', { 'type': 'button', @@ -716,8 +795,7 @@ function ipa_hbac_accesstime_widget(spec) { var title = 'Add '+that.label+' to '+that.entity_name+' '+pkey; var dialog = ipa_dialog({ - 'title': title, - 'parent': container + 'title': title }); dialog.add_field(ipa_text_widget({ @@ -782,7 +860,9 @@ function ipa_hbac_accesstime_widget(spec) { } dialog.add_button('Add', function() { - add(); + add( + function() { dialog.clear(container); } + ); }); dialog.add_button('Add and Close', function() { @@ -796,7 +876,9 @@ function ipa_hbac_accesstime_widget(spec) { dialog.close(); }); - dialog.open(); + dialog.init(); + + dialog.open(container); }; that.remove = function(container) { @@ -813,11 +895,10 @@ function ipa_hbac_accesstime_widget(spec) { var dialog = ipa_deleter_dialog({ 'title': title, - 'parent': container, 'values': values }); - that.remove = function() { + dialog.remove = function() { var batch = ipa_batch_command(); for (var i=0; iError: '+error_thrown.name+'

'); + div.append('

'+error_thrown.title+'

'); + div.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.save = function(container) { diff --git a/install/static/hbacsvc.js b/install/static/hbacsvc.js new file mode 100755 index 000000000..268ce4c5d --- /dev/null +++ b/install/static/hbacsvc.js @@ -0,0 +1,177 @@ +/* Authors: + * Endi Sukma Dewata + * + * Copyright (C) 2010 Red Hat + * see file 'COPYING' for use and warranty information + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; version 2 only + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* REQUIRES: ipa.js, details.js, search.js, add.js, entity.js */ + +function ipa_hbacsvc() { + + var that = ipa_entity({ + 'name': 'hbacsvc' + }); + + that.super_init = that.super('init'); + + that.init = function() { + + var dialog = ipa_hbacsvc_add_dialog({ + 'name': 'add', + 'title': 'Add New HBAC Service' + }); + that.add_dialog(dialog); + dialog.init(); + + var facet = ipa_hbacsvc_search_facet({ + 'name': 'search', + 'label': 'Search' + }); + that.add_facet(facet); + + facet = ipa_hbacsvc_details_facet({ + 'name': 'details', + 'label': 'Details' + }); + that.add_facet(facet); + + that.super_init(); + }; + + return that; +} + +IPA.add_entity(ipa_hbacsvc()); + +function ipa_hbacsvc_add_dialog(spec) { + + spec = spec || {}; + + var that = ipa_add_dialog(spec); + + that.super_init = that.super('init'); + + that.init = function() { + + this.super_init(); + + this.add_field(ipa_text_widget({name:'cn', label:'Name'})); + this.add_field(ipa_text_widget({name:'description', label:'Description'})); + }; + + return that; +} + +function ipa_hbacsvc_search_facet(spec) { + + spec = spec || {}; + + var that = ipa_search_facet(spec); + + that.super_init = that.super('init'); + that.super_create = that.super('create'); + that.super_setup = that.super('setup'); + + that.init = function() { + + that.create_column({name:'cn', label:'Service', primary_key: true}); + that.create_column({name:'description', label:'Description'}); + + that.create_column({ + name: 'quick_links', + label: 'Quick Links', + setup: ipa_hbacsvc_quick_links + }); + + that.super_init(); + }; + + that.create = function(container) { + + var that = this; + + var right_buttons = $('', { + 'style': 'float: right;' + }).appendTo(container); + + right_buttons.append(ipa_button({ + 'label': 'HBAC Rules', + 'click': function() { + var state = {}; + state['entity'] = 'hbac'; + nav_push_state(state); + return false; + } + })); + container.append('

'); + + that.super_create(container); + }; + + return that; +} + + +function ipa_hbacsvc_quick_links(container, name, value, record) { + + var that = this; + + var pkey = IPA.metadata[that.entity_name].primary_key; + var pkey_value = record[pkey]; + + var link = $('
', { + 'href': '#details', + 'title': 'Details', + 'text': 'Details', + 'click': function() { + var state = {}; + state[that.entity_name+'-facet'] = 'details'; + state[that.entity_name+'-pkey'] = pkey_value; + nav_push_state(state); + return false; + } + }); + + var span = $('span[name="'+name+'"]', container); + span.html(link); +} + +function ipa_hbacsvc_details_facet(spec) { + + spec = spec || {}; + + var that = ipa_details_facet(spec); + + that.super_init = that.super('init'); + that.super_create = that.super('create'); + that.super_setup = that.super('setup'); + + that.init = function() { + + var section = that.create_section({ + 'name': 'general', + 'label': 'General' + }); + + section.create_field({ 'name': 'cn', 'label': 'Name' }); + section.create_field({ 'name': 'description', 'label': 'Description' }); + + that.super_init(); + }; + + return that; +} \ No newline at end of file diff --git a/install/static/index.xhtml b/install/static/index.xhtml index 4ba51fa38..4ca93f712 100644 --- a/install/static/index.xhtml +++ b/install/static/index.xhtml @@ -24,6 +24,7 @@ + diff --git a/install/static/ipa.js b/install/static/ipa.js index f7fd90500..ca4e958d3 100644 --- a/install/static/ipa.js +++ b/install/static/ipa.js @@ -22,7 +22,6 @@ /*global $:true, location:true */ /*Forward defined due to circular dependency with IPA.*/ -var ipa_cmd; var IPA = ( function () { var that = { diff --git a/install/static/navigation.js b/install/static/navigation.js index 0434f58ca..6b4419c99 100644 --- a/install/static/navigation.js +++ b/install/static/navigation.js @@ -134,7 +134,12 @@ function _nav_update_tabs(nls, container) _nav_update_tabs(tab.children, container2); } else if (tab.setup) { - var entity = IPA.get_entity(tab.name); + var entity_name = tab.name; + + // TODO: do not hard-code + if (entity_name == 'hbac' && nav_get_state('entity')) entity_name = nav_get_state('entity'); + + var entity = IPA.get_entity(entity_name); entity.setup(container2); } } diff --git a/install/static/policy.js b/install/static/policy.js index c5ca523a9..deefab0c6 100644 --- a/install/static/policy.js +++ b/install/static/policy.js @@ -249,13 +249,16 @@ function ipa_records_facet(spec){ return pkey != that.pkey || record != that.record; }; + function create(container) { + that.setup_views(container); + } + function setup(container, unspecified){ that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; that.record = $.bbq.getState(that.entity_name + '-record', true) || ''; that.container = container; - that.setup_views(container); container.attr('title', that.entity_name); @@ -445,6 +448,7 @@ function ipa_records_facet(spec){ } + that.create = create; that.setup = setup; that.load = load; diff --git a/install/static/search.js b/install/static/search.js index 1dfeda41e..ecdf56d2b 100644 --- a/install/static/search.js +++ b/install/static/search.js @@ -1,6 +1,7 @@ /* Authors: * Pavel Zuna * Adam Young + * Endi S. Dewata * * Copyright (C) 2010 Red Hat * see file 'COPYING' for use and warranty information @@ -21,22 +22,175 @@ /* REQUIRES: ipa.js */ +function ipa_search_widget(spec) { + + spec = spec || {}; + + var that = ipa_table_widget(spec); + + that.super_create = that.super('create'); + that.super_setup = that.super('setup'); + + that.create = function(container) { + + var div = $('#'+that.id); + + var search_controls = $('
', { + 'class': 'search-controls' + }).appendTo(div); + + var search_filter = $('', { + 'class': 'search-filter' + }).appendTo(search_controls); + + this.filter = $('', { + 'type': 'text', + 'name': 'search-' + that.entity_name + '-filter' + }).appendTo(search_filter); + + ipa_button({ + 'label': IPA.messages.button.find, + 'icon': 'ui-icon-search', + 'click': function() { that.find(container); } + }).appendTo(search_filter); + + ipa_button({ + 'label': IPA.messages.button.remove, + 'icon': 'ui-icon-trash', + 'click': function() { that.remove(container); } + }).appendTo(search_filter); + + ipa_button({ + 'label': IPA.messages.button.add, + 'icon': 'ui-icon-plus', + 'click': function() { that.add(container); } + }).appendTo(search_filter); + + search_controls.append(''); + + var search_results = $('
', { + 'class': 'search-results' + }).appendTo(div); + + that.super_create(container); + }; + + that.setup = function(container) { + + that.super_setup(container); + + var filter = $.bbq.getState(that.entity_name + '-filter', true) || ''; + this.filter.val(filter); + }; + + that.find = function(container) { + var filter = this.filter.val(); + var state = {}; + state[that.entity_name + '-filter'] = filter; + $.bbq.pushState(state); + }; + + that.add = function(container) { + + var entity = IPA.get_entity(that.entity_name); + + var dialog = entity.get_dialog('add'); + dialog.open(container); + + return false; + }; + + that.remove = function(container) { + + var values = that.get_selected_values(); + + if (!values.length) { + alert('Select '+that.label+' to be removed.'); + return; + } + + var title = 'Remove '+that.label; + + var dialog = ipa_deleter_dialog({ + 'title': title, + 'parent': container, + 'values': values + }); + + dialog.remove = function() { + var batch = ipa_batch_command(); + + for (var i=0; iError: '+error_thrown.name+'

'); + search_results.append('

'+error_thrown.title+'

'); + search_results.append('

'+error_thrown.message+'

'); + } + + var filter = $.bbq.getState(that.entity_name + '-filter', true) || ''; + ipa_cmd( + 'find', [filter], {all: true}, on_success, on_error, that.entity_name + ); + }; + + return that; +} + function ipa_search_column(spec) { spec = spec || {}; - spec.init = spec.init || init; - spec.setup = spec.setup || setup; - var that = ipa_column_widget(spec); - function init() { - } - - function setup(tr, attr, value, entry_attrs) { - search_generate_td(tr, attr, value, entry_attrs); - } - return that; } @@ -47,7 +201,9 @@ function ipa_search_facet(spec) { var that = ipa_facet(spec); that.init = spec.init || init; + that.create = spec.create || ipa_search_facet_create; that.setup = spec.setup || setup; + that.load = spec.load || load; that.columns = []; that.columns_by_name = {}; @@ -85,6 +241,24 @@ function ipa_search_facet(spec) { }; function init() { + + that.table = ipa_search_widget({ + 'id': that.entity_name+'-search', + 'name': that.entity_name, 'label': IPA.metadata[that.entity_name].label, + 'entity_name': that.entity_name + }); + + for (var i=0; i', { + 'id': that.entity_name+'-search' + }).appendTo(container); + + that.table.create(container); + } + function setup(container, unspecified) { + that.table.setup(container); + } + function load(container, unspecified) { that.filter = $.bbq.getState(that.entity_name + '-filter', true) || ''; - - search_create(that.entity_name, that.columns, container); - - ipa_button({ - 'label': IPA.messages.button.add, - 'icon': 'ui-icon-plus', - 'click': function() { - var entity = IPA.get_entity(that.entity_name); - if (entity) { - entity.add_dialog.open(); - return false; - } - - var dialog = ipa_entity_get_add_dialog(that.entity_name); - dialog.open(); - - return false; - } - }).appendTo($('.search-controls', container)); - - search_load(container, that.filter); + that.table.refresh(container); } if (spec.columns) { @@ -126,196 +294,9 @@ function ipa_search_facet(spec) { } } - that.init(); - return that; } - -function search_create(entity_name, columns, container) { - - function find_on_click() { - var filter = $(this).prev('input[type=text]').val(); - var state = {}; - state[entity_name + '-filter'] = filter; - $.bbq.pushState(state); - } - - function delete_on_click_outer() { - var delete_list = []; - var delete_dialog = $('
', { - title: IPA.messages.button.remove - }); - - function delete_on_click() { - ipa_cmd('del', delete_list, {}, delete_on_win, null, entity_name); - delete_dialog.dialog('close'); - } - - function delete_on_win() { - for (var i = 0; i < delete_list.length; ++i) { - var chk = container.find( - '.search-selector[title=' + delete_list[i] + ']' - ); - if (chk) - chk.closest('tr').remove(); - } - } - - function cancel_on_click() { - delete_dialog.dialog('close'); - } - - container.find('.search-selector').each(function () { - var jobj = $(this); - if (jobj.attr('checked')) - delete_list.push(jobj.attr('title')); - }); - - if (delete_list.length == 0) - return; - - delete_dialog.text(IPA.messages.search.delete_confirm); - - delete_dialog.dialog({ - modal: true, - buttons: { - 'Delete': delete_on_click, - 'Cancel': cancel_on_click - } - }); - } - - if (!container) { - alert('ERROR: search_create: Second argument "container" missing!'); - return null; - } - - container.attr('title', entity_name); - - var search_controls = $('
', { - 'class': 'search-controls' - }).appendTo(container); - - var search_filter = $('', { - 'class': 'search-filter' - }).appendTo(search_controls); - - var filter = $('', { - 'type': 'text', - 'name': 'search-' + entity_name + '-filter' - }).appendTo(search_filter); - - ipa_button({ - 'label': IPA.messages.button.find, - 'icon': 'ui-icon-search', - 'click': find_on_click - }).appendTo(search_filter); - - ipa_button({ - 'label': IPA.messages.button.remove, - 'icon': 'ui-icon-trash', - 'click': delete_on_click_outer - }).appendTo(search_filter); - - search_controls.append(''); - - var search_results = $('
', { - 'class': 'search-results' - }).appendTo(container); - - var search_table = $('', { - 'class': 'search-table' - }).appendTo(search_results); - - search_table.append(''); - search_table.append(''); - search_table.append(''); - - var tr = search_table.find('tr'); - search_insert_checkbox_th(tr); - for (var i = 0; i < columns.length; ++i) { - var c = columns[i]; - search_insert_th(tr, entity_name, c.name, c.label, c.setup); - } -} - -function search_insert_checkbox_th(jobj) -{ - function select_all_on_click() { - var jobj = $(this); - - var checked = jobj.is(':checked'); - if (checked) { - jobj.attr('title', 'Unselect All'); - } else { - jobj.attr('title', 'Select All'); - } - - var chks = jobj.closest('.entity-container').find('.search-selector').get(); - for (var i = 0; i < chks.length; ++i) - chks[i].checked = checked; - } - - var checkbox = $('', { - type: 'checkbox', - title: 'Select All' - }); - checkbox.click(select_all_on_click); - - var th = $(''); - th.append(checkbox); - - jobj.append(th); -} - -var _search_th_template = ''; - -function search_insert_th(jobj, obj_name, attr, name, render_call) -{ - var th = _search_th_template.replace('A', attr); - - var param_info = ipa_get_param_info(obj_name, attr); - if (param_info && param_info['label']) - th = th.replace('N', param_info['label']); - else - th = th.replace('N', name); - - if (typeof render_call == 'function') - th = th.replace('C', render_call.name); - else - th = th.replace('C', '-'); - - jobj.append(th); -} - -function search_load(container, criteria, on_win, on_fail) -{ - var entity_name = container.attr('id'); - - function search_on_success(data, text_status, xhr) { - if (on_win) - on_win(data, text_status, xhr); - if (data.error) - return; - search_display(entity_name, data); - } - - function search_on_error(xhr, text_status, error_thrown) { - if (on_fail) - on_fail(xhr, text_status, error_thrown); - - var search_results = $('.search-results', container); - search_results.append('

Error: '+error_thrown.name+'

'); - search_results.append('

'+error_thrown.title+'

'); - search_results.append('

'+error_thrown.message+'

'); - } - - ipa_cmd( - 'find', [criteria], {all: true}, search_on_success, search_on_error, entity_name - ); -} - function search_generate_tr(thead, tbody, entry_attrs) { var obj_name = tbody.closest('.entity-container').attr('title'); @@ -387,27 +368,3 @@ function search_generate_td(tr, attr, value, entry_attrs) tr.append(_search_td_template.replace('A', attr).replace('V', value)); } - -function search_display(obj_name, data) -{ - var selector = '.entity-container[title=' + obj_name + ']'; - var thead = $(selector + ' thead'); - var tbody = $(selector + ' tbody'); - var tfoot = $(selector + ' tfoot'); - - tbody.find('tr').remove(); - - var result = data.result.result; - for (var i = 0; i < result.length; ++i) - search_generate_tr(thead, tbody, result[i]); - - if (data.result.truncated) { - tfoot.text( - 'Query returned results than configured size limit will show.' + - 'First ' + data.result.count + ' results shown.' - ); - } else { - tfoot.text(data.result.summary); - } -} - diff --git a/install/static/service.js b/install/static/service.js index 1b467cb59..6a79af074 100644 --- a/install/static/service.js +++ b/install/static/service.js @@ -26,115 +26,202 @@ function ipa_service() { 'name': 'service' }); + that.super_init = that.super('init'); + that.init = function() { - that.create_add_dialog({ + + var dialog = ipa_service_add_dialog({ 'name': 'add', - 'title': 'Add New Service', - 'init': ipa_service_add_init + 'title': 'Add New Service' }); + that.add_dialog(dialog); + dialog.init(); - that.create_search_facet({ + var facet = ipa_service_search_facet({ 'name': 'search', - 'label': 'Search', - 'init': ipa_service_search_init + 'label': 'Search' }); + that.add_facet(facet); - that.create_details_facet({ + facet = ipa_service_details_facet({ 'name': 'details', - 'label': 'Details', - 'init': ipa_service_details_init + 'label': 'Details' }); - }; + that.add_facet(facet); - that.init(); + facet = ipa_association_facet({ + 'name': 'associate' + }); + that.add_facet(facet); + + that.create_association({ + 'name': 'host', + 'add_method': 'add_host', + 'delete_method': 'remove_host' + }); + + that.super_init(); + }; return that; } IPA.add_entity(ipa_service()); -function ipa_service_add_init() { +function ipa_service_add_dialog(spec) { - this.create_field({ - name: 'krbprincipalname', - label: 'Principal', - setup: service_add_krbprincipalname - }); + spec = spec || {}; - this.create_field({name:'service', label:'Service'}); - this.create_field({name:'host', label:'Host Name'}); + var that = ipa_add_dialog(spec); + + that.super_init = that.super('init'); + + that.init = function() { + + this.super_init(); + + this.add_field(ipa_widget({ + name: 'krbprincipalname', + label: 'Principal' + })); + + this.add_field(ipa_text_widget({name:'service', label:'Service'})); + this.add_field(ipa_text_widget({name:'host', label:'Host Name'})); + }; + + that.create = function() { + + var table = $('
N
').appendTo(that.container); + + var field = that.get_field('service'); + + var tr = $('').appendTo(table); + + var td = $('').appendTo(table); + + td = $('').appendTo(search_table); var tr = $('').appendTo(tbody); + var td = $('
', { + 'style': 'vertical-align: top;' + }).appendTo(tr); + td.append(field.label+': '); + + td = $('', { + 'style': 'vertical-align: top;' + }).appendTo(tr); + + $('', { + 'type': 'text', + 'name': 'service', + 'size': 20 + }).appendTo(td); + + field = that.get_field('host'); + + tr = $('
', { + 'style': 'vertical-align: top;' + }).appendTo(tr); + td.append(field.label+': '); + + td = $('', { + 'style': 'vertical-align: top;' + }).appendTo(tr); + + $('', { + 'type': 'text', + 'name': 'host', + 'size': 40 + }).appendTo(td); + }; + + that.get_record = function() { + var record = {}; + + var field = that.get_field('service'); + var service = field.save(that.container)[0]; + + field = that.get_field('host'); + var host = field.save(that.container)[0]; + + record['krbprincipalname'] = service+'/'+host; + + return record; + }; + + return that; } -function ipa_service_search_init() { +function ipa_service_search_facet(spec) { - this.create_column({name:'krbprincipalname', label:'Principal'}); + spec = spec || {}; - this.create_column({ - name: 'quick_links', - label: 'Quick Links', - setup: ipa_entity_quick_links - }); + var that = ipa_search_facet(spec); + + that.super_init = that.super('init'); + + that.init = function() { + + this.create_column({name:'krbprincipalname', label:'Principal'}); + + this.create_column({ + name: 'quick_links', + label: 'Quick Links', + setup: ipa_entity_quick_links + }); + + that.super_init(); + }; + + return that; } -function ipa_service_details_init() { +function ipa_service_details_facet(spec) { - var section = this.create_section({name:'details', label:'Service Details'}); + spec = spec || {}; - section.create_field({ - name: 'krbprincipalname', - label: 'Principal', - setup: service_krbprincipalname_setup, - load: service_krbprincipalname_load - }); + var that = ipa_details_facet(spec); - section.create_field({ - name: 'service', - label: 'Service', - load: service_service_load - }); + that.super_init = that.super('init'); - section.create_field({ - name: 'host', - label: 'Host Name', - load: service_host_load - }); + that.init = function() { - section = this.create_section({name:'provisioning', label:'Provisioning'}); + var section = this.create_section({name:'details', label:'Service Details'}); - section.create_field({ - name: 'provisioning_status', - label: 'Status', - load: service_provisioning_status_load - }); + section.create_field({ + name: 'krbprincipalname', + label: 'Principal' + }); - section = this.create_section({name:'certificate', label:'Service Certificate'}); + section.create_field({ + name: 'service', + label: 'Service', + load: service_service_load + }); - section.create_field({ - name: 'certificate_status', - label: 'Status', - load: service_usercertificate_load - }); -} + section.create_field({ + name: 'host', + label: 'Host Name', + load: service_host_load + }); -function service_add_krbprincipalname(add_dialog, mode) { - if (mode == IPA_ADD_UPDATE) { - var service = add_dialog.find('input[name=service]').val(); - var host = add_dialog.find('input[name=host]').val(); - return service+'/'+host; - } - return null; -} + section = this.create_section({name:'provisioning', label:'Provisioning'}); -ipa_entity_set_association_definition('service', { - 'host': { add_method: 'add_host', delete_host: 'remove_host' } -}); + section.create_field({ + name: 'provisioning_status', + label: 'Status', + load: service_provisioning_status_load + }); -function service_krbprincipalname_setup(container) { - // skip krbprincipalname -} + section = this.create_section({name:'certificate', label:'Service Certificate'}); -function service_krbprincipalname_load(container, result) { - // skip krbprincipalname + section.create_field({ + name: 'certificate_status', + label: 'Status', + load: service_usercertificate_load + }); + + that.super_init(); + }; + + return that; } function service_service_load(container, result) { diff --git a/install/static/test/details_tests.js b/install/static/test/details_tests.js index 1dd0ddf13..80dbc3986 100644 --- a/install/static/test/details_tests.js +++ b/install/static/test/details_tests.js @@ -19,7 +19,7 @@ */ -test("Testing ipa_details_section.setup().", function() { +test("Testing ipa_details_section.create().", function() { IPA.ajax_options.async = false; @@ -34,8 +34,6 @@ test("Testing ipa_details_section.setup().", function() { } ); - var result = {}; - var section = ipa_details_section({name:'IDIDID', label:'NAMENAMENAME'}). input({name:'cn', label:'Entity Name'}). input({name:'description', label:'Description'}). @@ -44,7 +42,7 @@ test("Testing ipa_details_section.setup().", function() { var fields = section.fields; var container = $("
"); - section.setup(container, result); + section.create(container); var dl = container.find('dl'); @@ -80,7 +78,7 @@ test("Testing ipa_details_section.setup().", function() { -test("Testing details lifecycle: create, save ().", function(){ +test("Testing details lifecycle: create, setup, load.", function(){ IPA.ajax_options.async = false; @@ -168,7 +166,9 @@ test("Testing details lifecycle: create, save ().", function(){ var entity = ipa_get_entity(obj_name); var facet = entity.get_facet('details'); - facet.create(container, result); + facet.create(container); + facet.setup(container); + facet.load(container, result); var contact = container.find('dl#contact.entryattrs'); @@ -192,7 +192,7 @@ test("Testing details lifecycle: create, save ().", function(){ ); same( - dts[5].title, facet.get_sections()[0].get_fields()[5].name, + dts[5].title, facet.sections[0].fields[5].name, 'Checking dt title' ); @@ -205,7 +205,7 @@ test("Testing details lifecycle: create, save ().", function(){ ok (load_manager_called, 'load manager called'); - ipa_details_update(container, + facet.update(container, 'kfrog', function(){update_success_called = true}, function(){update_failure_called = true}); @@ -265,7 +265,11 @@ test("Testing ipa_details_section_setup again()",function(){ var details = $("
"); container.append(details); - section.setup(container, details, section); + var result = {}; + + section.create(container); + section.setup(container); + section.load(container, result); ok(container.find('hr'),'hr'); diff --git a/install/static/test/entity_tests.js b/install/static/test/entity_tests.js index 08fc3111d..5d98d7b1b 100644 --- a/install/static/test/entity_tests.js +++ b/install/static/test/entity_tests.js @@ -61,7 +61,7 @@ test('Testing ipa_entity_set_search_definition().', function() { ); }); -test('Testing ipa_entity_generate_views().', function() { +test('Testing ipa_facet_setup_views().', function() { var orig_show_page = IPA.show_page; IPA.ajax_options.async = false; @@ -83,9 +83,10 @@ test('Testing ipa_entity_generate_views().', function() { IPA.add_entity(entity); - var facet = entity.create_association_facet({ + var facet = ipa_association_facet({ 'name': 'associate' }); + entity.add_facet(facet); var container = $('
'); @@ -179,11 +180,12 @@ test('Testing ipa_entity_quick_links().', function() { var tbody = $('
').appendTo(tr); + var span = $('', {name:'quick_links'}).appendTo(td); - ipa_entity_quick_links(tr, null, null, entry_attrs); + ipa_entity_quick_links(tr, 'quick_links', null, entry_attrs); - var td = tr.children().first(); - var link = td.children().first(); + var link = span.children().first(); equals( link.attr('href'), '#details', diff --git a/install/static/test/ipa_tests.html b/install/static/test/ipa_tests.html index 3f3c16869..903e71545 100644 --- a/install/static/test/ipa_tests.html +++ b/install/static/test/ipa_tests.html @@ -7,6 +7,7 @@ + diff --git a/install/static/webui.js b/install/static/webui.js index 804f06f86..bf367ee94 100644 --- a/install/static/webui.js +++ b/install/static/webui.js @@ -68,6 +68,11 @@ $(function() { $('#loggedinas a').fragment( {'user-facet':'details', 'user-pkey':ipa_whoami_pkey},2); + for (var i=0; i', { + 'type': 'text', + 'name': that.name, + 'size': that.size + }).appendTo(container); + }; + that.load = function(container, result) { that.value = result[that.name] || ''; var input = $('input[name="'+that.name+'"]', container); @@ -101,6 +119,46 @@ function ipa_text_widget(spec) { return values; }; + that.clear = function(container) { + var input = $('input[name="'+that.name+'"]', container); + input.val(''); + }; + + return that; +} + +function ipa_checkbox_widget(spec) { + + spec = spec || {}; + + var that = ipa_widget(spec); + + that.create = function(container) { + $('', { + 'type': 'checkbox', + 'name': that.name + }).appendTo(container); + }; + + that.load = function(container, result) { + var value = result[that.name] || ''; + $('input[name="'+that.name+'"][value="'+value+'"]', container).attr('checked', 'checked'); + }; + + that.save = function(container) { + var values = []; + + var value = $('input[name="'+that.name+'"]', container).is(':checked'); + values.push(value); + + return values; + }; + + that.clear = function(container) { + var input = $('input[name="'+that.name+'"]', container).get(0); + input.checked = false; + }; + return that; } @@ -108,28 +166,21 @@ function ipa_radio_widget(spec) { spec = spec || {}; - spec.setup = spec.setup || setup; - spec.load = spec.load || load; - spec.save = spec.save || save; - var that = ipa_widget(spec); - function setup(container) { - } - - function load(container, result) { + that.load = function(container, result) { var value = result[that.name] || ''; $('input[name="'+that.name+'"][value="'+value+'"]', container).attr('checked', 'checked'); - } + }; - function save(container) { + that.save = function(container) { var values = []; var value = $('input[name="'+that.name+'"]:checked', container).val(); values.push(value); return values; - } + }; return that; } @@ -138,28 +189,37 @@ function ipa_textarea_widget(spec) { spec = spec || {}; - spec.setup = spec.setup || setup; - spec.load = spec.load || load; - spec.save = spec.save || save; - var that = ipa_widget(spec); - function setup(container) { - } + that.rows = spec.rows || 5; + that.cols = spec.cols || 40; - function load(container, result) { + that.create = function(container) { + $('