diff --git a/platform/commonUI/edit/src/actions/SaveAsAction.js b/platform/commonUI/edit/src/actions/SaveAsAction.js index cee67ebbfe..d13f723bb8 100644 --- a/platform/commonUI/edit/src/actions/SaveAsAction.js +++ b/platform/commonUI/edit/src/actions/SaveAsAction.js @@ -105,7 +105,8 @@ define( SaveAsAction.prototype.save = function () { var self = this, domainObject = this.domainObject, - copyService = this.copyService; + copyService = this.copyService, + toUndirty = []; function doWizardSave(parent) { var wizard = self.createWizard(parent); @@ -127,14 +128,28 @@ define( } function allowClone(objectToClone) { - return (objectToClone.getId() === domainObject.getId()) || - objectToClone.getCapability('location').isOriginal(); + var allowed = + (objectToClone.getId() === domainObject.getId()) || + objectToClone.getCapability('location').isOriginal(); + if (allowed) { + toUndirty.push(objectToClone); + } + return allowed; } function cloneIntoParent(parent) { return copyService.perform(domainObject, parent, allowClone); } + function undirty(domainObject) { + return domainObject.getCapability('persistence').refresh(); + } + + function undirtyOriginals(object) { + return Promise.all(toUndirty.map(undirty)) + .then(resolveWith(object)); + } + function commitEditingAfterClone(clonedObject) { return domainObject.getCapability("editor").save() .then(resolveWith(clonedObject)); @@ -144,6 +159,7 @@ define( .then(doWizardSave) .then(getParent) .then(cloneIntoParent) + .then(undirtyOriginals) .then(commitEditingAfterClone) .catch(resolveWith(false)); }; diff --git a/platform/commonUI/edit/src/capabilities/TransactionalPersistenceCapability.js b/platform/commonUI/edit/src/capabilities/TransactionalPersistenceCapability.js index 9bcf19c002..7bb4486b4f 100644 --- a/platform/commonUI/edit/src/capabilities/TransactionalPersistenceCapability.js +++ b/platform/commonUI/edit/src/capabilities/TransactionalPersistenceCapability.js @@ -49,6 +49,7 @@ define( this.domainObject = domainObject; this.$q = $q; this.persistPending = false; + this.removeFromTransaction = undefined; } /** @@ -75,6 +76,7 @@ define( }); } else { self.persistPending = false; + self.removeFromTransaction = undefined; //Model is undefined in persistence, so return undefined. return self.$q.when(undefined); } @@ -82,7 +84,8 @@ define( if (this.transactionService.isActive()) { if (!this.persistPending) { - this.transactionService.addToTransaction(onCommit, onCancel); + this.removeFromTransaction = this.transactionService + .addToTransaction(onCommit, onCancel); this.persistPending = true; } //Need to return a promise from this function @@ -93,6 +96,11 @@ define( }; TransactionalPersistenceCapability.prototype.refresh = function () { + if (this.persistPending) { + this.persistPending = false; + this.removeFromTransaction(); + this.removeFromTransaction = undefined; + } return this.persistenceCapability.refresh(); }; diff --git a/platform/commonUI/edit/src/services/TransactionService.js b/platform/commonUI/edit/src/services/TransactionService.js index 8d6c465959..59f196cf4b 100644 --- a/platform/commonUI/edit/src/services/TransactionService.js +++ b/platform/commonUI/edit/src/services/TransactionService.js @@ -81,6 +81,15 @@ define( //Log error because this is a programming error if it occurs. this.$log.error("No transaction in progress"); } + + return function () { + this.onCommits = this.onCommits.filter(function (callback) { + return callback !== onCommit; + }); + this.onCancels = this.onCancels.filter(function (callback) { + return callback !== onCancel; + }); + }.bind(this); }; /**