import {Component, View, Injectable, CSSClass, NgIf, NgFor, onInit} from 'angular2/angular2'; import {Overlay} from '../overlay/overlay'; import {Animation} from '../../animations/animation'; 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', onTap: (event, popupRef) => { // Allow it to close //resolve(); } }; context = { cancel: () => { //reject(); }, title: context, buttons: [ button ] }; } 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) { if (handle) { return this.getByHandle(handle, OVERLAY_TYPE); } return this.getByType(OVERLAY_TYPE); } } const OVERLAY_TYPE = 'popup'; @Component({ selector: 'ion-popup-default', lifecycle: [onInit] }) @View({ template: '
' + '