PDA

View Full Version : Loading modules dynamically in desktop app



joenilson
3 Feb 2013, 12:51 PM
Hi all, i'm using extjs 4.1.1 using the webdesktop example and i want to load dynamically the modules, in the App.js file change:



getModules : function(){
return [
new MyDesktop.VideoWindow(),
..........
new MyDesktop.BogusModule()
];
}


with this:



getModules : function(){
Ext.Ajax.request({
url: '/app/core/mget',
method:'POST',
callback: function (options,success,response){
var modulesClasses = [];
if(success){
modules = Ext.decode(response.responseText);
Ext.each(modules, function(resp){
modulesClasses.push('[new MyDesktop.LoadModule({init : function(){ this.launcher = { id: '+resp.mid+', text: "'+resp.mshortdesc+'", windowId: '+resp.mid+' } }})]');
})
}
console.log(eval(modulesClasses.join(',')));
return eval(modulesClasses.join(','));
}
});
}


In the console log it appears how is creating the objects correctly but its dont appears in the Menu list, i do a test writing manually the object creation in:



return [
new MyDesktop.VideoWindow(),
new MyDesktop.TabWindow(),
new MyDesktop.AccordionWindow(),
new MyDesktop.Notepad(),
new MyDesktop.LoadModule({init : function(){ this.launcher = { text: 'Module 2', windowId: 16 } }}),
new MyDesktop.LoadModule({init : function(){ this.launcher = { text: 'Module 3', windowId: 17 } }}),
new MyDesktop.LoadModule({init : function(){ this.launcher = { text: 'Module 4', windowId: 18 } }}),
new MyDesktop.LoadModule({init : function(){ this.launcher = { text: 'Module 5', windowId: 19 } }})
];


And it work well, the menu is populated correctly.

I dont understand why it isn't working with the each function, if anyone can help me i will apreciate.

JN