Skip to content
Snippets Groups Projects
Commit 92a3c59b authored by Renaud Le Gac's avatar Renaud Le Gac
Browse files

Add a "global variable" App.storeCfgs.

It is fill by the controller get_api.
parent f5124393
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,8 @@ App.REMOTE_API = {
'url': '/%s/plugin_dbui/call',
'type': 'remoting',
'actions': %s
};
};
App.storeCfgs = %s;
App.withMathJax = %s; """
......@@ -128,6 +129,11 @@ def get_api():
di[action] = []
di[action].append({'name': method, 'len': nargs})
# the stores configuration
storeCfgs = {}
for table in cfgSvc.get_tables()['tables']:
storeCfgs[table] = cfgSvc.get_jsonstore(table)
# determine if the MathJax plugin is there
server_path, client_path = dbui.get_reference_paths(globals())
......@@ -136,7 +142,11 @@ def get_api():
# fill the javascript template
app = request.application
script = SCRIPT % (app, app, json.dumps(di), str(withMathJax).lower())
script = SCRIPT % (app,
app,
json.dumps(di),
json.dumps(storeCfgs),
str(withMathJax).lower())
# return the response as a javascript
response.headers['Content-Type'] = 'text/javascript'
......
......@@ -14,6 +14,11 @@ Ext.namespace('App');
* This constants is defined by the server.
*/
/**
* @cfg {Array} App.storeCfgs
* Configuration option for all json stores
*/
/**
* @cfg {String} App.dburl
* Define the URL of the database router/controller
......@@ -40,6 +45,42 @@ App.encodeField = function (table, field) {
return t + f;
}
/**
* Helper function returning the App.data.DirectStore identifies by its id.
* If the store does not exit it is created and register in the store manager.
*
* NOTE: The storeId is defined by the server as a configuration option
* for each widget: combobox, form and grid.
* The syntax of the storeId is "tableStore".
* If the store does not exist, its configuration is extract from
* the application constant App.storeCfgs.Then it is created and registered.
* In the current frame work a unique store is associated to a database table.
* This property garanty that widget share the same store.
*
* @param {String} storeId
*/
App.getDirectStore = function (storeId) {
var cfg,
store,
table;
store = Ext.StoreMgr.lookup(storeId);
if (!store && !Ext.isString(storeId)) {
throw new Error('Fail to instanciate the store: "'+storeId+'"');
}
if (!store && Ext.isString(storeId)) {
table = storeId.slice(0, storeId.search('Store'));
cfg = App.storeCfgs[table];
store = new App.data.DirectStore(cfg);
}
return store;
}
/**
* Helper function returning the name of the database table
* associated to the store. works with store configured using the
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment