summaryrefslogtreecommitdiffstats
path: root/install/static/details.js
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2010-10-27 22:32:30 -0500
committerAdam Young <ayoung@redhat.com>2010-10-28 09:28:17 -0400
commit528145d5df30d4b344cd0edafa8e8adba0b817b1 (patch)
treebd5df2342bbf1144a484b0f39b70b906524cf9b1 /install/static/details.js
parent70a57924c8e265df1e97b7f0be1adf8da802fbfd (diff)
downloadfreeipa.git-528145d5df30d4b344cd0edafa8e8adba0b817b1.tar.gz
freeipa.git-528145d5df30d4b344cd0edafa8e8adba0b817b1.tar.xz
freeipa.git-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.
Diffstat (limited to 'install/static/details.js')
-rw-r--r--install/static/details.js290
1 files changed, 190 insertions, 100 deletions
diff --git a/install/static/details.js b/install/static/details.js
index d0688f55..d4593d82 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;