From 4a3f213f320e99e1562f43cefb31cd9e961ee7b3 Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Tue, 21 Jul 2015 15:50:07 -0500 Subject: [PATCH] Popup promise --- ionic/components/popup/extensions/ios.scss | 4 + ionic/components/popup/popup.ts | 119 ++++++++++++++++++--- ionic/components/popup/test/basic/index.ts | 20 +++- 3 files changed, 125 insertions(+), 18 deletions(-) diff --git a/ionic/components/popup/extensions/ios.scss b/ionic/components/popup/extensions/ios.scss index 97a46b7422..20175a5709 100644 --- a/ionic/components/popup/extensions/ios.scss +++ b/ionic/components/popup/extensions/ios.scss @@ -24,6 +24,10 @@ $popup-ios-bg-color: #f8f8f8 !default; min-height: 42px; color: get-color('primary', base); font-size: 14px; + + &:last-child { + font-weight: bold; + } } } } diff --git a/ionic/components/popup/popup.ts b/ionic/components/popup/popup.ts index 2837255c64..d164d52194 100644 --- a/ionic/components/popup/popup.ts +++ b/ionic/components/popup/popup.ts @@ -1,4 +1,4 @@ -import {Component, View, Injectable, CSSClass, NgIf, NgFor} from 'angular2/angular2'; +import {Component, View, Injectable, CSSClass, NgIf, NgFor, onInit} from 'angular2/angular2'; import {Overlay} from '../overlay/overlay'; import {Animation} from '../../animations/animation'; @@ -8,27 +8,103 @@ import * as util from 'ionic/util'; @Injectable() export class Popup extends Overlay { + popup(context, opts={}) { + return new Promise((resolve, reject)=> { + let defaults = { + enterAnimation: 'popup-pop-in', + leaveAnimation: 'popup-pop-out', + }; + + context.promiseResolve = resolve; + context.promiseReject = reject; + + return this.create(OVERLAY_TYPE, StandardPopup, util.extend(defaults, opts), context); + }); + } + alert(context={}, opts={}) { if(typeof context === 'string') { let button = { - text: 'Ok', + text: 'OK', onTap: (event, popupRef) => { // Allow it to close + //resolve(); } - } + }; context = { + cancel: () => { + //reject(); + }, title: context, buttons: [ button ] - } + }; } - let defaults = { - enterAnimation: 'popup-pop-in', - leaveAnimation: 'popup-pop-out', - }; - return this.create(OVERLAY_TYPE, StandardPopup, util.extend(defaults, opts), context); + return this.popup(context, opts); + } + + confirm(context={}, opts={}) { + return new Promise((resolve, reject)=> { + if(typeof context === 'string') { + let okButton = { + text: 'OK', + onTap: (event, popupRef) => { + // Allow it to close + resolve(true); + } + } + let cancelButton = { + text: 'Cancel', + onTap: (event, popupRef) => { + // Allow it to close + reject(); + } + } + context = { + cancel: () => { + reject(); + }, + title: context, + buttons: [ + cancelButton, okButton + ] + } + } + this.popup(context, opts); + }); + } + + prompt(context={}, opts={}) { + return new Promise((resolve, reject)=> { + if(typeof context === 'string') { + let okButton = { + text: 'Ok', + onTap: (event, popupRef) => { + // Allow it to close + } + } + let cancelButton = { + text: 'Cancel', + onTap: (event, popupRef) => { + // Allow it to close + reject(); + } + } + context = { + cancel: () => { + reject(); + }, + title: context, + buttons: [ + cancelButton, okButton + ] + } + } + this.popup(context, opts); + }); + } get(handle) { @@ -44,10 +120,11 @@ const OVERLAY_TYPE = 'popup'; @Component({ - selector: 'ion-popup-default' + selector: 'ion-popup-default', + lifecycle: [onInit] }) @View({ - template: '' + + template: '' + '