/
picker.ts
103 lines (82 loc) · 2.33 KB
/
picker.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { EventEmitter, Injectable, Output } from '@angular/core';
import { App } from '../app/app';
import { isPresent } from '../../util/util';
import { NavOptions } from '../../navigation/nav-util';
import { PickerCmp } from './picker-component';
import { PickerOptions, PickerColumn } from './picker-options';
import { ViewController } from '../../navigation/view-controller';
/**
* @private
*/
export class Picker extends ViewController {
private _app: App;
@Output() ionChange: EventEmitter<any>;
constructor(app: App, opts: PickerOptions = {}) {
opts.columns = opts.columns || [];
opts.buttons = opts.buttons || [];
opts.enableBackdropDismiss = isPresent(opts.enableBackdropDismiss) ? !!opts.enableBackdropDismiss : true;
super(PickerCmp, opts, null);
this._app = app;
this.isOverlay = true;
this.ionChange = new EventEmitter<any>();
}
/**
* @private
*/
getTransitionName(direction: string) {
let key = (direction === 'back' ? 'pickerLeave' : 'pickerEnter');
return this._nav && this._nav.config.get(key);
}
/**
* @param {any} button Picker toolbar button
*/
addButton(button: any) {
this.data.buttons.push(button);
}
/**
* @param {any} button Picker toolbar button
*/
addColumn(column: PickerColumn) {
this.data.columns.push(column);
}
getColumns(): PickerColumn[] {
return this.data.columns;
}
getColumn(name: string): PickerColumn {
return this.getColumns().find(column => column.name === name);
}
refresh() {
this._cmp && this._cmp.instance.refresh && this._cmp.instance.refresh();
}
/**
* @param {string} cssClass CSS class name to add to the picker's outer wrapper.
*/
setCssClass(cssClass: string) {
this.data.cssClass = cssClass;
}
/**
* Present the picker instance.
*
* @param {NavOptions} [opts={}] Nav options to go with this transition.
* @returns {Promise} Returns a promise which is resolved when the transition has completed.
*/
present(navOptions: NavOptions = {}) {
return this._app.present(this, navOptions);
}
}
/**
* @private
* @name PickerController
* @description
*
*/
@Injectable()
export class PickerController {
constructor(private _app: App) {}
/**
* Open a picker.
*/
create(opts: PickerOptions = {}): Picker {
return new Picker(this._app, opts);
}
}