Multiple fields for one attribute

Current implementation has a limitation to have one field per one attribute. This is fine for most cases. For cases where an attribute can have two editor widgets which can be swapped a need for two different types of field may occur.

This patch introduces 'param' option which supposes to contain attribute name. If 'param' is not specified it will contain field's name therefore backward compatibility is maintained. This extension allows to have two fields with different name and same param -> two fields get/supply value from/to the same attribute.

Needed for:

https://fedorahosted.org/freeipa/ticket/2372
This commit is contained in:
Petr Voborník 2012-02-22 09:21:56 +01:00 committed by Petr Vobornik
parent 34f742bec2
commit 885ffe5a3e
5 changed files with 21 additions and 18 deletions

View File

@ -122,17 +122,17 @@ IPA.entity_adder_dialog = function(spec) {
for (var j=0; j<fields.length; j++) {
var field = fields[j];
var values = record[field.name];
var values = record[field.param];
if (!values) continue;
// TODO: Handle multi-valued attributes like in detail facet's update()
var value = values.join(',');
if (!value) continue;
if (field.name == pkey_name) {
if (field.param === pkey_name) {
command.add_arg(value);
} else {
command.set_option(field.name, value);
command.set_option(field.param, value);
}
}

View File

@ -493,7 +493,7 @@ IPA.details_facet = function(spec) {
if (only_dirty && !field.is_dirty()) continue;
var values = record[field.name];
var values = record[field.param];
if (require_value && !values) continue;
update_info.append_field(field, values);
@ -838,23 +838,25 @@ IPA.command_builder = function() {
that.add_field_option = function(command, field, values) {
if (!field || !values) return;
var name = field.param;
if (field.metadata) {
if (field.metadata.primary_key) return;
if (values.length === 1) {
command.set_option(field.name, values[0]);
command.set_option(name, values[0]);
} else if (field.join) {
command.set_option(field.name, values.join(','));
command.set_option(name, values.join(','));
} else {
command.set_option(field.name, values);
command.set_option(name, values);
}
} else {
if (values.length) {
command.add_option('setattr', field.name+'='+values[0]);
command.add_option('setattr', name+'='+values[0]);
} else {
command.add_option('setattr', field.name+'=');
command.add_option('setattr', name+'=');
}
for (var k=1; k<values.length; k++) {
command.add_option('addattr', field.name+'='+values[k]);
command.add_option('addattr', name+'='+values[k]);
}
}
};

View File

@ -32,6 +32,7 @@ IPA.field = function(spec) {
that.entity = IPA.get_entity(spec.entity);
that.container = null;
that.name = spec.name;
that.param = spec.param || spec.name;
that.label = spec.label;
that.tooltip = spec.tooltip;
that.formatter = spec.formatter;
@ -66,7 +67,7 @@ IPA.field = function(spec) {
var init = function() {
if (!that.metadata && that.entity) {
that.metadata = IPA.get_entity_param(that.entity.name, that.name);
that.metadata = IPA.get_entity_param(that.entity.name, that.param);
}
if (that.metadata) {
if (that.label === undefined) {
@ -148,7 +149,7 @@ IPA.field = function(spec) {
that.load = function(record) {
that.record = record;
that.values = that.get_value(record, that.name);
that.values = that.get_value(record, that.param);
that.load_writable(record);
@ -185,7 +186,7 @@ IPA.field = function(spec) {
}
if (record.attributelevelrights) {
var rights = record.attributelevelrights[that.name];
var rights = record.attributelevelrights[that.param];
if (!rights || rights.indexOf('w') < 0) {
that.writable = false;
}
@ -249,7 +250,7 @@ IPA.field = function(spec) {
}
if(record) {
record[that.name] = values;
record[that.param] = values;
}
return values;
@ -600,7 +601,7 @@ IPA.sshkeys_field = function(spec) {
that.load = function(record) {
var keys = that.get_value(record, that.name);
var keys = that.get_value(record, that.param);
var fingerprints = that.get_value(record, that.sshfp_attr);
var values = [];

View File

@ -170,7 +170,7 @@ IPA.rule_association_table_field = function(spec) {
if (typeof record !== 'object') {
record = {};
record[that.name] = values[i];
record[that.param] = values[i];
}
record[that.external] = external;
@ -180,7 +180,7 @@ IPA.rule_association_table_field = function(spec) {
};
that.load = function(result) {
that.values = result[that.name] || [];
that.values = result[that.param] || [];
if (that.external) {
that.set_values_external(that.values, '');

View File

@ -347,7 +347,7 @@ IPA.service_provisioning_status_field = function (spec) {
that.load = function(record) {
that.values = {
value: record[that.name],
value: record[that.param],
pkey: record['krbprincipalname'][0]
};