]>
git.proxmox.com Git - sencha-touch.git/blob - src/src/picker/Picker.js
2 * A general picker class. {@link Ext.picker.Slot}s are used to organize multiple scrollable slots into a single picker. {@link #slots} is
3 * the only necessary configuration.
5 * The {@link #slots} configuration with a few key values:
7 * - `name`: The name of the slot (will be the key when using {@link #getValues} in this {@link Ext.picker.Picker}).
8 * - `title`: The title of this slot (if {@link #useTitles} is set to `true`).
9 * - `data`/`store`: The data or store to use for this slot.
11 * Remember, {@link Ext.picker.Slot} class extends from {@link Ext.dataview.DataView}.
15 * @example miniphone preview
16 * var picker = Ext.create('Ext.Picker', {
19 * name : 'limit_speed',
22 * {text: '50 KB/s', value: 50},
23 * {text: '100 KB/s', value: 100},
24 * {text: '200 KB/s', value: 200},
25 * {text: '300 KB/s', value: 300}
30 * Ext.Viewport.add(picker);
33 * You can also customize the top toolbar on the {@link Ext.picker.Picker} by changing the {@link #doneButton} and {@link #cancelButton} configurations:
35 * @example miniphone preview
36 * var picker = Ext.create('Ext.Picker', {
37 * doneButton: 'I\'m done!',
38 * cancelButton: false,
41 * name : 'limit_speed',
44 * {text: '50 KB/s', value: 50},
45 * {text: '100 KB/s', value: 100},
46 * {text: '200 KB/s', value: 200},
47 * {text: '300 KB/s', value: 300}
52 * Ext.Viewport.add(picker);
55 * Or by passing a custom {@link #toolbar} configuration:
57 * @example miniphone preview
58 * var picker = Ext.create('Ext.Picker', {
60 * cancelButton: false,
67 * name : 'limit_speed',
70 * {text: '50 KB/s', value: 50},
71 * {text: '100 KB/s', value: 100},
72 * {text: '200 KB/s', value: 200},
73 * {text: '300 KB/s', value: 300}
78 * Ext.Viewport.add(picker);
81 Ext
. define ( 'Ext.picker.Picker' , {
83 alias
: 'widget.picker' ,
84 alternateClassName
: 'Ext.Picker' ,
85 requires
: [ 'Ext.picker.Slot' , 'Ext.TitleBar' , 'Ext.data.Model' , 'Ext.util.InputBlocker' ],
91 * Fired when a slot has been picked
92 * @param {Ext.Picker} this This Picker.
93 * @param {Object} The values of this picker's slots, in `{name:'value'}` format.
94 * @param {Ext.Picker.Slot} slot An instance of Ext.Picker.Slot that has been picked.
99 * Fired when the value of this picker has changed the Done button has been pressed.
100 * @param {Ext.picker.Picker} this This Picker.
101 * @param {Object} value The values of this picker's slots, in `{name:'value'}` format.
106 * Fired when the cancel button is tapped and the values are reverted back to
108 * @param {Ext.Picker} this This Picker.
116 baseCls
: Ext
. baseCSSPrefix
+ 'picker' ,
119 * @cfg {String/Mixed} doneButton
122 * - A {String} text to be used on the Done button.
123 * - An {Object} as config for {@link Ext.Button}.
124 * - `false` or `null` to hide it.
130 * @cfg {String/Mixed} cancelButton
133 * - A {String} text to be used on the Cancel button.
134 * - An {Object} as config for {@link Ext.Button}.
135 * - `false` or `null` to hide it.
141 * @cfg {Boolean} useTitles
142 * Generate a title header for each individual slot and use
143 * the title configuration of the slot.
150 * An array of slot configurations.
152 * - `name` {String} - Name of the slot
153 * - `data` {Array} - An array of text/value pairs in the format `{text: 'myKey', value: 'myValue'}`
154 * - `title` {String} - Title of the slot. This is used in conjunction with `useTitles: true`.
161 * @cfg {String/Number} value The value to initialize the picker with.
167 * @cfg {Number} height
168 * The height of the picker.
207 defaultType
: 'pickerslot' ,
209 toolbarPosition
: 'top' ,
212 * @cfg {Ext.TitleBar/Ext.Toolbar/Object} toolbar
213 * The toolbar which contains the {@link #doneButton} and {@link #cancelButton} buttons.
214 * You can override this if you wish, and add your own configurations. Just ensure that you take into account
215 * the {@link #doneButton} and {@link #cancelButton} configurations.
217 * The default xtype is a {@link Ext.TitleBar}:
234 * Or to use a {@link Ext.Toolbar instead}:
260 toolbarPosition
: 'bottom' ,
279 theme
: [ 'CupertinoClassic' ],
284 theme
: [ 'MountainView' ],
285 toolbarPosition
: 'bottom' ,
293 initialize : function () {
295 clsPrefix
= Ext
. baseCSSPrefix
,
296 innerElement
= this . innerElement
;
298 //insert the mask, and the picker bar
299 this . mask
= innerElement
. createChild ({
300 cls
: clsPrefix
+ 'picker-mask'
303 this . bar
= this . mask
. createChild ({
304 cls
: clsPrefix
+ 'picker-bar'
309 delegate
: 'pickerslot' ,
310 slotpick
: 'onSlotPick'
317 applyToolbar : function ( config
) {
318 if ( config
=== true ) {
322 Ext
. applyIf ( config
, {
323 docked
: this . getToolbarPosition ()
326 return Ext
. factory ( config
, 'Ext.TitleBar' , this . getToolbar ());
332 updateToolbar : function ( newToolbar
, oldToolbar
) {
334 this . add ( newToolbar
);
338 this . remove ( oldToolbar
);
343 * Updates the {@link #doneButton} configuration. Will change it into a button when appropriate, or just update the text if needed.
344 * @param {Object} config
347 applyDoneButton : function ( config
) {
349 if ( Ext
. isBoolean ( config
)) {
353 if ( typeof config
== "string" ) {
359 Ext
. applyIf ( config
, {
366 return Ext
. factory ( config
, 'Ext.Button' , this . getDoneButton ());
369 updateDoneButton : function ( newDoneButton
, oldDoneButton
) {
370 var toolbar
= this . getToolbar ();
373 toolbar
. add ( newDoneButton
);
374 newDoneButton
. on ( 'tap' , this . onDoneButtonTap
, this );
375 } else if ( oldDoneButton
) {
376 toolbar
. remove ( oldDoneButton
);
381 * Updates the {@link #cancelButton} configuration. Will change it into a button when appropriate, or just update the text if needed.
382 * @param {Object} config
385 applyCancelButton : function ( config
) {
387 if ( Ext
. isBoolean ( config
)) {
391 if ( typeof config
== "string" ) {
397 Ext
. applyIf ( config
, {
403 return Ext
. factory ( config
, 'Ext.Button' , this . getCancelButton ());
406 updateCancelButton : function ( newCancelButton
, oldCancelButton
) {
407 var toolbar
= this . getToolbar ();
409 if ( newCancelButton
) {
410 toolbar
. add ( newCancelButton
);
411 newCancelButton
. on ( 'tap' , this . onCancelButtonTap
, this );
412 } else if ( oldCancelButton
) {
413 toolbar
. remove ( oldCancelButton
);
420 updateUseTitles : function ( useTitles
) {
421 var innerItems
= this . getInnerItems (),
422 ln
= innerItems
. length
,
423 cls
= Ext
. baseCSSPrefix
+ 'use-titles' ,
426 //add a cls onto the picker
433 //show the time on each of the slots
434 for ( i
= 0 ; i
< ln
; i
++) {
435 innerItem
= innerItems
[ i
];
437 if ( innerItem
. isSlot
) {
438 innerItem
. setShowTitle ( useTitles
);
443 applySlots : function ( slots
) {
444 //loop through each of the slots and add a reference to this picker
446 var ln
= slots
. length
,
449 for ( i
= 0 ; i
< ln
; i
++) {
450 slots
[ i
]. picker
= this ;
458 * Adds any new {@link #slots} to this picker, and removes existing {@link #slots}
461 updateSlots : function ( newSlots
) {
462 var bcss
= Ext
. baseCSSPrefix
,
471 innerItems
= this . getInnerItems ();
472 if ( innerItems
. length
> 0 ) {
473 innerItems
[ 0 ]. addCls ( bcss
+ 'first' );
474 innerItems
[ innerItems
. length
- 1 ]. addCls ( bcss
+ 'last' );
477 this . updateUseTitles ( this . getUseTitles ());
482 * Called when the done button has been tapped.
484 onDoneButtonTap : function () {
485 var oldValue
= this . _value
,
486 newValue
= this . getValue ( true );
488 if ( newValue
!= oldValue
) {
489 this . fireEvent ( 'change' , this , newValue
);
493 Ext
. util
. InputBlocker
. unblockInputs ();
498 * Called when the cancel button has been tapped.
500 onCancelButtonTap : function () {
501 this . fireEvent ( 'cancel' , this );
503 Ext
. util
. InputBlocker
. unblockInputs ();
508 * Called when a slot has been picked.
510 onSlotPick : function ( slot
) {
511 this . fireEvent ( 'pick' , this , this . getValue ( true ), slot
);
515 if ( this . getParent () === undefined ) {
516 Ext
. Viewport
. add ( this );
519 this . callParent ( arguments
);
521 if (! this . isHidden ()) {
522 this . setValue ( this . _value
);
524 Ext
. util
. InputBlocker
. blockInputs ();
528 * Sets the values of the pickers slots.
529 * @param {Object} values The values in a {name:'value'} format.
530 * @param {Boolean} animated `true` to animate setting the values.
531 * @return {Ext.Picker} this This picker.
533 setValue : function ( values
, animated
) {
535 slots
= me
. getInnerItems (),
537 key
, slot
, loopSlot
, i
, value
;
541 for ( i
= 0 ; i
< ln
; i
++) {
542 //set the value to false so the slot will return null when getValue is called
543 values
[ slots
[ i
]. config
. name
] = null ;
547 for ( key
in values
) {
550 for ( i
= 0 ; i
< slots
. length
; i
++) {
552 if ( loopSlot
. config
. name
== key
) {
560 slot
. setValueAnimated ( value
);
562 slot
. setValue ( value
);
567 me
. _values
= me
. _value
= values
;
572 setValueAnimated : function ( values
) {
573 this . setValue ( values
, true );
577 * Returns the values of each of the pickers slots
578 * @return {Object} The values of the pickers slots
580 getValue : function ( useDom
) {
582 items
= this . getItems (). items
,
587 for ( i
= 0 ; i
< ln
; i
++) {
589 if ( item
&& item
. isSlot
) {
590 values
[ item
. getName ()] = item
. getValue ( useDom
);
594 this . _values
= values
;
601 * Returns the values of each of the pickers slots.
602 * @return {Object} The values of the pickers slots.
604 getValues : function () {
605 return this . getValue ();
608 destroy : function () {
610 Ext
. destroy ( this . mask
, this . bar
);
613 //<deprecated product=touch since=2.0>
615 * @member Ext.picker.Picker
616 * @cfg {String} activeCls
617 * CSS class to be applied to individual list items when they have been chosen.
620 Ext
. deprecateProperty ( this , 'activeCls' , null , "Ext.picker.Picker.activeCls has been removed" );
624 * @inheritdoc Ext.picker.Picker#getActiveItem
625 * @deprecated 2.0.0 Please use {@link #getActiveItem} instead
627 Ext
. deprecateClassMethod ( this , 'getCard' , 'getActiveItem' );
631 * @inheritdoc Ext.picker.Picker#setActiveItem
632 * @deprecated 2.0.0 Please use {@link #setActiveItem} instead
634 Ext
. deprecateClassMethod ( this , 'setCard' , 'setActiveItem' );