Fixed inconsistent required/optional attributes.

The dialogs and details pages have been modified to use the * symbol
to mark required fields. The automount map and the DNS zone dialogs
have been modified to update the required fields according to the
input type.

Ticket #1696, #1973
This commit is contained in:
Endi S. Dewata 2011-10-19 18:11:09 -02:00
parent b4ebcad0e0
commit 09f3e9869a
15 changed files with 381 additions and 341 deletions

View File

@ -35,11 +35,7 @@ IPA.entity_factories.permission = function() {
{ {
name: 'identity', name: 'identity',
fields: [ fields: [
{ 'cn'
factory: IPA.text_widget,
name: 'cn',
read_only: true
}
] ]
}, },
{ {

View File

@ -35,7 +35,72 @@ IPA.add_dialog = function (spec) {
that.retry = typeof spec.retry !== 'undefined' ? spec.retry : true; that.retry = typeof spec.retry !== 'undefined' ? spec.retry : true;
that.command = null; that.command = null;
function show_edit_page(entity,result){ that.show_edit_page = spec.show_edit_page || show_edit_page;
var init = function() {
that.create_button({
name: 'add',
label: IPA.messages.buttons.add,
click: function() {
that.hide_message();
that.add(
function(data, text_status, xhr) {
var facet = IPA.current_entity.get_facet();
var table = facet.table;
table.refresh();
that.close();
},
that.on_error);
}
});
that.create_button({
name: 'add_and_add_another',
label: IPA.messages.buttons.add_and_add_another,
click: function() {
that.hide_message();
that.add(
function(data, text_status, xhr) {
var label = that.entity.metadata.label_singular;
var message = IPA.messages.dialogs.add_confirmation;
message = message.replace('${entity}', label);
that.show_message(message);
var facet = IPA.current_entity.get_facet();
var table = facet.table;
table.refresh();
that.reset();
},
that.on_error);
}
});
that.create_button({
name: 'add_and_edit',
label: IPA.messages.buttons.add_and_edit,
click: function() {
that.hide_message();
that.add(
function(data, text_status, xhr) {
that.close();
var result = data.result.result;
that.show_edit_page(that.entity, result);
},
that.on_error);
}
});
that.create_button({
name: 'cancel',
label: IPA.messages.buttons.cancel,
click: function() {
that.hide_message();
that.close();
}
});
};
function show_edit_page(entity,result) {
var pkey_name = entity.metadata.primary_key; var pkey_name = entity.metadata.primary_key;
var pkey = result[pkey_name]; var pkey = result[pkey_name];
if (pkey instanceof Array) { if (pkey instanceof Array) {
@ -44,8 +109,6 @@ IPA.add_dialog = function (spec) {
IPA.nav.show_entity_page(that.entity, 'default', pkey); IPA.nav.show_entity_page(that.entity, 'default', pkey);
} }
that.show_edit_page = spec.show_edit_page || show_edit_page;
that.add = function(on_success, on_error) { that.add = function(on_success, on_error) {
var pkey_name = that.entity.metadata.primary_key; var pkey_name = that.entity.metadata.primary_key;
@ -110,67 +173,28 @@ IPA.add_dialog = function (spec) {
command.execute(); command.execute();
}; };
/*dialog initialization*/ that.create = function() {
that.create_button({ that.dialog_create();
name: 'add',
label: IPA.messages.buttons.add,
click: function() {
that.hide_message();
that.add(
function(data, text_status, xhr) {
var facet = IPA.current_entity.get_facet();
var table = facet.table;
table.refresh();
that.close();
},
that.on_error);
}
});
that.create_button({ var div = $('<div/>', {
name: 'add_and_add_another', }).appendTo(that.container);
label: IPA.messages.buttons.add_and_add_another,
click: function() {
that.hide_message();
that.add(
function(data, text_status, xhr) {
var label = that.entity.metadata.label_singular;
var message = IPA.messages.dialogs.add_confirmation;
message = message.replace('${entity}', label);
that.show_message(message);
var facet = IPA.current_entity.get_facet(); $('<span/>', {
var table = facet.table; 'class': 'required-indicator',
table.refresh(); text: IPA.required_indicator
that.reset(); }).appendTo(div);
},
that.on_error);
}
});
that.create_button({ div.append(' ');
name: 'add_and_edit',
label: IPA.messages.buttons.add_and_edit,
click: function() {
that.hide_message();
that.add(
function(data, text_status, xhr) {
that.close();
var result = data.result.result;
that.show_edit_page(that.entity, result);
},
that.on_error);
}
});
that.create_button({ $('<span/>', {
name: 'cancel', text: IPA.messages.widget.validation.required
label: IPA.messages.buttons.cancel, }).appendTo(div);
click: function() { };
that.hide_message();
that.close(); // methods that should be invoked by subclasses
} that.add_dialog_create = that.create;
});
init();
return that; return that;
}; };

View File

@ -144,17 +144,17 @@ IPA.entity_factories.automountkey = function() {
entity({ name: 'automountkey' }). entity({ name: 'automountkey' }).
containing_entity('automountmap'). containing_entity('automountmap').
details_facet({ details_facet({
sections:[ sections: [
{ {
name:'identity', name:'identity',
label: IPA.messages.details.identity, label: IPA.messages.details.identity,
fields:[ fields: [
{ {
factory: IPA.text_widget, name: 'automountkey',
read_only: true, read_only: true
name: 'automountkey'
}, },
'automountinformation'] 'automountinformation'
]
} }
], ],
disable_breadcrumb: false, disable_breadcrumb: false,
@ -224,20 +224,26 @@ IPA.automountmap_adder_dialog = function(spec) {
var that = IPA.add_dialog(spec); var that = IPA.add_dialog(spec);
that.create = function() { that.create = function() {
that.dialog_create(); that.add_dialog_create();
var method_field = that.get_field('method'); var method_field = that.get_field('method');
var indirect_section = that.get_section('indirect');
var key_field = that.get_field('key');
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.method = 'add'; that.method = 'add';
that.get_section('indirect').set_visible(false);
key_field.set_required(false);
indirect_section.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.method = 'add_indirect'; that.method = 'add_indirect';
that.get_section('indirect').set_visible(true);
key_field.set_required(true);
indirect_section.set_visible(true);
}); });
direct_input.click(); direct_input.click();

View File

@ -234,44 +234,29 @@ IPA.details_table_section = function(spec) {
var tr = $('<tr/>').appendTo(table); var tr = $('<tr/>').appendTo(table);
var td = $('<td/>', { var td = $('<td/>', {
'class': 'section-cell-label' 'class': 'section-cell-label',
title: field.label
}).appendTo(tr); }).appendTo(tr);
$('<label/>', { $('<label/>', {
name: field.name, name: field.name,
title: field.label,
'class': 'field-label', 'class': 'field-label',
text: field.label+':' text: field.label+':'
}).appendTo(td); }).appendTo(td);
field.create_required(td);
td = $('<td/>', { td = $('<td/>', {
'class': 'section-cell-field' 'class': 'section-cell-field',
title: field.label
}).appendTo(tr); }).appendTo(tr);
var field_container = $('<div/>', { var field_container = $('<div/>', {
name: field.name, name: field.name,
title: field.label,
'class': 'field' 'class': 'field'
}).appendTo(td); }).appendTo(td);
field.create(field_container); 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));
}
} }
}; };

View File

@ -106,21 +106,32 @@ IPA.entity_factories.dnszone = function() {
adder_dialog({ adder_dialog({
factory: IPA.dnszone_adder_dialog, factory: IPA.dnszone_adder_dialog,
height: 300, height: 300,
fields: [ sections: [
{ {
name: 'idnsname', factory: IPA.dnszone_name_section,
optional: true name: 'name',
}, fields: [
'name_from_ip', {
'idnssoamname', name: 'idnsname',
{ required: false
name: 'idnssoarname', },
optional: true 'name_from_ip'
]
}, },
{ {
factory: IPA.force_dnszone_add_checkbox_widget, name: 'other',
name: 'force', fields: [
param_info: IPA.get_method_option('dnszone_add', 'force') 'idnssoamname',
{
name: 'idnssoarname',
required: false
},
{
factory: IPA.force_dnszone_add_checkbox_widget,
name: 'force',
param_info: IPA.get_method_option('dnszone_add', 'force')
}
]
} }
] ]
}). }).
@ -231,9 +242,143 @@ IPA.dnszone_details_facet = function(spec) {
return that; return that;
}; };
// TODO: Remove the custom create() by moving the fields into sections. IPA.dnszone_name_section = function(spec) {
// The idnsname and name_from_ip should be moved into a custom section.
// The idnssoamname, idnssoarname, and force into a standard section. spec = spec || {};
var that = IPA.details_table_section(spec);
that.create = function(container) {
that.container = container;
that.message_container = $('<div/>', {
style: 'display: none',
'class': 'dialog-message ui-state-highlight ui-corner-all'
}).appendTo(that.container);
var table = $('<table/>', {
'class': 'section-table'
}).appendTo(that.container);
var idnsname = that.get_field('idnsname');
var tr = $('<tr/>').appendTo(table);
var td = $('<td/>', {
'class': 'section-cell-label',
title: idnsname.label
}).appendTo(tr);
var label = $('<label/>', {
name: 'idnsname',
'class': 'field-label',
'for': 'dnszone-adder-dialog-idnsname-radio'
}).appendTo(td);
idnsname.radio = $('<input/>', {
type: 'radio',
id: 'dnszone-adder-dialog-idnsname-radio',
name: 'type',
value: idnsname.name
}).appendTo(label);
label.append(idnsname.label+':');
idnsname.create_required(td);
td = $('<td/>', {
'class': 'section-cell-field',
title: idnsname.label
}).appendTo(tr);
var span = $('<span/>', {
name: 'idnsname',
'class': 'field'
}).appendTo(td);
idnsname.create(span);
var idnsname_input = $('input', span);
var name_from_ip = that.get_field('name_from_ip');
tr = $('<tr/>').appendTo(table);
td = $('<td/>', {
'class': 'section-cell-label',
title: name_from_ip.label
}).appendTo(tr);
label = $('<label/>', {
name: 'name_from_ip',
'class': 'field-label',
'for': 'dnszone-adder-dialog-name_from_ip-radio'
}).appendTo(td);
name_from_ip.radio = $('<input/>', {
type: 'radio',
id: 'dnszone-adder-dialog-name_from_ip-radio',
name: 'type',
value: name_from_ip.name
}).appendTo(label);
label.append(name_from_ip.label+':');
name_from_ip.create_required(td);
td = $('<td/>', {
'class': 'section-cell-field',
title: name_from_ip.label
}).appendTo(tr);
span = $('<span/>', {
name: 'name_from_ip',
'class': 'field'
}).appendTo(td);
name_from_ip.create(span);
var name_from_ip_input = $('input', span);
idnsname.radio.click(function() {
idnsname_input.attr('disabled', false);
name_from_ip_input.attr('disabled', true);
idnsname.set_required(true);
name_from_ip.set_required(false);
name_from_ip.reset();
});
name_from_ip.radio.click(function() {
idnsname_input.attr('disabled', true);
name_from_ip_input.attr('disabled', false);
idnsname.set_required(false);
name_from_ip.set_required(true);
idnsname.reset();
});
idnsname.radio.click();
};
that.save = function(record) {
var idnsname = that.get_field('idnsname');
var name_from_ip = that.get_field('name_from_ip');
if (idnsname.radio.is(':checked')) {
record.idnsname = idnsname.save();
} else {
record.name_from_ip = name_from_ip.save();
}
};
return that;
};
IPA.dnszone_adder_dialog = function(spec) { IPA.dnszone_adder_dialog = function(spec) {
spec = spec || {}; spec = spec || {};
@ -241,185 +386,8 @@ IPA.dnszone_adder_dialog = function(spec) {
var that = IPA.add_dialog(spec); var that = IPA.add_dialog(spec);
that.create = function() { that.create = function() {
that.add_dialog_create();
that.container.addClass('dnszone-adder-dialog'); that.container.addClass('dnszone-adder-dialog');
that.message_container = $('<div/>', {
style: 'display: none',
'class': 'dialog-message ui-state-highlight ui-corner-all'
}).appendTo(that.container);
var table = $('<table/>').appendTo(that.container);
var field = that.get_field('idnsname');
var tr = $('<tr/>').appendTo(table);
var td = $('<td/>', {
title: field.label
}).appendTo(tr);
var label = $('<label/>', {
'for': 'dnszone-adder-dialog-idnsname-radio'
}).appendTo(td);
that.idnsname_radio = $('<input/>', {
type: 'radio',
id: 'dnszone-adder-dialog-idnsname-radio',
name: 'type',
value: 'idnsname'
}).appendTo(label);
label.append(field.label+':');
td = $('<td/>', {
title: field.label
}).appendTo(tr);
var span = $('<span/>', {
name: field.name
}).appendTo(td);
field.create(span);
var idnsname_input = $('input', span);
field = that.get_field('name_from_ip');
tr = $('<tr/>').appendTo(table);
td = $('<td/>', {
title: field.label
}).appendTo(tr);
label = $('<label/>', {
'for': 'dnszone-adder-dialog-name_from_ip-radio'
}).appendTo(td);
var name_from_ip_radio = $('<input/>', {
type: 'radio',
id: 'dnszone-adder-dialog-name_from_ip-radio',
name: 'type',
value: 'name_from_ip'
}).appendTo(label);
label.append(field.label+':');
td = $('<td/>', {
title: field.label
}).appendTo(tr);
span = $('<span/>', {
name: field.name
}).appendTo(td);
field.create(span);
var name_from_ip_input = $('input', span);
that.idnsname_radio.click(function() {
idnsname_input.attr('disabled', false);
name_from_ip_input.attr('disabled', true);
});
name_from_ip_radio.click(function() {
idnsname_input.attr('disabled', true);
name_from_ip_input.attr('disabled', false);
});
idnsname_input.focus(function() {
that.idnsname_radio.attr('checked', true);
});
name_from_ip_input.focus(function() {
name_from_ip_radio.attr('checked', true);
});
that.idnsname_radio.click();
tr = $('<tr/>').appendTo(table);
td = $('<td/>', {
colspan: 2,
html: '&nbsp;'
}).appendTo(tr);
field = that.get_field('idnssoamname');
tr = $('<tr/>').appendTo(table);
td = $('<td/>', {
title: field.label
}).appendTo(tr);
label = $('<label/>', {
text: field.label+':'
}).appendTo(td);
td = $('<td/>', {
title: field.label
}).appendTo(tr);
span = $('<span/>', {
name: field.name
}).appendTo(td);
field.create(span);
field = that.get_field('idnssoarname');
tr = $('<tr/>').appendTo(table);
td = $('<td/>', {
title: field.label
}).appendTo(tr);
label = $('<label/>', {
text: field.label+':'
}).appendTo(td);
td = $('<td/>', {
title: field.label
}).appendTo(tr);
span = $('<span/>', {
name: field.name
}).appendTo(td);
field.create(span);
field = that.get_field('force');
tr = $('<tr/>').appendTo(table);
td = $('<td/>', {
title: field.label
}).appendTo(tr);
label = $('<label/>', {
text: field.label+':'
}).appendTo(td);
td = $('<td/>', {
title: field.label
}).appendTo(tr);
span = $('<span/>', {
name: field.name
}).appendTo(td);
field.create(span);
};
that.save = function(record) {
that.dialog_save(record);
if (that.idnsname_radio.is(':checked')) {
delete record.name_from_ip;
} else {
delete record.idnsname;
}
}; };
return that; return that;
@ -624,7 +592,7 @@ IPA.entity_factories.dnsrecord = function() {
name: 'record_data', name: 'record_data',
label: IPA.messages.objects.dnsrecord.data, label: IPA.messages.objects.dnsrecord.data,
factory: IPA.text_widget, factory: IPA.text_widget,
param_info: {required:true} required: true
} }
] ]
}). }).

