3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
16 * Note that this control will most likely remain as an example, and not as a core Ext form
17 * control. However, the API will be changing in a future release and so should not yet be
18 * treated as a final, stable API at this time.
21 <div id="cls-Ext.ux.form.ItemSelector"></div>/**
22 * @class Ext.ux.form.ItemSelector
23 * @extends Ext.form.Field
24 * A control that allows selection of between two Ext.ux.form.MultiSelect controls.
27 * 2008-06-19 bpm Original code contributed by Toby Stuart (with contributions from Robert Williams)
30 * Create a new ItemSelector
31 * @param {Object} config Configuration options
34 Ext.ux.form.ItemSelector = Ext.extend(Ext.form.Field, {
40 iconRight:"right2.gif",
42 iconBottom:"bottom2.gif",
52 defaultAutoCreate:{tag: "div"},
53 <div id="cfg-Ext.ux.form.ItemSelector-multiselects"></div>/**
54 * @cfg {Array} multiselects An array of {@link Ext.ux.form.MultiSelect} config objects, with at least all required parameters (e.g., store)
58 initComponent: function(){
59 Ext.ux.form.ItemSelector.superclass.initComponent.call(this);
66 onRender: function(ct, position){
67 Ext.ux.form.ItemSelector.superclass.onRender.call(this, ct, position);
69 // Internal default configuration for both multiselects
84 this.fromMultiselect = new Ext.ux.form.MultiSelect(Ext.applyIf(this.multiselects[0], msConfig[0]));
85 this.fromMultiselect.on('dblclick', this.onRowDblClick, this);
87 this.toMultiselect = new Ext.ux.form.MultiSelect(Ext.applyIf(this.multiselects[1], msConfig[1]));
88 this.toMultiselect.on('dblclick', this.onRowDblClick, this);
90 var p = new Ext.Panel({
91 bodyStyle:this.bodyStyle,
94 layoutConfig:{columns:3}
97 p.add(this.fromMultiselect);
98 var icons = new Ext.Panel({header:false});
100 p.add(this.toMultiselect);
102 icons.el.down('.'+icons.bwrapCls).remove();
105 if (this.imagePath!="" && this.imagePath.charAt(this.imagePath.length-1)!="/")
107 this.iconUp = this.imagePath + (this.iconUp || 'up2.gif');
108 this.iconDown = this.imagePath + (this.iconDown || 'down2.gif');
109 this.iconLeft = this.imagePath + (this.iconLeft || 'left2.gif');
110 this.iconRight = this.imagePath + (this.iconRight || 'right2.gif');
111 this.iconTop = this.imagePath + (this.iconTop || 'top2.gif');
112 this.iconBottom = this.imagePath + (this.iconBottom || 'bottom2.gif');
113 var el=icons.getEl();
114 this.toTopIcon = el.createChild({tag:'img', src:this.iconTop, style:{cursor:'pointer', margin:'2px'}});
115 el.createChild({tag: 'br'});
116 this.upIcon = el.createChild({tag:'img', src:this.iconUp, style:{cursor:'pointer', margin:'2px'}});
117 el.createChild({tag: 'br'});
118 this.addIcon = el.createChild({tag:'img', src:this.iconRight, style:{cursor:'pointer', margin:'2px'}});
119 el.createChild({tag: 'br'});
120 this.removeIcon = el.createChild({tag:'img', src:this.iconLeft, style:{cursor:'pointer', margin:'2px'}});
121 el.createChild({tag: 'br'});
122 this.downIcon = el.createChild({tag:'img', src:this.iconDown, style:{cursor:'pointer', margin:'2px'}});
123 el.createChild({tag: 'br'});
124 this.toBottomIcon = el.createChild({tag:'img', src:this.iconBottom, style:{cursor:'pointer', margin:'2px'}});
125 this.toTopIcon.on('click', this.toTop, this);
126 this.upIcon.on('click', this.up, this);
127 this.downIcon.on('click', this.down, this);
128 this.toBottomIcon.on('click', this.toBottom, this);
129 this.addIcon.on('click', this.fromTo, this);
130 this.removeIcon.on('click', this.toFrom, this);
131 if (!this.drawUpIcon || this.hideNavIcons) { this.upIcon.dom.style.display='none'; }
132 if (!this.drawDownIcon || this.hideNavIcons) { this.downIcon.dom.style.display='none'; }
133 if (!this.drawLeftIcon || this.hideNavIcons) { this.addIcon.dom.style.display='none'; }
134 if (!this.drawRightIcon || this.hideNavIcons) { this.removeIcon.dom.style.display='none'; }
135 if (!this.drawTopIcon || this.hideNavIcons) { this.toTopIcon.dom.style.display='none'; }
136 if (!this.drawBotIcon || this.hideNavIcons) { this.toBottomIcon.dom.style.display='none'; }
138 var tb = p.body.first();
139 this.el.setWidth(p.body.first().getWidth());
140 p.body.removeClass();
142 this.hiddenName = this.name;
143 var hiddenTag = {tag: "input", type: "hidden", value: "", name: this.name};
144 this.hiddenField = this.el.createChild(hiddenTag);
147 doLayout: function(){
149 this.fromMultiselect.fs.doLayout();
150 this.toMultiselect.fs.doLayout();
154 afterRender: function(){
155 Ext.ux.form.ItemSelector.superclass.afterRender.call(this);
157 this.toStore = this.toMultiselect.store;
158 this.toStore.on('add', this.valueChanged, this);
159 this.toStore.on('remove', this.valueChanged, this);
160 this.toStore.on('load', this.valueChanged, this);
161 this.valueChanged(this.toStore);
165 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
167 if (selectionsArray.length > 0) {
168 selectionsArray.sort();
169 for (var i=0; i<selectionsArray.length; i++) {
170 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
171 records.push(record);
173 selectionsArray = [];
174 for (var i=records.length-1; i>-1; i--) {
176 this.toMultiselect.view.store.remove(record);
177 this.toMultiselect.view.store.insert(0, record);
178 selectionsArray.push(((records.length - 1) - i));
181 this.toMultiselect.view.refresh();
182 this.toMultiselect.view.select(selectionsArray);
185 toBottom : function() {
186 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
188 if (selectionsArray.length > 0) {
189 selectionsArray.sort();
190 for (var i=0; i<selectionsArray.length; i++) {
191 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
192 records.push(record);
194 selectionsArray = [];
195 for (var i=0; i<records.length; i++) {
197 this.toMultiselect.view.store.remove(record);
198 this.toMultiselect.view.store.add(record);
199 selectionsArray.push((this.toMultiselect.view.store.getCount()) - (records.length - i));
202 this.toMultiselect.view.refresh();
203 this.toMultiselect.view.select(selectionsArray);
208 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
209 selectionsArray.sort();
210 var newSelectionsArray = [];
211 if (selectionsArray.length > 0) {
212 for (var i=0; i<selectionsArray.length; i++) {
213 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
214 if ((selectionsArray[i] - 1) >= 0) {
215 this.toMultiselect.view.store.remove(record);
216 this.toMultiselect.view.store.insert(selectionsArray[i] - 1, record);
217 newSelectionsArray.push(selectionsArray[i] - 1);
220 this.toMultiselect.view.refresh();
221 this.toMultiselect.view.select(newSelectionsArray);
227 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
228 selectionsArray.sort();
229 selectionsArray.reverse();
230 var newSelectionsArray = [];
231 if (selectionsArray.length > 0) {
232 for (var i=0; i<selectionsArray.length; i++) {
233 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
234 if ((selectionsArray[i] + 1) < this.toMultiselect.view.store.getCount()) {
235 this.toMultiselect.view.store.remove(record);
236 this.toMultiselect.view.store.insert(selectionsArray[i] + 1, record);
237 newSelectionsArray.push(selectionsArray[i] + 1);
240 this.toMultiselect.view.refresh();
241 this.toMultiselect.view.select(newSelectionsArray);
245 fromTo : function() {
246 var selectionsArray = this.fromMultiselect.view.getSelectedIndexes();
248 if (selectionsArray.length > 0) {
249 for (var i=0; i<selectionsArray.length; i++) {
250 record = this.fromMultiselect.view.store.getAt(selectionsArray[i]);
251 records.push(record);
253 if(!this.allowDup)selectionsArray = [];
254 for (var i=0; i<records.length; i++) {
257 var x=new Ext.data.Record();
260 this.toMultiselect.view.store.add(record);
262 this.fromMultiselect.view.store.remove(record);
263 this.toMultiselect.view.store.add(record);
264 selectionsArray.push((this.toMultiselect.view.store.getCount() - 1));
268 this.toMultiselect.view.refresh();
269 this.fromMultiselect.view.refresh();
270 var si = this.toMultiselect.store.sortInfo;
272 this.toMultiselect.store.sort(si.field, si.direction);
274 this.toMultiselect.view.select(selectionsArray);
277 toFrom : function() {
278 var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
280 if (selectionsArray.length > 0) {
281 for (var i=0; i<selectionsArray.length; i++) {
282 record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
283 records.push(record);
285 selectionsArray = [];
286 for (var i=0; i<records.length; i++) {
288 this.toMultiselect.view.store.remove(record);
290 this.fromMultiselect.view.store.add(record);
291 selectionsArray.push((this.fromMultiselect.view.store.getCount() - 1));
295 this.fromMultiselect.view.refresh();
296 this.toMultiselect.view.refresh();
297 var si = this.fromMultiselect.store.sortInfo;
299 this.fromMultiselect.store.sort(si.field, si.direction);
301 this.fromMultiselect.view.select(selectionsArray);
304 valueChanged: function(store) {
307 for (var i=0; i<store.getCount(); i++) {
308 record = store.getAt(i);
309 values.push(record.get(this.toMultiselect.valueField));
311 this.hiddenField.dom.value = values.join(this.delimiter);
312 this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
315 getValue : function() {
316 return this.hiddenField.dom.value;
319 onRowDblClick : function(vw, index, node, e) {
320 if (vw == this.toMultiselect.view){
322 } else if (vw == this.fromMultiselect.view) {
325 return this.fireEvent('rowdblclick', vw, index, node, e);
329 range = this.toMultiselect.store.getRange();
330 this.toMultiselect.store.removeAll();
331 this.fromMultiselect.store.add(range);
332 var si = this.fromMultiselect.store.sortInfo;
334 this.fromMultiselect.store.sort(si.field, si.direction);
336 this.valueChanged(this.toMultiselect.store);
340 Ext.reg('itemselector', Ext.ux.form.ItemSelector);
343 Ext.ux.ItemSelector = Ext.ux.form.ItemSelector;