PDA

View Full Version : Initialising app with a global config variable so that the Stores can access it



putty
8 Jul 2013, 12:12 AM
I need to be able to launch two instances of my application so that a user can view information about two projects simultaneously. To do this I need to tell my EXTJS application what project ID it is currently using so that the store can pass it as an ajax parameter and the php script can return data for the correct project.

I am mapping two urls to my app.php (www.mysite/application/1234 and www.mysite/application/4321 for example) I am then trying to set the the project_id in the Ext.application.launch function so that I can then pass it as an extraParams in the store, the problem is that the stors keep initialising before the launch function is called.

What is the best method for passing initial configuration parameters into EXT so that you can pass them as part of an ajax request?

Example Code

Application
See method one and two I have tried to use to sett a global variable, neither worked.


Ext.application({


requires: [
...
],
models: [
...
],
stores: [
...
'InvoiceTree',
...
],
views: [
...
],
appFolder: '../js/desktop/src',
autoCreateViewport: true,
controllers: [
...
],
name: 'Accounts',
organisation_id: location.pathname.match(/\/application\/(.*)/)[1], //Method one of setting global variable


launch: function() {


Accounts.organisation_id: location.pathname.match(/\/application\/(.*)/)[1], //Method two of setting global variable

}
}

Store


Ext.define('Accounts.store.InvoiceTree', {
extend: 'Ext.data.TreeStore',


requires: [
'Accounts.model.InvoiceTree'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoSync: true,
model: 'Accounts.model.InvoiceTree',
remoteFilter: true,
remoteSort: true,
storeId: 'InvoiceTree',
proxy: {
type: 'ajax',
extraParams: {
organisation_id: Accounts.organisation_id // or Accounts.app.organisation_id
},
url: '/invoice_tree/',
reader: {
type: 'json'
}
}
}, cfg)]);
}

putty
8 Jul 2013, 12:22 AM
I found a solution that provides a much better oo solution however is not very Sencha Architect friendly. http://stackoverflow.com/questions/9261458/where-should-i-define-global-functions-in-extjs-4-mvc/9277950#9277950