mirror of
https://github.com/nasa/openmct.git
synced 2025-06-17 06:38:17 +00:00
[Common UI] Fix Save/Cancel quirk
Fix a defect in the Save/Cancel buttons in Edit mode that was causing the first click to be missed; this was due to Angular's inability to detect when a native promise (as opposed to one from ) had been resolved. Since the Editor capability is introduced indirectly and is a few degrees of separation removed from the declared extension layer (where we would be able to get a reference to ), and all we need to do is make something look Promise-like, a convenience function to do this is added. Part of ongoing transition of common user interface elements, WTD-574.
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
/*global define,Promise*/
|
/*global define*/
|
||||||
|
|
||||||
define(
|
define(
|
||||||
[],
|
[],
|
||||||
@ -26,6 +26,20 @@ define(
|
|||||||
cache
|
cache
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
// Simulate Promise.resolve (or $q.when); the former
|
||||||
|
// causes a delayed reaction from Angular (since it
|
||||||
|
// does not trigger a digest) and the latter is not
|
||||||
|
// readily accessible, since we're a few classes
|
||||||
|
// removed from the layer which gets dependency
|
||||||
|
// injection.
|
||||||
|
function resolvePromise(value) {
|
||||||
|
return value && value.then ? value : {
|
||||||
|
then: function (callback) {
|
||||||
|
return resolvePromise(callback(value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Update the underlying, "real" domain object's model
|
// Update the underlying, "real" domain object's model
|
||||||
// with changes made to the copy used for editing.
|
// with changes made to the copy used for editing.
|
||||||
function doMutate() {
|
function doMutate() {
|
||||||
@ -60,7 +74,7 @@ define(
|
|||||||
* persistence has completed.
|
* persistence has completed.
|
||||||
*/
|
*/
|
||||||
save: function () {
|
save: function () {
|
||||||
return Promise.resolve(doMutate())
|
return resolvePromise(doMutate())
|
||||||
.then(doPersist)
|
.then(doPersist)
|
||||||
.then(markClean)
|
.then(markClean)
|
||||||
.then(saveOthers);
|
.then(saveOthers);
|
||||||
@ -73,7 +87,7 @@ define(
|
|||||||
* cancellation has completed.
|
* cancellation has completed.
|
||||||
*/
|
*/
|
||||||
cancel: function () {
|
cancel: function () {
|
||||||
return Promise.resolve(undefined);
|
return resolvePromise(undefined);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user