Merge branch 'pu/2013.03/modelconfig-hr'
[tine20] / tine20 / Tinebase / js / widgets / grid / GridPanel.js
index 636a1a4..a892a0e 100644 (file)
@@ -312,7 +312,11 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
         this.deleteQueue = [];
         
         // init generic stuff
-        this.initGeneric();
+        if (this.modelConfig) {
+            this.initGeneric();
+        }
+        
+        this.initFilterPanel();
         
         // init store
         this.initStore();
@@ -355,38 +359,29 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
                 this.multipleEdit = true;
                 this.multipleEditRequiredRight = (this.modelConfig.hasOwnProperty('multipleEditRequiredRight')) ? this.modelConfig.multipleEditRequiredRight : null;
             }
-            
-            // init generic filter toolbar
-            this.initGenericFilterToolbar();
-            // init generic columnModel
-            this.initGenericColumnModel();
         }
+        
+        // init generic columnModel
+        this.initGenericColumnModel();
     },
     
     /**
-     * initializes generic filter toolbar when used with ModelConfiguration
+     * initialises the filter panel 
      * 
-     * @private
+     * @param {Object} config
      */
-    initGenericFilterToolbar: function() {
-        if (this.modelConfig && ! this.editDialog) {
-            // check if quicksearch plugin shall be assigned, do not use if grid is nested in an editdialog
-            var plugins = [];
-            if (! this.editDialog && (! Ext.isDefined(this.hasQuickSearchFilterToolbarPlugin) || this.hasQuickSearchFilterToolbarPlugin)) {
-                this.quickSearchFilterToolbarPlugin = new Tine.widgets.grid.FilterToolbarQuickFilterPlugin();
-                plugins.push(this.quickSearchFilterToolbarPlugin);
-            }
-            
-            // create the filter toolbar
-            this.filterToolbar = new Tine.widgets.grid.FilterToolbar({
-                defaultFilter: this.recordClass.getMeta('defaultFilter'),
+    initFilterPanel: function(config) {
+        if (! this.filterToolbar) {
+            this.filterToolbar = new Tine.widgets.grid.FilterPanel(Ext.apply({}, {
+                app: this.app,
                 recordClass: this.recordClass,
-                plugins: plugins,
-                filterModels: []
-            });
+                allowSaving: true,
+                filterModels: this.modelConfig ? this.getCustomfieldFilters() : this.recordClass.getFilterModel(),
+                defaultFilter: this.recordClass.getMeta('defaultFilter') ? this.recordClass.getMeta('defaultFilter') : 'query',
+                filters: this.defaultFilters || []
+            }, config || {}));
             
-            // add the filter toolbar to the gridpanel plugins
-            this.plugins = this.plugins ? this.plugins : [];
+            this.plugins = this.plugins || [];
             this.plugins.push(this.filterToolbar);
         }
     },
@@ -427,6 +422,10 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
                 }
             }, this);
             
