PDA

View Full Version : Desktop dynamic module load with PHP



vikinko
7 Nov 2010, 10:38 PM
I would appreciate your assistance related to dynamically loading modules, utilizing the below PHP and JS code. When viewing the error in FireBug -> "Referral is not defined"

Thanks!

PHP - "modules.php"

<?php
include('lock.php');
include('database.php');

$member_check=$_SESSION['login_member'];

$sql="SELECT mod_referrals, mod_mileage FROM modules WHERE email='$member_check'";
$query=mysql_query($sql);
$result=mysql_fetch_object($query);
$module_referrals=$result->mod_referrals;
$module_mileage=$result->mod_mileage;

if($module_referrals>0)
{
$mod_referral=array('mod_name'=>'Referral');
}
if($module_mileage>0)
{
$mod_mileage=array('mod_name'=>'Mileage');
}

$mods=array($mod_referral,$mod_mileage);
echo '{"mod_access":'.json_encode($mods).'}';
//echo "{mod:[{mod_name: 'Referral'},{mod_name: 'Mileage'}]}"
?>JSON OUTPUT - "modules.php"

{"mod_access":[{"mod_name":"Referral"},{"mod_name":"Mileage"}]}EXT JS 3.3.0

MyDesktop = new Ext.app.App({
init :function(){
Ext.QuickTips.init();
},

getModules : function(){
var moduleAccess = new Ext.data.JsonStore({
url: 'library/modules.php',
root: 'mod_access',
nocache: true,
autoLoad: false,
fields: ['mod_name']
});

moduleAccess.load();
moduleAccess.on('load', function(){
MyDesktop.modules = [];
for(i=0; i< moduleAccess.getCount(); i++){
var module = eval(moduleAccess.getAt(i).get("mod_name"));
MyDesktop.modules.push(module);
}
return MyDesktop.modules;
});
},

/* getAutorun: function () {
return [
new MyDesktop.Referral()
];
},*/

// config for the start menu
getStartConfig : function(){
return {
title: 'My Desktop!', //<?= $_SESSION['login_member']; ?>
iconCls: 'user',
toolItems: [{
text:'Settings',
iconCls: 'settings',
handler: function () { window.location = "../modules/mreferrals/gl_account.php"; }, //testing
scope:this
},'-',{
text:'Logout',
iconCls: 'logout',
handler: function () { window.location = "library/logout.php"; },
scope:this
}]
};
}
});



/*
* Modules - Standard no code changed, other than headings!
*/
MyDesktop.Referral = Ext.extend(Ext.app.Module, {
id: 'grid-win',
init: function () {
this.launcher = {
text: 'Referral Management',
iconCls: 'icon-grid',
handler: this.createWindow,
scope: this
}
},

createWindow: function () {
var desktop = this.app.getDesktop();
var win = desktop.getWindow('grid-win');
if (!win) {
win = desktop.createWindow({
id: 'grid-win',
title: 'Referral Management',
width: 740,
height: 480,
iconCls: 'icon-grid',
shim: false,
animCollapse: false,
constrainHeader: true,

layout: 'fit',
items:
new Ext.grid.GridPanel({
border: false,
ds: new Ext.data.Store({
reader: new Ext.data.ArrayReader({}, [
{ name: 'company' },
{ name: 'price', type: 'float' },
{ name: 'change', type: 'float' },
{ name: 'pctChange', type: 'float' }
]),
data: Ext.grid.dummyData
}),
cm: new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
{ header: "Company", width: 120, sortable: true, dataIndex: 'company' },
{ header: "Price", width: 70, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price' },
{ header: "Change", width: 70, sortable: true, dataIndex: 'change' },
{ header: "% Change", width: 70, sortable: true, dataIndex: 'pctChange' }
]),

viewConfig: {
forceFit: true
},
//autoExpandColumn:'company',

tbar: [{
text: 'Add Referral',
tooltip: 'Add a new row',
iconCls: 'add'
}, '-', {
text: 'Options',
tooltip: 'Blah blah blah blaht',
iconCls: 'option'
}, '-', {
text: 'Remove Referral',
tooltip: 'Remove the selected item',
iconCls: 'remove'
}]
})
});
}
win.show();
}
});



MyDesktop.Mileage = Ext.extend(Ext.app.Module, {
id: 'tab-win',
init: function () {
this.launcher = {
text: 'Mileage Tracker',
iconCls: 'tabs',
handler: this.createWindow,
scope: this
}
},

createWindow: function () {
var desktop = this.app.getDesktop();
var win = desktop.getWindow('tab-win');
if (!win) {
win = desktop.createWindow({
id: 'tab-win',
title: 'Mileage Tracker',
width: 740,
height: 480,
iconCls: 'tabs',
shim: false,
animCollapse: false,
border: false,
constrainHeader: true,

layout: 'fit',
items:
new Ext.TabPanel({
activeTab: 0,

items: [{
title: 'Car',
header: false,
html: '<p>Mileage for this month.</p>',
border: false
}, {
title: 'Tab Text 2',
header: false,
html: '<p>Something useful would be in here.</p>',
border: false
}, {
title: 'Tab Text 3',
header: false,
html: '<p>Something useful would be in here.</p>',
border: false
}, {
title: 'Tab Text 4',
header: false,
html: '<p>Something useful would be in here.</p>',
border: false
}]
})
});
}
win.show();
}
});

