PDA

View Full Version : Class instantiation Order



vuilled
22 Jan 2013, 2:34 AM
Hi,

I build an application in which I load several class

My home file look like this :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>ExtTop - Desktop Sample App</title>

<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>resources/extjs/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>desktop/css/desktop.css" />

<!-- GC -->

<!-- <x-compile> -->
<!-- <x-bootstrap> -->
<script type="text/javascript" src="<?php echo base_url();?>resources/extjs/ext-all-debug.js"></script>
<!-- </x-bootstrap> -->
<script type="text/javascript">
Ext.Loader.setPath({
'Ext.ux.desktop': '<?php echo base_url();?>desktop/js',
'Ext.ux.grid':'<?php echo base_url();?>desktop/js/grid',
'Ext.ux.IFrame': '<?php echo base_url();?>desktop/js/iframe/IFrame.js',
'Ext.ux.form.HtmlEditor.imageUpload':'<?php echo base_url();?>desktop/js/HtmlEditorImageUpload/HtmlEditorImage.js',
'Ext.ux.form.HtmlEditor.Hr': '<?php echo base_url();?>desktop/js/HtmlEditorHr/HtmlEditorHr.js',

Internal : '<?php echo base_url();?>desktop/internal',
MyDesktop: '<?php echo base_url();?>desktop/modules'

});

Ext.require('Internal.User');
Ext.require('MyDesktop.App');

var myDesktopApp;
var user;
var base_path = "<?php echo base_url();?>";





Ext.onReady(function () {


user = new Internal.User({id:'<?php echo $this->session->userdata("idPersonne");?>'});
myDesktopApp = new MyDesktop.App();

});
</script>
<!-- </x-compile> -->
</head>

<body>

<a href="http://www.sencha.com" target="_blank" alt="Powered by Ext JS"
id="poweredby"><div></div></a>

</body>
</html>

My question is How can I make that the this piece of code
myDesktopApp = new MyDesktop.App(); wait that this class
user = new Internal.User({id:'<?php echo $this->session->userdata("idPersonne");?>'}); has been fully instantiated ?

I know that I can pass the second class as a callback of the first but I don't know how to create a variable in the general namespace with this method of doing. I really need the capability to call my user class from anywhere using something like
user.name...

Thanks for your answer

Best regards,

David

mitchellsimoens
24 Jan 2013, 7:48 AM
MyDesktop.App class should require Internal.User but it depends how the MyDesktop.App is used.

vuilled
25 Jan 2013, 1:29 AM
MyDesktop.App class should require Internal.User but it depends how the MyDesktop.App is used.

I try to load the class using your method so I require the class in the MyDesktop.App and then to set a user config in the init method.


Ext.define('MyDesktop.App', {
extend: 'Ext.ux.desktop.App',

requires: [

'Internal.User',
'Ext.window.MessageBox',
'Ext.ux.desktop.ShortcutModel',
'MyDesktop.SystemStatus',
'MyDesktop.VideoWindow',
'MyDesktop.GridWindow',
'MyDesktop.TabWindow',
'MyDesktop.AccordionWindow',
'MyDesktop.Notepad',
'MyDesktop.BogusMenuModule',
'MyDesktop.BogusModule',
'MyDesktop.UserGrid',
'MyDesktop.UserForm',
'MyDesktop.GroupGrid',
'MyDesktop.GroupForm',
'MyDesktop.supportForm',
'MyDesktop.Manual',
'MyDesktop.AdminMessageGrid',
'MyDesktop.AdminMessageForm',
'MyDesktop.AlertUser',


//'MyDesktop.Blockalanche',
'MyDesktop.Settings'
],


config : {

user:null

},
init: function() {
// custom logic before getXYZ methods get called...

this.callParent();
this.setUser(new Internal.user({id:27}))

},


There is no error in the code but whatever i put in this line of code the user property of the Mydesktop.App stay null.

I also try to directly call the user class in the config property like that

config:{
user: this.setUser(new Internal.user({id:27}))
}


But in this case I get an error Internal not defined. the Internal.user is on the loading path and load properly see above post.

Any help is welcome

Thank you

David