[About] Provide default cancel for overlays

For overlays that do not need to do special things when a
window is dismissed, provide a default cancel function.
This simplifies implementation of the information-only
dialogs, such as the About dialog, WTD-667.
This commit is contained in:
Victor Woeltjen 2015-01-14 11:53:51 -08:00
parent 97d4f34ae2
commit 553eb2dd75
2 changed files with 17 additions and 11 deletions

View File

@ -76,8 +76,8 @@ define(
// Add the overlay using the OverlayService, which
// will handle actual insertion into the DOM
overlay = overlayService.createOverlay(
overlayModel,
"overlay-dialog"
"overlay-dialog",
overlayModel
);
// Track that a dialog is already visible, to

View File

@ -25,11 +25,21 @@ define(
* @constructor
*/
function OverlayService($document, $compile, $rootScope) {
function createOverlay(overlayModel, key) {
function createOverlay(key, overlayModel) {
// Create a new scope for this overlay
var scope = $rootScope.$new(),
element;
// Stop showing the overlay; additionally, release the scope
// that it uses.
function dismiss() {
scope.$destroy();
element.remove();
}
// If no model is supplied, just fill in a default "cancel"
overlayModel = overlayModel || { cancel: dismiss };
// Populate the scope; will be passed directly to the template
scope.overlay = overlayModel;
scope.key = key;
@ -38,12 +48,7 @@ define(
element = $compile(TEMPLATE)(scope);
$document.find('body').prepend(element);
// Stop showing the overlay; additionally, release the scope
// that it uses.
function dismiss() {
scope.$destroy();
element.remove();
}
return {
dismiss: dismiss
@ -57,11 +62,12 @@ define(
* template (as pointed to by the `key` argument) is
* responsible for having a useful z-order, and for
* blocking user interactions if appropriate.
*
* @param {string} key the symbolic key which identifies
* the template of the overlay to be shown
* @param {object} overlayModel the model to pass to the
* included overlay template (this will be passed
* in via ng-model)
* @param {string} key the symbolic key which identifies
* the template of the overlay to be shown
*/
createOverlay: createOverlay
};