mirror of
https://github.com/nasa/openmct.git
synced 2025-02-22 10:11:06 +00:00
[Dialog] Refactor dialogService
Refactor dialogService to remove redundant code after changes for WTD-1033.
This commit is contained in:
parent
27af3a6b88
commit
8c35f9eb81
@ -16,7 +16,7 @@
|
|||||||
href=''
|
href=''
|
||||||
class="btn lg"
|
class="btn lg"
|
||||||
title="{{option.description}}"
|
title="{{option.description}}"
|
||||||
ng-click="ngModel.click(option.key)"
|
ng-click="ngModel.confirm(option.key)"
|
||||||
ng-class="{ major: $first, subtle: !$first }">
|
ng-class="{ major: $first, subtle: !$first }">
|
||||||
{{option.name}}
|
{{option.name}}
|
||||||
</a>
|
</a>
|
||||||
|
@ -26,7 +26,7 @@ define(
|
|||||||
dialogVisible = false;
|
dialogVisible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserInput(formModel, value) {
|
function getDialogResponse(key, model, resultGetter) {
|
||||||
// We will return this result as a promise, because user
|
// We will return this result as a promise, because user
|
||||||
// input is asynchronous.
|
// input is asynchronous.
|
||||||
var deferred = $q.defer(),
|
var deferred = $q.defer(),
|
||||||
@ -35,9 +35,9 @@ define(
|
|||||||
// Confirm function; this will be passed in to the
|
// Confirm function; this will be passed in to the
|
||||||
// overlay-dialog template and associated with a
|
// overlay-dialog template and associated with a
|
||||||
// OK button click
|
// OK button click
|
||||||
function confirm() {
|
function confirm(value) {
|
||||||
// Pass along the result
|
// Pass along the result
|
||||||
deferred.resolve(overlayModel.value);
|
deferred.resolve(resultGetter(value));
|
||||||
|
|
||||||
// Stop showing the dialog
|
// Stop showing the dialog
|
||||||
dismiss();
|
dismiss();
|
||||||
@ -51,6 +51,10 @@ define(
|
|||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add confirm/cancel callbacks
|
||||||
|
model.confirm = confirm;
|
||||||
|
model.cancel = cancel;
|
||||||
|
|
||||||
if (dialogVisible) {
|
if (dialogVisible) {
|
||||||
// Only one dialog should be shown at a time.
|
// Only one dialog should be shown at a time.
|
||||||
// The application design should be such that
|
// The application design should be such that
|
||||||
@ -58,26 +62,15 @@ define(
|
|||||||
$log.warn([
|
$log.warn([
|
||||||
"Dialog already showing; ",
|
"Dialog already showing; ",
|
||||||
"unable to show ",
|
"unable to show ",
|
||||||
formModel.name
|
model.name
|
||||||
].join(""));
|
].join(""));
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
} else {
|
} else {
|
||||||
// To be passed to the overlay-dialog template,
|
|
||||||
// via ng-model
|
|
||||||
overlayModel = {
|
|
||||||
title: formModel.name,
|
|
||||||
message: formModel.message,
|
|
||||||
structure: formModel,
|
|
||||||
value: value,
|
|
||||||
confirm: confirm,
|
|
||||||
cancel: cancel
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add the overlay using the OverlayService, which
|
// Add the overlay using the OverlayService, which
|
||||||
// will handle actual insertion into the DOM
|
// will handle actual insertion into the DOM
|
||||||
overlay = overlayService.createOverlay(
|
overlay = overlayService.createOverlay(
|
||||||
"overlay-dialog",
|
key,
|
||||||
overlayModel
|
model
|
||||||
);
|
);
|
||||||
|
|
||||||
// Track that a dialog is already visible, to
|
// Track that a dialog is already visible, to
|
||||||
@ -88,54 +81,37 @@ define(
|
|||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getUserInput(formModel, value) {
|
||||||
|
var overlayModel = {
|
||||||
|
title: formModel.name,
|
||||||
|
message: formModel.message,
|
||||||
|
structure: formModel,
|
||||||
|
value: value
|
||||||
|
};
|
||||||
|
|
||||||
|
// Provide result from the model
|
||||||
|
function resultGetter() {
|
||||||
|
return overlayModel.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getDialogResponse(
|
||||||
|
"overlay-dialog",
|
||||||
|
overlayModel,
|
||||||
|
resultGetter
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function getUserChoice(dialogModel) {
|
function getUserChoice(dialogModel) {
|
||||||
// We will return this result as a promise, because user
|
// We just want to pass back the result from the template
|
||||||
// input is asynchronous.
|
function echo(value) {
|
||||||
var deferred = $q.defer();
|
return value;
|
||||||
|
|
||||||
// Confirm function; this will be passed in to the
|
|
||||||
// overlay-dialog template and associated with a
|
|
||||||
// OK button click
|
|
||||||
function confirm(value) {
|
|
||||||
// Pass along the result
|
|
||||||
deferred.resolve(value);
|
|
||||||
|
|
||||||
// Stop showing the dialog
|
|
||||||
dismiss();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel function; this will be passed in to the
|
return getDialogResponse(
|
||||||
// overlay-dialog template and associated with a
|
"overlay-options",
|
||||||
// Cancel or X button click
|
{ dialog: dialogModel },
|
||||||
function cancel() {
|
echo
|
||||||
deferred.reject();
|
);
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dialogVisible) {
|
|
||||||
// Only one dialog should be shown at a time.
|
|
||||||
// The application design should be such that
|
|
||||||
// we never even try to do this.
|
|
||||||
$log.warn([
|
|
||||||
"Dialog already showing; ",
|
|
||||||
"unable to show ",
|
|
||||||
dialogModel.name
|
|
||||||
].join(""));
|
|
||||||
deferred.reject();
|
|
||||||
} else {
|
|
||||||
// Add the overlay using the OverlayService, which
|
|
||||||
// will handle actual insertion into the DOM
|
|
||||||
overlay = overlayService.createOverlay(
|
|
||||||
"overlay-options",
|
|
||||||
{ dialog: dialogModel, click: confirm, cancel: cancel }
|
|
||||||
);
|
|
||||||
|
|
||||||
// Track that a dialog is already visible, to
|
|
||||||
// avoid spawning multiple dialogs at once.
|
|
||||||
dialogVisible = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user