diff --git a/ui/dialogs/dialogs.android.ts b/ui/dialogs/dialogs.android.ts index 58553419b..d54d53c08 100644 --- a/ui/dialogs/dialogs.android.ts +++ b/ui/dialogs/dialogs.android.ts @@ -7,6 +7,8 @@ import appmodule = require("application"); import view = require("ui/core/view"); var STRING = "string", + PROMPT = "Prompt", + CONFIRM = "Confirm", ALERT = "Alert", OK = "OK", CANCEL = "Cancel"; @@ -18,7 +20,7 @@ function createAlertDialog(message: string, options: dialogs.DialogOptions): and return alert; } -function addButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options: dialogs.ConfirmOptions, +function addButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options: dialogs.DialogButtonOptions, okCallback: Function, cancelCallback?: Function, neutralCallback?: Function): void { if (options.okButtonText) { @@ -41,8 +43,8 @@ function addButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options })); } - if (options.otherButtonText) { - alert.setNeutralButton(options.otherButtonText, new android.content.DialogInterface.OnClickListener({ + if (options.neutralButtonText) { + alert.setNeutralButton(options.neutralButtonText, new android.content.DialogInterface.OnClickListener({ onClick: function (dialog: android.content.DialogInterface, id: number) { dialog.cancel(); if (neutralCallback) { @@ -53,12 +55,12 @@ function addButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options } } -export function alert(message: string, options = { title: ALERT, buttonText: OK }): promises.Promise { +export function alert(message: string, options = { title: ALERT, okButtonText: OK }): promises.Promise { var d = promises.defer(); try { var alert = createAlertDialog(message, options); - alert.setPositiveButton(options.buttonText, new android.content.DialogInterface.OnClickListener({ + alert.setPositiveButton(options.okButtonText, new android.content.DialogInterface.OnClickListener({ onClick: function (dialog: android.content.DialogInterface, id: number) { dialog.cancel(); d.resolve(); @@ -74,7 +76,7 @@ export function alert(message: string, options = { title: ALERT, buttonText: OK return d.promise(); } -export function confirm(message: string, options = { title: ALERT, okButtonText: OK, cancelButtonText: CANCEL }): promises.Promise { +export function confirm(message: string, options = { title: CONFIRM, okButtonText: OK, cancelButtonText: CANCEL }): promises.Promise { var d = promises.defer(); try { var alert = createAlertDialog(message, options); @@ -90,13 +92,13 @@ export function confirm(message: string, options = { title: ALERT, okButtonText: return d.promise(); } -export function prompt(message: string, options = { title: ALERT, okButtonText: OK, cancelButtonText: CANCEL, defaultText: "" }): promises.Promise { +export function prompt(message: string, defaultText?: string, options = { title: PROMPT, okButtonText: OK, cancelButtonText: CANCEL }): promises.Promise { var d = promises.defer(); try { var alert = createAlertDialog(message, options); var input = new android.widget.EditText(appmodule.android.context); - input.setText(options.defaultText ? options.defaultText : ""); + input.setText(defaultText ? defaultText : ""); alert.setView(input); diff --git a/ui/dialogs/dialogs.d.ts b/ui/dialogs/dialogs.d.ts index 6e4da0228..014bbe8ac 100644 --- a/ui/dialogs/dialogs.d.ts +++ b/ui/dialogs/dialogs.d.ts @@ -14,14 +14,14 @@ * @param message Specifies the text to display in the confirm box. * @param options Specifies the options for the confirm box. Optional. */ - function confirm(message: string, options?: ConfirmOptions): promises.Promise; + function confirm(message: string, options?: DialogButtonOptions): promises.Promise; /** * 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 prompt(message: string, options?: PromptOptions): promises.Promise; + function prompt(message: string, defaultText?: string, options?: DialogButtonOptions): promises.Promise; /** * Provides options for the dialog. @@ -38,39 +38,24 @@ */ interface AlertOptions extends DialogOptions { /** - * Gets or sets the button name. + * Gets or sets the OK button text. */ - buttonText?: string; + okButtonText?: string; } /** * Provides options for the confirm. */ - interface ConfirmOptions extends DialogOptions { + interface DialogButtonOptions extends AlertOptions { /** - * Gets or sets the OK button name. - */ - okButtonText?: string; - - /** - * Gets or sets the Cancel button name. + * Gets or sets the Cancel button text. */ cancelButtonText?: string; /** - * Gets or sets the Cancel button name. + * Gets or sets the neutral button text. */ - otherButtonText?: string; - } - - /** - * Provides options for the prompt. - */ - interface PromptOptions extends ConfirmOptions { - /** - * Gets or sets the default text. - */ - defaultText?: string; + neutralButtonText?: string; } /** diff --git a/ui/dialogs/dialogs.ios.ts b/ui/dialogs/dialogs.ios.ts index 983f42e04..5553935d4 100644 --- a/ui/dialogs/dialogs.ios.ts +++ b/ui/dialogs/dialogs.ios.ts @@ -32,7 +32,7 @@ function createDelegate(callback) { return new delegateType; } -function addButtonsToAlertDialog(alert: UIKit.UIAlertView, options: dialogs.ConfirmOptions): void { +function addButtonsToAlertDialog(alert: UIKit.UIAlertView, options: dialogs.DialogButtonOptions): void { if (!options) return; @@ -44,18 +44,18 @@ function addButtonsToAlertDialog(alert: UIKit.UIAlertView, options: dialogs.Conf alert.addButtonWithTitle(options.cancelButtonText); } - if (options.otherButtonText) { - alert.addButtonWithTitle(options.otherButtonText); + if (options.neutralButtonText) { + alert.addButtonWithTitle(options.neutralButtonText); } } -export function alert(message: string, options = { title: ALERT, buttonText: OK }): promises.Promise { +export function alert(message: string, options = { title: ALERT, okButtonText: OK }): promises.Promise { var d = promises.defer(); try { var alert = createUIAlertView(message, options); - if (options.buttonText) { - alert.addButtonWithTitle(options.buttonText); + if (options.okButtonText) { + alert.addButtonWithTitle(options.okButtonText); } // Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference. @@ -100,7 +100,7 @@ export function confirm(message: string, options = { title: CONFIRM, okButtonTe return d.promise(); } -export function prompt(message: string, options = { title: PROMPT, okButtonText: OK, cancelButtonText: CANCEL, defaultText: "" }): promises.Promise { +export function prompt(message: string, defaultText?: string, options = { title: PROMPT, okButtonText: OK, cancelButtonText: CANCEL, defaultText: "" }): promises.Promise { var d = promises.defer(); try { var alert = createUIAlertView(message, options); @@ -109,7 +109,7 @@ export function prompt(message: string, options = { title: PROMPT, okButtonText: addButtonsToAlertDialog(alert, options); var textField = alert.textFieldAtIndex(0); - textField.text = options.defaultText ? options.defaultText : ""; + textField.text = defaultText ? defaultText : ""; // Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference. var delegate = createDelegate(function (view, index) {