View File

@ -177,8 +177,7 @@ IPA.hbacrule_details_facet = function(spec) {
}); });
section.text({ section.text({
name: 'cn', name: 'cn'
read_only: true
}); });
section.textarea({ section.textarea({
name: 'description' name: 'description'

View File

@ -124,14 +124,14 @@ IPA.entity_factories.host = function () {
{ {
factory: IPA.widget, factory: IPA.widget,
name: 'fqdn', name: 'fqdn',
optional: true, required: false,
hidden: true hidden: true
}, },
{ {
factory: IPA.text_widget, factory: IPA.text_widget,
name: 'hostname', name: 'hostname',
label: IPA.messages.objects.service.host, label: IPA.messages.objects.service.host,
param_info: { required: true } required: true
}, },
{ {
factory: IPA.dnszone_select_widget, factory: IPA.dnszone_select_widget,
@ -139,7 +139,7 @@ IPA.entity_factories.host = function () {
label: IPA.metadata.objects.dnszone.label_singular, label: IPA.metadata.objects.dnszone.label_singular,
editable: true, editable: true,
empty_option: false, empty_option: false,
param_info: { required: true } required: true
} }
] ]
}, },
@ -190,12 +190,22 @@ IPA.host_fqdn_section = function(spec) {
text: hostname.label text: hostname.label
}).appendTo(tr); }).appendTo(tr);
$('<span/>', {
'class': 'required-indicator',
text: IPA.required_indicator
}).appendTo(th);
th = $('<th/>', { th = $('<th/>', {
'class': 'dnszone', 'class': 'dnszone',
title: dnszone.label, title: dnszone.label,
text: dnszone.label text: dnszone.label
}).appendTo(tr); }).appendTo(tr);
$('<span/>', {
'class': 'required-indicator',
text: IPA.required_indicator
}).appendTo(th);
tr = $('<tr/>').appendTo(table); tr = $('<tr/>').appendTo(table);
var td = $('<td/>', { var td = $('<td/>', {
@ -256,7 +266,7 @@ IPA.host_adder_dialog = function(spec) {
var that = IPA.add_dialog(spec); var that = IPA.add_dialog(spec);
that.create = function() { that.create = function() {
that.dialog_create(); that.add_dialog_create();
that.container.addClass('host-adder-dialog'); that.container.addClass('host-adder-dialog');
}; };

View File

@ -1256,6 +1256,10 @@ table.scrollable tbody {
width: 100%; width: 100%;
} }
.dnszone-adder-dialog .section-cell-label {
width: 180px;
}
/* Info and simple pages (not main app) */ /* Info and simple pages (not main app) */
body.info-page { body.info-page {
@ -1294,3 +1298,6 @@ body.info-page {
padding: .15em; padding: .15em;
} }
.required-indicator {
color: red;
}

View File

@ -52,14 +52,16 @@ IPA.entity_factories.pwpolicy = function() {
}]}). }]}).
standard_association_facets(). standard_association_facets().
adder_dialog({ adder_dialog({
fields:[ fields: [
{ {
factory: IPA.entity_select_widget, factory: IPA.entity_select_widget,
name: 'cn', name: 'cn',
other_entity: 'group', other_entity: 'group',
other_field: 'cn' other_field: 'cn',
required: true
}, },
'cospriority'], 'cospriority'
],
height: 300 height: 300
}). }).
build(); build();

