PDA

View Full Version : Problem with variables



bizzdeveloper
11 Jul 2010, 9:06 AM
Hi there,

In my form i would use this.project_id



WebApp.module.projects.formsWindow = function (config) {

if (!config) {
config = {};
}

/* config */
config.title = 'Nieuw formulier'+this.project_id;
config.width = 500;
config.height = 300;
config.xtype = 'panel';
config.layout = 'fit';
config.region = 'center';
config.border = false;
config.closeAction = 'hide';

/* items */
config.items = [
this.form = new Ext.form.FormPanel({
xtype : 'panel',
border : false,
layout : 'fit',
region : 'center',
labelWidth : 100,

forceLayout : true,

defaults : {
anchor : '100%',
},

bodyStyle : 'background-color: transparent;',

items : [{
header : false,
border : true,
layout : 'border',

items : [{
header : false,
border : false,
region : 'north',
height : 180,
},{
header : false,
border : false,
region : 'center',
height : 180,
html : 'hahaha'+config.project_id+this.form_id
}]
}]
})
];

/* constructor */
WebApp.module.projects.formsWindow.superclass.constructor.call(this, config);\

Ext.extend(WebApp.module.projects.formsWindow, WebApp.windows,{
initComponent : function(){
WebApp.module.projects.formsWindow.superclass.initComponent.call(this);
},

/* getParams */
getParams : function () {
if (this.project_id > 0) {
return {id : this.project_id};
}
},

/* setId */
setId : function (id) {
this.project_id = id;
},

/* getId */
getId : function () {
return this.project_id;
},

loadForm : function (project_id, form_id) {
this.form.getForm().load({
url : '/project/getform',
method : 'GET',
params : {
project : project_id,
form : form_id
},

success : function () {
this.project_id = project_id;
this.form_id = form_id;

/**
* constructor
*/
WebApp.module.projects.formsWindow.superclass.show.call(this);
},

scope : this
});

WebApp.module.projects.formsWindow.superclass.show.call(this);
},

addForm : function () {
WebApp.module.projects.formsWindow.superclass.show.call(this);
}
});
};

But i get undefined, does anyone know how i can use this variable?

On this section it goes wrong :

html : 'hahaha'+config.project_id+this.form_id

11 Jul 2010, 9:20 AM
when exactly do you set the project_id?? do you do it when calling the constructor to instantiate a new instance of this class or with setId?

bizzdeveloper
11 Jul 2010, 9:24 AM
I am calling the loadForm from my grid listener :

formWindow = new WebApp.module.projects.formsWindow();
formWindow.loadForm(record.data.project_id, record.data.id);

11 Jul 2010, 9:27 AM
I can't tell what you're doing. you have some seriously weird logic :

For instance: WebApp.module.projects.formsWindow.superclass.show.call(this); will get called no matter what in this block.



loadForm : function (project_id, form_id) {
this.form.getForm().load({
url : '/project/getform',
method : 'GET',
params : {
project : project_id,
form : form_id
},

success : function () {
this.project_id = project_id;
this.form_id = form_id;

/**
* constructor
*/
WebApp.module.projects.formsWindow.superclass.show.call(this);
},

scope : this
});

WebApp.module.projects.formsWindow.superclass.show.call(this);
},

bizzdeveloper
11 Jul 2010, 9:32 AM
Can you tell what is the right way?
I want to open a new window from my grid listener where i can access the project_id and from_id,
becaus i need them to get data from a json store.

11 Jul 2010, 9:34 AM
the best way:

grid fires event,
causes an ajax request to fire,
if successful, render window and form panel, passing the data from the resulting ajax request.

You can't load a form panel if it's not rendered.

bizzdeveloper
11 Jul 2010, 9:38 AM
Can you give me a short example?

11 Jul 2010, 9:42 AM
Unfortunately not. I am currently working on helping a lot other forum members.

Btw, i covered this type of workflow in my book.

You can look at the code via http://app.extjsinaction.com or http://app.extjsinaction.com/app.zip