Resovled merge conflicts

This commit is contained in:
Henry
2016-05-12 15:58:17 -07:00
parent 116c6e57ed
commit e5ef7c0c22
6 changed files with 381 additions and 86 deletions

View File

@@ -24,12 +24,10 @@ define(
[],
function () {
/**
* Implements "save" and "cancel" as capabilities of
* the object. In editing mode, user is seeing/using
* a copy of the object (an EditableDomainObject)
* which is disconnected from persistence; the Save
* a copy of the object which is disconnected from persistence; the Save
* and Cancel actions can use this capability to
* propagate changes from edit mode to the underlying
* actual persistable object.
@@ -41,99 +39,37 @@ define(
* @memberof platform/commonUI/edit
*/
function EditorCapability(
persistenceCapability,
editableObject,
domainObject,
cache
transactionService,
dirtyModelCache,
domainObject
) {
this.editableObject = editableObject;
this.transactionService = transactionService;
this.dirtyModelCache = dirtyModelCache;
this.domainObject = domainObject;
this.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));
}
};
}
EditorCapability.prototype.edit = function () {
this.transactionService.startTransaction();
this.getCapability('status').set('editing', true);
};
/**
* Save any changes that have been made to this domain object
* (as well as to others that might have been retrieved and
* modified during the editing session)
* @param {boolean} nonrecursive if true, save only this
* object (and not other objects with associated changes)
* @returns {Promise} a promise that will be fulfilled after
* persistence has completed.
* @memberof platform/commonUI/edit.EditorCapability#
*/
EditorCapability.prototype.save = function (nonrecursive) {
var domainObject = this.domainObject,
editableObject = this.editableObject,
self = this,
cache = this.cache,
returnPromise;
EditorCapability.prototype.save = function () {
return this.transactionService.commit();
};
// Update the underlying, "real" domain object's model
// with changes made to the copy used for editing.
function doMutate() {
return domainObject.useCapability('mutation', function () {
return editableObject.getModel();
});
}
// Persist the underlying domain object
function doPersist() {
return domainObject.getCapability('persistence').persist();
}
editableObject.getCapability("status").set("editing", false);
if (nonrecursive) {
returnPromise = resolvePromise(doMutate())
.then(doPersist)
.then(function(){
self.cancel();
});
} else {
returnPromise = resolvePromise(cache.saveAll());
}
//Return the original (non-editable) object
return returnPromise.then(function() {
return domainObject.getOriginalObject ? domainObject.getOriginalObject() : domainObject;
EditorCapability.prototype.cancel = function () {
var domainObject = this.domainObject;
return this.transactionService.cancel().then(function(){
domainObject.getCapability("status").set("editing", false);
});
};
/**
* Cancel editing; Discard any changes that have been made to
* this domain object (as well as to others that might have
* been retrieved and modified during the editing session)
* @returns {Promise} a promise that will be fulfilled after
* cancellation has completed.
* @memberof platform/commonUI/edit.EditorCapability#
*/
EditorCapability.prototype.cancel = function () {
this.editableObject.getCapability("status").set("editing", false);
this.cache.markClean();
return resolvePromise(undefined);
EditorCapability.prototype.dirty = function () {
return this.dirtyModelCache.isDirty(this.domainObject);
};
/**
* Check if there are any unsaved changes.
* @returns {boolean} true if there are unsaved changes
* @memberof platform/commonUI/edit.EditorCapability#
*/
EditorCapability.prototype.dirty = function () {
return this.cache.dirty();
};
//TODO: add 'appliesTo'. EditorCapability should not be available
// for objects that should not be edited
return EditorCapability;
}