View File

@ -30,39 +30,48 @@ IPA.entity_factories.service = function() {
search_facet({ search_facet({
columns: [ 'krbprincipalname' ] columns: [ 'krbprincipalname' ]
}). }).
details_facet({sections:[ details_facet({
{ sections: [
name: 'details', {
fields:['krbprincipalname', name: 'details',
fields: [
'krbprincipalname',
{ {
factory:IPA.service_name_widget, factory: IPA.service_name_widget,
name: 'service', name: 'service',
label: IPA.messages.objects.service.service, label: IPA.messages.objects.service.service,
read_only: true read_only: true
}, },
{ {
factory:IPA.service_host_widget, factory: IPA.service_host_widget,
name: 'host', name: 'host',
label: IPA.messages.objects.service.host, label: IPA.messages.objects.service.host,
read_only: true read_only: true
}] }
}, ]
{ },
name: 'provisioning', {
fields:[{ name: 'provisioning',
factory:IPA.service_provisioning_status_widget, fields: [
name: 'provisioning_status', {
label: IPA.messages.objects.service.status factory: IPA.service_provisioning_status_widget,
}] name: 'provisioning_status',
}, label: IPA.messages.objects.service.status
{ }
name: 'certificate', ]
fields:[{ },
factory:IPA.service_certificate_status_widget, {
name: 'certificate_status', name: 'certificate',
label: IPA.messages.objects.service.status fields: [
}] {
}]}). factory: IPA.service_certificate_status_widget,
name: 'certificate_status',
label: IPA.messages.objects.service.status
}
]
}
]
}).
association_facet({ association_facet({
name: 'managedby_host', name: 'managedby_host',
add_method: 'add_host', add_method: 'add_host',
@ -84,7 +93,7 @@ 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, required: false,
entity: spec.entity, entity: spec.entity,
hidden: true hidden: true
})). })).
@ -106,7 +115,7 @@ IPA.service_add_dialog = function(spec) {
editable: true, editable: true,
size: 10, size: 10,
entity: spec.entity, entity: spec.entity,
param_info: { required: true } required: true
})). })).
field(IPA.entity_select_widget({ field(IPA.entity_select_widget({
name: 'host', name: 'host',
@ -114,7 +123,7 @@ IPA.service_add_dialog = function(spec) {
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 } required: true
})). })).
field(IPA.checkbox_widget({ field(IPA.checkbox_widget({
name: 'force', name: 'force',

View File

@ -181,8 +181,7 @@ IPA.sudorule_details_facet = function(spec) {
}); });
section.text({ section.text({
name: 'cn', name: 'cn'
read_only: true
}); });
section.textarea({ section.textarea({
name: 'description' name: 'description'

View File

@ -361,7 +361,6 @@
"true": "True", "true": "True",
"widget": { "widget": {
"next": "Next", "next": "Next",
"optional": "Optional field: click to show",
"page": "Page", "page": "Page",
"prev": "Prev", "prev": "Prev",
"undo": "undo", "undo": "undo",

View File

@ -141,9 +141,8 @@ IPA.entity_factories.user = function() {
adder_dialog({ adder_dialog({
fields: [ fields: [
{ {
factory : IPA.text_widget, name: 'uid',
optional: true, required: false
name:'uid'
}, },
'givenname', 'givenname',
'sn' 'sn'

View File

@ -24,6 +24,7 @@
/* REQUIRES: ipa.js */ /* REQUIRES: ipa.js */
IPA.checkbox_column_width = 22; IPA.checkbox_column_width = 22;
IPA.required_indicator = '*';
IPA.widget = function(spec) { IPA.widget = function(spec) {
@ -40,7 +41,9 @@ IPA.widget = function(spec) {
that.disabled = spec.disabled; that.disabled = spec.disabled;
that.hidden = spec.hidden; that.hidden = spec.hidden;
that.optional = spec.optional || false;
// override the required flag in metadata
that.required = spec.required;
// read_only is set when widget is created // read_only is set when widget is created
that.read_only = spec.read_only; that.read_only = spec.read_only;
@ -51,7 +54,7 @@ IPA.widget = function(spec) {
that.width = spec.width; that.width = spec.width;
that.height = spec.height; that.height = spec.height;
that.undo = typeof spec.undo == 'undefined' ? true : spec.undo; that.undo = spec.undo === undefined ? true : spec.undo;
that.join = spec.join; that.join = spec.join;
that.param_info = spec.param_info; that.param_info = spec.param_info;
@ -129,14 +132,38 @@ IPA.widget = function(spec) {
}).appendTo(container); }).appendTo(container);
}; };
that.check_required = function(){ that.create_required = function(container) {
that.required_indicator = $('<span/>', {
'class': 'required-indicator',
text: IPA.required_indicator,
style: 'display: none; float: right;'
}).appendTo(container);
};
that.is_required = function() {
if (that.read_only) return false;
if (!that.writable) return false;
if (that.required !== undefined) return that.required;
return that.param_info && that.param_info.required;
};
that.set_required = function(required) {
that.required = required;
that.update_required();
};
that.update_required = function() {
if (that.required_indicator) {
that.required_indicator.css('display', that.is_required() ? 'inline' : 'none');
}
};
that.check_required = function() {
var values = that.save(); var values = that.save();
if (!values || !values.length || values[0] === '' ) { if (!values || !values.length || values[0] === '') {
if (that.param_info && if (that.is_required()) {
that.param_info.required &&
!that.optional &&
!that.read_only &&
that.writable) {
that.valid = false; that.valid = false;
that.show_error(IPA.messages.widget.validation.required); that.show_error(IPA.messages.widget.validation.required);
return false; return false;
@ -265,6 +292,7 @@ IPA.widget = function(spec) {
}; };
that.reset = function() { that.reset = function() {
that.update_required();
that.update(); that.update();
that.validate(); that.validate();
that.set_dirty(false); that.set_dirty(false);
@ -838,6 +866,11 @@ IPA.checkbox_widget = function (spec) {
that.input.attr('checked', value); that.input.attr('checked', value);
}; };
// a checkbox will always have a value, so it's never required
that.is_required = function() {
return false;
};
that.checkbox_save = that.save; that.checkbox_save = that.save;
that.checkbox_load = that.load; that.checkbox_load = that.load;
@ -1006,6 +1039,11 @@ IPA.radio_widget = function(spec) {
} }
}; };
// a radio will always have a value, so it's never required
that.is_required = function() {
return false;
};
// methods that should be invoked by subclasses // methods that should be invoked by subclasses
that.radio_create = that.create; that.radio_create = that.create;
that.radio_save = that.save; that.radio_save = that.save;

View File

@ -455,7 +455,6 @@ class i18n_messages(Command):
"true": _("True"), "true": _("True"),
"widget": { "widget": {
"next": _("Next"), "next": _("Next"),
"optional": _("Optional field: click to show"),
"page": _("Page"), "page": _("Page"),
"prev": _("Prev"), "prev": _("Prev"),
"undo": _("undo"), "undo": _("undo"),