diff options
author | Endi S. Dewata <edewata@redhat.com> | 2010-10-27 22:32:30 -0500 |
---|---|---|
committer | Adam Young <ayoung@redhat.com> | 2010-10-28 09:28:17 -0400 |
commit | 528145d5df30d4b344cd0edafa8e8adba0b817b1 (patch) | |
tree | bd5df2342bbf1144a484b0f39b70b906524cf9b1 | |
parent | 70a57924c8e265df1e97b7f0be1adf8da802fbfd (diff) | |
download | freeipa-528145d5df30d4b344cd0edafa8e8adba0b817b1.tar.gz freeipa-528145d5df30d4b344cd0edafa8e8adba0b817b1.tar.xz freeipa-528145d5df30d4b344cd0edafa8e8adba0b817b1.zip |
Framework for custom UI
This patch introduces a new framework for implementing custom UI.
It consists of the following classes:
Main:
- IPA: global namespace and object repository
- ipa_entity: base class for entities
- ipa_facet: base class for facets
Add dialog:
- ipa_add_dialog: default add dialog
- ipa_add_field: the fields used in the dialog
Search facet:
- ipa_search_facet: default search facet
- ipa_search_column: the columns in the search result
Details facet:
- ipa_details_facet: default details facet
- ipa_details_section: the sections in the details facet
- ipa_details_field: the fields in the details facet
Association facet:
- ipa_association_facet: default association facet
- ipa_association_config: the association configurations
To use this framework, create a class extending the ipa_entity (e.g.
ipa_hbac). Use the create_* methods to create add dialog, search facet,
details facet, and association facet. The fields/columns for the dialog
and facets can be specified using the init() function. Custom UI can be
defined by overwriting the base methods (e.g. setup, save, load).
The entity must be added into the repository using IPA.add_entity().
The original ipa_entity_setup() has been generalized by moving facet-
specific codes into the corresponding facet. Some facet names are still
hard-coded. This will be fixed in follow-up patches.
Some global variables have been removed because their function has been
replaced by the object repository:
- ipa_entity_add_list
- ipa_entity_search_list
- ipa_entity_details_list
- window_hash_cache
Some functions and variables have been moved into IPA namespace:
- ipa_json_url -> IPA.json_url
- ipa_use_static_files -> IPA.use_static_files
- ipa_ajax_options -> IPA.ajax_options
- ipa_objs -> IPA.metadata
- ipa_messages -> IPA.messages
- ipa_dialog -> IPA.error_dialog
- ipa_init() -> IPA.init()
Initially the HBAC and Service entities have been rewritten to use the
new framework. The DNS is partially converted, the ipa_records_facet
is used to define custom records facet.
Other entities can still work using the old framework. The old framework
has been modified to be a wrapper for the new framework. Eventually all
entities will be converted to use the new framework.
Some unit tests have been modified to use the new framework.
-rw-r--r-- | install/static/Makefile.am | 1 | ||||
-rw-r--r-- | install/static/add.js | 143 | ||||
-rw-r--r-- | install/static/associate.js | 201 | ||||
-rw-r--r-- | install/static/details.js | 290 | ||||
-rw-r--r-- | install/static/develop.js | 4 | ||||
-rw-r--r-- | install/static/entity.js | 461 | ||||
-rwxr-xr-x | install/static/hbac.js | 214 | ||||
-rw-r--r-- | install/static/hostgroup.js | 3 | ||||
-rw-r--r-- | install/static/index.xhtml | 1 | ||||
-rw-r--r-- | install/static/ipa.js | 132 | ||||
-rw-r--r-- | install/static/navigation.js | 23 | ||||
-rw-r--r-- | install/static/netgroup.js | 2 | ||||
-rw-r--r-- | install/static/policy.js | 112 | ||||
-rw-r--r-- | install/static/search.js | 205 | ||||
-rw-r--r-- | install/static/serverconfig.js | 3 | ||||
-rw-r--r-- | install/static/service.js | 123 | ||||
-rw-r--r-- | install/static/test/details_tests.js | 19 | ||||
-rw-r--r-- | install/static/test/entity_tests.html | 2 | ||||
-rw-r--r-- | install/static/test/entity_tests.js | 160 | ||||
-rw-r--r-- | install/static/test/ipa_tests.js | 16 | ||||
-rw-r--r-- | install/static/test/navigation_tests.js | 2 | ||||
-rw-r--r-- | install/static/user.js | 4 | ||||
-rw-r--r-- | install/static/webui.js | 46 |
23 files changed, 1409 insertions, 758 deletions
diff --git a/install/static/Makefile.am b/install/static/Makefile.am index ef16a2e99..7097a1f6a 100644 --- a/install/static/Makefile.am +++ b/install/static/Makefile.am @@ -18,6 +18,7 @@ app_DATA = \ jquery-ui.css \ certificate.js \ group.js \ + hbac.js \ host.js \ hostgroup.js \ index.xhtml \ diff --git a/install/static/add.js b/install/static/add.js index 71d08338e..b5f9c16d4 100644 --- a/install/static/add.js +++ b/install/static/add.js @@ -1,5 +1,6 @@ /* Authors: * Pavel Zuna <pzuna@redhat.com> + * Endi Sukma Dewata <edewata@redhat.com> * * Copyright (C) 2010 Red Hat * see file 'COPYING' for use and warranty information @@ -23,40 +24,108 @@ var IPA_ADD_POPULATE = 1; var IPA_ADD_UPDATE = 2; -function add_dialog_create(obj_name, adl) -{ - var add_dialog = $('<div></div>'); +function ipa_add_field(spec) { - function add(evt, called_from_add_and_edit) { + spec = spec || {}; + + var that = {}; + that.name = spec.name; + that.label = spec.label; + + that.init = spec.init; + that.setup = spec.setup; + + return that; +} + +function ipa_add_dialog(spec) { + + spec = spec || {}; + + var that = {}; + that.name = spec.name; + that.title = spec.title; + that.entity_name = spec.entity_name; + + that.init = spec.init; + + that.fields = []; + that.fields_by_name = {}; + + var dialog = $('<div/>'); + + that.get_fields = function() { + return that.fields; + }; + + that.get_field = function(name) { + return that.fields_by_name[name]; + }; + + that.add_field = function(field) { + that.fields.push(field); + that.fields_by_name[field.name] = field; + }; + + that.create_field = function(spec) { + var field = ipa_add_field(spec); + that.add_field(field); + return field; + }; + + that.open = function() { + dialog.empty(); + dialog.attr('id', that.name); + dialog.attr('title', that.title); + + for (var i = 0; i < that.fields.length; ++i) { + var field = that.fields[i]; + if (field.setup) { + field.setup(dialog, IPA_ADD_POPULATE); + } else { + dialog.append('<label>' + field.label + '</label>'); + dialog.append('<input type="text" name="' + field.name + '" />'); + } + } + + dialog.dialog({ + modal: true, + buttons: { + 'Add': that.add, + 'Add and edit': that.add_and_edit, + 'Cancel': that.cancel + } + }); + }; + + that.add = function(evt, called_from_add_and_edit) { var pkey = []; var options = {}; - var pkey_name = ipa_objs[obj_name].primary_key; + 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[obj_name + '-facet'] = 'details'; - state[obj_name + '-pkey'] = pkey[0]; + state[that.entity_name + '-facet'] = 'details'; + state[that.entity_name + '-pkey'] = pkey[0]; $.bbq.pushState(state); } - }; - - var fields = adl[2]; - for (var i = 0; i < fields.length; ++i) { - var f = fields[i]; - var attr = f[0]; - if (typeof f[2] == 'function') { - var value = f[2](add_dialog, IPA_ADD_UPDATE); + } + + for (var i = 0; i < that.fields.length; ++i) { + var field = that.fields[i]; + if (field.setup) { + var value = field.setup(dialog, IPA_ADD_UPDATE); if (value != null) { - if (attr == pkey_name) + if (field.name == pkey_name) pkey = [value]; else - options[attr] = value; + options[field.name] = value; } } } - add_dialog.find('input').each(function () { + dialog.find('input').each(function () { var jobj = $(this); var attr = jobj.attr('name'); var value = jobj.val(); @@ -68,40 +137,20 @@ function add_dialog_create(obj_name, adl) } }); - ipa_cmd('add', pkey, options, add_win, null, obj_name); - add_dialog.dialog('close'); + ipa_cmd('add', pkey, options, add_win, null, that.entity_name); }; - function add_and_edit(evt) { - add(evt, true); - add_dialog.dialog('close'); + that.add_and_edit = function(evt) { + that.add(evt, true); + dialog.dialog('close'); }; - function cancel() { - add_dialog.dialog('close'); + that.cancel = function() { + dialog.dialog('close'); }; - add_dialog.attr('id', adl[0]); - add_dialog.attr('title', adl[1]); - - var fields = adl[2]; - for (var i = 0; i < fields.length; ++i) { - var f = fields[i]; - if (typeof f[2] == 'function') { - f[2](add_dialog, IPA_ADD_POPULATE); - } else { - add_dialog.append('<label>' + f[1] + '</label>'); - add_dialog.append('<input type="text" name="' + f[0] + '" />'); - } - } - - add_dialog.dialog({ - modal: true, - buttons: { - 'Add': add, - 'Add and edit': add_and_edit, - 'Cancel': cancel - } - }); + if (that.init) that.init(); + + return that; } diff --git a/install/static/associate.js b/install/static/associate.js index be189963f..a99fd907b 100644 --- a/install/static/associate.js +++ b/install/static/associate.js @@ -44,13 +44,13 @@ function SerialAssociator(form, manyObjPkeys, on_success) ipa_cmd( form.method,args, options , function(data, text_status, xhr) { if (data.error){ - alert("error adding member: "+data.error.message); + alert('error adding member: '+data.error.message); }else{ associator.associateNext(); } }, function(xhr, text_status, error_thrown) { - alert("associateFailure"); + alert('associateFailure'); }, form.manyObj ); }else{ @@ -74,11 +74,11 @@ function BulkAssociator(form, manyObjPkeys, on_success) var form = this.form; var option = manyObjPkeys.shift(); while(manyObjPkeys.length > 0) { - option += "," + manyObjPkeys.shift(); + option += ',' + manyObjPkeys.shift(); } var options = { - "all":true + 'all':true }; options[form.manyObj] = option; @@ -87,13 +87,13 @@ function BulkAssociator(form, manyObjPkeys, on_success) ipa_cmd( form.method,args, options , function(data, text_status, xhr) { if (data.error){ - alert("error adding member: "+data.error.message); + alert('error adding member: '+data.error.message); }else{ associator.on_success(); } }, function(xhr, text_status, error_thrown) { - alert("associateFailure"); + alert('associateFailure'); }, form.oneObj ); } @@ -127,7 +127,7 @@ function AssociationForm(oneObj, pkey, manyObj, on_success, associatorConstructo this.associatorConstructor = BulkAssociator; this.setup = function() { - var label = ipa_objs[form.manyObj].label; + var label = IPA.metadata[form.manyObj].label; form.dialog.attr('title', 'Enroll '+form.oneObj+' '+form.pkey+' in '+label); @@ -139,20 +139,20 @@ function AssociationForm(oneObj, pkey, manyObj, on_success, associatorConstructo var enrollments = $('#enrollments', form.dialog); enrollments.html(''); - $("#addToList", form.dialog).click(function(){ + $('#addToList', form.dialog).click(function(){ $('#availableList :selected', form.dialog).each(function(i, selected){ enrollments.append(selected); }); $('#availableList :selected', form.dialog).remove(); }); - $("#removeFromList", form.dialog).click(function(){ + $('#removeFromList', form.dialog).click(function(){ $('#enrollments :selected', form.dialog).each(function(i, selected){ availableList.append(selected); }); $('#enrollments :selected', form.dialog).remove(); }); - $("#find", form.dialog).click(function(){ + $('#find', form.dialog).click(function(){ form.search(); }); @@ -170,29 +170,29 @@ function AssociationForm(oneObj, pkey, manyObj, on_success, associatorConstructo this.close = function() { form.dialog.dialog('close'); - } + }; this.search = function() { function search_on_win(data, text_status, xhr) { var results = data.result; - var list = $("#availableList", form.dialog); - list.html(""); + var list = $('#availableList', form.dialog); + list.html(''); - var searchColumn = ipa_objs[form.manyObj].primary_key; + var searchColumn = IPA.metadata[form.manyObj].primary_key; for (var i =0; i != results.count; i++){ var result = results.result[i]; - $("<option></option>",{ + $('<option></option>',{ value: result[searchColumn][0], html: result[searchColumn][0] }).appendTo(list); } - }; + } function search_on_fail(xhr, text_status, errow_thrown) { - alert("associationSearchFailure"); - }; + alert('associationSearchFailure'); + } var queryFilter = $('#associateFilter', form.dialog).val(); ipa_cmd('find', [queryFilter], {}, search_on_win, null, form.manyObj); @@ -209,32 +209,109 @@ function AssociationForm(oneObj, pkey, manyObj, on_success, associatorConstructo }; } -/** - A modfied version of search. It shows the associations for an object. -*/ -function AssociationList(obj, pkey, manyObj, associationColumns, jobj, associationConstructor, method) -{ - var form = this; +function ipa_association_config(spec) { + spec = spec || {}; - this.obj = obj; - this.pkey = pkey; - this.associationColumns = associationColumns; - this.manyObj = manyObj; - this.container = jobj; - this.associationConstructor = associationConstructor; - this.method = method; + var that = {}; + + that.name = spec.name; + that.associator = spec.associator; + that.method = spec.method; + + return that; +} + +function ipa_association_facet(spec) { + + spec = spec || {}; + + var that = ipa_facet(spec); + + that.configs = []; + that.configs_by_name = {}; + + that.other_entity = null; + + that.get_configs = function() { + return that.configs; + }; + + that.get_config = function(name) { + return that.configs_by_name[name]; + }; + + that.add_config = function(config) { + that.configs.push(config); + that.configs_by_name[config.name] = config; + }; + + that.create_config = function(spec) { + var config = ipa_association_config(spec); + that.add_config(config); + return config; + }; + + that.is_dirty = function() { + var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; + var other_entity = $.bbq.getState(that.entity_name + '-enroll', true) || ''; + return pkey != that.pkey || other_entity != that.other_entity; + }; + + that.setup = function(container, unspecified) { - this.refresh = function() { + that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; + that.other_entity = $.bbq.getState(that.entity_name + '-enroll', true) || ''; + + that.member_attrribute = ipa_get_member_attribute(that.entity_name, that.other_entity); + that.columns = [ + { + 'title': IPA.metadata[that.other_entity].label, + 'column': that.member_attrribute + '_' + that.other_entity + } + ]; + + var config = that.get_config(that.other_entity); + that.associator = config ? config.associator : null; + that.method = config ? config.method : null; + + that.setup_views(container); + + //TODO I18N + var header_message = that.other_entity + '(s) enrolled in ' + + that.entity_name + ' ' + that.pkey; + container.append($('<h2/>',{html: header_message }) ); + association_list_create(that.entity_name, container); + container.find('.search-filter').css('display', 'none'); + container.find('.search-buttons').html(''); + + $('<input/>', { + type: 'button', + value: 'enroll', + click: function() { + that.show_enrollment_dialog(); + } + }).appendTo(container.find('.search-buttons')); + + var header = $('<tr></tr>').appendTo(container.find('.search-table thead:last')); + for (var i =0 ; i != that.columns.length ;i++){ + $('<th></th>',{ + html: that.columns[i].title + }).appendTo(header); + } + that.refresh(container); + }; + + that.refresh = function(container) { function refresh_on_success(data, text_status, xhr) { - var tbody = form.container.find('.search-table tbody'); + var tbody = container.find('.search-table tbody'); tbody.empty(); - var associationList = data.result.result[form.associationColumns[0].column]; + var associationList = data.result.result[that.columns[0].column]; for (var j = 0; j < associationList.length; j++){ - var row = $("<tr/>").appendTo(tbody); - for (var k = 0; k < associationColumns.length ;k++){ - var column = form.associationColumns[k].column; - $("<td></td>",{ + var row = $('<tr/>').appendTo(tbody); + for (var k = 0; k < that.columns.length ;k++){ + var column = that.columns[k].column; + $('<td></td>',{ html: data.result.result[column][j] }).appendTo(row); } @@ -242,54 +319,32 @@ function AssociationList(obj, pkey, manyObj, associationColumns, jobj, associati } function refresh_on_error(xhr, text_status, error_thrown) { - var search_results = $('.search-results', jobj).empty(); + var search_results = $('.search-results', container).empty(); search_results.append('<p>Error: '+error_thrown.name+'</p>'); search_results.append('<p>URL: '+this.url+'</p>'); search_results.append('<p>'+error_thrown.message+'</p>'); } - ipa_cmd('show', [this.pkey], {}, refresh_on_success, refresh_on_error, form.obj); - } - - this.setup = function() { - //TODO I18N - var header_message = manyObj + "(s) enrolled in " + - this.obj + " " + pkey; - this.container.append($("<h2/>",{html: header_message }) ); - association_list_create(this.obj, this.container); - this.container.find(".search-filter").css("display", "none"); - this.container.find(".search-buttons").html(""); - $("<input/>", { - type: 'button', - value: 'enroll', - click: function() { - form.show_enrollment_dialog(); - } - }).appendTo(this.container.find(".search-buttons")); - var header = $("<tr></tr>").appendTo(this.container.find('.search-table thead:last')); - for (var i =0 ; i != associationColumns.length ;i++){ - $("<th></th>",{ - html: associationColumns[i].title - }).appendTo(header); - } - this.refresh(); - } + ipa_cmd('show', [that.pkey], {}, refresh_on_success, refresh_on_error, that.entity_name); + }; - this.show_enrollment_dialog = function() { + that.show_enrollment_dialog = function() { var enrollment_dialog = new AssociationForm( - this.obj, - this.pkey, - this.manyObj, + that.entity_name, + that.pkey, + that.other_entity, function() { - form.refresh(); + that.refresh(); enrollment_dialog.close(); }, - this.associationConstructor, - this.method + that.associator, + that.method ); enrollment_dialog.setup(); - } + }; + + return that; } diff --git a/install/static/details.js b/install/static/details.js index d0688f55d..d4593d82e 100644 --- a/install/static/details.js +++ b/install/static/details.js @@ -25,134 +25,222 @@ /* REQUIRES: ipa.js */ var ipa_details_cache = {}; -var ipa_entity_details_list = {}; +function ipa_details_field(spec) { + + spec = spec || {}; -function ipa_stanza(spec){ var that = {}; + that.name = spec.name; + that.label = spec.label; + + that.setup = spec.setup || setup; + that.load = spec.load || load; + that.save = spec.save || save; + + function setup(container, dl, section) { + + var obj_name = container.attr('title'); + var title = this.name; + var label = ''; + var param_info = ipa_get_param_info(obj_name, this.name); + if (param_info) + label = param_info['label']; + if (!label) + label = this.label; + $('<dt></dt>', { + id: this.name, + title: title, + html: label + ':' + }).appendTo(dl); + } - that.name = spec.name || ''; - that.label = spec.label || ''; + function load(container, dt, entry_attrs) { - function input(spec){ + var obj_name = container.attr('id'); + var multivalue = false; + var hint_span = null; + var dd; - /*Was ipa_details_field_setup*/ - function setup(container, dl, section) { - - var obj_name = container.attr('title'); - var title = this.name; - var label = ''; - var param_info = ipa_get_param_info(obj_name, this.name); - if (param_info) - label = param_info['label']; - if (!label) - label = this.label; - $('<dt></dt>', { - id: this.name, - title: title, - html: label + ':' - }).appendTo(dl); + var param_info = ipa_get_param_info(obj_name, this.name); + if (param_info) { + if (param_info['multivalue'] || param_info['class'] == 'List') + multivalue = true; + var hint = param_info['hint']; + if (hint){ + hint_span = $('<span />',{ + 'class': 'attrhint', + 'html': 'Hint: ' + hint}); + } } - /*Was ipa_details_field_load*/ - function load(container, dt, entry_attrs) { - - var obj_name = container.attr('id'); - var multivalue = false; - var hint_span = null; - var dd; - - var param_info = ipa_get_param_info(obj_name, this.name); - if (param_info) { - if (param_info['multivalue'] || param_info['class'] == 'List') - multivalue = true; - var hint = param_info['hint']; - if (hint){ - hint_span = $('<span />',{ - 'class': 'attrhint', - 'html': 'Hint: ' + hint}); - } + var value = entry_attrs[this.name]; + if (value) { + dd = ipa_create_first_dd( + this.name, ipa_create_input(obj_name, this.name, value[0],hint_span) + ); + dt.after(dd); + var last_dd = dd; + for (var i = 1; i < value.length; ++i) { + dd = ipa_create_other_dd( + this.name, ipa_create_input(obj_name, this.name, value[i],hint_span) + ); + last_dd.after(dd); + last_dd = dd; } - - var value = entry_attrs[this.name]; - if (value) { + if (multivalue) { + dd = ipa_create_other_dd( + this.name, _ipa_a_add_template.replace('A', this.name) + ); + last_dd.after(dd); + } + } else { + if (multivalue) { dd = ipa_create_first_dd( - this.name, ipa_create_input(obj_name, this.name, value[0],hint_span) + this.name, _ipa_a_add_template.replace('A', this.name) /*.append(hint_span)*/ ); dt.after(dd); - var last_dd = dd; - for (var i = 1; i < value.length; ++i) { - dd = ipa_create_other_dd( - this.name, ipa_create_input(obj_name, this.name, value[i],hint_span) - ); - last_dd.after(dd); - last_dd = dd; - } - if (multivalue) { - dd = ipa_create_other_dd( - this.name, _ipa_a_add_template.replace('A', this.name) - ); - last_dd.after(dd); - } } else { - if (multivalue) { - dd = ipa_create_first_dd( - this.name, _ipa_a_add_template.replace('A', this.name) /*.append(hint_span)*/ - ); - dt.after(dd); - } else { - dd = ipa_create_first_dd( - this.name, ipa_create_input(obj_name, this.name, '') /*.append(hint_span)*/ - ); - dt.after(dd); - } + dd = ipa_create_first_dd( + this.name, ipa_create_input(obj_name, this.name, '') /*.append(hint_span)*/ + ); + dt.after(dd); } } - /*Was ipa_details_field_save*/ - function save(container) { - var field = this; - var values = []; + } - var dd = $('dd[title='+field.name+']', container); - dd.each(function () { - var input = $('input', $(this)); - if (!input.length) return; + function save(container) { + var field = this; + var values = []; - if (input.is('.strikethrough')) return; + var dd = $('dd[title='+field.name+']', container); + dd.each(function () { + var input = $('input', $(this)); + if (!input.length) return; - var value = $.trim(input.val()); - if (!value) value = ''; + if (input.is('.strikethrough')) return; + var value = $.trim(input.val()); + if (!value) value = ''; - values.push(value); - }); + values.push(value); + }); - return values; - } + return values; + } - that.fields.push(spec); - that.controls[spec.name] = spec; + return that; +} - if (!spec.setup){ - spec.setup = setup; - } - if (!spec.load){ - spec.load = load; - } +function ipa_details_section(spec){ - if (!spec.save){ - spec.save = save; - } + spec = spec || {}; - return that; + var that = {}; + that.name = spec.name || ''; + that.label = spec.label || ''; + + that.fields = []; + that.fields_by_name = {}; + + that.get_fields = function() { + return that.fields; + }; + + that.get_field = function(name) { + return that.fields_by_name[name]; + }; + + that.add_field = function(field) { + that.fields.push(field); + that.fields_by_name[field.name] = field; + }; + + that.create_field = function(spec) { + var field = ipa_details_field(spec); + that.add_field(field); + return field; }; + + // Deprecated: Used for backward compatibility only. + function input(spec){ + that.create_field(spec); + return that; + } + that.input = input; - that.fields = []; - that.controls={}; + return that; -}; +} + +// Deprecated: Used for backward compatibility only. +function ipa_stanza(spec) { + return ipa_details_section(spec); +} + +function ipa_details_facet(spec) { + spec = spec || {}; + + var that = ipa_facet(spec); + + that.init = spec.init; + that.setup = spec.setup || setup; + + that.sections = []; + that.sections_by_name = {}; + + that.get_sections = function() { + return that.sections; + }; + that.get_section = function(name) { + return that.sections_by_name[name]; + }; + + that.add_section = function(section) { + that.sections.push(section); + that.sections_by_name[section.name] = section; + }; + + that.create_section = function(spec) { + var section = ipa_stanza(spec); + that.add_section(section); + return section; + }; + + that.is_dirty = function() { + var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; + return pkey != that.pkey; + }; + + function setup(container, unspecified) { + + that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; + + that.setup_views(container); + ipa_details_create(container, that.sections); + + container.find('.details-reset').click(function() { + ipa_details_reset(container); + return false; + }); + + container.find('.details-update').click(function() { + var pkey_name = IPA.metadata[that.entity_name].primary_key; + ipa_details_update(container, ipa_details_cache[that.entity_name][pkey_name][0]); + return false; + }); + + if (that.pkey||unspecified){ + ipa_details_load(container, that.pkey, null, null); + } + } + + if (that.init) that.init(); + + return that; +} function ipa_make_button(which,text,details_class){ @@ -286,7 +374,8 @@ function ipa_details_update(container, pkey, on_win, on_fail) var modlist = {'all': true, 'setattr': [], 'addattr': []}; var attrs_wo_option = {}; - var sections = ipa_entity_get_details_sections(obj_name); + var facet = ipa_entity_get_details_facet(obj_name); + var sections = facet.get_sections(); for (var i=0; i<sections.length; i++) { var section = sections[i]; var fields = section.fields; @@ -355,7 +444,8 @@ function ipa_details_display(container, entry_attrs) $('dd', container).remove(); /* go through all <dt> tags and pair them with newly created <dd>s */ - var sections = ipa_entity_get_details_sections(obj_name); + var facet = ipa_entity_get_details_facet(obj_name); + var sections = facet.get_sections(); for (var i=0; i<sections.length; i++) { var section = sections[i]; var fields = section.fields; diff --git a/install/static/develop.js b/install/static/develop.js index f161f7826..251be0faf 100644 --- a/install/static/develop.js +++ b/install/static/develop.js @@ -1,4 +1,4 @@ if (window.location.protocol == 'file:') { - ipa_json_url = "test/data"; - ipa_use_static_files = true; + IPA.json_url = "test/data"; + IPA.use_static_files = true; } diff --git a/install/static/entity.js b/install/static/entity.js index f63296421..f26f219b7 100644 --- a/install/static/entity.js +++ b/install/static/entity.js @@ -21,262 +21,298 @@ /* REQUIRES: ipa.js, details.js, search.js, add.js */ -var ipa_entity_search_list = {}; -var ipa_entity_add_list = {}; +function ipa_facet(spec) { -//moving this to details -//var ipa_entity_details_list = {}; -var ipa_entity_association_list = {}; + spec = spec || {}; -var ipa_entity_facet_list = {}; + var that = {}; + that.name = spec.name; + that.label = spec.label; + that.entity_name = spec.entity_name; -function ipa_facet(spec){ - return spec; -}; + that.init = spec.init; + that.setup = spec.setup; + that.setup_views = ipa_facet_setup_views; + + return that; +} + +function ipa_entity(spec) { + + spec = spec || {}; + + var that = {}; + that.name = spec.name; + that.label = spec.label; + + that.setup = spec.setup; + + that.add_dialog = null; + + that.facets = []; + that.facets_by_name = {}; + + this.facet_name = null; + + that.get_add_dialog = function() { + return that.add_dialog; + }; + + that.create_add_dialog = function(spec) { + spec.entity_name = that.name; + that.add_dialog = ipa_add_dialog(spec); + return that.add_dialog; + }; + + that.get_facets = function() { + return that.facets; + }; + + that.get_facet = function(name) { + return that.facets_by_name[name]; + }; + + that.add_facet = function(facet) { + that.facets.push(facet); + that.facets_by_name[facet.name] = facet; + }; + + that.create_search_facet = function(spec) { + spec.entity_name = that.name; + var facet = ipa_search_facet(spec); + that.add_facet(facet); + return facet; + }; + + that.create_details_facet = function(spec) { + spec.entity_name = that.name; + var facet = ipa_details_facet(spec); + that.add_facet(facet); + return facet; + }; + + that.create_association_facet = function(spec) { + spec.entity_name = that.name; + var facet = ipa_association_facet(spec); + that.add_facet(facet); + return facet; + }; + + return that; +} /* use this to track individual changes between two hashchange events */ var window_hash_cache = {}; -function ipa_entity_set_search_definition(obj_name, data) -{ - ipa_entity_search_list[obj_name] = data; -} +function ipa_get_entity(entity_name) { -function ipa_entity_set_add_definition(obj_name, data) -{ - ipa_entity_add_list[obj_name] = data; -} + var entity = IPA.get_entity(entity_name); + if (entity) return entity; + + entity = ipa_entity({ + 'name': entity_name + }); -function ipa_entity_set_details_definition(obj_name, data) -{ - ipa_entity_details_list[obj_name] = data; + IPA.add_entity(entity); + return entity; } -function ipa_entity_get_details_sections(obj_name) -{ - var sections = ipa_entity_details_list[obj_name]; - if (sections) return sections; - return []; +function ipa_entity_get_search_facet(entity_name) { + + var entity = ipa_get_entity(entity_name); + + var facet = entity.get_facet('search'); + if (facet) return facet; + + facet = entity.create_search_facet({ + 'name': 'search', + 'label': 'Search' + }); + + return facet; } -function ipa_entity_set_association_definition(obj_name, data) -{ - ipa_entity_association_list[obj_name] = data; +function ipa_entity_set_search_definition(entity_name, data) { + + var facet = ipa_entity_get_search_facet(entity_name); + + for (var i=0; i<data.length; i++) { + var defn = data[i]; + facet.create_column({ + 'name': defn[0], + 'label': defn[1], + 'setup': defn[2] + }); + } } +function ipa_entity_set_add_definition(entity_name, data) { -function ipa_entity_set_facet_definition(obj_name, data) -{ - function facet(spec){ - return spec; + var entity = ipa_get_entity(entity_name); + + var dialog = entity.create_add_dialog({ + 'name': data[0], + 'title': data[1] + }); + + for (var i=0; i<data[2].length; i++) { + var field = data[2][i]; + dialog.create_field({ + name: field[0], + label: field[1], + setup: field[2] + }); } +} - ipa_entity_facet_list[obj_name] = data; +function ipa_entity_get_add_dialog(entity_name) { + + var entity = ipa_get_entity(entity_name); + return entity.get_add_dialog(); } +function ipa_entity_get_details_facet(entity_name) { -function ipa_details_only_setup(container){ - ipa_entity_setup(container, 'details'); + var entity = ipa_get_entity(entity_name); + + var facet = entity.get_facet('details'); + if (facet) return facet; + + facet = entity.create_details_facet({ + 'name': 'details', + 'label': 'Details' + }); + + return facet; } -function ipa_entity_setup(container, unspecified) -{ - - var id = container.attr('id'); - var state = id + '-facet'; - var facet = $.bbq.getState(state, true) || unspecified || 'search'; - var last_facet = window_hash_cache[state]; - - var facet_renders = { - search : function(){ - state = id + '-filter'; - var filter = $.bbq.getState(state, true); - var last_filter = window_hash_cache[state]; - if (filter == last_filter) return; - _ipa_entity_setup(container); - window_hash_cache[state] = filter; - - }, - details : function (){ - state = id + '-pkey'; - var pkey = $.bbq.getState(state, true); - var last_pkey = window_hash_cache[state]; - if (pkey == last_pkey) return; - _ipa_entity_setup(container); - window_hash_cache[state] = pkey; - }, - associate : function () { - state = id + '-enroll'; - var enroll = $.bbq.getState(state, true); - var last_enroll = window_hash_cache[state]; - if (enroll == last_enroll) return; - _ipa_entity_setup(container); - window_hash_cache[state] = enroll; - }, - records : function () { - state = id + '-record'; - var records = $.bbq.getState(state, true); - var last_records = window_hash_cache[state]; - if (records == last_records) return; - _ipa_entity_setup(container); - window_hash_cache[state] = record; - } - }; +function ipa_entity_set_details_definition(entity_name, sections) { - if (facet != last_facet) { - _ipa_entity_setup(container,unspecified); - window_hash_cache[state] = facet; - } else{ - var render = facet_renders[facet]; - if (render) { - render(); - } - //TODO handle error. + var facet = ipa_entity_get_details_facet(entity_name); + + for (var i=0; i<sections.length; i++) { + var section = sections[i]; + facet.add_section(section); } +} + +function ipa_entity_get_association_facet(entity_name) { + + var entity = ipa_get_entity(entity_name); + + var facet = entity.get_facet('associate'); + if (facet) return facet; + facet = entity.create_association_facet({ + 'name': 'associate' + }); + + return facet; } -function _ipa_entity_setup(container, unspecified) { +function ipa_entity_set_association_definition(entity_name, data) { - var obj_name = container.attr('id'); + var facet = ipa_entity_get_association_facet(entity_name); - function reset_on_click() { - ipa_details_reset(container); - return (false); + for (var other_entity in data) { + var config = data[other_entity]; + facet.create_config({ + 'name': other_entity, + 'associator': config.associator, + 'method': config.method + }); } +} - function update_on_click() { - var pkey_name = ipa_objs[obj_name].primary_key; - ipa_details_update(container, ipa_details_cache[obj_name][pkey_name][0]); - return (false); - } +function ipa_entity_set_facet_definition(entity_name, list) { - function new_on_click() { - add_dialog_create(obj_name, ipa_entity_add_list[obj_name]); - return (false); - } + var entity = ipa_get_entity(entity_name); - function switch_view() { - var enroll_obj_name = $(this).attr('title'); - var state = {}; - if (enroll_obj_name != 'search' && - enroll_obj_name != 'details' && - enroll_obj_name != 'records') { - state[obj_name + '-facet'] = 'associate'; - state[obj_name + '-enroll'] = enroll_obj_name; - } else { - state[obj_name + '-facet'] = enroll_obj_name; - state[obj_name + '-enroll'] = ''; - } - $.bbq.pushState(state); + for (var i=0; i<list.length; i++) { + var facet = list[i]; + facet.entity_name = entity_name; + entity.add_facet(facet); } +} - var facet_setups = { - search : function (unspecified) { - var filter = $.bbq.getState(obj_name + '-filter', true) || ''; - search_create(obj_name, ipa_entity_search_list[obj_name], container); - ipa_make_button( 'ui-icon-plus',ipa_messages.button.add). - click(new_on_click). - appendTo($( "div#" + obj_name + " > div.search-controls")) - search_load(container, filter); - }, - - details : function(unspecified) { - var pkey = $.bbq.getState(obj_name + '-pkey', true); - ipa_entity_generate_views(obj_name, container, switch_view); - var sections = ipa_entity_get_details_sections(obj_name); - ipa_details_create(container, sections); - container.find('.details-reset').click(reset_on_click); - container.find('.details-update').click(update_on_click); - if (pkey||unspecified){ - ipa_details_load(container, pkey, null, null); - } - }, - - associate : function facet(unspecified) { - var pkey = $.bbq.getState(obj_name + '-pkey', true) || ''; - var enroll_obj_name = $.bbq.getState(obj_name + '-enroll', true) || ''; - var attr = ipa_get_member_attribute(obj_name, enroll_obj_name); - var columns = [ - { - title: ipa_objs[enroll_obj_name].label, - column: attr + '_' + enroll_obj_name - } - ]; - var association = ipa_entity_association_list[obj_name]; - var association_config = association ? association[enroll_obj_name] : null; - var associator = association_config ? association_config.associator : null; - var method = association_config ? association_config.method : null; - var frm = new AssociationList( - obj_name, pkey, enroll_obj_name, columns, container, - associator, method - ); - ipa_entity_generate_views(obj_name, container, switch_view); - frm.setup(); - }, - - records: function(unspecified) { - records_facet.setup(obj_name, container, switch_view ); - } +function ipa_details_only_setup(container){ + ipa_entity_setup.call(this, container, 'details'); +} - } +function ipa_entity_setup(container, unspecified) { + var entity = this; container.empty(); - var facet = $.bbq.getState(obj_name + '-facet', true) || - unspecified || 'search'; + var facet_name = $.bbq.getState(entity.name + '-facet', true) || unspecified || 'search'; - var facet_setup_function = facet_setups[facet]; - if (facet_setup_function){ - facet_setup_function(unspecified); - } -} + var facet = entity.get_facet(facet_name); + if (!facet) return; -function ipa_entity_generate_views(obj_name, container, switch_view) -{ - var ul = $('<ul></ul>', {'class': 'entity-views'}); - - //TODO for single instance entites, don't display search - ul.append($('<li></li>', { - title: 'search', - text: 'Search', - click: switch_view - })); - - ul.append($('<li></li>', { - text: 'Details', - title: 'details', - click: switch_view - }).prepend('| ')); - - var attribute_members = ipa_objs[obj_name].attribute_members; - for (attr in attribute_members) { - var objs = attribute_members[attr]; - for (var i = 0; i < objs.length; ++i) { - var m = objs[i]; - var label = ipa_objs[m].label; + if (IPA.entity_name == entity.name) { + if (entity.facet_name == facet_name) { + if (!facet.is_dirty()) return; - ul.append($('<li></li>', { - title: m, - text:label, - click: switch_view - }).prepend('| ')); + } else { + entity.facet_name = facet_name; } + } else { + IPA.entity_name = entity.name; } - //TODO Additional facets go here - - var facets = ipa_entity_facet_list[obj_name]; - if (facets){ - for (var f = 0; f < facets.length; f += 1){ - var facet = facets[f]; - ul.append($('<li></li>', { - text: facet.name, - title: facet.name, - click: switch_view - }).prepend('| ')); + if (facet.setup) { + facet.setup(container, unspecified); + } +} + +function ipa_facet_setup_views(container) { + + var facet = this; + + var ul = $('<ul/>', {'class': 'entity-views'}); + + var entity = IPA.get_entity(facet.entity_name); + var facets = entity.get_facets(); + + for (var i=0; i<facets.length; i++) { + var other_facet = facets[i]; + var facet_name = other_facet.name; + + if (other_facet.label) { + + var label = other_facet.label; + if (i > 0) label = '| '+label; + + ul.append($('<li/>', { + title: other_facet.name, + text: label, + click: function(entity_name, facet_name) { + return function() { IPA.show_page(entity_name, facet_name); } + }(facet.entity_name, facet_name) + })); + + } else { // For now empty label indicates an association facet + + var attribute_members = IPA.metadata[facet.entity_name].attribute_members; + for (var attribute_member in attribute_members) { + var other_entities = attribute_members[attribute_member]; + for (var j = 0; j < other_entities.length; j++) { + var other_entity = other_entities[j]; + var label = IPA.metadata[other_entity].label; + + if (i > 0 || j > 0) label = '| ' + label; + + ul.append($('<li/>', { + title: other_entity, + text: label, + click: function(entity_name, facet_name, other_entity) { + return function() { IPA.show_page(entity_name, facet_name, other_entity); } + }(facet.entity_name, facet_name, other_entity) + })); + } + } } } @@ -286,11 +322,10 @@ function ipa_entity_generate_views(obj_name, container, switch_view) function ipa_entity_quick_links(tr, attr, value, entry_attrs) { var obj_name = tr.closest('.search-container').attr('title'); - var pkey = ipa_objs[obj_name].primary_key; + var pkey = IPA.metadata[obj_name].primary_key; var pkey_value = entry_attrs[pkey][0]; - var td = $("<td/>"); - tr.append(td); + var td = $("<td/>").appendTo(tr); $("<a/>", { href: "#details", @@ -304,12 +339,12 @@ function ipa_entity_quick_links(tr, attr, value, entry_attrs) { } }).appendTo(td); - var attribute_members = ipa_objs[obj_name].attribute_members; + var attribute_members = IPA.metadata[obj_name].attribute_members; for (attr_name in attribute_members) { var objs = attribute_members[attr_name]; for (var i = 0; i < objs.length; ++i) { var m = objs[i]; - var label = ipa_objs[m].label; + var label = IPA.metadata[m].label; $("<a/>", { href: '#'+m, diff --git a/install/static/hbac.js b/install/static/hbac.js new file mode 100755 index 000000000..94b05fbd4 --- /dev/null +++ b/install/static/hbac.js @@ -0,0 +1,214 @@ +/* Authors: + * Endi Sukma Dewata <edewata@redhat.com> + * + * 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_hbac() { + + var that = ipa_entity({ + 'name': 'hbac' + }); + + that.init = function() { + that.create_add_dialog({ + 'name': 'add', + 'title': 'Add New Rule', + 'init': ipa_hbac_add_init + }); + + that.create_search_facet({ + 'name': 'search', + 'label': 'Search', + 'init': ipa_hbac_search_init, + 'setup': ipa_hbac_search_setup + }); + + that.create_details_facet({ + 'name': 'details', + 'label': 'Details', + 'init': ipa_hbac_details_init, + 'setup': ipa_hbac_details_setup + }); + + that.create_association_facet({ + 'name': 'associate' + }); + }; + + that.init(); + + return that; +} + +IPA.add_entity(ipa_hbac()); + +function ipa_hbac_add_init() { + this.create_field({name:'cn', label:'Rule Name'}); +} + +function ipa_hbac_search_init() { + + 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'}); + + this.create_column({ + name: 'quick_links', + label: 'Quick Links', + setup: ipa_hbac_quick_links + }); +} + +function ipa_hbac_search_setup(container) { + + var facet = this; + + facet.filter = $.bbq.getState(facet.entity_name + '-filter', true) || ''; + + var toolbar = $('<span/>').appendTo(container); + + $('<input/>', { + 'type': 'button', + 'value': 'Troubleshoot Rules', + 'click': function() { + } + }).appendTo(toolbar); + + $('<input/>', { + 'type': 'button', + 'value': 'Cull Disabled Rules', + 'click': function() { + } + }).appendTo(toolbar); + + $('<input/>', { + 'type': 'button', + 'value': 'Login Services', + 'click': function() { + } + }).appendTo(toolbar); + + $('<input/>', { + 'type': 'button', + 'value': 'Login Svc Groups', + 'click': function() { + } + }).appendTo(toolbar); + + search_create(facet.entity_name, facet.columns, container); + + ipa_make_button('ui-icon-plus', IPA.messages.button.add). + click(function() { + var entity = IPA.get_entity(facet.entity_name); + entity.add_dialog.open(); + return false; + }). + appendTo($('.search-controls', container)); + + search_load(container, facet.filter); +} + +function ipa_hbac_quick_links(tr, attr, value, entry_attrs) { + + var column = this; + var facet = column.facet; + + var pkey = IPA.metadata[facet.entity_name].primary_key; + var pkey_value = entry_attrs[pkey][0]; + + var td = $('<td/>').appendTo(tr); + + $('<a/>', { + 'href': '#details', + 'title': 'Details', + 'text': 'Details', + 'click': function() { + var state = {}; + state[facet.entity_name+'-facet'] = 'details'; + state[facet.entity_name+'-pkey'] = pkey_value; + nav_push_state(state); + return false; + } + }).appendTo(td); + + td.append(' | '); + + $('<a/>', { + 'href': '#test-rule', + 'title': 'Test Rule', + 'text': 'Test Rule', + 'click': function() { + var state = {}; + state[facet.entity_name+'-facet'] = 'test-rule'; + state[facet.entity_name+'-pkey'] = pkey_value; + nav_push_state(state); + return false; + } + }).appendTo(td); +} + +function ipa_hbac_details_init() { + + var section = this.create_section({name:'general', label:'General'}); + section.create_field({name:'cn', label:'Name'}); + section.create_field({name:'accessruletype', label:'Rule Type'}); + section.create_field({name:'description', label:'Description'}); + section.create_field({name:'ipaenabledflag', label:'Enabled'}); + + section = this.create_section({name:'user', label:'Who'}); + section.create_field({name:'usercategory', label:'User Category'}); + + section = this.create_section({name:'host', label:'Accessing'}); + section.create_field({name:'hostcategory', label:'Host Category'}); + + section = this.create_section({name:'service', label:'Via Service'}); + section.create_field({name:'servicecategory', label:'Service Category'}); + + section = this.create_section({name:'sourcehost', label:'From'}); + section.create_field({name:'sourcehostcategory', label:'Source Host Category'}); +} + +function ipa_hbac_details_setup(container, unspecified) { + + var facet = this; + + var pkey = $.bbq.getState(facet.entity_name + '-pkey', true); + var pkey_name = IPA.metadata[facet.entity_name].primary_key; + + facet.setup_views(container); + + var sections = facet.get_sections(); + ipa_details_create(container, sections); + + container.find('.details-reset').click(function() { + ipa_details_reset(container); + return false; + }); + + container.find('.details-update').click(function() { + ipa_details_update(container, ipa_details_cache[facet.entity_name][pkey_name][0]); + return false; + }); + + ipa_details_load(container, pkey, null, null); +} diff --git a/install/static/hostgroup.js b/install/static/hostgroup.js index 37af6d6e5..02418bf05 100644 --- a/install/static/hostgroup.js +++ b/install/static/hostgroup.js @@ -38,3 +38,6 @@ ipa_entity_set_details_definition('hostgroup', [ input({name:'cn', label:'Name'}). input({name: 'description', label:'Description'}) ]); + +ipa_entity_set_association_definition('hostgroup', { +}); diff --git a/install/static/index.xhtml b/install/static/index.xhtml index 58c631e8c..bcb7cd0bb 100644 --- a/install/static/index.xhtml +++ b/install/static/index.xhtml @@ -22,6 +22,7 @@ <script type="text/javascript" src="certificate.js"></script> <script type="text/javascript" src="user.js"></script> <script type="text/javascript" src="group.js"></script> + <script type="text/javascript" src="hbac.js"></script> <script type="text/javascript" src="host.js"></script> <script type="text/javascript" src="hostgroup.js"></script> <script type="text/javascript" src="netgroup.js"></script> diff --git a/install/static/ipa.js b/install/static/ipa.js index 74fde9299..9da693051 100644 --- a/install/static/ipa.js +++ b/install/static/ipa.js @@ -22,48 +22,82 @@ var IPA_DEFAULT_JSON_URL = '/ipa/json'; -var ipa_json_url; -var ipa_use_static_files; - -var ipa_ajax_options = { - type: 'POST', - contentType: 'application/json', - dataType: 'json', - async: true, - processData: false -}; - /* JSON-RPC ID counter */ var ipa_jsonrpc_id = 0; -/* IPA objects data in JSON format */ -var ipa_messages = {}; -var ipa_objs = {}; +var IPA = function() { -var ipa_dialog = $('<div/>', {id: 'ipa_dialog'}); + var that = {}; -/* initialize the IPA JSON-RPC helper - * arguments: - * url - JSON-RPC URL to use (optional) */ -function ipa_init(url, use_static_files, on_win, on_error) -{ - if (url) - ipa_json_url = url; - - if (use_static_files) - ipa_use_static_files = use_static_files; - - $.ajaxSetup(ipa_ajax_options); - - ipa_cmd('json_metadata', [], {}, - function(data, text_status, xhr) { - ipa_objs = data.result.metadata; - ipa_messages = data.result.messages; - if (on_win) on_win(data, text_status, xhr); - }, - on_error - ); -} + that.json_url = null; + that.use_static_files = false; + + that.ajax_options = { + type: 'POST', + contentType: 'application/json', + dataType: 'json', + async: true, + processData: false + }; + + that.messages = {}; + that.metadata = {}; + + that.entities = []; + that.entities_by_name = {}; + + that.error_dialog = $('<div/>', { + id: 'error_dialog' + }); + + /* initialize the IPA JSON-RPC helper + * arguments: + * url - JSON-RPC URL to use (optional) */ + that.init = function(url, use_static_files, on_success, on_error) { + if (url) + that.json_url = url; + + if (use_static_files) + that.use_static_files = use_static_files; + + $.ajaxSetup(that.ajax_options); + + ipa_cmd('json_metadata', [], {}, + function(data, text_status, xhr) { + that.metadata = data.result.metadata; + that.messages = data.result.messages; + if (on_success) on_success(data, text_status, xhr); + }, + on_error + ); + }; + + that.get_entities = function() { + return that.entities; + }; + + that.get_entity = function(name) { + return that.entities_by_name[name]; + }; + + that.add_entity = function(entity) { + that.entities.push(entity); + that.entities_by_name[entity.name] = entity; + }; + + that.show_page = function(entity_name, facet_name, other_entity) { + + var entity = IPA.get_entity(entity_name); + var facet = entity.get_facet(facet_name); + + var state = {}; + state[entity_name + '-facet'] = facet_name; + state[entity_name + '-enroll'] = other_entity ? other_entity : ''; + $.bbq.pushState(state); + }; + + return that; +}(); /* call an IPA command over JSON-RPC * arguments: @@ -96,26 +130,26 @@ function ipa_cmd(name, args, options, win_callback, fail_callback, objname) } function ipa_error_handler(xhr, text_status, error_thrown) { - ipa_dialog.empty(); - ipa_dialog.attr('title', 'Error: '+error_thrown.name); + IPA.error_dialog.empty(); + IPA.error_dialog.attr('title', 'Error: '+error_thrown.name); - ipa_dialog.append('<p>URL: '+this.url+'</p>'); + IPA.error_dialog.append('<p>URL: '+this.url+'</p>'); if (error_thrown.message) { - ipa_dialog.append('<p>'+error_thrown.message+'</p>'); + IPA.error_dialog.append('<p>'+error_thrown.message+'</p>'); } var that = this; - ipa_dialog.dialog({ + IPA.error_dialog.dialog({ modal: true, width: 400, buttons: { 'Retry': function() { - ipa_dialog.dialog('close'); + IPA.error_dialog.dialog('close'); ipa_cmd(name, args, options, win_callback, fail_callback, objname); }, 'Cancel': function() { - ipa_dialog.dialog('close'); + IPA.error_dialog.dialog('close'); fail_callback.call(that, xhr, text_status, error_thrown); } } @@ -129,12 +163,12 @@ function ipa_cmd(name, args, options, win_callback, fail_callback, objname) if (objname) method_name = objname + '_' + name; - var url = ipa_json_url; + var url = IPA.json_url; if (!url) url = IPA_DEFAULT_JSON_URL; - if (ipa_use_static_files) + if (IPA.use_static_files) url += '/' + method_name + '.json'; var data = { @@ -182,7 +216,7 @@ function ipa_parse_qs(qs) /* helper function used to retrieve information about an attribute */ function ipa_get_param_info(obj_name, attr) { - var ipa_obj = ipa_objs[obj_name]; + var ipa_obj = IPA.metadata[obj_name]; if (!ipa_obj) return null; var takes_params = ipa_obj.takes_params; @@ -200,10 +234,10 @@ function ipa_get_param_info(obj_name, attr) /* helper function used to retrieve attr name with members of type `member` */ function ipa_get_member_attribute(obj_name, member) { - var ipa_obj = ipa_objs[obj_name]; + var ipa_obj = IPA.metadata[obj_name]; if (!ipa_obj) return null; - var attribute_members = ipa_obj.attribute_members + var attribute_members = ipa_obj.attribute_members; for (var a in attribute_members) { var objs = attribute_members[a]; for (var i = 0; i < objs.length; ++i) { diff --git a/install/static/navigation.js b/install/static/navigation.js index 4135cb44b..72b58ee09 100644 --- a/install/static/navigation.js +++ b/install/static/navigation.js @@ -71,21 +71,25 @@ function nav_generate_tabs(nls, container, tabclass, depth) container.append(ul); for (var i = 0; i < nls.length; ++i) { - var n = nls[i]; + var tab = nls[i]; - var name = n.name; - if ((ipa_objs[n.name]) && (ipa_objs[n.name].label)){ - name = ipa_objs[n.name].label; + var label = tab.name; + if ((IPA.metadata[tab.name]) && (IPA.metadata[tab.name].label)){ + label = IPA.metadata[tab.name].label; } - var li = nav_create_tab_li(n.name, name); + var li = nav_create_tab_li(tab.name, label); ul.append(li); - var div = nav_create_tab_div(n.name); + var div = nav_create_tab_div(tab.name); container.append(div); - if (n.children) { - nav_generate_tabs(n.children, div, tabclass, depth +1 ); + if (tab.children) { + nav_generate_tabs(tab.children, div, tabclass, depth +1 ); + } else { + var entity = ipa_get_entity(tab.name); + entity.label = tab.label; + entity.setup = tab.setup; } } } @@ -126,6 +130,7 @@ function _nav_update_tabs(nls, container) _nav_update_tabs(tab.children, container2); } else if (tab.setup) { - tab.setup(container2); + var entity = IPA.get_entity(tab.name); + entity.setup(container2); } } diff --git a/install/static/netgroup.js b/install/static/netgroup.js index 9a738877d..5bedc9357 100644 --- a/install/static/netgroup.js +++ b/install/static/netgroup.js @@ -40,3 +40,5 @@ ipa_entity_set_details_definition('netgroup', [ input({name:'nisdomainname', label:'NIS Domain'}) ]); +ipa_entity_set_association_definition('netgroup', { +}); diff --git a/install/static/policy.js b/install/static/policy.js index 4d30c5732..dd5447718 100644 --- a/install/static/policy.js +++ b/install/static/policy.js @@ -20,33 +20,6 @@ /* REQUIRES: ipa.js, details.js, search.js, add.js, entity.js */ -ipa_entity_set_search_definition('hbac', [ - ['cn', 'Name', null], - ['description', 'description', null], - ['quick_links', 'Quick Links', ipa_entity_quick_links] -]); - -ipa_entity_set_add_definition('hbac', [ - 'dialog-add-hbac', 'Add New Zone', [ - ['cn', 'Name', null] - ] -]); - -ipa_entity_set_details_definition('hbac', [ - ipa_stanza({name:'identity', label:'HBAC Details'}). - input({name:'cn', label:'HBAC Name'}). - input({name:'accessruletype', label:'Rule Type'}). - input({name:'description', label:'Description'}). - input({name:'hostcategory', label:'Host Category'}). - input({name:'ipaenabledflag', label:'Enabled'}). - input({name:'servicecategory', label:'Service Category'}). - input({name:'sourcehostcategory', label:'Source Host Category'}). - input({name:'usercategory', label:'User Category'}) -]); - -ipa_entity_set_association_definition('hbac', { -}); - /* DNS */ ipa_entity_set_search_definition('dns', [ ['idnsname', 'Zone Name', null], @@ -84,12 +57,19 @@ ipa_entity_set_association_definition('dns', { ipa_entity_set_facet_definition('dns', [ - ipa_facet({name:'records'})] + ipa_records_facet({ + 'name': 'records', + 'label': 'Records' + })] ); -function create_records_facet(){ +function ipa_records_facet(spec){ - var that = {}; + spec = spec || {}; + + var that = ipa_facet(spec); + + that.record = null; var record_types =[ 'a', 'aaaa', 'dname', 'cname', 'mx', 'ns', 'ptr', 'srv', 'txt', 'a6', 'afsdb', 'cert', 'ds', 'hinfo', @@ -149,10 +129,10 @@ function create_records_facet(){ reload(); if (called_from_add_and_edit) { } - }; + } function add_fail(data, text_status, xhr) { - }; + } params.push( $.bbq.getState('dns-pkey', true)); params.push(add_dialog.find('#dns-record-resource').val()); @@ -161,16 +141,16 @@ function create_records_facet(){ ipa_cmd('dns_add_rr', params, options, add_win, add_fail); //add_dialog.dialog('close'); - }; + } function add_and_close(evt) { add(evt, true); add_dialog.dialog('close'); - }; + } function cancel() { add_dialog.dialog('close'); - }; + } add_dialog.dialog({ @@ -199,8 +179,8 @@ function create_records_facet(){ var delete_dialog = $('<div/>', { - title: ipa_messages.button.delete, - 'class': 'search-dialog-delete', + title: IPA.messages.button.delete, + 'class': 'search-dialog-delete' }); var to_delete_table = $('<table class="search-table" >'+ @@ -240,40 +220,49 @@ function create_records_facet(){ ipa_cmd('dns_del_rr',delete_list[i],{}, delete_complete,delete_complete); } - }; + } function cancel_on_click() { delete_dialog.dialog('close'); - }; + } if (delete_list.length == 0) return; delete_dialog.append($('<P/>', - {text:ipa_messages.search.delete_confirm})); + {text: IPA.messages.search.delete_confirm})); delete_dialog.dialog({ modal: true, buttons: { 'Delete': delete_on_click, - 'Cancel': cancel_on_click, - }, + 'Cancel': cancel_on_click + } }); } - function setup(obj_name, container,switch_view){ + that.is_dirty = function() { + var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; + var record = $.bbq.getState(that.entity_name + '-record', true) || ''; + return pkey != that.pkey || record != that.record; + }; + + 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; - var pkey = $.bbq.getState('dns' + '-pkey', true); - ipa_entity_generate_views(obj_name, container, switch_view); + that.setup_views(container); - container.attr('title', obj_name); + container.attr('title', that.entity_name); container.addClass('search-container'); var h2 = $('<h2></h2>',{ - text: "Records for DNS Zone:" + pkey + text: "Records for DNS Zone:" + that.pkey }).appendTo(container); @@ -286,7 +275,7 @@ function create_records_facet(){ control_span.append($('<input />',{ type: "text", id: 'dns-record-resource-filter', - name: 'search-' + obj_name + '-filter' + name: 'search-' + that.entity_name + '-filter' })); control_span.append('Type'); @@ -302,13 +291,13 @@ function create_records_facet(){ //})); - ipa_make_button('ui-icon-search',ipa_messages.button.find). + ipa_make_button('ui-icon-search', IPA.messages.button.find). click(function(){load(container)}).appendTo(control_span); - ipa_make_button('ui-icon-plus',ipa_messages.button.add). + ipa_make_button('ui-icon-plus', IPA.messages.button.add). click(add_click).appendTo(control_span); - ipa_make_button('ui-icon-trash',ipa_messages.button.delete). + ipa_make_button('ui-icon-trash', IPA.messages.button.delete). click(function(){delete_records(records_table);}). appendTo(control_span); @@ -316,16 +305,16 @@ function create_records_facet(){ div.append('<span class="records-buttons"></span>'); var records_results = $('<div/>', { - class: 'records-results' + 'class': 'records-results' }).appendTo(container); var records_table = $('<table/>', { - class: 'search-table', + 'class': 'search-table' }).appendTo(records_results); var thead = $('<thead><tr></tr></thead>').appendTo(records_table); - var tbody = $('<tbody></tbody>').appendTo(records_table);; - var tfoot = $('<tfoot></tfoot>').appendTo(records_table);; + var tbody = $('<tbody></tbody>').appendTo(records_table); + var tfoot = $('<tfoot></tfoot>').appendTo(records_table); var tr = thead.find('tr'); tr.append($('<th style="width: 15px" />').append( @@ -363,17 +352,17 @@ function create_records_facet(){ var options = {}; var resource_filter = container.find("#dns-record-resource-filter") - .val() + .val(); if (resource_filter){ options.idnsname = resource_filter; } - var type_filter = container.find("#dns-record-type-filter").val() + var type_filter = container.find("#dns-record-type-filter").val(); if (type_filter){ options.type = type_filter; } - var data_filter = container.find("#dns-record-data-filter").val() + var data_filter = container.find("#dns-record-data-filter").val(); if (data_filter){ options.data = data_filter; } @@ -454,12 +443,7 @@ function create_records_facet(){ that.load = load; return that; -}; - - -var records_facet = create_records_facet(); - - +} /**Automount*/ diff --git a/install/static/search.js b/install/static/search.js index e4efcb0ef..fd123c094 100644 --- a/install/static/search.js +++ b/install/static/search.js @@ -21,30 +21,127 @@ /* REQUIRES: ipa.js */ -function search_create(obj_name, scl, container) -{ - if (!scl){ - scl = []; +function ipa_search_column(spec) { + + spec = spec || {}; + + var that = {}; + + that.name = spec.name; + that.label = spec.label || that.name; + that.facet = spec.facet; + + that.init = spec.init || init; + that.setup = spec.setup || setup; + + function init() { + } + + function setup(tr, attr, value, entry_attrs) { + search_generate_td(tr, attr, value, entry_attrs); } + return that; +} + +function ipa_search_facet(spec) { + + spec = spec || {}; + + var that = ipa_facet(spec); + + that.init = spec.init || init; + that.setup = spec.setup || setup; + + that.columns = []; + that.columns_by_name = {}; + + that.get_columns = function() { + return that.columns; + }; + + that.get_column = function(name) { + return that.columns_by_name[name]; + }; + + that.add_column = function(column) { + that.columns.push(column); + that.columns_by_name[column.name] = column; + }; + + that.create_column = function(spec) { + spec.facet = that; + var column = ipa_search_column(spec); + that.add_column(column); + return column; + }; + + function init() { + } + + that.is_dirty = function() { + var filter = $.bbq.getState(that.entity_name + '-filter', true) || ''; + return filter != that.filter; + }; + + function setup(container, unspecified) { + + that.filter = $.bbq.getState(that.entity_name + '-filter', true) || ''; + + search_create(that.entity_name, that.columns, container); + + ipa_make_button('ui-icon-plus', IPA.messages.button.add). + 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); + } + + if (spec.columns) { + for (var i=0; i<spec.columns.length; i++) { + var column = spec.columns[i]; + column.facet = that; + that.add_column(column); + } + } + + 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[obj_name + '-filter'] = filter; + state[entity_name + '-filter'] = filter; $.bbq.pushState(state); - }; + } function delete_on_click_outer() { var delete_list = []; var delete_dialog = $('<div></div>', { - title: ipa_messages.button.delete, - 'class': 'search-dialog-delete', + title: IPA.messages.button.delete, + 'class': 'search-dialog-delete' }); function delete_on_click() { - ipa_cmd('del', delete_list, {}, delete_on_win, null, obj_name); + 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) { @@ -54,11 +151,11 @@ function search_create(obj_name, scl, container) if (chk) chk.closest('tr').remove(); } - }; + } function cancel_on_click() { delete_dialog.dialog('close'); - }; + } container.find('.search-selector').each(function () { var jobj = $(this); @@ -69,45 +166,52 @@ function search_create(obj_name, scl, container) if (delete_list.length == 0) return; - delete_dialog.text(ipa_messages.search.delete_confirm); + delete_dialog.text(IPA.messages.search.delete_confirm); delete_dialog.dialog({ modal: true, buttons: { 'Delete': delete_on_click, - 'Cancel': cancel_on_click, - }, + 'Cancel': cancel_on_click + } }); - }; + } if (!container) { alert('ERROR: search_create: Second argument "container" missing!'); - return; + return null; } - container.attr('title', obj_name); + container.attr('title', entity_name); container.addClass('search-container'); - container.append('<div class="search-controls"></div>'); - var div = container.children().last(); - div.append('<span class="search-filter"></span>'); - var jobj = div.children().last(); - jobj.append('<input type="text" />'); - jobj.children().last().attr('name', 'search-' + obj_name + '-filter') - ipa_make_button('ui-icon-search',ipa_messages.button.find). - click(find_on_click).appendTo(jobj); + var search_controls = $('<div/>', { + 'class': 'search-controls' + }).appendTo(container); + + var search_filter = $('<span/>', { + 'class': 'search-filter' + }).appendTo(search_controls); + + var filter = $('<input/>', { + 'type': 'text', + 'name': 'search-' + entity_name + '-filter' + }).appendTo(search_filter); - ipa_make_button('ui-icon-trash',ipa_messages.button.delete). - click(delete_on_click_outer).appendTo(jobj); + ipa_make_button('ui-icon-search', IPA.messages.button.find). + click(find_on_click).appendTo(search_filter); - div.append('<span class="search-buttons"></span>'); + ipa_make_button('ui-icon-trash',IPA.messages.button.delete). + click(delete_on_click_outer).appendTo(search_filter); + + search_controls.append('<span class="search-buttons"></span>'); var search_results = $('<div/>', { - class: 'search-results' + 'class': 'search-results' }).appendTo(container); var search_table = $('<table/>', { - class: 'search-table' + 'class': 'search-table' }).appendTo(search_results); search_table.append('<thead><tr></tr></thead>'); @@ -116,9 +220,9 @@ function search_create(obj_name, scl, container) var tr = search_table.find('tr'); search_insert_checkbox_th(tr); - for (var i = 0; i < scl.length; ++i) { - var c = scl[i]; - search_insert_th(tr, obj_name, c[0], c[1], c[2]); + for (var i = 0; i < columns.length; ++i) { + var c = columns[i]; + search_insert_th(tr, entity_name, c.name, c.label, c.setup); } } @@ -144,7 +248,7 @@ function search_insert_checkbox_th(jobj) var checkbox = $('<input />', { type: 'checkbox', - title: 'Select All', + title: 'Select All' }); checkbox.click(select_all_on_click); @@ -174,39 +278,42 @@ function search_insert_th(jobj, obj_name, attr, name, render_call) jobj.append(th); } -function search_load(jobj, criteria, on_win, on_fail) +function search_load(container, criteria, on_win, on_fail) { - var obj_name = jobj.attr('id'); + 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(obj_name, data); - }; + 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', jobj); + var search_results = $('.search-results', container); search_results.append('<p>Error: '+error_thrown.name+'</p>'); search_results.append('<p>URL: '+this.url+'</p>'); search_results.append('<p>'+error_thrown.message+'</p>'); } ipa_cmd( - 'find', [criteria], {all: true}, search_on_success, search_on_error, obj_name + '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('.search-container').attr('title'); - var pkey = ipa_objs[obj_name].primary_key; + var pkey = IPA.metadata[obj_name].primary_key; var pkey_value = entry_attrs[pkey]; + var entity = IPA.get_entity(obj_name); + var facet = entity ? entity.get_facet('search') : null; + tbody.append('<tr></tr>'); var tr = tbody.children().last(); search_generate_checkbox_td(tr, pkey_value); @@ -217,11 +324,17 @@ function search_generate_tr(thead, tbody, entry_attrs) var attr = jobj.attr('abbr'); var value = entry_attrs[attr]; + var column = facet ? facet.get_column(attr) : null; var render_call = window[jobj.attr('title')]; - if (typeof render_call == 'function') { + + if (column && column.setup) { + column.setup(tr, attr, value, entry_attrs); + + } else if (typeof render_call == 'function') { render_call(tr, attr, value, entry_attrs); + } else - search_generate_td(tr, attr, value); + search_generate_td(tr, attr, value, entry_attrs); } tbody.find('.search-a-pkey').click(function () { @@ -242,7 +355,7 @@ function search_generate_checkbox_td(tr, pkey) name: pkey, title: pkey, type: 'checkbox', - 'class': 'search-selector', + 'class': 'search-selector' }); var td = $('<td></td>'); @@ -253,7 +366,7 @@ function search_generate_checkbox_td(tr, pkey) var _search_td_template = '<td title="A">V</td>'; var _search_a_pkey_template = '<a href="jslink" class="search-a-pkey">V</a>'; -function search_generate_td(tr, attr, value) +function search_generate_td(tr, attr, value, entry_attrs) { var obj_name = tr.closest('.search-container').attr('title'); diff --git a/install/static/serverconfig.js b/install/static/serverconfig.js index a73eb1349..cb61265ee 100644 --- a/install/static/serverconfig.js +++ b/install/static/serverconfig.js @@ -66,6 +66,9 @@ ipa_entity_set_details_definition('taskgroup', [ input({name:'description', label:'Description'}) ]); +ipa_entity_set_association_definition('taskgroup', { +}); + ipa_entity_set_association_definition('rolegroup', { 'rolegroup': { associator: BulkAssociator } }); diff --git a/install/static/service.js b/install/static/service.js index 620c1babe..21b2d0b92 100644 --- a/install/static/service.js +++ b/install/static/service.js @@ -20,34 +20,101 @@ /* REQUIRES: ipa.js, details.js, search.js, add.js, entity.js */ -ipa_entity_set_search_definition('service', [ - ['krbprincipalname', 'Principal', null], - ['quick_links', 'Quick Links', ipa_entity_quick_links] -]); - -ipa_entity_set_add_definition('service', [ - 'dialog-add-service', 'Add New Service', [ - ['krbprincipalname', 'Principal', service_add_krbprincipalname], - ['service', 'Service', null], - ['host', 'Host Name', null] - ] -]); - -ipa_entity_set_details_definition('service', [ - ipa_stanza({name:'details', label:'Service Details'}). - input({name:'krbprincipalname', - label:'Principal', - setup:service_krbprincipalname_setup, - load:service_krbprincipalname_load}). - input({name:'service', label:'Service', load:service_service_load}). - input({name:'host', label:'Host Name', load:service_host_load}), - ipa_stanza({name:'provisioning', label:'Provisioning'}). - input({name:'provisioning_status', label:'Status', - load:service_provisioning_status_load}), - ipa_stanza({name:'certificate', label:'Service Certificate'}). - input({name:'certificate_status', label:'Status', - load:service_usercertificate_load}) -]); +function ipa_service() { + + var that = ipa_entity({ + 'name': 'service' + }); + + that.init = function() { + that.create_add_dialog({ + 'name': 'add', + 'title': 'Add New Service', + 'init': ipa_service_add_init + }); + + that.create_search_facet({ + 'name': 'search', + 'label': 'Search', + 'init': ipa_service_search_init + }); + + that.create_details_facet({ + 'name': 'details', + 'label': 'Details', + 'init': ipa_service_details_init + }); + }; + + that.init(); + + return that; +} + +IPA.add_entity(ipa_service()); + +function ipa_service_add_init() { + + this.create_field({ + name: 'krbprincipalname', + label: 'Principal', + setup: service_add_krbprincipalname + }); + + this.create_field({name:'service', label:'Service'}); + this.create_field({name:'host', label:'Host Name'}); +} + +function ipa_service_search_init() { + + this.create_column({name:'krbprincipalname', label:'Principal'}); + + this.create_column({ + name: 'quick_links', + label: 'Quick Links', + setup: ipa_entity_quick_links + }); +} + +function ipa_service_details_init() { + + var section = this.create_section({name:'details', label:'Service Details'}); + + section.create_field({ + name: 'krbprincipalname', + label: 'Principal', + setup: service_krbprincipalname_setup, + load: service_krbprincipalname_load + }); + + section.create_field({ + name: 'service', + label: 'Service', + load: service_service_load + }); + + section.create_field({ + name: 'host', + label: 'Host Name', + load: service_host_load + }); + + section = this.create_section({name:'provisioning', label:'Provisioning'}); + + section.create_field({ + name: 'provisioning_status', + label: 'Status', + load: service_provisioning_status_load + }); + + section = this.create_section({name:'certificate', label:'Service Certificate'}); + + section.create_field({ + name: 'certificate_status', + label: 'Status', + load: service_usercertificate_load + }); +} function service_add_krbprincipalname(add_dialog, mode) { if (mode == IPA_ADD_UPDATE) { diff --git a/install/static/test/details_tests.js b/install/static/test/details_tests.js index 78d633634..4a60216ef 100644 --- a/install/static/test/details_tests.js +++ b/install/static/test/details_tests.js @@ -114,7 +114,10 @@ test("Testing details lifecycle:setup, load, save ().", function(){ input({name:'carlicense', label:'Car License'}) ]); - ipa_details_create(container, ipa_entity_details_list[obj_name]); + var entity = ipa_get_entity(obj_name); + var facet = entity.get_facet('details'); + var sections = facet.get_sections(); + ipa_details_create(container, sections); var contact = container.find('dl#contact.entryattrs'); ok(contact); @@ -126,10 +129,10 @@ test("Testing details lifecycle:setup, load, save ().", function(){ same('initials',dts[5].title); //TODO extract into Fixture - ipa_ajax_options["async"] = false; - $.ajaxSetup(ipa_ajax_options); - ipa_json_url = './data'; - ipa_use_static_files = true; + IPA.ajax_options.async = false; + $.ajaxSetup(IPA.ajax_options); + IPA.json_url = './data'; + IPA.use_static_files = true; container.attr('id','user'); @@ -139,7 +142,7 @@ test("Testing details lifecycle:setup, load, save ().", function(){ ipa_details_load(container, 'kfrog', function(){load_success_called = true}, - function(){load_failure_called = true}) + function(){load_failure_called = true}); ok (load_success_called,'load success called'); ok (!load_failure_called,'load failure not called'); @@ -151,13 +154,13 @@ test("Testing details lifecycle:setup, load, save ().", function(){ ipa_details_load(container, 'kfrog', function(){load_success_called = true}, - function(){load_failure_called = true}) + function(){load_failure_called = true}); ipa_details_update(container, 'kfrog', function(){update_success_called = true}, - function(){update_failure_called = true}) + function(){update_failure_called = true}); ok (update_success_called,'update success called'); ok (!update_failure_called,'update failure not called'); diff --git a/install/static/test/entity_tests.html b/install/static/test/entity_tests.html index b8da0f444..0f7962952 100644 --- a/install/static/test/entity_tests.html +++ b/install/static/test/entity_tests.html @@ -5,10 +5,12 @@ <link rel="stylesheet" href="qunit.css" type="text/css" media="screen"> <script type="text/javascript" src="qunit.js"></script> <script type="text/javascript" src="../jquery.js"></script> + <script type="text/javascript" src="../jquery.ba-bbq.js"></script> <script type="text/javascript" src="../ipa.js"></script> <script type="text/javascript" src="../details.js"></script> <script type="text/javascript" src="../search.js"></script> <script type="text/javascript" src="../add.js"></script> + <script type="text/javascript" src="../associate.js"></script> <script type="text/javascript" src="../navigation.js"></script> <script type="text/javascript" src="../entity.js"></script> <script type="text/javascript" src="entity_tests.js"></script> diff --git a/install/static/test/entity_tests.js b/install/static/test/entity_tests.js index 09967c2c5..cc43b8798 100644 --- a/install/static/test/entity_tests.js +++ b/install/static/test/entity_tests.js @@ -18,110 +18,102 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -test("Testing ipa_entity_set_search_definition().", function() { +test('Testing ipa_entity_set_search_definition().', function() { var uid_callback = function() { return true; }; - ipa_entity_set_search_definition("user", [ - ["uid", "Login", uid_callback], + ipa_entity_set_search_definition('user', [ + ['uid', 'Login', uid_callback] ]); - var list = ipa_entity_search_list["user"]; + var facet = ipa_entity_get_search_facet('user'); ok( - list, - "ipa_entity_search_list[\"user\"] is not null" + facet, + 'ipa_entity_get_search_facet(\'user\') is not null' ); - var attr = list[0]; + var column = facet.get_columns()[0]; ok( - attr, - "ipa_entity_search_list[\"user\"][0] is not null" + column, + 'column is not null' ); equals( - attr[0], "uid", - "ipa_entity_search_list[\"user\"][0][0]" + column.name, 'uid', + 'column.name' ); equals( - attr[1], "Login", - "ipa_entity_search_list[\"user\"][0][1]" + column.label, 'Login', + 'column.label' ); - var callback = attr[2]; ok( - callback, - "ipa_entity_search_list[\"user\"][0][2] not null" + column.setup, + 'column.setup not null' ); ok( - callback(), - "ipa_entity_search_list[\"user\"][0][2]() works" + column.setup(), + 'column.setup() works' ); }); -test("Testing ipa_entity_generate_views().", function() { +test('Testing ipa_entity_generate_views().', function() { - ipa_ajax_options["async"] = false; + var orig_show_page = IPA.show_page; + IPA.ajax_options.async = false; - ipa_init( - "data", + IPA.init( + 'data', true, function(data, text_status, xhr) { - ok(true, "ipa_init() succeeded."); + ok(true, 'ipa_init() succeeded.'); }, function(xhr, text_status, error_thrown) { - ok(false, "ipa_init() failed: "+error_thrown); + ok(false, 'ipa_init() failed: '+error_thrown); } ); - var container = $("<div/>"); + var entity = ipa_entity({ + 'name': 'user' + }); + + IPA.add_entity(entity); + + var facet = entity.create_association_facet({ + 'name': 'associate' + }); + + var container = $('<div/>'); var counter = 0; - var callback = function() { + IPA.show_page = function(entity_name, facet_name, other_entity) { counter++; }; - ipa_entity_generate_views("user", container, callback); + facet.setup_views(container); var list = container.children(); - var facets = list.children(); - - equals( - facets.length, 6, - "Checking number of facets" - ) - - var search = facets.first(); + var views = list.children(); equals( - search.attr("title"), "search", - "Checking the search facet" - ) - - search.click(); - - var details = search.next(); - - equals( - details.attr("title"), "details", - "Checking the details facet" - ) - - details.click(); + views.length, 4, + 'Checking number of views' + ); - var facet = details.next(); - var attribute_members = ipa_objs["user"].attribute_members; + facet = views.first(); + var attribute_members = IPA.metadata['user'].attribute_members; for (attribute_member in attribute_members) { var objects = attribute_members[attribute_member]; for (var i = 0; i < objects.length; i++) { var object = objects[i]; equals( - facet.attr("title"), object, - "Checking the "+object+" facet" + facet.attr('title'), object, + 'Checking the '+object+' facet' ); facet.click(); @@ -131,12 +123,14 @@ test("Testing ipa_entity_generate_views().", function() { } equals( - counter, 6, - "Checking callback invocations" + counter, 4, + 'Checking callback invocations' ); + + IPA.show_page = orig_show_page; }); -test("Testing ipa_entity_quick_links().", function() { +test('Testing ipa_entity_quick_links().', function() { var orig_push_state = nav_push_state; var orig_get_state = nav_get_state; @@ -154,37 +148,37 @@ test("Testing ipa_entity_quick_links().", function() { delete state[key]; }; - ipa_ajax_options["async"] = false; + IPA.ajax_options.async = false; - ipa_init( - "data", + IPA.init( + 'data', true, function(data, text_status, xhr) { - ok(true, "ipa_init() succeeded."); + ok(true, 'ipa_init() succeeded.'); }, function(xhr, text_status, error_thrown) { - ok(false, "ipa_init() failed: "+error_thrown); + ok(false, 'ipa_init() failed: '+error_thrown); } ); - var obj_name = "user"; - var pkey = ipa_objs[obj_name].primary_key; - var pkey_value = "test"; + var obj_name = 'user'; + var pkey = IPA.metadata[obj_name].primary_key; + var pkey_value = 'test'; var entry_attrs = {}; entry_attrs[pkey] = [pkey_value]; - var container = $("<div/>", { + var container = $('<div/>', { title: obj_name, - class: "search-container" + class: 'search-container' }); var search_table = $('<table/>', { class: 'search-table' }).appendTo(container); - var tbody = $("<tbody/>").appendTo(search_table); - var tr = $("<tr/>").appendTo(tbody); + var tbody = $('<tbody/>').appendTo(search_table); + var tr = $('<tr/>').appendTo(tbody); ipa_entity_quick_links(tr, null, null, entry_attrs); @@ -192,23 +186,23 @@ test("Testing ipa_entity_quick_links().", function() { var link = td.children().first(); equals( - link.attr("href"), "#details", - "Checking details link" + link.attr('href'), '#details', + 'Checking details link' ); link.click(); equals( - state[obj_name+"-facet"], "details", - "Checking state[\""+obj_name+"-facet\"]" + state[obj_name+'-facet'], 'details', + 'Checking state[\''+obj_name+'-facet\']' ); equals( - state[obj_name+"-pkey"], pkey_value, - "Checking state[\""+obj_name+"-pkey\"]" + state[obj_name+'-pkey'], pkey_value, + 'Checking state[\''+obj_name+'-pkey\']' ); - var attribute_members = ipa_objs[obj_name].attribute_members; + var attribute_members = IPA.metadata[obj_name].attribute_members; for (attr_name in attribute_members) { var objs = attribute_members[attr_name]; for (var i = 0; i < objs.length; ++i) { @@ -217,25 +211,25 @@ test("Testing ipa_entity_quick_links().", function() { link = link.next(); equals( - link.attr("href"), "#"+m, - "Checking "+m+" link" + link.attr('href'), '#'+m, + 'Checking '+m+' link' ); link.click(); equals( - state[obj_name+"-facet"], "associate", - "Checking state[\""+obj_name+"-facet\"]" + state[obj_name+'-facet'], 'associate', + 'Checking state[\''+obj_name+'-facet\']' ); equals( - state[obj_name+"-enroll"], m, - "Checking state[\""+obj_name+"-enroll\"]" + state[obj_name+'-enroll'], m, + 'Checking state[\''+obj_name+'-enroll\']' ); equals( - state[obj_name+"-pkey"], pkey_value, - "Checking state[\""+obj_name+"-pkey\"]" + state[obj_name+'-pkey'], pkey_value, + 'Checking state[\''+obj_name+'-pkey\']' ); } } diff --git a/install/static/test/ipa_tests.js b/install/static/test/ipa_tests.js index 58315585d..7124aa764 100644 --- a/install/static/test/ipa_tests.js +++ b/install/static/test/ipa_tests.js @@ -22,9 +22,9 @@ test("Testing ipa_init().", function() { expect(1); - ipa_ajax_options["async"] = false; + IPA.ajax_options.async = false; - ipa_init( + IPA.init( "data", true, function(data, text_status, xhr) { @@ -153,7 +153,7 @@ test("Testing successful ipa_cmd().", function() { "Checking ajax invocation counter" ); - var dialog = ipa_dialog.parent('.ui-dialog'); + var dialog = IPA.error_dialog.parent('.ui-dialog'); ok( !dialog.length, @@ -223,7 +223,7 @@ test("Testing unsuccessful ipa_cmd().", function() { ipa_cmd(method, args, options, success_handler, error_handler, object); - var dialog = ipa_dialog.parent('.ui-dialog'); + var dialog = IPA.error_dialog.parent('.ui-dialog'); equals( ajax_counter, 1, @@ -231,7 +231,7 @@ test("Testing unsuccessful ipa_cmd().", function() { ); ok( - dialog.length == 1 && ipa_dialog.dialog('isOpen'), + dialog.length == 1 && IPA.error_dialog.dialog('isOpen'), "The dialog box is created and open." ); @@ -256,7 +256,7 @@ test("Testing unsuccessful ipa_cmd().", function() { // search the retry button from the beginning again because the dialog // has been recreated - dialog = ipa_dialog.parent('.ui-dialog'); + dialog = IPA.error_dialog.parent('.ui-dialog'); retry = $('button', dialog).first(); retry.trigger('click'); @@ -272,7 +272,7 @@ test("Testing unsuccessful ipa_cmd().", function() { // search the cancel button from the beginning because the dialog has // been recreated - dialog = ipa_dialog.parent('.ui-dialog'); + dialog = IPA.error_dialog.parent('.ui-dialog'); var cancel = $('button', dialog).first().next(); cancel.trigger('click'); @@ -282,7 +282,7 @@ test("Testing unsuccessful ipa_cmd().", function() { ); ok( - !ipa_dialog.dialog('isOpen'), + !IPA.error_dialog.dialog('isOpen'), "After cancel, the dialog box is closed." ); diff --git a/install/static/test/navigation_tests.js b/install/static/test/navigation_tests.js index 318ac664d..68d4694f6 100644 --- a/install/static/test/navigation_tests.js +++ b/install/static/test/navigation_tests.js @@ -40,7 +40,7 @@ test("Testing nav_create().", function() { same(jobj[0].nodeName,'DIV','group Div'); } - ipa_objs= {}; + IPA.metadata = {}; var navigation = $('<div id="navigation"/>').appendTo(document.body); var user_mock_called = false; var group_mock_called = false; diff --git a/install/static/user.js b/install/static/user.js index 926cdf00a..3ac828fe1 100644 --- a/install/static/user.js +++ b/install/static/user.js @@ -90,12 +90,12 @@ function toggle_on_click(obj) if (val == 'Active') { ipa_cmd( 'lock', [qs['pkey']], {}, on_lock_win, on_fail, - ipa_objs['user']['name'] + IPA.metadata['user']['name'] ); } else { ipa_cmd( 'unlock', [qs['pkey']], {}, on_lock_win, on_fail, - ipa_objs['user']['name'] + IPA.metadata['user']['name'] ); } return (false); diff --git a/install/static/webui.js b/install/static/webui.js index 60ccc25e6..42c559dce 100644 --- a/install/static/webui.js +++ b/install/static/webui.js @@ -59,41 +59,37 @@ var ipa_whoami_pkey; /* main (document onready event handler) */ $(function() { - function whoami_on_win(data, text_status, xhr) { $(window).bind('hashchange', window_hashchange); - if (!data.error){ - var whoami = data.result.result[0]; - ipa_whoami_pkey=whoami.uid[0]; - $('#loggedinas').find('strong').text(whoami.krbprincipalname[0]); - $('#loggedinas a').fragment( - {'user-facet':'details', 'user-pkey':ipa_whoami_pkey},2); - - var navigation = $('#navigation'); - if (whoami.hasOwnProperty('memberof_rolegroup') && - whoami.memberof_rolegroup.length > 0){ - nav_create(admin_tab_set, navigation, 'tabs'); + var whoami = data.result.result[0]; + ipa_whoami_pkey=whoami.uid[0]; + $('#loggedinas').find('strong').text(whoami.krbprincipalname[0]); + $('#loggedinas a').fragment( + {'user-facet':'details', 'user-pkey':ipa_whoami_pkey},2); - }else{ - nav_create(self_serv_tab_set, navigation, 'tabs'); + var navigation = $('#navigation'); - var state = {'user-pkey':ipa_whoami_pkey , - 'user-facet': jQuery.bbq.getState('user-facet') || - 'details'}; - $.bbq.pushState(state); - } + if (whoami.hasOwnProperty('memberof_rolegroup') && + whoami.memberof_rolegroup.length > 0){ + nav_create(admin_tab_set, navigation, 'tabs'); + } else { + nav_create(self_serv_tab_set, navigation, 'tabs'); - $('#login_header').html(ipa_messages.login.header); - }else{ - alert("Unable to find prinicpal for logged in user"); + var state = {'user-pkey':ipa_whoami_pkey , + 'user-facet': jQuery.bbq.getState('user-facet') || + 'details'}; + $.bbq.pushState(state); } - }; + + + $('#login_header').html(IPA.messages.login.header); + } function init_on_win(data, text_status, xhr) { ipa_cmd('user_find', [], {"whoami":"true","all":"true"}, whoami_on_win, init_on_error, null); - }; + } function init_on_error(xhr, text_status, error_thrown) { var navigation = $('#navigation').empty(); @@ -102,7 +98,7 @@ $(function() { navigation.append('<p>'+error_thrown.message+'</p>'); } - ipa_init(null, null, init_on_win, init_on_error); + IPA.init(null, null, init_on_win, init_on_error); }); /* main loop (hashchange event handler) */ |