dialogs module added with alert implementation for iOS

This commit is contained in:
Vladimir Enchev
2014-06-03 15:11:49 +03:00
parent a2d890905b
commit 8440509a48
6 changed files with 119 additions and 0 deletions

View File

@ -216,6 +216,14 @@
<ItemGroup>
<TypeScriptCompile Include="ui\core\view.ts" />
<TypeScriptCompile Include="ui\core\observable.ts" />
<TypeScriptCompile Include="ui\dialogs\dialogs.android.ts">
<DependentUpon>dialogs.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="ui\dialogs\dialogs.d.ts" />
<TypeScriptCompile Include="ui\dialogs\dialogs.ios.ts">
<DependentUpon>dialogs.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="ui\dialogs\index.ts" />
<Content Include="_references.ts" />
<Content Include="image-source\Readme.md" />
<Content Include="http\Readme.md" />
@ -234,6 +242,9 @@
<Folder Include="Deploy\Full\" />
<Folder Include="Deploy\xCode\" />
</ItemGroup>
<ItemGroup>
<Content Include="ui\dialogs\Readme.md" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Full'">
<TypeScriptModuleKind>commonjs</TypeScriptModuleKind>
<TypeScriptRemoveComments>True</TypeScriptRemoveComments>

1
ui/dialogs/Readme.md Normal file
View File

@ -0,0 +1 @@
Dialogs module.

View File

@ -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 {
}

47
ui/dialogs/dialogs.d.ts vendored Normal file
View File

@ -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<any>;
/**
* 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<any>;
/**
* 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;
}
}

43
ui/dialogs/dialogs.ios.ts Normal file
View File

@ -0,0 +1,43 @@
/**
* iOS specific dialogs functions implementation.
*/
import promises = require("promises");
export function alert(arg: any): promises.Promise<any> {
var d = promises.defer<any>();
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 {
}

2
ui/dialogs/index.ts Normal file
View File

@ -0,0 +1,2 @@
declare var module, require;
module.exports = require("ui/dialogs/dialogs");