mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-26 03:01:51 +08:00
login dialog definition added and implemented for iOS
This commit is contained in:
@ -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
|
||||
}
|
29
ui/dialogs/dialogs.d.ts
vendored
29
ui/dialogs/dialogs.d.ts
vendored
@ -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.
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user