webui: better value-change reporting

- widget save() save method should try to always return value even if read only
- report value-change event with actual value to allow processing of the value

https://fedorahosted.org/freeipa/ticket/4402

Reviewed-By: Endi Sukma Dewata <edewata@redhat.com>
This commit is contained in:
Petr Vobornik 2014-07-30 10:08:48 +02:00
parent 935a6a1b0b
commit a43af5cd70
6 changed files with 25 additions and 29 deletions

View File

@ -880,7 +880,7 @@ IPA.cert.status_widget = function(spec) {
status = IPA.cert.CERTIFICATE_STATUS_REVOKED; status = IPA.cert.CERTIFICATE_STATUS_REVOKED;
} }
that.set_status(status, certificate.revocation_reason); that.set_status(status, certificate.revocation_reason);
that.on_value_changed(); that.on_value_changed(certificate);
}; };
that.clear = function() { that.clear = function() {

View File

@ -599,7 +599,7 @@ IPA.host_keytab_widget = function(spec) {
that.update = function(values) { that.update = function(values) {
set_status(values[0] ? 'present' : 'missing'); set_status(values[0] ? 'present' : 'missing');
that.on_value_changed(); that.on_value_changed(values);
}; };
that.clear = function() { that.clear = function() {
@ -759,7 +759,7 @@ IPA.host_password_widget = function(spec) {
that.update = function(values) { that.update = function(values) {
set_status(values[0] ? 'present' : 'missing'); set_status(values[0] ? 'present' : 'missing');
that.on_value_changed(); that.on_value_changed(values);
}; };
that.clear = function() { that.clear = function() {

View File

@ -330,7 +330,7 @@ IPA.service_provisioning_status_widget = function (spec) {
that.update = function(values) { that.update = function(values) {
that.status = values && values.length ? values[0] : false; that.status = values && values.length ? values[0] : false;
set_status(that.status ? 'valid' : 'missing'); set_status(that.status ? 'valid' : 'missing');
that.on_value_changed(); that.on_value_changed(values);
}; };
that.clear = function() { that.clear = function() {

View File

@ -515,7 +515,7 @@ IPA.user_password_widget = function(spec) {
} else { } else {
that.display_control.text(that.unset_value); that.display_control.text(that.unset_value);
} }
that.on_value_changed(); that.on_value_changed(values);
}; };
that.clear = function() { that.clear = function() {

View File

@ -111,7 +111,7 @@ define([
function is_empty(value) { function is_empty(value) {
var empty = false; var empty = false;
if (!value) empty = true; if (value === null || value === undefined) empty = true;
if (lang.isArray(value)) { if (lang.isArray(value)) {
empty = empty || value.length === 0 || empty = empty || value.length === 0 ||

View File

@ -578,10 +578,12 @@ IPA.input_widget = function(spec) {
* Raise value change event * Raise value change event
* @protected * @protected
*/ */
that.on_value_changed = function() { that.on_value_changed = function(value) {
var value = that.save(); var old = that.value;
if (value === undefined) value = that.save();
that.value = value;
that.value_changed.notify([value], that); that.value_changed.notify([value], that);
that.emit('value-change', { source: that, value: value }); that.emit('value-change', { source: that, value: value, old: old });
}; };
/** /**
@ -797,7 +799,7 @@ IPA.text_widget = function(spec) {
var value = values && values.length ? values[0] : ''; var value = values && values.length ? values[0] : '';
that.display_control.text(value); that.display_control.text(value);
that.input.val(value); that.input.val(value);
that.on_value_changed(); that.on_value_changed(values);
}; };
/** /**
@ -818,12 +820,9 @@ IPA.text_widget = function(spec) {
* @inheritDoc * @inheritDoc
*/ */
that.save = function() { that.save = function() {
if (!that.is_writable()) {
return null; var value = that.input.val();
} else { return value === '' ? [] : [value];
var value = that.input.val();
return value === '' ? [] : [value];
}
}; };
/** /**
@ -832,7 +831,7 @@ IPA.text_widget = function(spec) {
that.clear = function() { that.clear = function() {
that.input.val(''); that.input.val('');
that.display_control.text(''); that.display_control.text('');
that.on_value_changed(); that.on_value_changed([]);
}; };
/** /**
@ -1741,7 +1740,7 @@ IPA.option_widget_base = function(spec, that) {
} }
if (that.on_value_changed) { if (that.on_value_changed) {
that.on_value_changed(); that.on_value_changed(values);
} }
}; };
@ -2044,7 +2043,7 @@ IPA.select_widget = function(spec) {
// default was selected instead of supplied value, hence notify // default was selected instead of supplied value, hence notify
util.emit_delayed(that,'value-change', { source: that }); util.emit_delayed(that,'value-change', { source: that });
} }
that.on_value_changed(); that.on_value_changed(values);
}; };
that.update_read_only = function() { that.update_read_only = function() {
@ -2153,9 +2152,6 @@ IPA.textarea_widget = function (spec) {
}; };
that.save = function() { that.save = function() {
if (!that.is_writable()) {
return null;
}
var value = that.input.val(); var value = that.input.val();
return [value]; return [value];
}; };
@ -2164,7 +2160,7 @@ IPA.textarea_widget = function (spec) {
var value = values && values.length ? values[0] : ''; var value = values && values.length ? values[0] : '';
that.input.val(value); that.input.val(value);
that.on_value_changed(); that.on_value_changed(values);
}; };
that.update_read_only = function() { that.update_read_only = function() {
@ -2949,7 +2945,7 @@ IPA.table_widget = function (spec) {
that.values.push(record[that.value_attr_name]); that.values.push(record[that.value_attr_name]);
that.add_record(record); that.add_record(record);
} }
that.on_value_changed(); that.on_value_changed(records);
}; };
that.save = function() { that.save = function() {
@ -3841,7 +3837,7 @@ IPA.combobox_widget = function(spec) {
that.select(value); that.select(value);
} }
); );
that.on_value_changed(); that.on_value_changed(values);
}; };
that.update_read_only = function() { that.update_read_only = function() {
@ -3881,7 +3877,7 @@ IPA.combobox_widget = function(spec) {
that.set_value(option.val()); that.set_value(option.val());
that.value_changed.notify([], that); that.value_changed.notify([], that);
that.emit('value-change', { source: that }); that.emit('value-change', { source: that, value: value });
}; };
that.select_next = function() { that.select_next = function() {
@ -4061,7 +4057,7 @@ IPA.link_widget = function(spec) {
that.nonlink.html(that.value); that.nonlink.html(that.value);
that.check_entity_link(); that.check_entity_link();
that.on_value_changed(); that.on_value_changed(values);
}; };
that.update_link = function() { that.update_link = function() {
@ -5306,7 +5302,7 @@ IPA.sshkey_widget = function(spec) {
that.original_key = that.key.key; that.original_key = that.key.key;
} }
that.update_link(); that.update_link();
that.on_value_changed(); that.on_value_changed(value);
}; };
that.set_deleted = function(deleted) { that.set_deleted = function(deleted) {
@ -5617,7 +5613,7 @@ IPA.value_map_widget = function(spec) {
} }
that.display_control.text(label); that.display_control.text(label);
that.on_value_changed(); that.on_value_changed(values);
}; };
that.save = function() { that.save = function() {