PDA

View Full Version : Questions on Plugins



cnelissen
19 Feb 2010, 4:45 PM
So this may seem like a stupid question to some, but I can't seem to figure this one out...

I am using plugins as a simple way to add some often used config options to various components, and for some reason certain options don't get applied from the plugin. I must be missing something fairly basic, but I have no idea where to look. Here is a simple example of what I am trying to do:



Ext.ux.AppWindow = Ext.extend(Ext.Window, {
init: function(c) {
Ext.apply(c, {
width: (c.width ? c.width : 500),
height: (c.height ? c.height : 500),
maximizable: (c.maximizable ? c.maximizable : true),
minimizable: (c.minimizable ? c.minimizable : true),
constrain: (c.minimizable ? c.minimizable : true)
});
}
});


The height, width, and constrain options get applied fine, however the maximizable and minimizable options do not get applied.

Any ideas?

tobiu
20 Feb 2010, 7:08 AM
hi cnelissen,

i searched another example in the forums, extending a window.
they use initComponent instead of init (never tried init myself).
if you do so, it is important to call the superclass.initComponent.



kind regards,
tobiu



Ext.namespace("Ext.ux");
Ext.ux.ExtensionRepository = Ext.extend(Ext.Window, {
initComponent: function() {
Ext.apply(this, {
width: 1024,
height: 768,
id: 'ExtensionRepository',
title: 'Extension Repository',
iconCls: 'bogus',
shim: false,
animCollapse: false,
constrainHeader: true,
html: 'Test'
});

Ext.ux.ExtensionRepository.superclass.initComponent.apply(this, arguments);
},

onRender: function() {
Ext.MessageBox.alert("Sporocilo", 'Test');
Ext.ux.ExtensionRepository.superclass.onRender.apply(this, arguments);
}
});
Ext.reg('ExtensionRepository', Ext.ux.ExtensionRepository);
var win = new Ext.ux.ExtensionRepository();
win.show();

evant
20 Feb 2010, 4:12 PM
@OP You're getting confused between extending and writing a plugin.

You're extending there, which means you need to change initComponent, then call the superclass initComponent method.

cnelissen
22 Feb 2010, 9:43 AM
@OP You're getting confused between extending and writing a plugin.

You're extending there, which means you need to change initComponent, then call the superclass initComponent method.

Right, I realize that I am extending, however I would rather make use of plugins to add little bits of functionality rather than extending the objects as a whole in my code. Is there any way to get the desired results by making use of plugins? It would seem that some config options can be changed via a plugin, ones that can be set after the component has been initialized, and some config options cannot, I suppose ones that need to happen before the component has been laid out.

I guess the more specific question would be, is there a way to (re)call initComponent from a plugin?

Ideally I would like to be able to do something like:

var win = new Ext.Window({
plugins: new Ext.ux.ExtendedWindow()
});

rather than:

var win = new Ext.ux.ExtendedWindow({
});

Make sense?

tobiu
22 Feb 2010, 10:25 AM
this should help ;)

http://www.extjs.com/learn/Tutorial:Writing_Ext_2_Plugins


kind regards,
tobiu