PDA

View Full Version : Access properly to dateField and datastore



tdikarim
9 Mar 2011, 5:30 AM
Hi,

I have a window that contain a toolbar with a dateField. And I want to know if I access to the Field with the best way. Because I must also to acces to the Datastore and I don't like the way the I have done global definition. Must I do taht also for the grid
the field is : tb_dateField

Here is the code


QoDesk.GridWindow = Ext.extend(Ext.app.Module, {
id: 'facturation-electronique-grid'
,type: 'facturation-electronique/grid'
,silent: false

, tb_dateField: null
,init : function(){
Ext.Ajax.timeout = 60000;
}

,createWindow : function(){
var desktop = this.app.getDesktop();
var win = desktop.getWindow('facturation-electronique-win');
tb_dateField = new Ext.form.DateField({
width: 150
,format: 'Y-m-d'
});


if(!win){

var ds = new Ext.data.JsonStore({
root: 'results',
totalProperty: 'total',
idProperty: 'threadid',
remoteSort: false,

fields: [
{name: 'DFD_DOS_NUM', type: 'string'},
{name: 'DFD_DOS_NOM', type: 'string'},
{name: 'DFD_CLI_SOC', type: 'string'},
{name: 'DFD_CLI_NUM', type: 'string'},
{name: 'DFD_TYP_FORMAT', type: 'string'},
{name: 'DFD_FLAG_TRT', type: 'string'}
],

proxy: new Ext.data.ScriptTagProxy({
url:'http://xxx.xxx.xxx.xx/TK/DEV/serveur/php/facturation-electronique.php'
, timeout : 60000
})
});
//--- Ordre de tri par défaut
ds.setDefaultSort('DFD_DOS_NOM', 'asc');

var colModel = new Ext.grid.ColumnModel([
{header: "DFD_DOS_NUM", hidden: true, width: 120, sortable: true, locked:false, dataIndex: 'DFD_DOS_NUM'}
,{header: "DFD_DOS_NOM", hidden: false, width: 120, sortable: true, locked:false, dataIndex: 'DFD_DOS_NOM'}
,{header: "DFD_CLI_SOC",hidden: false, width: 120,sortable: true,dataIndex: 'DFD_CLI_SOC'}
,{header: "DFD_CLI_NUM",hidden: false, width: 180,sortable: true,dataIndex: 'DFD_CLI_NUM'}
,{header: "DFD_TYP_FORMAT",hidden: false, width: 180,sortable: true,dataIndex: 'DFD_TYP_FORMAT'}
]);

var grid = new Ext.grid.GridPanel({
border:false,
ds: ds,
trackMouseOver:false,
disableSelection:true,
loadMask: true,
cm:colModel,
sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
tbar: [
{
//text:TK_convertToHtml('Généré la facturation électronique'),
text:'Généré la facturation électronique',
tooltip:'Your options',
//handler: this.Launch_facturation_electronique,
handler: function() {
this.Launch_facturation_electronique(win);
},
scope: this,
iconCls:'demo-grid-option'
},
'->',
tb_dateField
]

,bbar: new Ext.PagingToolbar({
pageSize: 25,
store: ds,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display",
items:[
'-', {
pressed: true,
enableToggle:true,
text: 'Afficher détail',
//cls: 'tk-grid-details',
iconCls: 'tk-grid-details',
toggleHandler: function(btn, pressed){
var view = grid.getView();
view.showPreview = pressed;
view.refresh();
}
}]
})

//--- customize view config
,viewConfig: {
forceFit:true,
enableRowBody:true,
showPreview:true,
getRowClass : function(record, rowIndex, p, store){
if(this.showPreview){
p.body = '<p><b>N° Interne : ' + record.data.DFD_DOS_NUM+'</b></p>';
return 'x-grid3-row-expanded';
}
return 'x-grid3-row-collapsed';
}
}

});

win = desktop.createWindow({
animCollapse:true,
constrainHeader:true,
height:480,
iconCls: 'grid-icon',
id: 'facturation-electronique-win',
items: grid,
layout: 'fit',
shim:false,
taskbuttonTooltip: '<b>Grid Window</b><br />A window with a grid',
title:'Facturation Electronique',
tools: [
{
id: 'refresh',
handler: Ext.emptyFn,
scope: this
}
],
width:740
});

}

win.show();

// render it
grid.render();

// trigger the data store load
ds.baseParams = {"facturation_electronique_liste":'facturation_electronique_liste'};
ds.load({params:{start:0, limit:25}});

}

, Launch_facturation_electronique : function(win) {

alert (tb_dateField.getValue());
/*
Ext.Ajax.request({
url: 'http://xxx.xxx.xxx.xx/TK/DEV/serveur/php/facturation-electronique.php',
params: {
module: 'facturation_electronique'
,action: 'LaunchFacturationElectronique'
//,data : ...
//,dateLaunch : this.tb_dateField.getValue() || null
,userNAme: ''
},
callback: function(options, success, response) {
result = Ext.decode(response.responseText);

},
scope: this
});
*/

}

});

Thanks
Karim

brittongr
9 Mar 2011, 10:52 PM
I think the reason why you haven't received any response is because the question is not clear... Based on the post i take that your first language is not english but that's not a problem and maybe you can explain the situation a little more, si por casualidad tu primer idioma es español envia la pregunta en español y yo con gusto te respondere...

tdikarim
10 Mar 2011, 1:25 AM
Hi,
I'll try to explain a little better. (Effectively my natural langage is French)
I have a toolbar that contains a button and a DateField.
I want to recover the value of my DateField when I click the button on my toolbar.
The function Launch_facturation_electronique unknown variable tb_dateField unless I declare it in Global.
I ask because I have also recovered the line of the grid was selected. And so I also wanted to know if I should declare any global objects that I want to access?
The alternative would be to pass a parameter to the function Launch_facturation_electronique all the objects I want to retrieve the value.
I would like to know what is the most appropriate method?

Thanks
Karim

brittongr
10 Mar 2011, 2:05 AM
Well, you you are getting undefined because the variable is out of the scope you are not assigning the property to that class you are just using a variable that has the same name as the member one, when you want to use properties or members variables inside the functions created inside a class you must use the keyword "this" like you are doing to call this.Launch_facturation_electronique(win); because they are members of the class, so in order to use it in Launch_facturation_electronique you should do it like:



createWindow: function(){
var desktop = this.app.getDesktop();
var win = desktop.getWindow('facturation-electronique-win');
this.tb_dateField = new Ext.form.DateField(
{
width: 150,
format: 'Y-m-d'
});
...

Launch_facturation_electronique: function(win){

alert(this.tb_dateField.getValue());
}
Hope it helps!

tdikarim
10 Mar 2011, 2:30 AM
Hi,
that works !!

Thanks guy

Karim