PDA

View Full Version : How to refresh/reload a component after overriding the prototype of its class?



Ant0nin
18 Apr 2013, 1:58 AM
Hello,

I'm a beginner with ExtJS framework, and I'm trying to develop a module for an application which aims at switching between languages without refreshing the entire page but only graphical components. So I override the class of my object with an AJAX request but I don't know how to apply the changes to my components. Also, I would like my components not to be instantiated in the success method of the request, is it possible?

LanguageChoice.js :



Ext.ns('MyCompany.form');


MyCompany.form.LanguageChoice = Ext.extend(Ext.form.FormPanel, {

constructor: function(config) {

// Here is my store which contains languages and associated codes (fr, en, es...)
var languagesStore = new Ext.data.ArrayStore({
fields: ['code','label'],
data: Docuged.resources.languages
});

config = Ext.apply({
items:[
// On ajoute une combobox
new Ext.form.ComboBox({
fieldLabel:'Language',
emptyText: 'Choose language...',
store: languagesStore,
displayField:'label',
triggerAction: 'all',


// Overrides of a class with new Strings
onSelect: function(record) {
var url = String.format("ext/src/locale/ext-lang-{0}.js", record.get('code'));
Ext.Ajax.request({
url: url,
success: function(response) {
eval(response.responseText);


// TODO : How to refresh the component?

},
failure: function() {
Ext.Msg.alert('Failure', 'Failed to load locale file.');
},
scope: this
});
},
mode: 'local'
})
],
autoHeight: true,
autoWidth: true,
renderTo: 'langBar',
}, config);

MyCompany.form.LanguageChoice.superclass.constructor.call(this, config);
}
});




main.js :


Ext.onReady( function() {
Ext.QuickTips.init();
var panel = new Ext.ux.BubblePanel({}); // The component I want to refresh!
var form = new MyCompany.form.LanguageChoice({});
});


Thank you in advance for your valuable answers!

ExtJS used version : 3.4

mitchellsimoens
22 Apr 2013, 6:17 AM
What do you mean refresh the component?

willigogs
22 Apr 2013, 7:41 AM
I assume he probably means "replace all existing text strings with those of the selected language"?

For starters, I guess he would have to dynamically remove the existing locale file and attach the correct locale_xx file - but then apart from that I'm not sure, apart from manually updating every panel title, etc? :\