MyDesktop.SupaGrid = Ext.extend(Ext.app.Module, {
id: 'grid-win',
init: function () {
this.launcher = {
text: 'Supa Grid',
iconCls: 'icon-grid',
handler: this.createWindow,
scope: this
}
},

createWindow: function () {
var desktop = this.app.getDesktop();
var win = desktop.getWindow('grid-win');
if (!win) {
win = desktop.createWindow({
id: 'grid-win',
title: 'Supa Grid',
width: 740,
height: 480,
iconCls: 'icon-grid',
shim: false,
animCollapse: false,
constrainHeader: true,

layout: 'fit',
items:
new Ext.grid.GridPanel({
border: false,
ds: new Ext.data.Store({
reader: new Ext.data.ArrayReader({}, [
{ name: 'company' },
{ name: 'price', type: 'float' },
{ name: 'change', type: 'float' },
{ name: 'pctChange', type: 'float' }
]),
data: Ext.grid.dummyData
}),
cm: new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
{ header: "Company", width: 120, sortable: true, dataIndex: 'company' },
{ header: "Price", width: 70, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price' },
{ header: "Change", width: 70, sortable: true, dataIndex: 'change' },
{ header: "% Change", width: 70, sortable: true, dataIndex: 'pctChange' }
]),

viewConfig: {
forceFit: true
},
//autoExpandColumn:'company',

tbar: [{
text: 'Add Referral',
tooltip: 'Add a new row',
iconCls: 'add'
}, '-', {
text: 'Options',
tooltip: 'Blah blah blah blaht',
iconCls: 'option'
}, '-', {
text: 'Remove Referral',
tooltip: 'Remove the selected item',
iconCls: 'remove'
}]
})
});
}
win.show();
}
});


// Array data for the grid
Ext.grid.dummyData = [
['3m Co', 71.72, 0.02, 0.03, '9/1 12:00am'],
['Alcoa Inc', 29.01, 0.42, 1.47, '9/1 12:00am'],
['American Express Company', 52.55, 0.01, 0.02, '9/1 12:00am'],
['American International Group, Inc.', 64.13, 0.31, 0.49, '9/1 12:00am'],
['AT&T Inc.', 31.61, -0.48, -1.54, '9/1 12:00am'],
['Caterpillar Inc.', 67.27, 0.92, 1.39, '9/1 12:00am'],
['Citigroup, Inc.', 49.37, 0.02, 0.04, '9/1 12:00am'],
['Exxon Mobil Corp', 68.1, -0.43, -0.64, '9/1 12:00am'],
['General Electric Company', 34.14, -0.08, -0.23, '9/1 12:00am'],
['General Motors Corporation', 30.27, 1.09, 3.74, '9/1 12:00am'],
['Hewlett-Packard Co.', 36.53, -0.03, -0.08, '9/1 12:00am'],
['Honeywell Intl Inc', 38.77, 0.05, 0.13, '9/1 12:00am'],
['Intel Corporation', 19.88, 0.31, 1.58, '9/1 12:00am'],
['Johnson & Johnson', 64.72, 0.06, 0.09, '9/1 12:00am'],
['Merck & Co., Inc.', 40.96, 0.41, 1.01, '9/1 12:00am'],
['Microsoft Corporation', 25.84, 0.14, 0.54, '9/1 12:00am'],
['The Coca-Cola Company', 45.07, 0.26, 0.58, '9/1 12:00am'],
['The Procter & Gamble Company', 61.91, 0.01, 0.02, '9/1 12:00am'],
['Wal-Mart Stores, Inc.', 45.45, 0.73, 1.63, '9/1 12:00am'],
['Walt Disney Company (The) (Holding Company)', 29.89, 0.24, 0.81, '9/1 12:00am']
];:((

Condor
7 Nov 2010, 11:36 PM
Your 'getModules' method will never work! You are returning the modules from a callback function, but the actual getModules function will already have returned 'undefined' by then.

You will have to rewrite this so it load the store first and only starts building the desktop after the store has loaded.

ps. Do you really need a store for this? A simple Ext.Ajax.request would do just job just fine.

Achoy
13 Apr 2015, 11:05 PM
all please help me

var moduleAccess = new Ext.data.JsonStore({
url: 'menu.php',
root: 'mod_access',
fields: ['mod_name'],
nocache: true
});
moduleAccess.load();
moduleAccess.on('load', function(){
test = [];
for(i=0; i< moduleAccess.getCount(); i++){
md = moduleAccess.getAt(i).get("mod_name");
mde = eval(md);
test.push(mde);
//console.log(moduleAccess.getAt(i).get("mod_name"));
}
console.log(test);
//alert(MyDesktop.modules);
//return MyDesktop.modules;
});

;return test;

how to fix return test,?