From b0cb8a8455a9fae5455cc6520c9e6fbe1b75d3b4 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 25 Nov 2014 22:58:34 -0800 Subject: [PATCH] [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. --- .../edit/src/capabilities/EditorCapability.js | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/platform/commonUI/edit/src/capabilities/EditorCapability.js b/platform/commonUI/edit/src/capabilities/EditorCapability.js index 7956ac26ee..5ac88d0b68 100644 --- a/platform/commonUI/edit/src/capabilities/EditorCapability.js +++ b/platform/commonUI/edit/src/capabilities/EditorCapability.js @@ -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); } }; };