]>
git.proxmox.com Git - extjs.git/blob - extjs/classic/classic/src/view/MultiSelector.js
2 * This component provides a grid holding selected items from a second store of potential
3 * members. The `store` of this component represents the selected items. The "search store"
4 * represents the potentially selected items.
6 * While this component is a grid and so you can configure `columns`, it is best to leave
7 * that to this class in its `initComponent` method. That allows this class to create the
8 * extra column that allows the user to remove rows. Instead use `{@link #fieldName}` and
9 * `{@link #fieldTitle}` to configure the primary column's `dataIndex` and column `text`,
14 Ext
.define('Ext.view.MultiSelector', {
15 extend
: 'Ext.grid.Panel',
17 xtype
: 'multiselector',
21 * @cfg {Object} search
22 * This object configures the search popup component. By default this contains the
23 * `xtype` for a `Ext.view.MultiSelectorSearch` component and specifies `autoLoad`
27 xtype
: 'multiselector-search',
37 * @cfg {String} [fieldName="name"]
38 * The name of the data field to display in the primary column of the grid.
44 * @cfg {String} [fieldTitle]
45 * The text to display in the column header for the primary column of the grid.
51 * @cfg {String} removeRowText
52 * The text to display in the "remove this row" column. By default this is a Unicode
56 removeRowText
: '\u2716',
59 * @cfg {String} removeRowTip
60 * The tooltip to display when the user hovers over the remove cell.
63 removeRowTip
: 'Remove this item',
65 emptyText
: 'Nothing selected',
68 * @cfg {String} addToolText
69 * The tooltip to display when the user hovers over the "+" tool in the panel header.
72 addToolText
: 'Search for items to add',
74 initComponent: function () {
76 emptyText
= me
.emptyText
,
77 store
= me
.getStore(),
78 search
= me
.getSearch(),
79 fieldTitle
= me
.fieldTitle
,
84 Ext
.raise('The search configuration is required for the multi selector');
88 searchStore
= search
.store
;
89 if (searchStore
.isStore
) {
90 model
= searchStore
.getModel();
92 model
= searchStore
.model
;
101 if (emptyText
&& !me
.viewConfig
) {
103 deferEmptyText
: false,
109 me
.hideHeaders
= !fieldTitle
;
111 { text
: fieldTitle
, dataIndex
: me
.fieldName
, flex
: 1 },
112 me
.makeRemoveRowColumn()
119 addTools: function () {
122 tooltip
: this.addToolText
,
123 callback
: 'onShowSearch',
128 convertSearchRecord
: Ext
.identityFn
,
130 convertSelectionRecord
: Ext
.identityFn
,
132 makeRemoveRowColumn: function () {
138 tdCls
: Ext
.baseCSSPrefix
+ 'multiselector-remove',
139 processEvent
: me
.processRowEvent
.bind(me
),
140 renderer
: me
.renderRemoveRow
,
141 updater
: Ext
.emptyFn
,
146 processRowEvent: function (type
, view
, cell
, recordIndex
, cellIndex
, e
, record
, row
) {
147 if (e
.type
!== 'click') {
151 if (Ext
.fly(cell
).hasCls(Ext
.baseCSSPrefix
+ 'multiselector-remove')) {
152 this.store
.remove(record
);
153 if (this.searchPopup
) {
154 this.searchPopup
.deselectRecords(record
);
159 renderRemoveRow: function () {
160 return '<span data-qtip="'+ this.removeRowTip
+ '" role="button">' +
161 this.removeRowText
+ '</span>';
164 beforeDestroy: function() {
166 mousedown
: 'onDismissSearch',
173 onDismissSearch: function (e
) {
174 var searchPopup
= this.searchPopup
;
176 if (searchPopup
&& !(searchPopup
.owns(e
.getTarget()) || this.owns(e
.getTarget()))) {
178 mousedown
: 'onDismissSearch',
185 onShowSearch: function (panel
, tool
) {
187 searchPopup
= me
.searchPopup
,
188 store
= me
.getStore();
191 searchPopup
= Ext
.merge({
196 me
.searchPopup
= searchPopup
= me
.add(searchPopup
);
198 // If we were configured with records prior to the UI requesting the popup,
199 // ensure that the records are selected in the popup.
200 if (store
.getCount()) {
201 searchPopup
.selectRecords(store
.getRange());
205 searchPopup
.showBy(me
, 'tl-tr?');
207 mousedown
: 'onDismissSearch',