+            if (this.modelConfig.hasCustomFields) {
+                columns = columns.concat(this.getCustomfieldColumns());
+            }
+            
             this.gridConfig.cm = new Ext.grid.ColumnModel({
                 defaults: {
                     resizable: true
@@ -974,7 +973,7 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
      * perform the initial load of grid data
      */
     initialLoad: function() {
-        var defaultFavorite = Tine.widgets.persistentfilter.model.PersistentFilter.getDefaultFavorite(this.app.appName);
+        var defaultFavorite = Tine.widgets.persistentfilter.model.PersistentFilter.getDefaultFavorite(this.app.appName, this.recordClass.prototype.modelName);
         var favoritesPanel  = this.app.getMainScreen() && typeof this.app.getMainScreen().getWestPanel().getFavoritesPanel === 'function' && this.hasFavoritesPanel 
             ? this.app.getMainScreen().getWestPanel().getFavoritesPanel() 
             : null;
@@ -1005,6 +1004,24 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
      * @private
      */
     initGrid: function() {
+        if (Tine.Tinebase.registry.containsKey('preferences')) {
+            this.gridConfig = Ext.applyIf(this.gridConfig || {}, {
+                stripeRows: Tine.Tinebase.registry.get('preferences').containsKey('gridStripeRows') ? Tine.Tinebase.registry.get('preferences').get('gridStripeRows') : false,
+                loadMask: Tine.Tinebase.registry.get('preferences').containsKey('gridLoadMask') ? Tine.Tinebase.registry.get('preferences').get('gridLoadMask') : false
+            });
+            
+            // added paging number of result read from settings
+            if (Tine.Tinebase.registry.get('preferences').containsKey('pageSize')) {
+                this.defaultPaging = {
+                    start: 0,
+                    limit: parseInt(Tine.Tinebase.registry.get('preferences').get('pageSize'), 10)
+                };
+            }
+        }
+        
+        // generic empty text
+        this.i18nEmptyText = Tine.Tinebase.translation.gettext('No data to display');
+        
         // init sel model
         this.selectionModel = new Tine.widgets.grid.FilterSelectionModel({
             store: this.store,
@@ -1390,19 +1407,12 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
      */
     getFilterToolbar: function(config) {
         config = config || {};
-        var plugins = [];
-        if (! Ext.isDefined(this.hasQuickSearchFilterToolbarPlugin) || this.hasQuickSearchFilterToolbarPlugin) {
-            this.quickSearchFilterToolbarPlugin = new Tine.widgets.grid.FilterToolbarQuickFilterPlugin();
-            plugins.push(this.quickSearchFilterToolbarPlugin);
-        }
-
         return new Tine.widgets.grid.FilterPanel(Ext.apply(config, {
             app: this.app,
             recordClass: this.recordClass,
             filterModels: this.recordClass.getFilterModel().concat(this.getCustomfieldFilters()),
             defaultFilter: 'query',
-            filters: this.defaultFilters || [],
-            plugins: plugins
+            filters: this.defaultFilters || []
         }));
     },
 
@@ -1547,9 +1557,10 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
      * @param {Object} actionButton the button the action was called from
      * @param {Tine.Tinebase.data.Record} record the record to display/edit in the dialog
      * @param {Array} plugins the plugins used for the edit dialog
+     * @param {Object} additionalConfig plain Object, which will be applied to the edit dialog on initComponent
      * @return {Boolean}
      */
-    onEditInNewWindow: function(button, record, plugins) {
+    onEditInNewWindow: function(button, record, plugins, additionalConfig) {
         if (! record) {
             if (button.actionType == 'edit' || button.actionType == 'copy') {
                 if (! this.action_editInNewWindow || this.action_editInNewWindow.isDisabled()) {
@@ -1569,7 +1580,8 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
         var totalcount = this.selectionModel.getCount(),
             selectedRecords = [],
             fixedFields = (button.hasOwnProperty('fixedFields') && Ext.isObject(button.fixedFields)) ? Ext.encode(button.fixedFields) : null,
-            editDialogClass = this.editDialogClass || Tine[this.app.appName][this.recordClass.getMeta('modelName') + 'EditDialog'];
+            editDialogClass = this.editDialogClass || Tine[this.app.appName][this.recordClass.getMeta('modelName') + 'EditDialog'],
+            additionalConfig = additionalConfig ? additionalConfig : {};
         
         // add "multiple_edit_dialog" plugin to dialog, if required
         if (((totalcount > 1) && (this.multipleEdit) && (button.actionType == 'edit'))) {
@@ -1590,13 +1602,14 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
             this.editDialogConfig || {}, {
                 plugins: plugins ? Ext.encode(plugins) : null,
                 fixedFields: fixedFields,
+                additionalConfig: Ext.encode(additionalConfig),
                 record: editDialogClass.prototype.mode == 'local' ? Ext.encode(record.data) : record,
                 copyRecord: (button.actionType == 'copy'),
                 listeners: {
                     scope: this,
                     'update': ((this.selectionModel.getCount() > 1) && (this.multipleEdit)) ? this.onUpdateMultipleRecords : this.onUpdateRecord
                 }
-            }, 'record,listeners,fixedFields,copyRecord,plugins')
+            }, 'record,listeners,fixedFields,copyRecord,plugins,additionalConfig')
         );
         return true;
     },
@@ -1614,6 +1627,11 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
      * @param {String|Tine.Tinebase.data.Record} record
      */
     onUpdateRecord: function(record, mode) {
+        
+        if (! this.rendered) {
+            return;
+        }
+        
         if (Ext.isString(record) && this.recordProxy) {
             record = this.recordProxy.recordReader({responseText: record});
         } else if (record && Ext.isFunction(record.copy)) {
@@ -1710,7 +1728,7 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
             // don't show confirmation question for record deletion
             this.deleteRecords(sm, records);
         } else {
-            var recordNames = records[0].get(this.recordClass.getMeta('titleProperty'));
+            var recordNames = records[0].getTitle();
             if (records.length > 1) {
                 recordNames += ', ...';
             }