X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Roo%2FToolbar.js;h=b6ecbd6f3ecfb2283aa1fd0dfde82ed62365b83d;hb=61bc45258e16a779856dd2ad0862630b489e4583;hp=8d7de71344a3205f7220bb28e9bfc755f3293d9d;hpb=4d9cd83949f3c24871af08cebb30b1f8102ac4c9;p=roojs1 diff --git a/Roo/Toolbar.js b/Roo/Toolbar.js index 8d7de71344..b6ecbd6f3e 100644 --- a/Roo/Toolbar.js +++ b/Roo/Toolbar.js @@ -14,7 +14,7 @@ * Basic Toolbar class. * @constructor * Creates a new Toolbar - * @param {Object} config The config object + * @param {Object} container The config object */ Roo.Toolbar = function(container, buttons, config) { @@ -27,7 +27,7 @@ Roo.Toolbar = function(container, buttons, config) if (typeof(container) == 'object' && container.xtype) { config = container; container = config.container; - buttons = config.buttons; // not really - use items!! + buttons = config.buttons || []; // not really - use items!! } var xitems = []; if (config && config.items) { @@ -40,6 +40,7 @@ Roo.Toolbar = function(container, buttons, config) if(container){ this.render(container); } + this.xitems = xitems; Roo.each(xitems, function(b) { this.add(b); }, this); @@ -48,8 +49,8 @@ Roo.Toolbar = function(container, buttons, config) Roo.Toolbar.prototype = { /** - * @cfg {Roo.data.Store} items - * array of button configs or elements to add + * @cfg {Array} items + * array of button configs or elements to add (will be converted to a MixedCollection) */ /** @@ -283,8 +284,9 @@ Roo.Toolbar.prototype = { fields : false, /** - * Adds a dynamically rendered Roo.form field (TextField, ComboBox, etc). Note: the field should not have - * been rendered yet. For a field that has already been rendered, use {@link #addElement}. + * Adds a dynamically rendered Roo.form field (TextField, ComboBox, etc). + * Note: the field should not have been rendered yet. For a field that has already been + * rendered, use {@link #addElement}. * @param {Roo.form.Field} field * @return {Roo.ToolbarItem} */ @@ -354,12 +356,28 @@ Roo.Toolbar.prototype = { * @param {HTMLElement} el */ Roo.Toolbar.Item = function(el){ + var cfg = {}; + if (typeof (el.xtype) != 'undefined') { + cfg = el; + el = cfg.el; + } + this.el = Roo.getDom(el); this.id = Roo.id(this.el); this.hidden = false; + + this.addEvents({ + /** + * @event render + * Fires when the button is rendered + * @param {Button} this + */ + 'render': true + }); + Roo.Toolbar.Item.superclass.constructor.call(this,cfg); }; - -Roo.Toolbar.Item.prototype = { +Roo.extend(Roo.Toolbar.Item, Roo.util.Observable, { +//Roo.Toolbar.Item.prototype = { /** * Get this item's HTML Element @@ -371,8 +389,11 @@ Roo.Toolbar.Item.prototype = { // private render : function(td){ - this.td = td; + + this.td = td; td.appendChild(this.el); + + this.fireEvent('render', this); }, /** @@ -434,7 +455,7 @@ Roo.Toolbar.Item.prototype = { this.disabled = false; this.el.disabled = false; } -}; +}); /** @@ -444,10 +465,15 @@ Roo.Toolbar.Item.prototype = { * @constructor * Creates a new Separator */ -Roo.Toolbar.Separator = function(){ +Roo.Toolbar.Separator = function(cfg){ + var s = document.createElement("span"); s.className = "ytb-sep"; - Roo.Toolbar.Separator.superclass.constructor.call(this, s); + if (cfg) { + cfg.el = s; + } + + Roo.Toolbar.Separator.superclass.constructor.call(this, cfg || s); }; Roo.extend(Roo.Toolbar.Separator, Roo.Toolbar.Item, { enable:Roo.emptyFn, @@ -462,10 +488,13 @@ Roo.extend(Roo.Toolbar.Separator, Roo.Toolbar.Item, { * @constructor * Creates a new Spacer */ -Roo.Toolbar.Spacer = function(){ +Roo.Toolbar.Spacer = function(cfg){ var s = document.createElement("div"); s.className = "ytb-spacer"; - Roo.Toolbar.Spacer.superclass.constructor.call(this, s); + if (cfg) { + cfg.el = s; + } + Roo.Toolbar.Spacer.superclass.constructor.call(this, cfg || s); }; Roo.extend(Roo.Toolbar.Spacer, Roo.Toolbar.Item, { enable:Roo.emptyFn, @@ -496,16 +525,25 @@ Roo.Toolbar.Fill = Roo.extend(Roo.Toolbar.Spacer, { * Creates a new TextItem * @param {String} text */ -Roo.Toolbar.TextItem = function(text){ - if (typeof(text) == 'object') { - text = text.text; +Roo.Toolbar.TextItem = function(cfg){ + var text = cfg || ""; + if (typeof(cfg) == 'object') { + text = cfg.text || ""; + } else { + cfg = null; } var s = document.createElement("span"); s.className = "ytb-text"; s.innerHTML = text; - Roo.Toolbar.TextItem.superclass.constructor.call(this, s); + if (cfg) { + cfg.el = s; + } + + Roo.Toolbar.TextItem.superclass.constructor.call(this, cfg || s); }; Roo.extend(Roo.Toolbar.TextItem, Roo.Toolbar.Item, { + + enable:Roo.emptyFn, disable:Roo.emptyFn, focus:Roo.emptyFn