login dialog definition added and implemented for iOS

This commit is contained in:
Vladimir Enchev
2014-06-09 17:48:21 +03:00
parent 4e9464ad26
commit dc02169584
3 changed files with 65 additions and 3 deletions

View File

@ -2,6 +2,7 @@
PROMPT = "Prompt",
CONFIRM = "Confirm",
ALERT = "Alert",
LOGIN = "Login",
OK = "OK",
CANCEL = "Cancel";
@ -17,5 +18,5 @@ export enum InputType {
/**
* Password input type.
*/
Password,
Password
}

View File

@ -24,7 +24,14 @@
* @param message The text to display in the dialog box.
* @param options The options for the dialog box. Optional.
*/
function prompt(message: string, defaultText?: string, options?: PromptOptions): promises.Promise<string>;
function prompt(message: string, defaultText?: string, options?: PromptOptions): promises.Promise<PromptResult>;
/**
* The prompt() method displays a dialog box that prompts the visitor for input.
* @param message The text to display in the dialog box.
* @param options The options for the dialog box. Optional.
*/
function login(message: string, userName?: string, password?: string, options?: DialogButtonsOptions): promises.Promise<LoginResult>;
/**
* Provides options for the dialog.
@ -86,6 +93,26 @@
text: string;
}
/**
* Provides result data from the login dialog.
*/
interface LoginResult {
/**
* Gets or sets the login dialog boolean result.
*/
result: boolean;
/**
* Gets or sets the user entered in the login dialog.
*/
userName: string;
/**
* Gets or sets the password entered in the login dialog.
*/
password: string;
}
export class Dialog {
/**
* Shows the dialog.

View File

@ -104,7 +104,7 @@ export function prompt(message: string, defaultText?: string,
try {
var alert = createUIAlertView(message, options);
if (options.inputType === dialogs_common.InputType.Password) {
if (options.inputType === dialogs_common.InputType.Password) {
alert.alertViewStyle = UIKit.UIAlertViewStyle.UIAlertViewStyleSecureTextInput;
} else {
alert.alertViewStyle = UIKit.UIAlertViewStyle.UIAlertViewStylePlainTextInput;
@ -133,6 +133,40 @@ export function prompt(message: string, defaultText?: string,
return d.promise();
}
export function login(message: string, userName?: string, password?: string,
options = { title: dialogs_common.LOGIN, okButtonText: dialogs_common.OK, cancelButtonText: dialogs_common.CANCEL }): promises.Promise<dialogs.LoginResult> {
var d = promises.defer<dialogs.LoginResult>();
try {
var alert = createUIAlertView(message, options);
alert.alertViewStyle = UIKit.UIAlertViewStyle.UIAlertViewStyleLoginAndPasswordInput;
addButtonsToAlertDialog(alert, options);
var userNameTextField = alert.textFieldAtIndex(0);
userNameTextField.text = userName ? userName : "";
var pwdTextField = alert.textFieldAtIndex(1);
pwdTextField.text = password ? password : "";
// Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference.
var delegate = createDelegate(function (view, index) {
d.resolve({ result: index === 2 ? undefined : index === 0, userName: userNameTextField.text, password: pwdTextField.text });
// Remove the local variable for the delegate.
delegate = undefined;
});
alert.delegate = delegate;
alert.show();
} catch (ex) {
d.reject(ex);
}
return d.promise();
}
export class Dialog {
private _ios: UIKit.UIAlertView;
//private _view: view.View;