This commit is contained in:
Adam Bradley
2015-12-22 22:47:32 -06:00
parent c1d2d48b7d
commit 819d1a2b05
3 changed files with 54 additions and 25 deletions

View File

@@ -32,8 +32,8 @@ export class Alert extends ViewController {
this.data.subTitle = subTitle;
}
setBodyText(text) {
this.data.text = text;
setBody(body) {
this.data.body = body;
}
addInput(input) {
@@ -75,11 +75,11 @@ export class Alert extends ViewController {
'<h2 class="alert-title" *ngIf="d.title">{{d.title}}</h2>' +
'<h3 class="alert-sub-title" *ngIf="d.subTitle">{{d.subTitle}}</h3>' +
'</div>' +
'<div class="alert-body" *ngIf="d.text">{{d.text}}</div>' +
'<div class="alert-body" *ngIf="d.body">{{d.body}}</div>' +
'<div class="alert-body alert-inputs" *ngIf="d.inputs.length">' +
'<div class="alert-input-wrapper" *ngFor="#i of d.inputs">' +
'<div class="alert-input-title" *ngIf="i.title">{{i.title}}</div>' +
'<input [placeholder]="i.placeholder" [type]="i.input" [value]="i.value" class="alert-input">' +
'<input [placeholder]="i.placeholder" [(ngModel)]="i.input" [value]="i.value" class="alert-input">' +
'</div>' +
'</div>' +
'<div class="alert-buttons">' +
@@ -112,7 +112,7 @@ class AlertCmp {
if (button.handler) {
// a handler has been provided, run it
if (button.handler() === false) {
if (button.handler(this.getValue()) === false) {
// if the return value is a false then do not close
shouldClose = false;
}
@@ -127,9 +127,24 @@ class AlertCmp {
this._viewCtrl.close();
}
getValue() {
let inputs = this.d.inputs;
if (inputs) {
if (inputs.length > 1) {
// array of values for each input
return inputs.map(i => i.input);
} else if (inputs.length === 1) {
// single value of the one input
return inputs[0].input;
}
}
// there are no inputs
return null;
}
onPageDidLeave() {
let values = this.d.inputs.map(i => i.value);
this.d.onClose && this.d.onClose(values);
this.d.onClose && this.d.onClose(this.getValue());
}
}

View File

@@ -9,7 +9,6 @@ class E2EApp {
constructor(private overlay: OverlayController) {
this.alertOpen = false;
this.confirmOpen = false;
this.confirmResult = '';
this.promptOpen = false;
this.promptResult = '';
}
@@ -17,17 +16,36 @@ class E2EApp {
doAlert() {
let alert = Alert.create({
title: 'Alert!',
subTitle: 'My alert subtitle',
bodyText: 'My alert body text',
buttons: ['Ok']
subTitle: 'Subtitle!!!',
buttons: ['Ok'],
onClose: () => {
this.alertOpen = false;
}
});
alert.onClose(() => {
this.alertOpen = false;
this.overlay.push(alert);
this.alertOpen = true;
}
doConfirm() {
let alert = Alert.create();
alert.setTitle('Confirm!');
alert.setBody('Body text!!!');
alert.addButton('Cancel');
alert.addButton({
text: 'Ok',
handler: () => {
console.log('Confirm Ok');
}
});
alert.onClose(data => {
this.confirmOpen = false;
});
this.overlay.push(alert).then(() => {
this.alertOpen = true;
this.confirmOpen = true;
});
}
@@ -40,12 +58,12 @@ class E2EApp {
});
alert.addButton({
text: 'Cancel',
handler: () => {
handler: data => {
console.log('500ms delayed prompt close');
setTimeout(() => {
console.log('Prompt close');
alert.close();
alert.close(data);
}, 500);
return false;
@@ -53,21 +71,18 @@ class E2EApp {
});
alert.addButton({
text: 'Ok',
handler: () => {
console.log('Prompt Ok');
handler: data => {
console.log('Prompt data:', data);
}
});
alert.onClose(data => {
this.promptOpen = false;
this.promptResult = data;
});
this.overlay.push(alert).then(() => {
this.promptOpen = true;
});
}
doConfirm() {
}
}

View File

@@ -2,15 +2,14 @@
<ion-content padding>
<button class="e2eOpenAlert" (click)="doAlert()">Alert</button>
<button class="e2eOpenPrompt" (click)="doPrompt()">Prompt</button>
<button class="e2eOpenConfirm" (click)="doConfirm()">Confirm</button>
<button class="e2eOpenPrompt" (click)="doPrompt()">Prompt</button>
<pre>
Alert Opened: {{alertOpen}}
Confirm Opened: {{confirmOpen}}
Prompt Opened: {{promptOpen}}
Prompt Result: {{promptResult}}
Confirm Opened: {{confirmOpen}}
Confirm Result: {{confirmResult}}
</pre>
</ion-content>