PDA

View Full Version : Parameter issue



elardev
2 Aug 2012, 5:34 AM
Hello World !

I have an issue with a function which takes parameters.

Let me explain :


loadFiche: function(cbo, rec) {
if(cbo == undefined) {
cbo = Ext.getCmp('comboSelectionStructureAAfficher');
}
console.log(cbo);
console.log(rec);
var ctnStructure = cbo.up('container[name="choixStructure"]').up('container[name="Structure"]');
if (Ext.getCmp('InfoStructure')) {
ctnStructure.remove('InfoStructure');
}
ctnStructure.add(
[
{
xtype: 'container',
id: 'InfoStructure',
items: [
{
xtype: 'container',
name: 'infoStructure',
layout: 'vbox',
defaultWidth: 1500,
items: [
{
xtype: 'container',
layout: 'hbox',
padding: 10,
items: [
{
xtype: 'container',
width: 300,
items: [
{
xtype: 'displayfield',
fieldLabel: 'Statut ',
name: 'civiliteLongue'
},
{
xtype: 'hidden',
name: 'idCivilite'
}
]
},
{
xtype: 'container',
width: 300,
items: [
{
xtype: 'displayfield',
name: 'sigle',
fieldLabel: 'Sigle '
}
]
}
]
},
{
xtype: 'container',
padding: 10,
items: [
{
xtype: 'displayfield',
name: 'raisonSociale',
fieldLabel: 'Raison Sociale '
}
]
},
{
xtype: 'container',
padding: 10,
items: [
{
xtype: 'displayfield',
name: 'SIRET',
fieldLabel: 'S.I.R.E.T '
},
{
xtype: 'hiddenfield',
name: 'idStructure'
},
{
xtype: 'hidden',
name: 'idEtablissement'
}
]
}
]
},
{
xtype: 'container',
name: 'coordonneesStructure',
layout: 'vbox',
items: [
{
xtype: 'fieldset',
name: 'coordonneesPostales',
padding: 20,
title: 'Coordonnees Postales',
style: {backgroundColor: '#EFEFEF'},
layout: 'hbox',
width: 500,
items: [
{
xtype: 'container',
style: {
backgroundImage: 'url(images/icons/AdressePostale.png)',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center top'
},
width: 80,
height: 20
},
{
xtype: 'container',
name: 'coordPostales',
layout: 'vbox',
items: [
{
xtype: 'fieldcontainer',
name: 'adresseStructure',
layout: 'hbox',
width: 500,
items: [
{
xtype: 'displayfield',
name: 'numeroVoie',
fieldLabel: 'Adresse ',
labelWidth: 130,
width: 140
},
{
xtype: 'displayfield',
name: 'libelleCNR',
width: 30
},
{
xtype: 'displayfield',
name: 'longRue',
width: 50
},
{
xtype: 'displayfield',
name: 'nomVoie',
width: 100
},
{
xtype: 'hidden',
name: 'idComplementNumeroRue'
},
{
xtype: 'hidden',
name: 'idTypeVoie'
}
]
},
{
xtype: 'fieldcontainer',
name: 'complementAdresseStructure',
width: 300,
items: [
{
xtype: 'displayfield',
name: 'complement',
fieldLabel: 'Complement ',
labelWidth: 130
}
]
},
{
xtype: 'fieldcontainer',
name: 'villeStructure',
width: 600,
layout: 'hbox',
items: [
{
xtype: 'displayfield',
name: 'codePostal',
fieldLabel: 'Code Postal / Ville ',
labelWidth: 130,
width: 250
},
{
xtype: 'displayfield',
name: 'nom',
width: 150
},
{
xtype: 'hidden',
name: 'idCommune'
}
]
}
]
},
{
xtype: 'hidden',
name: 'idAdresse'
}
]
},
{
xtype: 'fieldset',
name: 'coordonneesAutres',
padding: 20,
width: 500,
layout: 'vbox',
style: {backgroundColor: '#EFEFEF'},
title: 'Autres coordonnees',
items: [
{
xtype: 'container',
name: 'coordonneesTelephoniques',
layout: 'hbox',
items: [
{
xtype: 'container',
style: {
backgroundImage: 'url(images/icons/BlackPhone.png)',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center top'
},
height: 20,
width: 80
},
{
xtype: 'displayfield',
name: 'telephone',
width: 150
},
{
xtype: 'displayfield',
name: 'libelle',
width: 90
},
{
xtype: 'checkbox',
name: 'listeRouge',
fieldLabel: 'Liste rouge ',
disabled: true
},
{
xtype: 'hidden',
name: 'idTelephone'
},
{
xtype: 'hidden',
name: 'idTypeTelephone'
}
]
},
{
xtype: 'container',
name: 'coordonneesElectroniques',
layout: 'hbox',
items: [
{
xtype: 'container',
style: {
backgroundImage: 'url(images/icons/AdresseElectronique.png)',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center top'
},
width: 80,
height: 20
},
{
xtype: 'displayfield',
name: 'adresse',
vtype: 'email',
width: 150
},
{
xtype: 'checkbox',
name: 'envoiAutorise',
fieldLabel: 'Envoi autorise ',
disabled: true
},
{
xtype: 'hidden',
name: 'idMail'
}
]
},
{
xtype: 'container',
name: 'coordonneesBancaires',
layout: 'hbox',
items: [
{
xtype: 'container',
style: {
backgroundImage: 'url(images/icons/dollar.png)',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center top'
},
width: 80,
height: 20
},
{
xtype: 'container',
layout: 'vbox',
height: 70,
items: [
{
xtype: 'displayfield',
name: 'titulaire',
width: 150,
flex: 1,
height: 15
},
{
xtype: 'displayfield',
name: 'IBAN',
width: 450,
flex: 1,
height: 15,
id: 'IBANDisplayedOnFormulaireInfo'
},
{
xtype: 'displayfield',
name: 'BIC',
width: 450,
flex: 1,
height: 15,
id: 'BICDisplayedOnFormulaireInfo'
}
]
},
{
xtype: 'hiddenfield',
name: 'idRIB'
}
]
}
]
}
]
}
]
}
]
);
var formulaire = ctnStructure.up('panel[name="structureInfo"]');
formulaire.loadRecord(rec[0]);
formulaire.setTitle(rec[0].data.sigle);
ctnStructure.child('container[name="choixStructure"]').child('button[name="modifierStructure"]').show();
}


