Modified dialog to use sections.

The IPA.dialog has been modified to store sections instead of fields.
If there is no sections specified, it will create a default section.

The adder dialog for automount map has been modified such that the
fields related to indirect map are stored in a section which will
only be visible when the map type is set to indirect.

The adder dialog for host has been modified such that it uses a
custom section for hostname and DNS zone and standard section for
the other fields.

Ticket #1394
This commit is contained in:
Endi S. Dewata
2011-09-10 11:54:02 -05:00
parent a90e50cdf7
commit 390d017e32
16 changed files with 380 additions and 409 deletions

View File

@@ -65,12 +65,20 @@ IPA.entity_factories.permission = function() {
adder_dialog({ adder_dialog({
width: 500, width: 500,
height: 400, height: 400,
fields: [ sections: [
'cn',
{ {
factory: IPA.rights_widget, name: 'general',
name: 'permissions', fields: [
join: true, undo: false {
name: 'cn',
undo: false
},
{
factory: IPA.rights_widget,
name: 'permissions',
join: true, undo: false
}
]
}, },
{ {
factory: IPA.target_section, factory: IPA.target_section,
@@ -274,7 +282,7 @@ IPA.attributes_widget = function(spec) {
} }
if (that.object_type){ if (that.object_type){
that.populate (that.object_type); that.populate(that.object_type);
} }
}; };
@@ -392,7 +400,6 @@ IPA.target_section = function(spec) {
spec = spec || {}; spec = spec || {};
var that = IPA.details_section(spec); var that = IPA.details_section(spec);
that.section = true;
that.undo = typeof spec.undo == 'undefined' ? true : spec.undo; that.undo = typeof spec.undo == 'undefined' ? true : spec.undo;
var target_types = [ var target_types = [
@@ -406,7 +413,7 @@ IPA.target_section = function(spec) {
that.filter_text.load(record); that.filter_text.load(record);
}, },
save: function(record) { save: function(record) {
record.filter = that.filter_text.save()[0]; record.filter = that.filter_text.save();
} }
}, },
{ {
@@ -419,7 +426,7 @@ IPA.target_section = function(spec) {
that.subtree_textarea.load(record); that.subtree_textarea.load(record);
}, },
save: function(record) { save: function(record) {
record.subtree = that.subtree_textarea.save()[0]; record.subtree = that.subtree_textarea.save();
} }
}, },
{ {
@@ -432,7 +439,7 @@ IPA.target_section = function(spec) {
that.group_select.list.val(record.targetgroup); that.group_select.list.val(record.targetgroup);
}, },
save: function(record) { save: function(record) {
record.targetgroup = that.group_select.save()[0]; record.targetgroup = that.group_select.save();
} }
}, },
{ {
@@ -478,17 +485,17 @@ IPA.target_section = function(spec) {
that.type_select.select_update(); that.type_select.select_update();
that.attribute_table.object_type = that.attribute_table.object_type =
that.type_select.save()[0]; that.type_select.save()[0];
that.attribute_table.reset(); that.attribute_table.reset();
}; };
}, },
load: function(record){ load: function(record) {
that.type_select.load(record); that.type_select.load(record);
that.attribute_table.object_type = record.type; that.attribute_table.object_type = record.type;
that.attribute_table.reset(); that.attribute_table.reset();
}, },
save: function(record){ save: function(record) {
record.type = that.type_select.save()[0]; record.type = that.type_select.save();
record.attrs = that.attribute_table.save().join(','); record.attrs = that.attribute_table.save();
} }
}] ; }] ;
@@ -507,12 +514,14 @@ IPA.target_section = function(spec) {
undo: that.undo undo: that.undo
}); });
that.group_select = IPA.entity_select_widget({ that.group_select = IPA.entity_select_widget({
entity: spec.entity,
name: 'targetgroup', name: 'targetgroup',
other_entity: 'group', other_entity: 'group',
other_field: 'cn', other_field: 'cn',
undo: that.undo undo: that.undo
}); });
that.type_select = IPA.select_widget({ that.type_select = IPA.select_widget({
entity: spec.entity,
name: 'type', name: 'type',
undo: that.undo undo: that.undo
}); });

View File

