move records picker (layer) combo to common place
authorCornelius Weiß <c.weiss@metaways.de>
Fri, 30 Jun 2017 17:20:48 +0000 (19:20 +0200)
committerCornelius Weiss <c.weiss@metaways.de>
Tue, 4 Jul 2017 22:17:53 +0000 (00:17 +0200)
Change-Id: Iad8eb830df27d3a4778154c828e2805d2146c0c3
Reviewed-on: http://gerrit.tine20.com/customers/5016
Reviewed-by: Cornelius Weiss <c.weiss@metaways.de>
Tested-by: Cornelius Weiss <c.weiss@metaways.de>
tine20/Tinebase/Tinebase.jsb2
tine20/Tinebase/js/widgets/form/RecordPickerComboBox.js
tine20/Tinebase/js/widgets/form/RecordsPickerCombo.js [new file with mode: 0644]
tine20/Tinebase/js/widgets/grid/PickerGridLayerCombo.js

index b118051..2559f38 100644 (file)
           "path": "js/widgets/grid/"
         },
         {
-          "text": "PickerGridLayerCombo.js",
-          "path": "js/widgets/grid/"
-        },
-        {
           "text": "LinkGridPanel.js",
           "path": "js/widgets/grid/"
         },
           "path": "js/widgets/relation/"
         },
         {
+          "text": "RecordsPickerCombo.js",
+          "path": "js/widgets/form/"
+        },
+        {
+          "text": "PickerGridLayerCombo.js",
+          "path": "js/widgets/grid/"
+        },
+        {
           "text": "ConfigPanel.js",
           "path": "js/widgets/form/"
         },
