4 * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
5 * @author Cornelius Weiss <c.weiss@metaways.de>
6 * @copyright Copyright (c) 2007-2012 Metaways Infosystems GmbH (http://www.metaways.de)
9 Ext.ns('Tine.widgets', 'Tine.widgets.customfields');
11 Tine.widgets.customfields.ConfigManager = function() {
14 var getStore = function(app) {
15 app = Tine.Tinebase.appMgr.get(app);
16 if (! stores[app.appName]) {
17 var allCfs = (Ext.isFunction(app.getRegistry)) ? app.getRegistry().get('customfields') : null;
18 stores[app.appName] = new Ext.data.JsonStore({
19 fields: Tine.Tinebase.Model.Customfield,
20 data: allCfs ? allCfs : []
23 // place keyFieldConfig in registry so we can use the standard widgets
24 stores[app.appName].each(function(cfConfig) {
25 var definition = cfConfig.get('definition'),
26 options = definition.options ? definition.options : {},
27 keyFieldConfig = definition.keyFieldConfig ? definition.keyFieldConfig : null;
30 app.getRegistry().get('config')[cfConfig.get('name')] = keyFieldConfig;
35 return stores[app.appName];
39 * convert config record to record field
41 * @param {Record} cfConfig
42 * @return {Ext.data.Field} field definition
44 var config2Field = function(cfConfig) {
45 var def = cfConfig.get('definition');
47 return new Ext.data.Field(Ext.apply({
48 name: '#' + cfConfig.get('name')
54 * returns a single field config
56 * @param {String/Application} app
57 * @param {String} model
58 * @param {String} name
59 * @param {Boolean} asField
62 getConfig: function (app, model, name, asField) {
63 var cfStore = getStore(app),
66 cfStore.clearFilter(true);
67 cfStore.filter('model', model);
68 cfConfig = cfStore.findExact('name', name);
69 cfConfig = cfConfig > -1 ? cfStore.getAt(cfConfig): null;
70 cfStore.clearFilter(true);
72 return asField ? config2Field(cfConfig) : cfConfig;
77 * returns a single field config
79 * @param {String/Application} app
80 * @param {String} model
81 * @param {Boolean} asFields
84 getConfigs: function(app, model, asFields) {
85 if (Ext.isFunction(model.getMeta)) {
86 model = model.getMeta('appName') + '_Model_' + model.getMeta('modelName');
89 var cfStore = getStore(app),
92 cfStore.clearFilter(true);
93 cfStore.filter('model', model);
94 cfStore.each(function(r) {cfConfigs.push(r);});
95 cfStore.clearFilter(true);
98 Ext.each(cfConfigs, function(cfConfig, idx) {
99 cfConfigs[idx] = config2Field(cfConfig);