@@ -46,9 +46,8 @@ IPA.add_dialog = function (spec) {
that.show_edit_page = spec.show_edit_page || show_edit_page; that.show_edit_page = spec.show_edit_page || show_edit_page;
that.add = function(record, on_success, on_error) { that.add = function(on_success, on_error) {
var field, value, pkey_prefix;
var pkey_name = that.entity.metadata.primary_key; var pkey_name = that.entity.metadata.primary_key;
var command = IPA.command({ var command = IPA.command({
@@ -60,46 +59,36 @@ IPA.add_dialog = function (spec) {
}); });
that.command = command; that.command = command;
pkey_prefix = that.entity.get_primary_key_prefix(); command.add_args(that.entity.get_primary_key_prefix());
for (var h=0; h<pkey_prefix.length; h++) { var record = {};
command.add_arg(pkey_prefix[h]); that.save(record);
}
var fields = that.fields.values; var fields = that.get_fields();
for (var i=0; i<fields.length; i++) { for (var i=0; i<fields.length; i++) {
fields[i].validate(); fields[i].validate();
} }
var required_fields_filled = true;
for (i=0; i<fields.length; i++) {
field = fields[i];
if (!field.valid) return;
required_fields_filled = field.check_required() && var valid = true;
required_fields_filled;
value = record[field.name];
if (!value) continue;
if (field.name == pkey_name) {
command.add_arg(value);
} else {
command.set_option(field.name, value);
}
}
var sections = that.sections.values; var sections = that.sections.values;
for (var j=0; j<sections.length; j++) { for (i=0; i<sections.length; i++) {
var section = sections[j]; var section = sections[i];
if (!section.is_valid() || !valid) {
valid = false;
continue;
}
var section_fields = section.fields.values; var section_fields = section.fields.values;
for (var k=0; k<section_fields.length; k++) { for (var j=0; j<section_fields.length; j++) {
field = section_fields[k]; var field = section_fields[j];
if (!field.valid) return;
required_fields_filled = field.check_required() &&
required_fields_filled;
value = record[field.name]; var values = record[field.name];
if (!values) continue;
// TODO: Handle multi-valued attributes like in detail facet's update()
var value = values.join(',');
if (!value) continue; if (!value) continue;
if (field.name == pkey_name) { if (field.name == pkey_name) {
@@ -110,23 +99,20 @@ IPA.add_dialog = function (spec) {
} }
} }
if (!valid) return;
//alert(JSON.stringify(command.to_json())); //alert(JSON.stringify(command.to_json()));
if (that.pre_execute_hook){ if (that.pre_execute_hook) {
that.pre_execute_hook(command); that.pre_execute_hook(command);
} }
if (required_fields_filled){
command.execute();
}
command.execute();
}; };
/*dialog initialization*/ /*dialog initialization*/
that.add_button(IPA.messages.buttons.add, function() { that.add_button(IPA.messages.buttons.add, function() {
var record = {};
that.save(record);
that.add( that.add(
record,
function(data, text_status, xhr) { function(data, text_status, xhr) {
var facet = IPA.current_entity.get_facet(); var facet = IPA.current_entity.get_facet();
var table = facet.table; var table = facet.table;
@@ -137,10 +123,7 @@ IPA.add_dialog = function (spec) {
}); });
that.add_button(IPA.messages.buttons.add_and_add_another, function() { that.add_button(IPA.messages.buttons.add_and_add_another, function() {
var record = {};
that.save(record);
that.add( that.add(
record,
function(data, text_status, xhr) { function(data, text_status, xhr) {
var facet = IPA.current_entity.get_facet(); var facet = IPA.current_entity.get_facet();
var table = facet.table; var table = facet.table;
@@ -151,14 +134,11 @@ IPA.add_dialog = function (spec) {
}); });
that.add_button(IPA.messages.buttons.add_and_edit, function() { that.add_button(IPA.messages.buttons.add_and_edit, function() {
var record = {};
that.save(record);
that.add( that.add(
record,
function(data, text_status, xhr) { function(data, text_status, xhr) {
that.close(); that.close();
var result = data.result.result; var result = data.result.result;
that.show_edit_page(that.entity,result); that.show_edit_page(that.entity, result);
}, },
that.on_error); that.on_error);
}); });
@@ -167,7 +147,6 @@ IPA.add_dialog = function (spec) {
that.close(); that.close();
}); });
return that; return that;
}; };

View File

@@ -650,7 +650,7 @@ IPA.association_table_widget = function (spec) {
entity: that.entity.name, entity: that.entity.name,
method: 'show', method: 'show',
args: [pkey], args: [pkey],
options: {'all': true, 'rights': true}, options: { all: true, rights: true },
on_success: on_success, on_success: on_success,
on_error: on_error on_error: on_error
}).execute(); }).execute();

View File

@@ -36,25 +36,26 @@ IPA.entity_factories.automountlocation = function() {
}). }).
nested_search_facet({ nested_search_facet({
facet_group: 'automountmap', facet_group: 'automountmap',
nested_entity : 'automountmap', nested_entity: 'automountmap',
label : IPA.metadata.objects.automountmap.label, label: IPA.metadata.objects.automountmap.label,
name: 'maps', name: 'maps',
columns:['automountmapname'] columns: [ 'automountmapname' ]
}). }).
details_facet({ details_facet({
sections:[ sections:[
{ {
name:'identity', name: 'identity',
label: IPA.messages.details.identity, label: IPA.messages.details.identity,
fields:['cn'] fields: [ 'cn' ]
} }
] ]
}). }).
adder_dialog({ adder_dialog({
fields:['cn'] fields: [ 'cn' ]
}). }).
build(); build();
}; };
IPA.entity_factories.automountmap = function() { IPA.entity_factories.automountmap = function() {
return IPA.entity_builder(). return IPA.entity_builder().
entity({ name: 'automountmap' }). entity({ name: 'automountmap' }).
@@ -62,63 +63,78 @@ IPA.entity_factories.automountmap = function() {
facet_groups([ 'automountkey', 'settings' ]). facet_groups([ 'automountkey', 'settings' ]).
nested_search_facet({ nested_search_facet({
facet_group: 'automountkey', facet_group: 'automountkey',
nested_entity : 'automountkey', nested_entity: 'automountkey',
label : IPA.metadata.objects.automountkey.label, label: IPA.metadata.objects.automountkey.label,
name: 'keys', name: 'keys',
get_values: IPA.get_option_values, get_values: IPA.get_option_values,
columns:[ columns: [
{ {
factory: IPA.automount_key_column, factory: IPA.automount_key_column,
name:'automountkey', name: 'automountkey',
label:IPA.get_entity_param('automountkey', 'automountkey'). label: IPA.get_entity_param('automountkey', 'automountkey').label
label
}, },
'automountinformation'] 'automountinformation'
]
}). }).
details_facet({ details_facet({
sections:[ sections: [
{ {
name:'identity', name: 'identity',
label: IPA.messages.details.identity, label: IPA.messages.details.identity,
fields:['automountmapname','description'] fields: [ 'automountmapname', 'description' ]
} }
] ]
}). }).
adder_dialog({ adder_dialog({
factory: IPA.automountmap_adder_dialog, factory: IPA.automountmap_adder_dialog,
fields: [ sections: [
{ {
factory: IPA.radio_widget, name: 'general',
name: 'method', fields: [
undo: false,
label: IPA.messages.objects.automountmap.map_type,
options: [
{ {
value: 'add', factory: IPA.radio_widget,
label: IPA.messages.objects.automountmap.direct name: 'method',
label: IPA.messages.objects.automountmap.map_type,
options: [
{
value: 'add',
label: IPA.messages.objects.automountmap.direct
},
{
value: 'add_indirect',
label: IPA.messages.objects.automountmap.indirect
}
],
undo: false
}, },
{ {
value: 'add_indirect', name: 'automountmapname',
label: IPA.messages.objects.automountmap.indirect undo: false
},
{
name: 'description',
undo: false
} }
] ]
}, },
'automountmapname',
'description',
{ {
name: 'key', name: 'indirect',
label: IPA.get_method_option( fields: [
'automountmap_add_indirect', 'key').label, {
conditional: true, name: 'key',
undo: false label: IPA.get_method_option(
}, 'automountmap_add_indirect', 'key').label,
{ undo: false
name: 'parentmap', },
label: IPA.get_method_option( {
'automountmap_add_indirect', 'parentmap').label, name: 'parentmap',
conditional: true, label: IPA.get_method_option(
undo: false 'automountmap_add_indirect', 'parentmap').label,
}] undo: false
}
]
}
]
}). }).
build(); build();
}; };
@@ -202,7 +218,6 @@ IPA.automount_key_column = function(spec){
return that; return that;
}; };
IPA.automountmap_adder_dialog = function(spec) { IPA.automountmap_adder_dialog = function(spec) {
var that = IPA.add_dialog(spec); var that = IPA.add_dialog(spec);
@@ -214,12 +229,14 @@ IPA.automountmap_adder_dialog = function(spec) {
var direct_input = $('input[value="add"]', method_field.container); var direct_input = $('input[value="add"]', method_field.container);
direct_input.change(function() { direct_input.change(function() {
that.disable_conditional_fields(); that.method = 'add';
that.get_section('indirect').set_visible(false);
}); });
var indirect_input = $('input[value="add_indirect"]', method_field.container); var indirect_input = $('input[value="add_indirect"]', method_field.container);
indirect_input.change(function() { indirect_input.change(function() {
that.enable_conditional_fields(); that.method = 'add_indirect';
that.get_section('indirect').set_visible(true);
}); });
direct_input.click(); direct_input.click();
@@ -237,7 +254,6 @@ IPA.automountmap_adder_dialog = function(spec) {
return that; return that;
}; };
IPA.get_option_values = function(){ IPA.get_option_values = function(){
var values = []; var values = [];

View File

@@ -43,17 +43,42 @@ IPA.details_section = function(spec) {
that.dirty = false; that.dirty = false;
that.dirty_changed = IPA.observer(); that.dirty_changed = IPA.observer();
that.undo = typeof spec.undo == 'undefined' ? true : spec.undo;
var init = function() {
var fields = spec.fields || [];
that.add_fields(fields);
};
that.get_field = function(name) { that.get_field = function(name) {
return that.fields.get(name); return that.fields.get(name);
}; };
that.add_field = function(field) { that.add_field = function(field) {
field.entity = that.entity; field.entity = that.entity;
field.undo = that.undo;
that.fields.put(field.name, field); that.fields.put(field.name, field);
field.dirty_changed.attach(that.field_dirty_changed); field.dirty_changed.attach(that.field_dirty_changed);
return field; return field;
}; };
that.add_fields = function(fields) {
for (var i=0; i<fields.length; i++) {
var field_spec = fields[i];
var field;
if (field_spec instanceof Object) {
var factory = field_spec.factory || IPA.text_widget;
field_spec.entity = that.entity;
field = factory(field_spec);
that.add_field(field);
} else {
that.text({ name: field_spec });
}
}
};
that.field = function(field) { that.field = function(field) {
that.add_field(field); that.add_field(field);
return that; return that;
@@ -93,6 +118,8 @@ IPA.details_section = function(spec) {
var fields = that.fields.values; var fields = that.fields.values;
for (var i=0; i<fields.length; i++) { for (var i=0; i<fields.length; i++) {
var field = fields[i]; var field = fields[i];
if (field.hidden) continue;
var field_container = $('<div/>', { var field_container = $('<div/>', {
name: field.name, name: field.name,
title: field.label, title: field.label,
@@ -102,7 +129,6 @@ IPA.details_section = function(spec) {
} }
}; };
that.load = function(record) { that.load = function(record) {
that.record = record; that.record = record;
@@ -114,6 +140,14 @@ IPA.details_section = function(spec) {
} }
}; };
that.save = function(record) {
var fields = that.fields.values;
for (var i=0; i<fields.length; i++) {
var field = fields[i];
record[field.name] = field.save();
}
};
that.reset = function() { that.reset = function() {
var fields = that.fields.values; var fields = that.fields.values;
for (var i=0; i<fields.length; i++) { for (var i=0; i<fields.length; i++) {
@@ -159,6 +193,16 @@ IPA.details_section = function(spec) {
return valid; return valid;
}; };
that.set_visible = function(visible) {
if (visible) {
that.container.show();
} else {
that.container.hide();
}
};
init();
// methods that should be invoked by subclasses // methods that should be invoked by subclasses
that.section_create = that.create; that.section_create = that.create;
that.section_setup = that.setup; that.section_setup = that.setup;
@@ -272,6 +316,15 @@ IPA.details_facet = function(spec) {
return section; return section;
}; };
that.get_fields = function() {
var fields = [];
for (var i=0; i<that.sections.length; i++) {
var section = that.sections.values[i];
$.merge(fields, section.fields.values);
}
return fields;
};
/* the primary key used for show and update is built as an array. /* the primary key used for show and update is built as an array.
for most entities, this will be a single element long, but for some for most entities, this will be a single element long, but for some
it requires the containing entities primary keys as well.*/ it requires the containing entities primary keys as well.*/
@@ -509,6 +562,14 @@ IPA.details_facet = function(spec) {
that.enable_update(false); that.enable_update(false);
}; };
that.save = function(record) {
var sections = that.sections.values;
for (var i=0; i<sections.length; i++) {
var section = sections[i];
section.save(record);
}
};
that.reset = function() { that.reset = function() {
var sections = that.sections.values; var sections = that.sections.values;
for (var i=0; i<sections.length; i++) { for (var i=0; i<sections.length; i++) {
@@ -554,31 +615,34 @@ IPA.details_facet = function(spec) {
on_error: on_error on_error: on_error
}); });
var values; var record = {};
that.save(record);
var fields = that.get_fields();
for (var i=0; i<fields.length; i++) {
fields[i].validate();
}
var valid = true; var valid = true;
var sections = that.sections.values; var sections = that.sections.values;
for (var i=0; i<sections.length; i++) { for (i=0; i<sections.length; i++) {
var section = sections[i]; var section = sections[i];
if(!section.is_valid() || !valid) { if (!section.is_valid() || !valid) {
valid = false; valid = false;
continue; continue;
} }
if (section.save) {
section.save(command.options);
continue;
}
var section_fields = section.fields.values; var section_fields = section.fields.values;
for (var j=0; j<section_fields.length; j++) { for (var j=0; j<section_fields.length; j++) {
var field = section_fields[j]; var field = section_fields[j];
if (!field.is_dirty()) continue; if (!field.is_dirty()) continue;
values = field.save(); var values = record[field.name];
if (!values) continue; if (!values) continue;
var param_info = field.param_info;
var param_info = field.param_info;
if (param_info) { if (param_info) {
if (param_info.primary_key) continue; if (param_info.primary_key) continue;
if (values.length === 1) { if (values.length === 1) {
@@ -588,7 +652,7 @@ IPA.details_facet = function(spec) {
} else { } else {
command.set_option(field.name, values); command.set_option(field.name, values);
} }
} else { } else {
if (values.length) { if (values.length) {
command.add_option('setattr', field.name+'='+values[0]); command.add_option('setattr', field.name+'='+values[0]);
} else { } else {
@@ -601,7 +665,7 @@ IPA.details_facet = function(spec) {
} }
} }
if(!valid) { if (!valid) {
var dialog = IPA.message_dialog({ var dialog = IPA.message_dialog({
title: IPA.messages.dialogs.validation_title, title: IPA.messages.dialogs.validation_title,
message: IPA.messages.dialogs.validation_message message: IPA.messages.dialogs.validation_message

View File

@@ -39,32 +39,22 @@ IPA.dialog = function(spec) {
that.buttons = {}; that.buttons = {};
that.fields = $.ordered_map();
that.sections = $.ordered_map(); that.sections = $.ordered_map();
that.conditional_fields = []; var init = function() {
that.enable_conditional_fields = function(){ var sections = spec.sections || [];
for (var i =0; i < that.conditional_fields.length; i+=1) {
$('label[id='+ for (var i=0; i<sections.length; i++) {
that.conditional_fields[i] +'-label]', var section_spec = sections[i];
that.container).css('visibility','visible'); that.create_section(section_spec);
$('input[name='+
that.conditional_fields[i] +
']',that.container).css('visibility','visible');
} }
};
that.disable_conditional_fields = function(){ var fields = spec.fields || [];
for (var i =0; i < that.conditional_fields.length; i+=1) {
$('label[id='+
that.conditional_fields[i] +'-label]',
that.container).css('visibility','hidden');
$('input[name='+ // add fields to the default section
that.conditional_fields[i] + var section = that.get_section();
']',that.container).css('visibility','hidden'); section.add_fields(fields);
}
}; };
that.add_button = function(name, handler) { that.add_button = function(name, handler) {
@@ -72,15 +62,29 @@ IPA.dialog = function(spec) {
}; };
that.get_field = function(name) { that.get_field = function(name) {
return that.fields.get(name); for (var i=0; i<that.sections.length; i++) {
var section = that.sections.values[i];
var field = section.fields.get(name);
if (field) return field;
}
return null;
};
that.get_fields = function() {
var fields = [];
for (var i=0; i<that.sections.length; i++) {
var section = that.sections.values[i];
$.merge(fields, section.fields.values);
}
return fields;
}; };
that.add_field = function(field) { that.add_field = function(field) {
field.dialog = that; field.dialog = that;
that.fields.put(field.name, field);
if (field.conditional){ var section = that.get_section();
that.conditional_fields.push(field.name); section.add_field(field);
}
return field; return field;
}; };
@@ -90,23 +94,13 @@ IPA.dialog = function(spec) {
}; };
that.is_valid = function() { that.is_valid = function() {
var fields = that.fields.values; for (var i=0; i<that.sections.length; i++) {
for (var i=0; i<fields.length; i++) { var section = that.sections.values[i];
var field = fields[i]; if (!section.is_valid()) return false;
if (!field.valid) return false;
} }
return true; return true;
}; };
that.text = function(name){
that.field(IPA.text_widget({
name: name,
undo: false,
entity : that.entity
}));
return that;
};
that.add_section = function(section) { that.add_section = function(section) {
that.sections.put(section.name, section); that.sections.put(section.name, section);
return that; return that;
@@ -118,72 +112,42 @@ IPA.dialog = function(spec) {
}; };
that.create_section = function(spec) { that.create_section = function(spec) {
var section = IPA.details_section(spec);
var factory = spec.factory || IPA.details_table_section;
spec.entity = that.entity;
spec.undo = false;
var section = factory(spec);
that.add_section(section); that.add_section(section);
return section; return section;
}; };
that.get_section = function(name) {
if (name) {
return that.sections.get(name);
} else {
var length = that.sections.length;
if (length) {
// get the last section
return that.sections.values[length-1];
} else {
// create a default section
return that.create_section({ name: 'general' });
}
}
};
/** /**
* Create content layout * Create content layout
*/ */
that.create = function() { that.create = function() {
var table = $('<table/>', {
'class': 'section-table'
}).appendTo(that.container);
var fields = that.fields.values;
for (var i=0; i<fields.length; i++) {
var field = fields[i];
if (field.hidden) continue;
var tr = $('<tr/>').appendTo(table);
var td = $('<td/>', {
'class': 'section-cell-label'
}).appendTo(tr);
$('<label/>', {
name: field.name,
title: field.label,
'class': 'field-label',
text: field.label+':'
}).appendTo(td);
td = $('<td/>', {
'class': 'section-cell-field'
}).appendTo(tr);
var field_container = $('<div/>', {
name: field.name,
title: field.label,
'class': 'field'
}).appendTo(td);
field.create(field_container);
if (field.optional) {
field_container.css('display', 'none');
var link = $('<a/>', {
text: IPA.messages.widget.optional,
href: ''
}).appendTo(td);
link.click(function(field_container, link) {
return function() {
field_container.css('display', 'inline');
link.css('display', 'none');
return false;
};
}(field_container, link));
}
}
var sections = that.sections.values; var sections = that.sections.values;
for (var j=0; j<sections.length; j++) { for (var i=0; i<sections.length; i++) {
var section = sections[j]; var section = sections[i];
var div = $('<div/>', { var div = $('<div/>', {
name: section.name, name: section.name,
@@ -228,20 +192,10 @@ IPA.dialog = function(spec) {
}; };
that.save = function(record) { that.save = function(record) {
var fields = that.fields.values;
for (var i=0; i<fields.length; i++) {
var field = fields[i];
var values = field.save();
record[field.name] = values.join(',');
}
var sections = that.sections.values; var sections = that.sections.values;
for (var j=0; j<sections.length; j++) { for (var i=0; i<sections.length; i++) {
var section = sections[j]; var section = sections[i];
section.save(record);
if (section.save) {
section.save(record);
}
} }
}; };
@@ -251,55 +205,20 @@ IPA.dialog = function(spec) {
}; };
that.reset = function() { that.reset = function() {
var fields = that.fields.values;
for (var i=0; i<fields.length; i++) {
var field = fields[i];
field.reset();
}
var sections = that.sections.values; var sections = that.sections.values;
for (var j=0; j<sections.length; j++) { for (var i=0; i<sections.length; i++) {
sections[j].reset(); sections[i].reset();
} }
}; };
init();
that.dialog_create = that.create; that.dialog_create = that.create;
that.dialog_open = that.open; that.dialog_open = that.open;
that.dialog_close = that.close; that.dialog_close = that.close;
that.dialog_save = that.save; that.dialog_save = that.save;
that.dialog_reset = that.reset; that.dialog_reset = that.reset;
var fields = spec.fields || [];
for (var i=0; i<fields.length; i++) {
var field_spec = fields[i];
var field;
if (field_spec instanceof Object) {
var factory = field_spec.factory || IPA.text_widget;
field_spec.entity = that.entity;
field = factory(field_spec);
/* This is a bit of a hack, and is here to support ACI
permissions. The target section is a group of several
widgets together. It makes more sense to do them as a
section than as a widget. However, since they can be mixed
into the flow with the other widgets, the section needs to
be defined here with the fields to get the order correct.*/
if (field.section) {
that.add_section(field);
} else {
that.add_field(field);
}
} else {
field = IPA.text_widget({
name: field_spec,
entity:that.entity,
undo: false });
that.add_field(field);
}
}
return that; return that;
}; };

View File

@@ -105,7 +105,8 @@ IPA.entity_factories.dnszone = function() {
}, },
{ {
factory: IPA.force_dnszone_add_checkbox_widget, factory: IPA.force_dnszone_add_checkbox_widget,
name: 'force' name: 'force',
param_info: IPA.get_method_option('dnszone_add', 'force')
} }
] ]
}). }).

View File

@@ -580,9 +580,9 @@ IPA.entitle.register_online_dialog = function(spec) {
that.save(record); that.save(record);
that.entity.register_online( that.entity.register_online(
record.username, record.username[0],
record.password, record.password[0],
record.ipaentitlementid, record.ipaentitlementid[0],
function() { function() {
var facet = that.entity.get_facet(); var facet = that.entity.get_facet();
facet.refresh(); facet.refresh();
@@ -638,7 +638,7 @@ IPA.entitle.consume_dialog = function(spec) {
that.save(record); that.save(record);
that.entity.consume( that.entity.consume(
record.quantity, record.quantity[0],
function() { function() {
var facet = that.entity.get_facet(); var facet = that.entity.get_facet();
facet.refresh(); facet.refresh();

View File

@@ -885,25 +885,6 @@ IPA.entity_builder = function(){
section = IPA.details_table_section(spec); section = IPA.details_table_section(spec);
} }
facet.add_section(section); facet.add_section(section);
var fields = spec.fields;
if (fields) {
for (var i=0; i<fields.length; i++) {
var field_spec = fields[i];
var field;
if (field_spec instanceof Object) {
field_spec.entity = entity;
var factory = field_spec.factory || IPA.text_widget;
field = factory(field_spec);
} else {
field = IPA.text_widget({
name: field_spec,
entity: entity
});
}
section.add_field(field);
}
}
}; };
function add_redirect_info(facet_name){ function add_redirect_info(facet_name){

View File

@@ -119,37 +119,50 @@ IPA.entity_factories.host = function () {
factory: IPA.host_adder_dialog, factory: IPA.host_adder_dialog,
width: 400, width: 400,
height: 250, height: 250,
fields: [ sections: [
{ {
factory: IPA.widget, factory: IPA.host_fqdn_section,
name: 'fqdn', name: 'fqdn',
optional: true, fields: [
hidden: true {
factory: IPA.widget,
name: 'fqdn',
optional: true,
hidden: true
},
{
factory: IPA.text_widget,
name: 'hostname',
label: IPA.messages.objects.service.host,
param_info: { required: true },
undo: false
},
{
factory: IPA.dnszone_select_widget,
name: 'dnszone',
label: IPA.metadata.objects.dnszone.label_singular,
editable: true,
empty_option: false,
param_info: { required: true },
undo: false
}
]
}, },
{ {
factory: IPA.text_widget, name: 'other',
name: 'hostname', fields: [
label: IPA.messages.objects.service.host, {
undo: false factory: IPA.text_widget,
}, name: 'ip_address',
{ param_info: IPA.get_method_option('host_add', 'ip_address'),
factory: IPA.dnszone_select_widget, undo: false
name: 'dnszone', },
label: IPA.metadata.objects.dnszone.label_singular, {
editable: true, factory: IPA.force_host_add_checkbox_widget,
empty_option: false, name: 'force',
undo: false param_info: IPA.get_method_option('host_add', 'force')
}, }
{ ]
factory: IPA.force_host_add_checkbox_widget,
name: 'force'
},
{
factory: IPA.text_widget,
name: 'ip_address',
label: IPA.get_method_option('host_add','ip_address')['label'],
tooltip: IPA.get_method_option('host_add','ip_address')['doc'],
undo: false
} }
] ]
}). }).
@@ -159,92 +172,56 @@ IPA.entity_factories.host = function () {
build(); build();
}; };
IPA.host_adder_dialog = function(spec) { IPA.host_fqdn_section = function(spec) {
spec = spec || {}; spec = spec || {};
spec.retry = typeof spec.retry !== 'undefined' ? spec.retry : false;
var that = IPA.add_dialog(spec); var that = IPA.details_section(spec);
that.create = function() { that.create = function(container) {
that.container = container;
that.container.addClass('host-adder-dialog');
var hostname = that.get_field('hostname'); var hostname = that.get_field('hostname');
var dnszone = that.get_field('dnszone'); var dnszone = that.get_field('dnszone');
var table = $('<table/>', { var table = $('<table/>', {
name: 'fqdn' 'class': 'fqdn'
}).appendTo(that.container); }).appendTo(that.container);
var tr = $('<tr/>').appendTo(table); var tr = $('<tr/>').appendTo(table);
var td = $('<td/>', { var th = $('<th/>', {
name: hostname.name, 'class': 'hostname',
title: hostname.label, title: hostname.label,
text: hostname.label text: hostname.label
}).appendTo(tr); }).appendTo(tr);
td = $('<td/>', { th = $('<th/>', {
name: dnszone.name, 'class': 'dnszone',
title: dnszone.label, title: dnszone.label,
text: dnszone.label text: dnszone.label
}).appendTo(tr); }).appendTo(tr);
tr = $('<tr/>').appendTo(table); tr = $('<tr/>').appendTo(table);
td = $('<td/>').appendTo(tr); var td = $('<td/>', {
'class': 'hostname'
}).appendTo(tr);
var span = $('<span/>', { var span = $('<span/>', {
name: hostname.name name: hostname.name
}).appendTo(td); }).appendTo(td);
hostname.create(span); hostname.create(span);
td = $('<td/>').appendTo(tr); td = $('<td/>', {
'class': 'dnszone'
}).appendTo(tr);
span = $('<span/>', { span = $('<span/>', {
name: dnszone.name name: dnszone.name
}).appendTo(td); }).appendTo(td);
dnszone.create(span); dnszone.create(span);
table = $('<table/>', {
name: 'other'
}).appendTo(that.container);
var force = that.get_field('force');
tr = $('<tr/>').appendTo(table);
td = $('<td/>', {
title: force.label,
text: force.label+':'
}).appendTo(tr);
td = $('<td/>', {
title: force.label
}).appendTo(tr);
span = $('<span/>', {
name: force.name
}).appendTo(td);
force.create(span);
var ip_address = that.get_field('ip_address');
tr = $('<tr/>').appendTo(table);
td = $('<td/>', {
title: ip_address.label,
text: ip_address.label+':'
}).appendTo(tr);
td = $('<td/>', {
title: ip_address.label
}).appendTo(tr);
span = $('<span/>', {
name: ip_address.name
}).appendTo(td);
ip_address.create(span);
var hostname_input = $('input', hostname.container); var hostname_input = $('input', hostname.container);
var dnszone_input = $('input', dnszone.container); var dnszone_input = $('input', dnszone.container);
@@ -271,13 +248,22 @@ IPA.host_adder_dialog = function(spec) {
field = that.get_field('dnszone'); field = that.get_field('dnszone');
var dnszone = field.save()[0]; var dnszone = field.save()[0];
record.fqdn = hostname && dnszone ? hostname+'.'+dnszone : null; record.fqdn = hostname && dnszone ? [ hostname+'.'+dnszone ] : [];
};
field = that.get_field('force'); return that;
record.force = field.save()[0]; };
field = that.get_field('ip_address'); IPA.host_adder_dialog = function(spec) {
record.ip_address = field.save()[0];
spec = spec || {};
spec.retry = typeof spec.retry !== 'undefined' ? spec.retry : false;
var that = IPA.add_dialog(spec);
that.create = function() {
that.dialog_create();
that.container.addClass('host-adder-dialog');
}; };
that.on_error = function(xhr, text_status, error_thrown) { that.on_error = function(xhr, text_status, error_thrown) {
@@ -660,8 +646,8 @@ IPA.host_password_widget = function(spec) {
var record = {}; var record = {};
dialog.save(record); dialog.save(record);
var new_password = record.password1; var new_password = record.password1[0];
var repeat_password = record.password2; var repeat_password = record.password2[0];
if (new_password != repeat_password) { if (new_password != repeat_password) {
alert(IPA.messages.password.password_must_match); alert(IPA.messages.password.password_must_match);

View File

@@ -807,7 +807,7 @@ hr {
} }
.dialog-section { .dialog-section {
margin-top: 10px; margin-bottom: 10px;
} }
.section-table { .section-table {
@@ -1231,14 +1231,22 @@ table.scrollable tbody {
margin-right: 3px; margin-right: 3px;
} }
.host-adder-dialog table[name=fqdn] { .host-adder-dialog table.fqdn {
width: 100%; width: 100%;
} }
.host-adder-dialog td[name=hostname] { .host-adder-dialog th.hostname {
width: 110px; width: 110px;
} }
.host-adder-dialog td.hostname {
vertical-align: top;
}
.host-adder-dialog td.dnszone {
vertical-align: top;
}
.host-adder-dialog input[name=hostname] { .host-adder-dialog input[name=hostname] {
width: 100%; width: 100%;
} }

View File

@@ -281,6 +281,10 @@ IPA.command = function(spec) {
that.args.push(arg); that.args.push(arg);
}; };
that.add_args = function(args) {
$.merge(that.args, args);
};
that.set_option = function(name, value) { that.set_option = function(name, value) {
that.options[name] = value; that.options[name] = value;
}; };

View File

@@ -110,31 +110,31 @@ IPA.service_add_dialog = function(spec) {
var that = IPA.add_dialog(spec). var that = IPA.add_dialog(spec).
field(IPA.widget({ field(IPA.widget({
name: 'krbprincipalname', name: 'krbprincipalname',
optional:true, optional: true,
entity:spec.entity, entity: spec.entity,
hidden: true hidden: true
})). })).
field(IPA.service_select_widget({ field(IPA.service_select_widget({
name: 'service', name: 'service',
label: IPA.messages.objects.service.service, label: IPA.messages.objects.service.service,
size: 20, size: 20,
entity:spec.entity, entity: spec.entity,
param_info: { required: true },
undo: false undo: false
})). })).
field(IPA.entity_select_widget({ field(IPA.entity_select_widget({
name: 'host', name: 'host',
other_entity: 'host', other_entity: 'host',
other_field: 'fqdn', other_field: 'fqdn',
entity:spec.entity, entity: spec.entity,
label: IPA.messages.objects.service.host, label: IPA.messages.objects.service.host,
param_info: { required: true },
undo: false undo: false
})). })).
field( field(IPA.checkbox_widget({
IPA.checkbox_widget({
name: 'force', name: 'force',
entity:spec.entity, entity: spec.entity,
label: IPA.get_method_option('service_add', 'force').label, param_info: IPA.get_method_option('service_add', 'force'),
tooltip: IPA.get_method_option('service_add', 'force').doc,
undo: false undo: false
})); }));
@@ -147,10 +147,10 @@ IPA.service_add_dialog = function(spec) {
field = that.get_field('host'); field = that.get_field('host');
var host = field.save()[0]; var host = field.save()[0];
record['krbprincipalname'] = service+'/'+host; record['krbprincipalname'] = [ service+'/'+host ];
field = that.get_field('force'); field = that.get_field('force');
record['force'] = field.save()[0]; record['force'] = field.save();
}; };
return that; return that;

View File

@@ -152,7 +152,7 @@ test("Testing type target.", function() {
$("input[type=checkbox]").attr("checked",true); $("input[type=checkbox]").attr("checked",true);
var response_record = {}; var response_record = {};
target_section.save(response_record); target_section.save(response_record);
same(response_record.type, sample_data_filter_only.type, same(response_record.type[0], sample_data_filter_only.type,
"saved type matches sample data"); "saved type matches sample data");
ok((response_record.attrs.length > 10), ok((response_record.attrs.length > 10),
"response length shows some attrs set"); "response length shows some attrs set");
@@ -180,7 +180,7 @@ test("Testing subtree target.", function() {
target_section.load(sample_data); target_section.load(sample_data);
var record = {}; var record = {};
target_section.save(record); target_section.save(record);
same(record.subtree, sample_data.subtree, 'subtree set correctly'); same(record.subtree[0], sample_data.subtree, 'subtree set correctly');
}); });

View File

@@ -340,8 +340,8 @@ IPA.user_password_widget = function(spec) {
var record = {}; var record = {};
dialog.save(record); dialog.save(record);
var new_password = record.password1; var new_password = record.password1[0];
var repeat_password = record.password2; var repeat_password = record.password2[0];
if (new_password != repeat_password) { if (new_password != repeat_password) {
alert(IPA.messages.password.password_must_match); alert(IPA.messages.password.password_must_match);

View File

@@ -40,7 +40,6 @@ IPA.widget = function(spec) {
that.disabled = spec.disabled; that.disabled = spec.disabled;
that.hidden = spec.hidden; that.hidden = spec.hidden;
that.conditional = spec.conditional;
that.optional = spec.optional || false; that.optional = spec.optional || false;
// read_only is set when widget is created // read_only is set when widget is created
@@ -65,8 +64,8 @@ IPA.widget = function(spec) {
that.dirty_changed = IPA.observer(); that.dirty_changed = IPA.observer();
function set_param_info(){ function set_param_info() {
if (!that.param_info && that.entity){ if (!that.param_info && that.entity) {
that.param_info = that.param_info =
IPA.get_entity_param(that.entity.name, that.name); IPA.get_entity_param(that.entity.name, that.name);
} }
@@ -88,7 +87,7 @@ IPA.widget = function(spec) {
if (!value.match(/^-?\d+$/)) { if (!value.match(/^-?\d+$/)) {
that.valid = false; that.valid = false;
that.show_error(IPA.messages.widget.validation.integer); that.show_error(IPA.messages.widget.validation.integer);
return; return that.valid;
} }
if (meta.minvalue !== undefined && value < meta.minvalue) { if (meta.minvalue !== undefined && value < meta.minvalue) {
@@ -96,7 +95,7 @@ IPA.widget = function(spec) {
message = IPA.messages.widget.validation.min_value; message = IPA.messages.widget.validation.min_value;
message = message.replace('${value}', meta.minvalue); message = message.replace('${value}', meta.minvalue);
that.show_error(message); that.show_error(message);
return; return that.valid;
} }
if (meta.maxvalue !== undefined && value > meta.maxvalue) { if (meta.maxvalue !== undefined && value > meta.maxvalue) {
@@ -104,7 +103,7 @@ IPA.widget = function(spec) {
message = IPA.messages.widget.validation.max_value; message = IPA.messages.widget.validation.max_value;
message = message.replace('${value}', meta.maxvalue); message = message.replace('${value}', meta.maxvalue);
that.show_error(message); that.show_error(message);
return; return that.valid;
} }
} }
if (meta.pattern) { if (meta.pattern) {
@@ -112,11 +111,13 @@ IPA.widget = function(spec) {
if (!value.match(regex)) { if (!value.match(regex)) {
that.valid = false; that.valid = false;
that.show_error(meta.pattern_errmsg); that.show_error(meta.pattern_errmsg);
return; return that.valid;
} }
} }
return that.valid;
} }
that.create_error_link = function(container){ that.create_error_link = function(container){
container.append(' '); container.append(' ');
@@ -153,22 +154,25 @@ IPA.widget = function(spec) {
var values = that.save(); var values = that.save();
if (!values) { if (!values) {
return; return that.valid;
} }
if (values.length === 0) { if (values.length === 0) {
return; return that.valid;
} }
var value = values[0]; var value = values[0];
if (!value) { if (!value) {
return; return that.valid;
} }
if (that.metadata) { if (that.metadata) {
meta_validate(that.metadata,value); meta_validate(that.metadata, value);
} }
if (that.param_info) {
meta_validate(that.param_info,value); if (that.valid && that.param_info) {
meta_validate(that.param_info, value);
} }
return that.valid;
}; };