API Docs for:
Show:

CordovaShims.Services.Dialogs Class

Extends Ember.Service
Module: cordova-shims/services/dialogs

Available since 0.2.0

Service that allows for displaying native dialogs for user interaction.

Configuration and setup of the service is done in an initializer:

import DialogsService from 'cordova-shims/services/dialogs';

export function initialize(container, application) {
  application.register('service:dialogs', DialogsService);
  application.inject('route', 'dialogs', 'service:dialogs');
}

export default {
  name: 'dialogs-service',
  initialize: initialize
};

The service has an interface for defining custom fallback methods for each dialog type.

  • alertFallback
  • confirmFallback
  • promptFallback

If your app targets both browser and native platforms, you should provide your own implementation of these fallbacks methods. There are simple default methods defined to get you started quickly.

Methods

alert

(
  • options
)
RSVP.Promise

Display an alert box to the user with a title, message and a customizable button name.

Example:

DialogsService.create().alert({
  title: 'Something important',
  message: 'This just happened!',
  button: 'OK'
});

Parameters:

  • options Object
    • title String

      Title for the alert box

    • message String

      Message to show in the alert box

    • button String

      Text for the button that dismisses the alert box

Returns:

RSVP.Promise:

A promise that will resolve when alert is dismissed.

confirm

(
  • options
)
RSVP.Promise

Display a confirm box to the user with a title, message and customizable button names.

Example:

DialogsService.create().confirm({
  title: 'Something important',
  message: 'This just happened!',
  buttons: [
    'OK',
    'Cancel'
  ]
});

Parameters:

  • options Object
    • title String

      Title for the confirm box

    • message String

      Message to show in the confirm box

    • buttons Array

      Text for the button that dismisses the confirm box

Returns:

RSVP.Promise:

A promise that will resolve with the index of the button pressed (1-indexed).

prompt

(
  • options
)
RSVP.Promise

Display a prompt to the user with a title, message, text input and a customizable button name.

Example:

DialogsService.create().prompt({
  title: 'Please provide some info',
  message: 'We need to know something.',
  defaultText: 'foo',
  buttons: [
    'OK',
    'Cancel'
  ]
});

Parameters:

  • options Object
    • title String

      Title for the confirm box

    • message String

      Message to show in the confirm box

    • buttons Array

      Text for the button that dismisses the confirm box

Returns:

RSVP.Promise:

A promise that will resolve with the following:

{
  text: "{text-from-input}",
  buttonIndex: 1 // Index of the button pressed
}

Properties

alertFallback

Function

Hook that gets triggered if the plugin API is not available. Useful for handling dialogs in a browser environment.

confirmFallback

Function

Hook that gets triggered if the plugin API is not available. Useful for handling dialogs in a browser environment.

promptFallback

Function

Hook that gets triggered if the plugin API is not available. Useful for handling dialogs in a browser environment.