-
Notifications
You must be signed in to change notification settings - Fork 1
/
signup-payment.ts
151 lines (135 loc) · 4.26 KB
/
signup-payment.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { Component, NgZone, ViewChild } from '@angular/core';
import { IonicPage, TextInput,
Platform, NavParams, NavController, ViewController, ModalController, ToastController, AlertController, LoadingController, ActionSheetController } from 'ionic-angular';
import { BasePage } from '../../pages/base-page/base-page';
import { SignupPasswordPage } from '../../pages/signup-password/signup-password';
import { Organization } from '../../models/organization';
import { User } from '../../models/user';
import { ApiProvider } from '../../providers/api/api';
import { StorageProvider } from '../../providers/storage/storage';
@IonicPage({
name: 'SignupPaymentPage',
segment: 'signup/payment',
defaultHistory: ['SignupEmailPage']
})
@Component({
selector: 'page-signup-payment',
templateUrl: 'signup-payment.html',
providers: [ ApiProvider, StorageProvider ],
entryComponents:[ SignupPasswordPage ]
})
export class SignupPaymentPage extends BasePage {
organization:Organization;
@ViewChild('number')
number:TextInput;
@ViewChild('expiry')
expiry:TextInput;
constructor(
protected zone:NgZone,
protected platform:Platform,
protected navParams:NavParams,
protected navController:NavController,
protected viewController:ViewController,
protected modalController:ModalController,
protected toastController:ToastController,
protected alertController:AlertController,
protected loadingController:LoadingController,
protected actionController:ActionSheetController,
protected api:ApiProvider,
protected storage:StorageProvider) {
super(zone, platform, navParams, navController, viewController, modalController, toastController, alertController, loadingController, actionController);
}
ionViewWillEnter() {
super.ionViewWillEnter();
let loading = this.showLoading("Loading...");
this.loadUpdates(true).then((loaded:any) => {
loading.dismiss();
},
(error:any) => {
loading.dismiss();
this.showToast(error);
});
}
ionViewDidEnter() {
super.ionViewDidEnter();
this.analytics.trackPage(this);
}
private loadUpdates(cache:boolean=true, event:any=null) {
this.logger.info(this, "loadUpdates");
return Promise.resolve()
.then(() => { return this.loadOrganization(cache); })
.then(() => {
this.logger.info(this, "loadUpdates", "Loaded");
if (event) {
event.complete();
}
})
.catch((error) => {
this.logger.error(this, "loadUpdates", "Failed", error);
if (event) {
event.complete();
}
this.showToast(error);
});
}
private loadOrganization(cache:boolean=true):Promise<Organization> {
return new Promise((resolve, reject) => {
if (cache && this.organization) {
resolve(this.organization);
}
else if (this.hasParameter("organization")){
this.organization = this.getParameter<Organization>("organization");
resolve(this.organization);
}
else {
this.storage.getOrganization().then((organization:Organization) => {
this.organization = organization;
resolve(this.organization);
},
(error:any) => {
this.organization = null;
resolve(null);
});
}
});
}
private showNext(event:any) {
this.logger.info(this, "showNext");
if (this.number.value.length == 0) {
this.showToast("Please enter credit card number");
setTimeout(() => {
this.number.setFocus();
}, 500);
}
else if (this.expiry.value.length == 0) {
this.showToast("Please enter credit card expiry");
setTimeout(() => {
this.expiry.setFocus();
}, 500);
}
else {
this.showPage(SignupPasswordPage, {
organization: this.organization
});
}
}
private showNextOnReturn(event:any) {
if (this.isKeyReturn(event)) {
if (this.number.value.length == 0) {
this.number.setFocus();
}
else if (this.expiry.value.length == 0) {
this.expiry.setFocus();
}
else {
this.hideKeyboard();
this.showNext(event);
}
return false;
}
return true;
}
private closeModal(event:any=null) {
this.hideModal();
}
}