index 621628a..8284406 100644 (file)
@@ -116,7 +116,7 @@ Tine.Tinebase.widgets.form.RecordPickerComboBox = Ext.extend(Ext.ux.form.Clearab
         this.valueField = this.recordClass.getMeta('idProperty');
         this.disableClearer = ! this.allowBlank;
 
-        this.emptyText = this.emptyText || i18n._('Search for records ...')
+        this.emptyText = this.emptyText || i18n._('Search for record ...')
 
         this.loadingText = i18n._('Searching...');
         
diff --git a/tine20/Tinebase/js/widgets/form/RecordsPickerCombo.js b/tine20/Tinebase/js/widgets/form/RecordsPickerCombo.js
new file mode 100644 (file)
index 0000000..07f9734
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Tine 2.0
+ *
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Philipp Schüle <p.schuele@metaways.de>
+ * @copyright   Copyright (c) 2016 Metaways Infosystems GmbH (http://www.metaways.de)
+ *
+ */
+Ext.ns('Tine.Tinebase.widgets.form');
+
+/**
+ * config grid panel
+ *
+ * @namespace   Tine.Tinebase.widgets.form
+ * @class       Tine.Tinebase.widgets.form.RecordsPickerCombo
+ * @extends     Tine.widgets.grid.LayerCombo
+ */
+Tine.Tinebase.widgets.form.RecordsPickerCombo = Ext.extend(Ext.ux.form.LayerCombo, {
+
+    hideButtons: false,
+    layerAlign: 'tr-br?',
+    minLayerWidth: 400,
+    layerHeight: 300,
+    allowBlur: true,
+
+    lazyInit: true,
+
+    formConfig: {
+        labelAlign: 'left',
+        labelWidth: 30
+    },
+
+    pickerGrid: null,
+    inEditor: true,
+    recordClass: null,
+
+    initComponent: function () {
+        this.emptyText = this.emptyText || i18n._('Search for records ...')
+
+        Tine.Tinebase.widgets.form.RecordsPickerCombo.superclass.initComponent.call(this);
+        this.store = new Ext.data.SimpleStore({
+            fields: this.recordClass
+        });
+
+        this.on('beforecollapse', this.onBeforeCollapse, this);
+    },
+
+    getItems: function () {
+        this.pickerGrid = new Tine.widgets.grid.PickerGridPanel({
+            recordClass: this.recordClass,
+            height: this.layerHeight - 40 || 'auto',
+            onStoreChange: Ext.emptyFn,
+            store: this.store
+        });
+
+        return [this.pickerGrid];
+    },
+
+    /**
+     * cancel collapse if ctx menu is shown
+     */
+    onBeforeCollapse: function () {
+        return this.pickerGrid
+            && (!this.pickerGrid.contextMenu || this.pickerGrid.contextMenu.hidden)
+            && !this.pickerGrid.editing;
+    },
+
+    /**
+     * @param {String} value
+     * @return {Ext.form.Field} this
+     */
+    setValue: function (value) {
+        var _ = window.lodash;
+
+        value = value || [];
+        this.setStoreFromArray(value);
+        if (this.rendered) {
+            var titles = _.reduce(this.store.data.items, function(result, record) {
+                return result.concat(record.getTitle());
+            }, []);
+            this.setRawValue(titles.join(', ') || this.emptyText);
+        }
+        this.currentValue = value;
+
+        // to string overwrite, to make sure record is changed.
+        Tine.Tinebase.common.assertComparable(this.currentValue);
+        return this;
+    },
+
+    afterRender: function () {
+
+        Tine.Tinebase.widgets.form.RecordsPickerCombo.superclass.afterRender.apply(this, arguments);
+        if (this.currentValue) {
+            this.setValue(this.currentValue);
+        }
+    },
+    /**
+     * sets values to innerForm (grid)
+     */
+    setFormValue: function (value) {
+        if (!value) {
+            value = [];
+        }
+
+        this.setStoreFromArray(value);
+    },
+
+    /**
+     * retrieves values from grid
+     *
+     * @returns {*|Array}
+     */
+    getFormValue: function () {
+        return this.getFromStoreAsArray();
+    },
+
+    /**
+     * get values from store (as array)
+     *
+     * @param {Array}
+     *
+     */
+    setStoreFromArray: function(data) {
+        data = data || [];
+        //this.pickerGrid.getStore().clearData();
+        this.store.removeAll();
+
+        for (var i = data.length-1; i >=0; --i) {
+            var recordData = data[i],
+                newRecord = new this.recordClass(recordData);
+            this.store.insert(0, newRecord);
+        }
+    },
+
+    /**
+     * get values from store (as array)
+     *
+     * @return {Array}
+     *
+     */
+    getFromStoreAsArray: function() {
+        var result = [];
+        this.store.each(function(record) {
+            result.push(record.data);
+        }, this);
+
+        return result;
+    }
+});
+
+Ext.reg('tinerecordspickercombobox', Tine.Tinebase.widgets.form.RecordsPickerCombo);
index d404607..49aa2f8 100644 (file)
@@ -13,138 +13,21 @@ Ext.ns('Tine.widgets.grid');
  *
  * @namespace   Tine.widgets.grid
  * @class       Tine.widgets.grid.PickerGridLayerCombo
- * @extends     Tine.widgets.grid.LayerCombo
+ * @extends     Tine.Tinebase.widgets.form.RecordPickerComboBox
  */
-Tine.widgets.grid.PickerGridLayerCombo = Ext.extend(Ext.ux.form.LayerCombo, {
+Tine.widgets.grid.PickerGridLayerCombo = Ext.extend(Tine.Tinebase.widgets.form.RecordPickerComboBox, {
 
-    hideButtons: false,
-    layerAlign: 'tr-br?',
-    minLayerWidth: 400,
-    layerHeight: 300,
-    allowBlur: true,
-
-    lazyInit: true,
-
-    formConfig: {
-        labelAlign: 'left',
-        labelWidth: 30
-    },
-
-    pickerGrid: null,
-    inEditor: true,
+    /**
+     * @cfg {Record} gridRecordClass
+     */
     gridRecordClass: null,
 
     initComponent: function () {
+        this.recordClass = this.gridRecordClass;
         Tine.widgets.grid.PickerGridLayerCombo.superclass.initComponent.call(this);
-        this.store = new Ext.data.SimpleStore({
-            fields: this.gridRecordClass
-        });
-
-        this.on('beforecollapse', this.onBeforeCollapse, this);
-    },
-
-    getItems: function () {
-        this.pickerGrid = new Tine.widgets.grid.PickerGridPanel({
-            recordClass: this.gridRecordClass,
-            height: this.layerHeight - 40 || 'auto',
-            onStoreChange: Ext.emptyFn,
-            store: this.store
-        });
-
-        return [this.pickerGrid];
-    },
-
-    /**
-     * cancel collapse if ctx menu is shown
-     */
-    onBeforeCollapse: function () {
-        return this.pickerGrid
-            && (!this.pickerGrid.contextMenu || this.pickerGrid.contextMenu.hidden)
-            && !this.pickerGrid.editing;
-    },
-
-    /**
-     * @param {String} value
-     * @return {Ext.form.Field} this
-     */
-    setValue: function (value) {
-        var _ = window.lodash;
-
-        if (!value) {
-            value = [];
-        }
-        this.setStoreFromArray(value);
-        if (this.rendered) {
-            var titles = _.reduce(this.store.data.items, function(result, record) {
-                return result.concat(record.getTitle());
-            }, []);
-            this.setRawValue(titles.join(', '));
-        }
-        this.currentValue = value;
-
-        // to string overwrite, to make sure record is changed.
-        Tine.Tinebase.common.assertComparable(this.currentValue);
-        return this;
-    },
 
-    afterRender: function () {
-
-        Tine.widgets.grid.PickerGridLayerCombo.superclass.afterRender.apply(this, arguments);
-        if (this.currentValue) {
-            this.setValue(this.currentValue);
-        }
-    },
-    /**
-     * sets values to innerForm (grid)
-     */
-    setFormValue: function (value) {
-        if (!value) {
-            value = [];
-        }
-
-        this.setStoreFromArray(value);
-    },
-
-    /**
-     * retrieves values from grid
-     *
-     * @returns {*|Array}
-     */
-    getFormValue: function () {
-        return this.getFromStoreAsArray();
-    },
-
-    /**
-     * get values from store (as array)
-     *
-     * @param {Array}
-     *
-     */
-    setStoreFromArray: function(data) {
-        //this.pickerGrid.getStore().clearData();
-        this.store.removeAll();
-
-        for (var i = data.length-1; i >=0; --i) {
-            var recordData = data[i],
-                newRecord = new this.gridRecordClass(recordData);
-            this.store.insert(0, newRecord);
-        }
-    },
-
-    /**
-     * get values from store (as array)
-     *
-     * @return {Array}
-     *
-     */
-    getFromStoreAsArray: function() {
-        var result = [];
-        this.store.each(function(record) {
-            result.push(record.data);
-        }, this);
-
-        return result;
     }
+
 });
 
 Ext.reg('tinepickergridlayercombo', Tine.widgets.grid.PickerGridLayerCombo);