diff --git a/BCL.csproj b/BCL.csproj index 84ea30936..127c76df3 100644 --- a/BCL.csproj +++ b/BCL.csproj @@ -216,6 +216,14 @@ + + dialogs.d.ts + + + + dialogs.d.ts + + @@ -234,6 +242,9 @@ + + + commonjs True diff --git a/ui/dialogs/Readme.md b/ui/dialogs/Readme.md new file mode 100644 index 000000000..274e534b5 --- /dev/null +++ b/ui/dialogs/Readme.md @@ -0,0 +1 @@ +Dialogs module. \ No newline at end of file diff --git a/ui/dialogs/dialogs.android.ts b/ui/dialogs/dialogs.android.ts new file mode 100644 index 000000000..3406effcb --- /dev/null +++ b/ui/dialogs/dialogs.android.ts @@ -0,0 +1,15 @@ +/** + * Android specific dialogs functions implementation. + */ + +export function alert(message: string): void { + +} + +export function confirm(message: string): void { + +} + +export function prompt(text: string, defaultText?: string): void { + +} \ No newline at end of file diff --git a/ui/dialogs/dialogs.d.ts b/ui/dialogs/dialogs.d.ts new file mode 100644 index 000000000..f22674102 --- /dev/null +++ b/ui/dialogs/dialogs.d.ts @@ -0,0 +1,47 @@ +declare module "dialogs" { + import promises = require("promises"); + /** + * The alert() method displays an alert box with a specified message. + * @param message Specifies the text to display in the alert box. + */ + function alert(message: string): promises.Promise; + + /** + * The alert() method displays an alert box with a specified options. + * @param options Specifies the options for the alert box. + */ + function alert(options: AlertOptions): promises.Promise; + + /** + * The confirm() method displays a dialog box with a specified message, along with an OK and a Cancel button. + * @param message Specifies the text to display in the confirm box. + */ + function confirm(message: string): void; + + /** + * The prompt() method displays a dialog box that prompts the visitor for input. + * @param text The text to display in the dialog box. + * @param defaultText The default input value. + */ + function prompt(text: string, defaultText?: string): void; + + /** + * Provides options for the alert. + */ + interface AlertOptions { + /** + * Gets or sets the alert message. + */ + message: string; + + /** + * Gets or sets the alert message. + */ + title?: string; + + /** + * Gets or sets the request headers in JSON format. + */ + buttonName?: any; + } +} \ No newline at end of file diff --git a/ui/dialogs/dialogs.ios.ts b/ui/dialogs/dialogs.ios.ts new file mode 100644 index 000000000..e0c4ca353 --- /dev/null +++ b/ui/dialogs/dialogs.ios.ts @@ -0,0 +1,43 @@ +/** + * iOS specific dialogs functions implementation. + */ +import promises = require("promises"); + +export function alert(arg: any): promises.Promise { + var d = promises.defer(); + try { + var options = typeof arg === "string" ? { message: arg, title: "Alert", buttonName: "OK" } : arg + var alert = new UIKit.UIAlertView(); + alert.title = options.title; + alert.message = options.message; + alert.addButtonWithTitle(options.buttonName); + + var delegateType = Foundation.NSObject.extends({}, {}).implements({ + protocol: "UIAlertViewDelegate", + implementation: { + alertViewClickedButtonAtIndex: function (view, index) { + d.resolve(); + // Remove the local variable for the delegate. + delegate = undefined; + } + } + }); + // Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference. + var delegate = new delegateType(); + alert.delegate = delegate; + + alert.show(); + } catch (ex) { + d.reject(ex); + } + + return d.promise(); +} + +export function confirm(message: string): void { + +} + +export function prompt(text: string, defaultText?: string): void { + +} \ No newline at end of file diff --git a/ui/dialogs/index.ts b/ui/dialogs/index.ts new file mode 100644 index 000000000..fac3ad1cb --- /dev/null +++ b/ui/dialogs/index.ts @@ -0,0 +1,2 @@ +declare var module, require; +module.exports = require("ui/dialogs/dialogs"); \ No newline at end of file