PDA

View Full Version : Dynamically create modules in Ext.Desktop



igmanvs
26 Feb 2010, 11:14 AM
Hi,

Could somebody help me how to create modules dynamically through php inm Ext.Desktop sample?

Or maybe help me resolve the next code:

apps.php:
$appsLenght=3;
for($i=0;$i<$appsLenght;$i++)
{ $appInstances .= 'new MyDesktop.BogusModule(),'; }
$appInstances = substr($appInstances,0,-1);
echo "<script>
_instance='$appInstances';
</script>";

sample.js:
var _instance;
var _apps=_instance.split();
MyDesktop = new Ext.app.App({
init :function(){
Ext.QuickTips.init();
},
getModules : function(){
return [
_apps
];
},....

Thanks in advance

Juanito
26 Feb 2010, 1:12 PM
I am strongly against generating js code with any server side language. What you should do is create a json object that can be used by your js to dynamically generate the modules based on data.

I've never worked with the desktop, so here's my help. it uses xtypes to create the modules.

apps.php:


<?
// Array of Module xtypes to be created
$modules = array('mydesktop.moduleA', 'mydesktop.moduleB', 'mydesktop.moduleC');
?>


// in a js file
var xtypes = <?= json_encode($modules);?>;
...
getModules : function(){
var modules = [];
for (var i=0,xtype; xtype=xtypes[i]; i++) {
// Note that you'd need to figure out any other config for the modules
// but the idea is the same (use json to encode the data)
modules[i] = Ext.ComponentMgr.create({xtype:xtype});
}
return modules;
},
....
<script>

igmanvs
26 Feb 2010, 1:51 PM
Thank you for the quick response

I will try your alternative and i'll let you know