summaryrefslogtreecommitdiffstats
path: root/install/static/associate.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/associate.js
parent70a57924c8e265df1e97b7f0be1adf8da802fbfd (diff)
downloadfreeipa-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.
Diffstat (limited to 'install/static/associate.js')
-rw-r--r--install/static/associate.js201
1 files changed, 128 insertions, 73 deletions
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;
}