summaryrefslogtreecommitdiffstats
path: root/install/ui/details.js
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2011-09-10 11:54:02 -0500
committerEndi S. Dewata <edewata@redhat.com>2011-09-23 13:13:10 +0000
commit390d017e321fd5ed56af094cf1f1c74f64e95735 (patch)
treeea90b38f292170059dd757f59ef6b757c5b9b5a5 /install/ui/details.js
parenta90e50cdf759a1b436381f0e9e91caf2d4288636 (diff)
downloadfreeipa-390d017e321fd5ed56af094cf1f1c74f64e95735.tar.gz
freeipa-390d017e321fd5ed56af094cf1f1c74f64e95735.tar.xz
freeipa-390d017e321fd5ed56af094cf1f1c74f64e95735.zip
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
Diffstat (limited to 'install/ui/details.js')
-rw-r--r--install/ui/details.js90
1 files changed, 77 insertions, 13 deletions
diff --git a/install/ui/details.js b/install/ui/details.js
index f7831114d..cecf97a61 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -43,17 +43,42 @@ IPA.details_section = function(spec) {
that.dirty = false;
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) {
return that.fields.get(name);
};
that.add_field = function(field) {
field.entity = that.entity;
+ field.undo = that.undo;
that.fields.put(field.name, field);
field.dirty_changed.attach(that.field_dirty_changed);
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.add_field(field);
return that;
@@ -93,6 +118,8 @@ IPA.details_section = function(spec) {
var fields = that.fields.values;
for (var i=0; i<fields.length; i++) {
var field = fields[i];
+ if (field.hidden) continue;
+
var field_container = $('<div/>', {
name: field.name,
title: field.label,
@@ -102,7 +129,6 @@ IPA.details_section = function(spec) {
}
};
-
that.load = function(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() {
var fields = that.fields.values;
for (var i=0; i<fields.length; i++) {
@@ -159,6 +193,16 @@ IPA.details_section = function(spec) {
return valid;
};
+ that.set_visible = function(visible) {
+ if (visible) {
+ that.container.show();
+ } else {
+ that.container.hide();
+ }
+ };
+
+ init();
+
// methods that should be invoked by subclasses
that.section_create = that.create;
that.section_setup = that.setup;
@@ -272,6 +316,15 @@ IPA.details_facet = function(spec) {
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.
for most entities, this will be a single element long, but for some
it requires the containing entities primary keys as well.*/
@@ -509,6 +562,14 @@ IPA.details_facet = function(spec) {
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() {
var sections = that.sections.values;
for (var i=0; i<sections.length; i++) {
@@ -554,31 +615,34 @@ IPA.details_facet = function(spec) {
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 sections = that.sections.values;
- for (var i=0; i<sections.length; i++) {
+ for (i=0; i<sections.length; i++) {
var section = sections[i];
- if(!section.is_valid() || !valid) {
+ if (!section.is_valid() || !valid) {
valid = false;
continue;
}
- if (section.save) {
- section.save(command.options);
- continue;
- }
-
var section_fields = section.fields.values;
for (var j=0; j<section_fields.length; j++) {
var field = section_fields[j];
if (!field.is_dirty()) continue;
- values = field.save();
+ var values = record[field.name];
if (!values) continue;
- var param_info = field.param_info;
+
+ var param_info = field.param_info;
if (param_info) {
if (param_info.primary_key) continue;
if (values.length === 1) {
@@ -588,7 +652,7 @@ IPA.details_facet = function(spec) {
} else {
command.set_option(field.name, values);
}
- } else {
+ } else {
if (values.length) {
command.add_option('setattr', field.name+'='+values[0]);
} else {
@@ -601,7 +665,7 @@ IPA.details_facet = function(spec) {
}
}
- if(!valid) {
+ if (!valid) {
var dialog = IPA.message_dialog({
title: IPA.messages.dialogs.validation_title,
message: IPA.messages.dialogs.validation_message