Currently I have a store that I am loading in my app.js at runtime:
stores: ['Neighbors']
Its autoLoad property is set to true.
I've now added a login system that is loaded if some info isn't found in localStorage:
//show login if user credentials are unknown
var username = window.localStorage.getItem("email");
var user_id = window.localStorage.getItem("user_id");
if(username == '' || username == undefined || user_id == '' || user_id == undefined) {
Ext.Viewport.add(Ext.create('aa.view.Login'));
} else {
Ext.Viewport.add(Ext.create('aa.view.Main'));
}
The login view fires an ajax request to log the user in, and the user's id and some other info is returned on success:
onLoginButtonTap: function() {
var values = this.getLoginForm().getValues();
var that = this;
// do the ajax login
Ext.Ajax.request({
url: 'http://localhost:8000/session',
method: 'POST',
params: values,
timeout: 10000, // time out for your request
success: function(result) {
// let's get the email and id into local storage
var json = Ext.decode(result.responseText);
console.log(json);
window.localStorage.setItem('user_id', json.user_id);
window.localStorage.setItem('email', json.email);
// var neighborsStore = Ext.getStore('Neighbors');
// neighborsStore.load();
// load up the tab holder and destroy the login view
Ext.getCmp('loginForm').destroy();
Ext.Viewport.add(Ext.create('aa.view.Main'));
},
failure: function(){
Ext.Msg.alert("Login Failed");
}
});
}
I use the user_id in my store to get a list of other users nearby. The only problem is, my user_id isn't known unless my user has logged in.
I either need to refresh the store, or I need to defer its loading until after a successful login. I'd rather do the second option and only attempt to load the store after login.
I can't seem to find any info on how to do this. I've tried
Ext.getStore('storename').load()
but it isn't refreshing the store. I've tried setting autoLoad to false but then the store never loads. How do I defer loading?