summaryrefslogtreecommitdiffstats
path: root/install/static/details.js
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2010-11-09 14:22:31 -0600
committerAdam Young <ayoung@redhat.com>2010-11-11 12:23:05 -0500
commit65c9442e2697f9e5d8b6cc2b7c22a6b8da426247 (patch)
treea998aa317a59102646fada66a4944d022ff2afa5 /install/static/details.js
parent569f4e1a5cb3ff4cf3a7bf3c2aa5fdfa9ced0134 (diff)
downloadfreeipa-65c9442e2697f9e5d8b6cc2b7c22a6b8da426247.tar.gz
freeipa-65c9442e2697f9e5d8b6cc2b7c22a6b8da426247.tar.xz
freeipa-65c9442e2697f9e5d8b6cc2b7c22a6b8da426247.zip
HBAC Services
The HBAC Service search and details pages have been added under the HBAC tab. This requires some changes to the framework. Currently the navigation framework doesn't support multiple entities under one tab. As a temporary solution, an 'entity' URL parameter is used to determine the entity to be displayed. This parameter is now only used by HBAC tab, but its use might be expanded later. The navigation framework needs be redesigned to provide more flexibility. The search page in all entities except DNS records have been changed to use the ipa_search_widget. The Select/Unselect All checbox and Delete button now work correctly and consistently. The Add dialog has been enhanced to render and work in a more consistent way while still supporting custom widgets & layouts. For the search page, the Add button will refresh the search results and clear the fields in the dialog box. The framework now provides some extension points which can be overriden by the subclasses: - init(): for initialization and configuration - create(): for creating the layout dynamically or from template - setup(): for setting the look and feel - load(): for loading the data Entity and facet initialization is now done after IPA.init(). This is to ensure the metadata is loaded first so the entities and facets can use localized messages/labels/titles. The group entity has been partially converted to use the new framework. The unit tests have been updated accordingly.
Diffstat (limited to 'install/static/details.js')
-rw-r--r--install/static/details.js235
1 files changed, 134 insertions, 101 deletions
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; i<that.fields.length; i++) {
+ var field = that.fields[i];
+ field.init();
+ }
+ };
+
// Deprecated: Used for backward compatibility only.
function input(spec){
that.create_field(spec);
@@ -253,10 +256,13 @@ function ipa_details_facet(spec) {
var that = ipa_facet(spec);
- that.init = spec.init || init;
that.is_dirty = spec.is_dirty || ipa_details_is_dirty;
- that.setup = spec.setup || ipa_details_setup;
that.create = spec.create || ipa_details_create;
+ that.setup = spec.setup || ipa_details_setup;
+ that.load = spec.load || ipa_details_load;
+ that.update = spec.update || ipa_details_update;
+ that.reset = spec.reset || ipa_details_reset;
+ that.display = spec.display || ipa_details_display;
that.sections = [];
that.sections_by_name = {};
@@ -273,10 +279,6 @@ function ipa_details_facet(spec) {
}
});
- that.get_sections = function() {
- return that.sections;
- };
-
that.get_section = function(name) {
return that.sections_by_name[name];
};
@@ -293,8 +295,12 @@ function ipa_details_facet(spec) {
return section;
};
- function init() {
- }
+ that.init = function() {
+ for (var i=0; i<that.sections.length; i++) {
+ var section = that.sections[i];
+ section.init();
+ }
+ };
return that;
}
@@ -321,38 +327,7 @@ function ipa_details_is_dirty() {
return pkey != this.pkey;
}
-function ipa_details_setup(container, unspecified) {
-
- var facet = this;
-
- facet.setup_views(container);
-
- facet.pkey = $.bbq.getState(facet.entity_name + '-pkey', true) || '';
- if (!facet.pkey && !unspecified) return;
-
- function on_success(data, text_status, xhr) {
- var result = data.result.result;
-
- ipa_details_cache[facet.entity_name] = $.extend(true, {}, result);
- facet.create(container, result);
- }
-
- function on_failure(xhr, text_status, error_thrown) {
- var details = $('.details', container).empty();
- details.append('<p>Error: '+error_thrown.name+'</p>');
- details.append('<p>'+error_thrown.title+'</p>');
- details.append('<p>'+error_thrown.message+'</p>');
- }
-
- 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 = $('<div/>', {
'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('<hr/>');
}
}
+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);
}
+}
- section.create(container);
+function ipa_details_load(container, unspecified) {
- for (var i = 0; i < fields.length; ++i) {
- var field = fields[i];
- field.create(container);
- field.setup(container);
- field.load(container, result);
+ 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);
+ }
}
+
+ function on_failure(xhr, text_status, error_thrown) {
+ var details = $('.details', container).empty();
+ details.append('<p>Error: '+error_thrown.name+'</p>');
+ details.append('<p>'+error_thrown.title+'</p>');
+ details.append('<p>'+error_thrown.message+'</p>');
+ }
+
+ 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, result) {
- var section = this;
+function ipa_details_section_create(container) {
+
+ var that = this;
+ if (that.template) return;
var dl = $('<dl/>', {
- 'id': section.name,
+ '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);
+ }
+}
+
+function ipa_details_section_setup(container, unspecified) {
+ var that = this;
+ if (that.template) return;
+
+ 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<fields.length; j++) {
var field = fields[j];
@@ -465,7 +501,8 @@ function ipa_details_section_load(container, result) {
function ipa_details_update(container, pkey, on_win, on_fail)
{
- var obj_name = container.attr('id');
+ var facet = this;
+ var entity_name = facet.entity_name;
function update_on_win(data, text_status, xhr) {
if (on_win)
@@ -474,8 +511,8 @@ function ipa_details_update(container, pkey, on_win, on_fail)
return;
var result = data.result.result;
- ipa_details_cache[obj_name] = $.extend(true, {}, result);
- ipa_details_display(container, result);
+ ipa_details_cache[entity_name] = $.extend(true, {}, result);
+ facet.display(container, result);
}
function update_on_fail(xhr, text_status, error_thrown) {
@@ -490,20 +527,17 @@ function ipa_details_update(container, pkey, on_win, on_fail)
var modlist = {'all': true, 'setattr': [], 'addattr': [], 'rights': true};
var attrs_wo_option = {};
- 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.get_fields();
+ for (var i=0; i<facet.sections.length; i++) {
+ var section = facet.sections[i];
var div = $('#'+facet.entity_name+'-'+facet.name+'-'+section.name, container);
- for (var j=0; j<fields.length; j++) {
- var field = fields[j];
+ for (var j=0; j<section.fields.length; j++) {
+ var field = section.fields[j];
values = field.save(div);
- var param_info = ipa_get_param_info(obj_name, field.name);
+ var param_info = ipa_get_param_info(entity_name, field.name);
if (param_info) {
if (param_info['primary_key']) continue;
if (values.length === 1) {
@@ -526,7 +560,7 @@ function ipa_details_update(container, pkey, on_win, on_fail)
modlist['addattr'].push(attr + '=' + values[i]);
}
- ipa_cmd('mod', [pkey], modlist, update_on_win, update_on_fail, obj_name);
+ ipa_cmd('mod', [pkey], modlist, update_on_win, update_on_fail, entity_name);
}
@@ -555,16 +589,14 @@ var _ipa_span_hint_template = '<span class="attrhint">Hint: D</span>';
* (basically an associative array with attr:value pairs) */
function ipa_details_display(container, result)
{
- var entity_name = container.attr('id');
+ var facet = this;
/* remove all <dd> tags i.e. all attribute values */
$('dd', container).remove();
/* go through all <dt> tags and pair them with newly created <dd>s */
- var facet = ipa_entity_get_details_facet(entity_name);
- var sections = facet.get_sections();
- for (var i=0; i<sections.length; i++) {
- var section = sections[i];
+ for (var i=0; i<facet.sections.length; i++) {
+ var section = facet.sections[i];
var div = $('#'+facet.entity_name+'-'+facet.name+'-'+section.name, container);
@@ -752,10 +784,11 @@ function _ipa_create_text_input(attr, value, param_info, rights)
function ipa_details_reset(container)
{
- var obj_name = container.attr('id');
+ var facet = this;
+ var entity_name = facet.entity_name;
- if (ipa_details_cache[obj_name]){
- ipa_details_display(container, ipa_details_cache[obj_name]);
+ if (ipa_details_cache[entity_name]){
+ facet.display(container, ipa_details_cache[entity_name]);
}
}