awesome-cordova-plugins/src/plugins/dialogs.ts

105 lines
3.0 KiB
TypeScript
Raw Normal View History

2016-07-08 06:54:38 +08:00
import { Cordova, Plugin } from './plugin';
2016-03-07 05:40:24 +08:00
export interface PromptCallback {
2016-03-07 05:40:24 +08:00
/**
* The index of the pressed button. (Number) Note that the index uses one-based indexing, so the value is 1, 2, 3, etc.
*/
buttonIndex: number;
2016-03-07 05:40:24 +08:00
/**
* The text entered in the prompt dialog box. (String)
*/
input1: string;
2016-03-07 05:40:24 +08:00
}
/**
* @name Dialogs
* @description
* This plugin gives you ability to access and customize the device native dialogs.
2016-03-07 05:40:24 +08:00
*
* Requires Cordova plugin: `cordova-plugin-dialogs`. For more info, please see the [Dialogs plugin docs](https://github.com/apache/cordova-plugin-dialogs).
*
* @usage
* ```js
* import {Dialogs} from 'ionic-native';
*
*
*
*
2016-03-07 05:40:24 +08:00
* ```
*/
@Plugin({
plugin: 'cordova-plugin-dialogs',
pluginRef: 'navigator.notification',
repo: 'https://github.com/apache/cordova-plugin-dialogs.git'
2016-03-07 05:40:24 +08:00
})
export class Dialogs {
/**
* Shows a custom alert or dialog box.
2016-07-09 03:19:13 +08:00
* @param {string} message Dialog message.
* @param {string} title Dialog title. (Optional, defaults to Alert)
* @param {string} buttonName Button name. (Optional, defaults to OK)
2016-03-07 05:40:24 +08:00
* @returns {Promise<any>} Returns a blank promise once the user has dismissed the alert.
*/
@Cordova({
successIndex: 1,
errorIndex: 4
})
static alert(
message,
title: string = 'Alert',
buttonName: string = 'OK'
2016-07-08 06:54:38 +08:00
): Promise<any> { return; }
2016-03-07 05:40:24 +08:00
/**
* Displays a customizable confirmation dialog box.
2016-07-09 03:19:13 +08:00
* @param {string} message Dialog message.
* @param {string} title Dialog title. (Optional, defaults to Confirm)
* @param {Array<string>} buttonLabels Array of strings specifying button labels. (Optional, defaults to [OK,Cancel])
2016-03-07 05:40:24 +08:00
* @returns {Promise<number>} Returns a promise that resolves the button index that was clicked. Note that the index use one-based indexing.
*/
@Cordova({
successIndex: 1,
errorIndex: 4
})
static confirm(
message,
title: string = 'Confirm',
buttonLabels: Array<string> = ['OK', 'Cancel']
2016-07-08 06:54:38 +08:00
): Promise<number> { return; }
2016-03-07 05:40:24 +08:00
/**
* Displays a native dialog box that is more customizable than the browser's prompt function.
2016-07-09 03:19:13 +08:00
* @param {string} message Dialog message.
* @param {string} title Dialog title. (Optional, defaults to Prompt)
* @param {Array<string>} buttonLabels Array of strings specifying button labels. (Optional, defaults to ["OK","Cancel"])
* @param {string} defaultText Default textbox input value. (Optional, Default: empty string)
2016-03-07 05:40:24 +08:00
* @returns {Promise<any>} Returns a promise that resolves an object with the button index clicked and the text entered
*/
@Cordova({
successIndex: 1,
errorIndex: 5
})
static prompt(
message?: string,
title: string = 'Prompt',
buttonLabels: Array<string> = ['OK', 'Cancel'],
defaultText: string = ''
2016-07-08 06:54:38 +08:00
): Promise<any> { return; }
2016-03-07 05:40:24 +08:00
/**
* The device plays a beep sound.
2016-07-09 03:19:13 +08:00
* @param {numbers} times The number of times to repeat the beep.
2016-03-07 05:40:24 +08:00
*/
@Cordova({
sync: true
})
2016-07-08 06:54:38 +08:00
static beep(times: number): void { }
2016-03-07 05:40:24 +08:00
2016-07-08 06:54:38 +08:00
}