PDA

View Full Version : Problem with reference to object



Wolfie
13 Sep 2010, 4:36 AM
Hey all,

I have this object , most interesting stuff marked with arrow:



VCC.Send.newCampaignTabPanel = function(isNew, config){

var self = this;

self.campaign_name = new Ext.form.TextField({
fieldLabel: 'Nazwa kampanii',
allowBlank: false,
name: 'campaign_name'
});

/*
other stuff here
*/

self.formPanel = new Ext.form.FormPanel({ <------ here most interesting stuff ;)
items: [self.campaign_name, self.sms_text, self.uploaded_numbers],
layout: 'form',
title : 'Kampania',
defaults: {anchor: '98%'},
bodyStyle:'padding: 5px',
fileUpload: true
});

var tabPanel = new Ext.TabPanel({
items: [self.formPanel],
activeTab: 0
});

return tabPanel;
}
So here I am returning tabPanel

And now I am using this object in onother one (marked with the arraw):



VCC.Send.CreateSmsCampaign = function(isNew, config){
var self = this;

config = config || {};

/*
some stuff here
*/

var newCampaignTabPanel = new VCC.Send.newCampaignTabPanel(isNew, config);
var sendNewSmsCampaign = new Ext.Window({
title: config.title ? config.title : 'Nowa kampania sms',
items: [newCampaignTabPanel],
width: 400,
height: 300,
constrainHeader: true,
layout: 'fit',
//closeAction: 'close',
modal:true,
buttonAlign: 'center',
buttons: [{text: 'Zapisz',
handler : function(){
if(newCampaignTabPanel.formPanel.getForm().isValid()){ <----- here using object
if(!config.id){
Ext.Msg.confirm('Wiadomo??', 'Czy na pewno chces zapisa? kampanie ? Edycja nazwy oraz tre?ci sms b?dzie niemo?liwa', confirmSubmitFn);
} else {
confirmSubmitFn();
}

}
}},
{text: 'Zamknij',
handler : function(){
sendNewSmsCampaign.close();
}}]
});


sendNewSmsCampaign.show();
//self.sendMainWin.reloadData();
return sendNewSmsCampaign;
}
So I am constructing newCampaignTabPanel and I want to refer to the formPanel object which is public (self.formPanel in newCampaignTabPanel object)

So where u can see arrow the error ocured in firebug :


newCampaignTabPanel.formPanel is undefined
What I am duing wrong, why I can't refere to the self.tabPanel ?

Animal
13 Sep 2010, 4:46 AM
You are constructing a completely seperate thing from the TabPanel. "self" is this "VCC.Send.newCampaignTabPanel" thing, NOT the TabPanel.

But you return the TabPanel.

Why bother with shoehorning use of a constructor into this? Just rethink that function as a factory function which creates and returns a TabPanel with properties set up within it.

jay@moduscreate.com
13 Sep 2010, 4:51 AM
You have issues understanding scope. Also your code seems to be a series of factory methods. You're going to run into a lot of trouble in the future.

A debugger would help you figure this out.

http://tdg-i.com/img/screencasts/2010-09-13_0848.png


http://tdg-i.com/img/screencasts/2010-09-13_0850.png

Animal
13 Sep 2010, 4:57 AM
That's not it Jay. VCC.Send.newCampaignTabPanel is being used as a constructor, not a singleton.

The OP needs to just rethink, and use it as a factory function.

jay@moduscreate.com
13 Sep 2010, 5:00 AM
That's not it Jay. VCC.Send.newCampaignTabPanel is being used as a constructor, not a singleton.

The OP needs to just rethink, and use it as a factory function.


Good call (and right as usual dude). i missed the "new" keyword. heh.

Wolfie
13 Sep 2010, 5:09 AM
Ahh...there shouldn't be the 'new' key word ;)

So in that cese I can use VCC.Send.formPanel reference....?

jay@moduscreate.com
13 Sep 2010, 5:20 AM
Yes.

I do suggest you read up on Object Oriented JavaScript and then perhaps on how Ext.extend works.

Wolfie
13 Sep 2010, 5:24 AM
Ok, I will, thanks for help....