PDA

View Full Version : best practice widget init


joer
08-24-2007, 04:42 AM
Hi,

I just started to have a look at extjs, and i luv what i see. However, there is a thing I would like to know before I get my hands dirty: is there a best practice how/where to initialize widgets? Is it all about Ext.onReady, or can widgets be initialized when loading (even when they depend on div to be created first).

I am currently working on a site that has the following layout:
a header, side bar and footer are all in a single php file, and the page with the content is loaded by simply include a file.
http://www.joer.se/design.gif

I would like to have a widget both in the side bar and in the content. How should the be initialized/loaded? At the bottom of the page, creating js loading function using php? Is it simply bad design and will not work with extjs? Since the side bar is having a widget, the load function must be placed in the main php file and not the included file..?

Confused...

thanx

para
08-24-2007, 10:52 AM
First, refrain from using the term 'luv'. :) Pet peeve...

The onReady() is pretty much the entry point for JS on a page. If an object depends on a tag or creates tags, it should go in/after the onReady().
Here's my onReady()

Ext.onReady(function(){
Ext.QuickTips.init();
Ext.QuickTips.autoHide = false;

tm.init();
editors.init();
menus.init();
History.init();
Properties.initGrid(); // must be before initializeLayout()
initializeLayout();
Properties.initForm(); // must be after initializeLayout()
eds.init(); // must be before tree creation (buildTrees)
transactionDialog.init();
htmlEditor.init();
smartGuide.setElement(document.getElementById('help'));
});

I try to keep it concise, but everything does need to be initialized here.

Yours would probably look more like...

Ext.onReady(function(){
initializeLayout();
menu.init();
centerWidget.init();
});

Does this help at all?

joer
08-27-2007, 06:35 PM
Hehe, sorry about the 'luv', will never ever write 'luv' again :D

Thanks for your answer, it did help a bit. My problem is really that due to the module design of the page it could be hard to know what to load in the onReady function. (since all the code that needs to run _every_ time is put outside the page module, the module will only contain unique code to keep them as small as possible)

I guess the current module design became strange when changed from dojo to ext.
Well, if I let each module implement the onRead, it should work...