Hello,
I'm trying to move some methods from my main controller to another controller as it has now too many lines.
What I do so far:
In my main controller: I call another controller like this:
Code:
'countriescombo': {
change: me.application.getController('Countries').getCountries
},
Inside this second controller, I have the following code with 2 methods. The first method is called from the previous piece of code and works. At the end of this method, I try to call the 'filterCountries' method but I must missing something as it doesn't work...
Code:
getCountries: function (combo, rec, index, e) {
if (!combo._isClearingValues)
{
Global.countries = combo.getValue();
var arrayCountries = combo.getValue().toString().split(",");
valueSelected = arrayCountries[arrayCountries.length-1];
if (valueSelected == 'All countries' || combo.getValue() == '')
{
var newCountries = new Array();
newCountries.push('All countries');
combo._isClearingValues = true;
Global.countries = '';
combo.clearValue();
combo.setValue('All countries');
delete combo._isClearingValues;
}
else if (valueSelected == 'All EU countries')
{
var newCountries = new Array();
Global.countries = '';
newCountries.push('All EU countries');
combo._isClearingValues = true;
newCountries.push('Belgium'); newCountries.push('Bulgaria'); newCountries.push('Czech Republic'); newCountries.push('Denmark');
newCountries.push('Cyprus'); newCountries.push('Estonia'); newCountries.push('Finland'); newCountries.push('France');
newCountries.push('Austria'); newCountries.push('Germany'); newCountries.push('Greece'); newCountries.push('Hungary');
newCountries.push('Ireland'); newCountries.push('Italy'); newCountries.push('Latvia'); newCountries.push('Lithuania');
newCountries.push('Luxembourg'); newCountries.push('Netherlands'); newCountries.push('Poland'); newCountries.push('Portugal');
newCountries.push('Romania'); newCountries.push('Slovakia'); newCountries.push('Slovenia'); newCountries.push('Spain');
newCountries.push('Sweden'); newCountries.push('Malta'); newCountries.push('United Kingdom');
Global.countries = newCountries;
combo.clearValue();
combo.setValue('All EU countries');
delete combo._isClearingValues;
}
else
{
var newCountries = new Array();
Global.countries = '';
for (var i = 0; i < arrayCountries.length; i++) {
if (arrayCountries[i] != 'All countries' && arrayCountries[i] != 'All EU countries')
newCountries.push(arrayCountries[i]);
}
combo._isClearingValues = true;
Global.countries = newCountries;
combo.clearValue();
combo.setValue(Global.countries);
delete combo._isClearingValues;
}
if (Global.indicatorGroup == 'TRAPS')
{
var store = Ext.getStore('MetrSeriesDisplayedStore');
var storeDetails = Ext.getStore('MetrSeriesDetailsStore');
}
else if (Global.indicatorGroup == 'NRR')
var store = Ext.getStore('NrrSeriesStore');
else if (Global.indicatorGroup == 'TXW')
{
var store = Ext.getStore('TaxWedgeDisplayedStore');
var storeDetails = Ext.getStore('TaxWedge');
}
else if (Global.indicatorGroup == 'SLTXEARN')
var store = Ext.getStore('EarningsDisplayedStore');
else if (Global.indicatorGroup == 'NIDI')
var store = Ext.getStore('NidiDisplayedStore');
else if (Global.indicatorGroup == 'WB')
var store = Ext.getStore('WbDisplayedStore');
else if (Global.indicatorGroup == 'TaxSSC')
var store = Ext.getStore('TaxSSCDisplayedStore');
filterCountries(store);
filterCountries(storeDetails);
}
},
filterCountries: function (store) {
// if (!countries._isClearingValues)
// {
// If nothing selected, I removed all previously selected filter so I display all datas of my store
if (Global.countries == '' || Global.countries.toString().match('All countries') != null) {
store.clearFilter();
//Ext.getCmp('countryComboId').resetOriginalValue();
} else {
// a string that will contain the instruction to evaluate
var result;
// I put the selected value of my combo into an Array
var countr = Global.countries.toString();
var valueArray = countr.split(",");
//store.filter("LABEISO", countr);
store.filterBy(function (s) {
//For each value I will concatenate the result value in order to filter on several options
for (var i = 0; i < valueArray.length; i++) {
if (i > 0) {
result = result + "|| s.get('LABEISO') =='" + valueArray[i] + "'";
} else {
result = "(s.get('LABEISO') == '" + valueArray[i] + "'";
}
}
/* I finish the string to have a string that will be a valid instruction
* Example if I selected Belgium and Denmark in my combo list:
* (s.get('LABEISO') == 'Belgium' || s.get('LABEISO') == 'Denmark');
*/
result = result + ");"
// I evaluate my string to execute it as an instruction
return eval(result);
});
}
}
Thanks for any help.
Regards