import {formDirectives, NgControl, NgControlGroup, 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') { context = { title: context } } let button = { text: 'OK', onTap: (event, popupRef) => { // Allow it to close //resolve(); } }; context = util.extend({ cancel: () => { //reject(); }, buttons: [ button ] }, context); return this.popup(context, opts); } confirm(context={}, opts={}) { if(typeof context === 'string') { context = { title: context } } let okButton = { text: 'OK', onTap: (event, popupRef) => { // Allow it to close } } let cancelButton = { text: 'Cancel', isCancel: true, onTap: (event, popupRef) => { // Allow it to close } } context = util.extend({ cancel: () => { }, buttons: [ cancelButton, okButton ] }, context); return this.popup(context, opts); } prompt(context={}, opts={}) { if(typeof context === 'string') { context = { title: context }; } let okButton = { text: 'Ok', onTap: (event, popupRef) => { // Allow it to close } } let cancelButton = { text: 'Cancel', isCancel: true, onTap: (event, popupRef) => { // Allow it to close } } context = util.extend({ showPrompt: true, promptPlaceholder: '', cancel: () => { }, buttons: [ cancelButton, okButton ] }, context); console.log('Context', context); return 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: '
' + '