This is a function that fires under two events :
when I select a record in the related combobox, it fires, and works really well.
when I call upon it from another function.

That's the matter : I can't pass the combobox in parameter, though I manage to pass its selected record.

Here's the code calling upon loadFiche :

enregistrerStructure: function(button) { // définition d'une variable pointant sur le formulaire à examiner
var form = button.up('window[name="formStructure"]').down('form[name="Structure"]');

var valeurs = form.getForm().getValues(); // récupération des données
if (form.getForm().isValid()) {
if (valeurs.idStructure == '-1') {
// Cas de la création d'une structure
Ext.Ajax.request({
url: 'structure/creer-structure',
params: valeurs,
method: 'POST'
});
} else {
// Cas de la modification d'une structure
Ext.Ajax.request({
url: 'structure/modifier-structure',
params: valeurs,
method: 'POST'
});
}
} else {
alert('Les champs soulignés sont obligatoires !');
}
form.close();
Ext.getCmp('ComboSelectionStructureAAfficher').store.load();
this.loadFiche(Ext.getCmp('comboSelectionStructureAAfficher'), Ext.getCmp('ComboSelectionStructureAAfficher').store.findRecord('idStructure', valeurs.idStructure));
// this.loadFiche() doesn't work. I don't know how to pass loadFiche the right combobox
}

I made a console.log(cbo) :
when it fires by the combo select, cbo is like I want it.
when it fires after the enregistrerStructure(), it's undefined.

I also made a console.log(rec) :
when it fires by the combo select and when it fires by the manual call both, nothing's wrong.

Can you please help me fixing it ?

--------

I found out : this was a case matter while typing the combo's id.

By the end of loadFiche, I perform a loadRecord(rec[0]).

When rec is set by the select parameters, everything's right.
When I send it by findRecord() method, rec[0] isn't defined, but rec exists.

I deduced from that the loadRecord has to be adapted.

So I tried this :



if(typeof(rec[0] != undefined) {
formulaire.loadRecord(rec[0]);
formulaire.setTitle(rec[0].data.sigle);
} else {
formulaire.loadRecord(rec);
formulaire.setTitle(rec.data.sigle);
}


And it always passes in the first node. So I don't know how to test correctly the undefined type. I'd appreciate if anyone can explain me how to test type.

Thanks in advance...

elardev
6 Aug 2012, 12:45 AM
Done