4 * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
5 * @author Philipp Schüle <p.schuele@metaways.de>
6 * @copyright Copyright (c) 2016 Metaways Infosystems GmbH (http://www.metaways.de)
9 Ext.ns('Tine.Tinebase.widgets.form');
14 * @namespace Tine.Tinebase.widgets.form
15 * @class Tine.Tinebase.widgets.form.RecordsPickerCombo
16 * @extends Tine.widgets.grid.LayerCombo
18 Tine.Tinebase.widgets.form.RecordsPickerCombo = Ext.extend(Ext.ux.form.LayerCombo, {
37 initComponent: function () {
38 this.emptyText = this.emptyText || i18n._('Search for records ...');
39 this.currentValue = this.currentValue || [];
41 Tine.Tinebase.widgets.form.RecordsPickerCombo.superclass.initComponent.call(this);
42 this.store = new Ext.data.SimpleStore({
43 fields: this.recordClass
46 this.on('beforecollapse', this.onBeforeCollapse, this);
49 getItems: function () {
50 this.pickerGrid = new Tine.widgets.grid.PickerGridPanel({
51 recordClass: this.recordClass,
52 height: this.layerHeight - 40 || 'auto',
53 onStoreChange: Ext.emptyFn,
57 return [this.pickerGrid];
61 * cancel collapse if ctx menu is shown
63 onBeforeCollapse: function () {
64 return this.pickerGrid
65 && (!this.pickerGrid.contextMenu || this.pickerGrid.contextMenu.hidden)
66 && !this.pickerGrid.editing;
70 * @param {String} value
71 * @return {Ext.form.Field} this
73 setValue: function (value) {
74 var _ = window.lodash;
77 this.setStoreFromArray(value);
79 var text = _.reduce(this.store.data.items, function(result, record) {
80 return result.concat(record.getTitle());
82 this.setRawValue(text || this.emptyText);
83 this.el[(text ? 'remove' : 'add') + 'Class'](this.emptyClass);
86 var oldValue = this.currentValue;
87 this.currentValue = value;
88 Tine.Tinebase.common.assertComparable(this.currentValue);
90 if (JSON.stringify(value) != JSON.stringify(oldValue)){
91 this.fireEvent('change', this, value, oldValue);
98 this.currentValue = this.originalValue;
100 Tine.Tinebase.widgets.form.RecordsPickerCombo.superclass.reset.apply(this, arguments);
103 afterRender: function () {
105 Tine.Tinebase.widgets.form.RecordsPickerCombo.superclass.afterRender.apply(this, arguments);
106 if (this.currentValue) {
107 this.setValue(this.currentValue);
111 * sets values to innerForm (grid)
113 setFormValue: function (value) {
118 this.setStoreFromArray(value);
122 * retrieves values from grid
126 getFormValue: function () {
127 return this.getFromStoreAsArray();
131 * get values from store (as array)
136 setStoreFromArray: function(data) {
138 //this.pickerGrid.getStore().clearData();
139 this.store.removeAll();
141 for (var i = data.length-1; i >=0; --i) {
142 var recordData = data[i],
143 newRecord = new this.recordClass(recordData);
144 this.store.insert(0, newRecord);
149 * get values from store (as array)
154 getFromStoreAsArray: function() {
156 this.store.each(function(record) {
157 result.push(record.data);
164 Ext.reg('tinerecordspickercombobox', Tine.Tinebase.widgets.form.RecordsPickerCombo);