[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:
Victor Woeltjen 2014-11-25 22:58:34 -08:00
parent 52ec1aeb89
commit b0cb8a8455

View File

@ -1,4 +1,4 @@
/*global define,Promise*/
/*global define*/
define(
[],
@ -26,6 +26,20 @@ define(
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
// with changes made to the copy used for editing.
function doMutate() {
@ -60,7 +74,7 @@ define(
* persistence has completed.
*/
save: function () {
return Promise.resolve(doMutate())
return resolvePromise(doMutate())
.then(doPersist)
.then(markClean)
.then(saveOthers);
@ -73,7 +87,7 @@ define(
* cancellation has completed.
*/
cancel: function () {
return Promise.resolve(undefined);
return resolvePromise(undefined);
}
};
};