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

View file

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