Bring back change event to Palette.

This commit is contained in:
Jürg Lehni 2014-10-04 19:51:10 +02:00
parent 6b9a40d987
commit b9af3af6f4
2 changed files with 19 additions and 12 deletions

View file

@ -85,11 +85,12 @@ var Component = Base.extend(Callback, /** @lends Component# */{
_visible: true,
_enabled: true,
initialize: function Component(parent, name, props, values, row) {
initialize: function Component(palette, parent, name, props, values, row) {
if (!name)
name = 'component-' + this._id;
var value = Base.pick(values[name], props.value);
this._id = Component._id = (Component._id || 0) + 1;
this._palette = palette;
this._parent = parent;
this._name = name;
// The row within which this component is contained. This can be a
@ -135,8 +136,8 @@ var Component = Base.extend(Callback, /** @lends Component# */{
if (columns)
this._row = currentRow;
}
components[key] = new Component(this, key, component,
values, currentRow);
components[key] = new Component(palette, this, key,
component, values, currentRow);
// Keep track of the maximum amount of cells per row, so we
// can adjust colspan after.
numCells = Math.max(numCells, this._numCells);
@ -214,10 +215,10 @@ var Component = Base.extend(Callback, /** @lends Component# */{
}
this._className = className;
// Attach default 'change' even that delegates to parent component.
// Attach default 'change' even that delegates to the palette.
this.attach('change', function(value) {
if (!this._dontFire && parent)
parent.fire('change', this, this._name, value);
if (!this._dontFire)
palette.fire('change', this, this._name, value);
});
this._dontFire = true;
// Now that everything is set up, copy over values fro, props.
@ -241,6 +242,14 @@ var Component = Base.extend(Callback, /** @lends Component# */{
return this._name;
},
getPalette: function() {
return this._palette;
},
getParent: function() {
return this._parent;
},
_setLabel: function(label, nodeName, parent) {
if (parent) {
this[nodeName] = DomElement.set(this[nodeName]

View file

@ -14,8 +14,9 @@
* @name Palette
* @class
*/
/* var Palette = */ Base.extend(/** @lends Palette# */{
/* var Palette = */ Base.extend(Callback, /** @lends Palette# */{
_class: 'Palette',
_events: [ 'onChange' ],
// DOCS: Palette#initialize(props)
// DOCS: Palette#initialize(title, components, values)
@ -36,11 +37,8 @@
this._components = components;
// Create one root component that handles the layout and contains all
// the components.
var root = this._root = new Component(null, 'root', components, values),
that = this;
root.attach('change', function(value) {
that.fire('change', this, this._name, value);
});
var root = this._root = new Component(this, null, 'root', components,
values);
// Write the created components back into the passed components object,
// so they are exposed and can easily be accessed from the outside.
Base.set(components, root._components);