33 */
44import promises = require( "promises" ) ;
55import dialogs = require( "ui/dialogs" ) ;
6+ import view = require( "ui/core/view" ) ;
67
78var UIALERTVIEWDELEGATE = "UIAlertViewDelegate" ,
89 STRING = "string" ,
@@ -29,14 +30,30 @@ function createDelegate(callback) {
2930 return new delegateType ;
3031}
3132
33+ function addButtonsToAlertDialog ( alert : UIKit . UIAlertView , options : dialogs . ConfirmOptions ) : void {
34+ if ( options . okButtonName ) {
35+ alert . addButtonWithTitle ( options . okButtonName ) ;
36+ }
37+
38+ if ( options . cancelButtonName ) {
39+ alert . addButtonWithTitle ( options . cancelButtonName ) ;
40+ }
41+
42+ if ( options . otherButtonName ) {
43+ alert . addButtonWithTitle ( options . otherButtonName ) ;
44+ }
45+ }
46+
3247export function alert ( arg : any ) : promises . Promise < void > {
3348 var d = promises . defer < void > ( ) ;
3449 try {
3550 var options = typeof arg === STRING ? { message : arg , title : ALERT , buttonName : OK } : arg
3651
3752 var alert = createUIAlertView ( options ) ;
3853
39- alert . addButtonWithTitle ( options . buttonName ) ;
54+ if ( options . buttonName ) {
55+ alert . addButtonWithTitle ( options . buttonName ) ;
56+ }
4057
4158 // Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference.
4259 var delegate = createDelegate ( function ( view , index ) {
@@ -62,12 +79,11 @@ export function confirm(arg: any): promises.Promise<boolean> {
6279
6380 var alert = createUIAlertView ( options ) ;
6481
65- alert . addButtonWithTitle ( options . okButtonName ) ;
66- alert . addButtonWithTitle ( options . cancelButtonName ) ;
82+ addButtonsToAlertDialog ( alert , options ) ;
6783
6884 // Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference.
6985 var delegate = createDelegate ( function ( view , index ) {
70- d . resolve ( index === 0 ) ;
86+ d . resolve ( index === 2 ? undefined : index === 0 ) ;
7187 // Remove the local variable for the delegate.
7288 delegate = undefined ;
7389 } ) ;
@@ -83,24 +99,22 @@ export function confirm(arg: any): promises.Promise<boolean> {
8399 return d . promise ( ) ;
84100}
85101
86- export function prompt ( arg : any ) : promises . Promise < string > {
87- var d = promises . defer < string > ( ) ;
102+ export function prompt ( arg : any ) : promises . Promise < dialogs . PromptResult > {
103+ var d = promises . defer < dialogs . PromptResult > ( ) ;
88104 try {
89105 var options = typeof arg === STRING ? { message : arg , title : ALERT , okButtonName : OK , cancelButtonName : CANCEL } : arg
90106
91107 var alert = createUIAlertView ( options ) ;
92108 alert . alertViewStyle = UIKit . UIAlertViewStyle . UIAlertViewStylePlainTextInput ;
93- alert . addButtonWithTitle ( options . okButtonName ) ;
94- alert . addButtonWithTitle ( options . cancelButtonName ) ;
109+
110+ addButtonsToAlertDialog ( alert , options ) ;
95111
96112 var textField = alert . textFieldAtIndex ( 0 ) ;
97113 textField . text = options . defaultText ? options . defaultText : "" ;
98114
99115 // Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference.
100116 var delegate = createDelegate ( function ( view , index ) {
101- if ( index === 0 ) {
102- d . resolve ( textField . text ) ;
103- }
117+ d . resolve ( { result : index === 2 ? undefined : index === 0 , text : textField . text } ) ;
104118 // Remove the local variable for the delegate.
105119 delegate = undefined ;
106120 } ) ;
@@ -118,6 +132,8 @@ export function prompt(arg: any): promises.Promise<string> {
118132
119133export class Dialog {
120134 private _ios : UIKit . UIAlertView ;
135+ //private _view: view.View;
136+ //private _nativeView: UIKit.UIView;
121137
122138 constructor ( ) {
123139 this . _ios = new UIKit . UIAlertView ( ) ;
@@ -133,6 +149,18 @@ export class Dialog {
133149 set title ( value : string ) {
134150 this . ios . title = value ;
135151 }
152+ /*
153+ get view(): view.View {
154+ return this._view;
155+ }
156+ set view(value: view.View) {
157+ this._view = value;
158+ this._nativeView = this._view.ios;
159+ this._nativeView.removeFromSuperview();
160+
161+ // Not working on iOS7!
162+ this.ios.addSubview(this._nativeView);
163+ }*/
136164
137165 public show ( ) {
138166 this . ios . show ( ) ;
0 commit comments