+
+
+
+
+ `
+})
+export class DialogsPage {
+ doAlert() {
+ Dialogs.alert('Hello');
+ }
+ doConfirm() {
+ Dialogs.confirm('Do you want to click that?').then((resp) => {
+ console.log(resp);
+ });
+ }
+ doPrompt() {
+ Dialogs.prompt('What is your fav ice cream?').then((resp) => {
+ console.log(resp);
+ });
+ }
+}
diff --git a/ionic/native/dialogs/dialogs.ts b/ionic/native/dialogs/dialogs.ts
new file mode 100644
index 0000000000..1890478747
--- /dev/null
+++ b/ionic/native/dialogs/dialogs.ts
@@ -0,0 +1,85 @@
+import * as Rx from 'rx';
+
+import * as util from 'ionic/util';
+import {NativePlugin} from '../plugin';
+
+/**
+ * A native dialogs system. Native dialogs can give you a bit more
+ * control over the UI than the browser built-ins, though the Dialogs
+ * plugin will fall back to the built-ins when necessary.
+ */
+@NativePlugin({
+ name: 'Dialogs',
+ platforms: {
+ cordova: 'cordova-plugin-dialogs'
+ }
+})
+export class Dialogs {
+ /**
+ * Trigger an alert prompt.
+ *
+ * @param message the message to show
+ * @param title the title to show
+ * @param buttonName the button label to use (not available on browser fallback)
+ * @return Promise
+ */
+ static alert(message, title, buttonName) {
+ return new Promise((resolve,reject) => {
+ if(!navigator.notification) {
+ this.pluginWarn();
+ alert(message);
+ resolve();
+ } else {
+ navigator.notification.alert(message, () => {
+ resolve();
+ }, title, buttonName);
+ }
+ });
+ }
+
+ /**
+ * Trigger a confirm prompt.
+ *
+ * @param message the message to show
+ * @param title the title to show
+ * @param buttonLabels the button labels to use (not available on browser fallback)
+ * @return Promise that resolves with the index of the button selected (zero indexed). 1 is OK on browser fallback
+ */
+ static confirm(message, title, buttonLabels) {
+ return new Promise((resolve,reject) => {
+ if(!navigator.notification) {
+ this.pluginWarn();
+ var ok = confirm(message);
+ // Use 2 as OK
+ resolve(ok ? 2 : 0);
+ } else {
+ navigator.notification.confirm(message, (buttonIndex) => {
+ resolve(buttonIndex - 1);
+ }, title, buttonLabels);
+ }
+ });
+ }
+
+ static prompt(message, title, buttonLabels, defaultText) {
+ return new Promise((resolve,reject) => {
+ if(!navigator.notification) {
+ this.pluginWarn();
+ var response = prompt(message);
+ // Use 1 as OK
+ resolve(response);
+ } else {
+ navigator.notification.prompt(message, (results) => {
+ resolve(results.input1, buttonIndex - 1);
+ }, title, buttonLabels, defaultText);
+ }
+ });
+ }
+
+ /**
+ * Beep n times. Not available on browser.
+ * @param times the number of times to beep
+ */
+ static beep(times) {
+ navigator.notification && navigator.notification.beep(times);
+ }
+}
diff --git a/ionic/native/plugin.ts b/ionic/native/plugin.ts
index 9b37805a92..2c5f660185 100644
--- a/ionic/native/plugin.ts
+++ b/ionic/native/plugin.ts
@@ -19,6 +19,11 @@ export class NativePluginDecorator {
};
cls.pluginWarn = () => {
+ if(cls._pluginWarned) {
+ // Only warn once
+ return;
+ }
+
let platformString = [];
for(var k in this.config.platforms) {
platformString.push('\t' + k + ': '+ this.config.platforms[k]);
@@ -26,6 +31,9 @@ export class NativePluginDecorator {
console.warn('Plugin for ' + this.config.name +
' not installed. For native functionality, please install the correct plugin for your platform:\n' +
platformString.join('\n'));
+
+ // Set a flag so we don't warn again
+ cls._pluginWarned = true;
}
}
}
diff --git a/ionic/native/plugins.ts b/ionic/native/plugins.ts
index 48accba1c4..7a3b3c79c8 100644
--- a/ionic/native/plugins.ts
+++ b/ionic/native/plugins.ts
@@ -2,6 +2,7 @@ export * from './plugin'
export * from './battery/battery'
export * from './camera/camera'
export * from './contacts/contacts'
+export * from './dialogs/dialogs'
export * from './device/device'
export * from './device-motion/device-motion'
export * from './device-orientation/device-orientation'