This library is part of the Aurelia platform and contains a dialog plugin.
To keep up to date on Aurelia, please visit and subscribe to the official blog. If you have questions, we invite you to join us on Gitter. If you would like to have deeper insight into our development process, please install the ZenHub Chrome Extension and visit any of our repository's boards. You can get an overview of all Aurelia work by visiting the framework board.
This library has NO external dependencies.
This library is a plugin and is not used by the core framework.
This library can be used in the browser as well as on the server.
To build the code, follow these steps.
-
Ensure that NodeJS is installed. This provides the platform on which the build tooling runs.
-
From the project folder, execute the following command:
npm install
-
Ensure that Gulp is installed. If you need to install it, use the following command:
npm install -g gulp
-
To build the code, you can now run:
gulp build
-
You will find the compiled code in the
dist
folder, available in three module formats: AMD, CommonJS and ES6. -
See
gulpfile.js
for other tasks related to generating the docs and linting.
To run the unit tests, first ensure that you have followed the steps above in order to install all dependencies and successfully build the library. Once you have done that, proceed with these additional steps:
-
Ensure that the Karma CLI is installed. If you need to install it, use the following command:
npm install -g karma-cli
-
Ensure that jspm is installed. If you need to install it, use the following commnand:
npm install -g jspm
-
Download the SystemJS module loader:
jspm dl-loader
-
Ensure that you have Chrome installed. Karma runs the test suite in Chrome.
-
You can now run the tests with this command:
karma start
There are a few ways you can take advantage of the Aurelia dialog.
- You can use the dialog service to open a prompt -
import {DialogService, Prompt} from 'aurelia-dialog';
export class Welcome {
submit(){
this.dialogService.open({ viewModel: Prompt, model: 'Good or Bad?'}).then(() => {
console.log('good');
}).catch(() => {
console.log('bad');
});
}
}
This will open a prompt that resolve
s if the user clicks ok. If the user clicks out, clicks cancel, or clicks the 'x' in the top right it will reject
the promise.
- You can create your own view / view-model and use the dialog service to call it from your app's view-model -
import {EditPerson} from './edit-person';
import {DialogService} from 'aurelia/modal';
export class Welcome {
person = { firstName: 'Wade', middleName: 'Owen', lastName: 'Watts' };
submit(){
this.dialogService.open({ viewModel: EditPerson, model: this.person}).then(() => {
console.log('edited');
}).catch(() => {
console.log('didnt edit');
});
}
}
This will open a dialog and control it the same way as the prompt. The important thing to keep in mind is you need to follow the same method of utilizing a DialogController
in your EditPerson
view-model as well as accepting the model in your activate method -
import {DialogController} from 'aurelia/modal';
export class EditPerson {
static inject = [DialogController];
person = { firstName: '' };
constructor(controller){
this.controller = controller;
}
activate(person){
this.person = person;
}
}
and the corresponding view -
<template>
<dialog>
<dialog-body>
<h2>Edit first name</h2>
<input value.bind="person.firstName" />
</dialog-body>
<dialog-footer>
<button click.trigger="controller.cancel()">Cancel</button>
<button click.trigger="controller.ok(person)">Ok</button>
</dialog-footer>
</dialog>
</template>
###Settings The settings available for the dialog are set on the dialog controller on a per-dialog basis.
lock
makes the dialog modal, and removes the close button from the top-right hand corner. (defaults to true)centerHorizontalOnly
means that the dialog will be centered horizontally, and the vertical alignment is left up to you. (defaults to false)
export class Prompt {
static inject = [DialogController];
constructor(controller){
this.controller = controller;
this.answer = null;
controller.settings.lock = false;
controller.settings.centerHorizontalOnly = true;
}
}