Merge branch 'pu/2013.03/modelconfig-hr'
[tine20] / tine20 / Tinebase / js / widgets / form / RecordPickerComboBox.js
index 6174a9c..da6de7f 100644 (file)
@@ -81,10 +81,17 @@ Tine.Tinebase.widgets.form.RecordPickerComboBox = Ext.extend(Ext.ux.form.Clearab
     /**
      * the editDialog, the form is nested in. Just needed if this.allowLinkingItself is set to false
      * 
-     * @cfg Tine.widgets.dialog.EditDialog editDialog
+     * @type Tine.widgets.dialog.EditDialog editDialog
      */
     editDialog: null,
     
+    /**
+     * always use additional filter
+     * 
+     * @type {Array}
+     */
+    additionalFilters: null,
+    
     triggerAction: 'all',
     pageSize: 10,
     minChars: 3,
@@ -148,7 +155,8 @@ Tine.Tinebase.widgets.form.RecordPickerComboBox = Ext.extend(Ext.ux.form.Clearab
             // TODO do we need to set start & limit here?
             start: options.params.start,
             limit: options.params.limit,
-            sort: (this.sortBy) ? this.sortBy : this.valueField,
+            // if sort is not set, use display field as default sort
+            sort: (this.sortBy) ? this.sortBy : this.displayField,
             dir: 'ASC'
         };
         
@@ -179,17 +187,14 @@ Tine.Tinebase.widgets.form.RecordPickerComboBox = Ext.extend(Ext.ux.form.Clearab
      * @param {Object} qevent
      */
     onBeforeQuery: function (qevent) {
-        
         var filter = [
             {field: 'query', operator: 'contains', value: qevent.query }
         ];
-        
         if (this.additionalFilters !== null && this.additionalFilters.length > 0) {
             for (var i = 0; i < this.additionalFilters.length; i++) {
                 filter.push(this.additionalFilters[i]);
             }
         }
-        
         this.store.baseParams.filter = filter;
     },
     
@@ -256,8 +261,8 @@ Tine.Tinebase.widgets.form.RecordPickerComboBox = Ext.extend(Ext.ux.form.Clearab
             
             // value is a js object
             else if (Ext.isObject(value)) {
-                if (! this.store.getById(value)) {
-                    var record = this.recordProxy ? this.recordProxy.recordReader({responseText: Ext.encode(value)}) : new this.recordClass(value)
+                var record = this.recordProxy ? this.recordProxy.recordReader({responseText: Ext.encode(value)}) : new this.recordClass(value)
+                if (! this.store.getById(value.id)) {
                     this.store.addSorted(record);
                 }
                 value = value[this.valueField] || '';
@@ -276,7 +281,8 @@ Tine.Tinebase.widgets.form.RecordPickerComboBox = Ext.extend(Ext.ux.form.Clearab
             text = r.getTitle();
             this.selectedRecord = r;
             if (this.allowLinkingItself === false) {
-                if (r.getId() == this.editDialog.record.getId()) {
+                // check if editDialog exists
+                if (this.editDialog && this.editDialog.record && r.getId() == this.editDialog.record.getId()) {
                     Ext.MessageBox.show({
                         title: _('Failure'),
                         msg: _('You tried to link a record with itself. This is not allowed!'),