webui: change widget updated event into value change event

This change allow us to use proper two way binding between a field and
a widget. In previous implementation field was not changed if something
changed the value of a widget in 'update'. Now listeners are notified
when the widget value is changed by: calling 'update', 'set_value'
or by user change.

Reviewed-By: Adam Misnyovszki <amisnyov@redhat.com>
This commit is contained in:
Petr Vobornik 2014-03-19 17:06:19 +01:00
parent aadde0f849
commit df18a3bc04
10 changed files with 38 additions and 47 deletions

View File

@ -610,7 +610,6 @@ IPA.association_table_widget = function (spec) {
that.add_record(that.values[i]);
}
}
that.updated.notify([], that);
};
that.create_add_dialog = function() {

View File

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

View File

@ -481,7 +481,6 @@ IPA.hbacrule_details_facet = function(spec) {
that.update_on_success = function(data, text_status, xhr) {
that.refresh();
that.on_update.notify();
that.emit('update', { source: that });
that.nofify_update_success();
};

View File

@ -610,8 +610,7 @@ IPA.host_keytab_widget = function(spec) {
that.update = function(values) {
set_status(values[0] ? 'present' : 'missing');
that.updated.notify([], that);
that.emit('update', { source: that });
that.on_value_changed();
};
that.clear = function() {
@ -771,8 +770,7 @@ IPA.host_password_widget = function(spec) {
that.update = function(values) {
set_status(values[0] ? 'present' : 'missing');
that.updated.notify([], that);
that.emit('update', { source: that });
that.on_value_changed();
};
that.clear = function() {

View File

@ -196,7 +196,6 @@ IPA.idrange_adder_policy = function(spec) {
}
type_f.widget.value_changed.attach(that.on_input_change);
type_f.widget.updated.attach(that.on_input_change);
baserid_f.widget.value_changed.attach(that.on_input_change);
secondarybaserid_f.widget.value_changed.attach(that.on_input_change);
};

View File

@ -398,6 +398,7 @@ otptoken.qr_widget = function(spec) {
that.qrcode.makeCode(that.text);
that.uri_control.text(that.text);
that.div_link_control.prop('href', that.text);
that.on_value_changed();
};
/**

View File

@ -50,7 +50,6 @@ IPA.rule_details_widget = function(spec) {
that.widgets.add_widget(that.enable_radio);
that.enable_radio.value_changed.attach(that.on_enable_radio_changed);
that.enable_radio.updated.attach(that.on_enable_radio_changed);
};
that.on_enable_radio_changed = function() {

View File

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

View File

@ -513,8 +513,7 @@ IPA.user_password_widget = function(spec) {
} else {
that.display_control.text(that.unset_value);
}
that.updated.notify([], that);
that.emit('update', { source: that });
that.on_value_changed();
};
that.clear = function() {

View File

@ -310,18 +310,6 @@ IPA.input_widget = function(spec) {
*/
that.undo_clicked = IPA.observer();
/**
* Updated event.
* @deprecated
*
* Raised when widget content gets updated - raised by
* {@link IPA.input_widget#update} method.
*
* @event
*/
that.updated = IPA.observer();
/**
* Creates HTML representation of error link
* @param {HTMLElement} container - node to place the error link
@ -356,6 +344,13 @@ IPA.input_widget = function(spec) {
that.update = function() {
};
/**
* Alias of update
*/
that.set_value = function(value) {
that.update(value);
};
/**
* This function saves the values entered in the UI.
* It returns the values in an array, or null if
@ -723,8 +718,7 @@ IPA.text_widget = function(spec) {
that.input.css('display', '');
}
that.updated.notify([], that);
that.emit('update', { source: that, value: value });
that.on_value_changed();
};
/**
@ -745,6 +739,7 @@ IPA.text_widget = function(spec) {
that.clear = function() {
that.input.val('');
that.display_control.text('');
that.on_value_changed();
};
/**
@ -794,6 +789,7 @@ IPA.multivalued_widget = function(spec) {
that.size = spec.size || 30;
that.undo_control;
that.initialized = true;
that.updating = false;
that.rows = [];
@ -806,6 +802,8 @@ IPA.multivalued_widget = function(spec) {
row.remove_link.show();
}
if (that.updating) return;
that.on_value_changed();
that.emit('value-change', { source: that });
that.emit('child-value-change', { source: that, row: row });
};
@ -1081,6 +1079,7 @@ IPA.multivalued_widget = function(spec) {
that.update = function(values, index) {
var value;
that.updating = true;
if (index === undefined) {
@ -1103,9 +1102,9 @@ IPA.multivalued_widget = function(spec) {
row.widget.update(values);
}
that.updated.notify([], that);
that.emit('update', { source: that });
that.updating = false;
that.on_value_changed();
};
that.update_add_link_visibility = function() {
@ -1185,7 +1184,6 @@ IPA.option_widget_base = function(spec, that) {
that.label = spec.label;
that.tooltip = spec.tooltip;
that.value_changed = that.value_changed || IPA.observer();
that.updated = that.updated || IPA.observer();
that.default_value = spec.default_value || null;
that.default_on_empty = spec.default_on_empty === undefined ? true : spec.default_on_empty;
@ -1539,8 +1537,9 @@ IPA.option_widget_base = function(spec, that) {
}
}
that.updated.notify([], that);
that.emit('update', { source: that });
if (that.on_value_changed) {
that.on_value_changed();
}
};
that.set_enabled = function(enabled) {
@ -1827,8 +1826,7 @@ IPA.select_widget = function(spec) {
// default was selected instead of supplied value, hence notify
util.emit_delayed(that,'value-change', { source: that });
}
that.updated.notify([], that);
that.emit('update', { source: that });
that.on_value_changed();
};
that.empty = function() {
@ -1937,8 +1935,7 @@ IPA.textarea_widget = function (spec) {
var value = values && values.length ? values[0] : '';
that.input.val(value);
that.updated.notify([], that);
that.emit('update', { source: that });
that.on_value_changed();
};
that.clear = function() {
@ -2685,8 +2682,7 @@ IPA.table_widget = function (spec) {
that.values.push(record[that.value_attr_name]);
that.add_record(record);
}
that.updated.notify([], that);
that.emit('update', { source: that });
that.on_value_changed();
};
that.save = function() {
@ -3590,8 +3586,7 @@ IPA.combobox_widget = function(spec) {
that.select(value);
}
);
that.updated.notify([], that);
that.emit('update', { source: that });
that.on_value_changed();
};
that.set_value = function(value) {
@ -3796,8 +3791,7 @@ IPA.link_widget = function(spec) {
that.nonlink.html(that.value);
that.check_entity_link();
that.updated.notify([], that);
that.emit('update', { source: that });
that.on_value_changed();
};
that.update_link = function() {
@ -5031,9 +5025,7 @@ IPA.sshkey_widget = function(spec) {
that.originally_set = true;
that.original_key = that.key.key;
}
that.update_link();
that.updated.notify([], that);
that.emit('update', { source: that });
that.on_value_changed();
};
that.set_deleted = function(deleted) {
@ -5308,6 +5300,7 @@ IPA.value_map_widget = function(spec) {
var that = IPA.input_widget(spec);
that.value_map = spec.value_map || {};
that.default_label = text.get(spec.default_label || '');
that.value = '';
that.create = function(container) {
that.widget_create(container);
@ -5323,6 +5316,7 @@ IPA.value_map_widget = function(spec) {
var value, found, label;
found = false;
that.value = '';
if ($.isArray(values)) {
for (value in that.value_map) {
@ -5331,6 +5325,7 @@ IPA.value_map_widget = function(spec) {
if (values.indexOf(value) > -1) {
label = text.get(that.value_map[value]);
that.value = value;
found = true;
}
}
@ -5341,8 +5336,11 @@ IPA.value_map_widget = function(spec) {
}
that.display_control.text(label);
that.updated.notify([], that);
that.emit('update', { source: that });
that.on_value_changed();
};
that.save = function() {
return [that.value];
};
that.clear = function() {