Resolved merge conflicts

This commit is contained in:
Henry 2016-05-12 16:03:19 -07:00
parent e5ef7c0c22
commit bd686790dc
11 changed files with 53 additions and 91 deletions

View File

@ -24,11 +24,8 @@
* Module defining CreateAction. Created by vwoeltje on 11/10/14.
*/
define(
[
'./CreateWizard',
'../../../edit/src/objects/EditableDomainObject'
],
function (CreateWizard, EditableDomainObject) {
[],
function () {
/**
* The Create Action is performed to create new instances of
@ -86,22 +83,19 @@ define(
CreateAction.prototype.perform = function () {
var newModel = this.type.getInitialModel(),
parentObject = this.navigationService.getNavigation(),
newObject,
editableObject;
newObject;
newModel.type = this.type.getKey();
newObject = parentObject.useCapability('instantiation', newModel);
editableObject = new EditableDomainObject(newObject, this.$q);
editableObject.setOriginalObject(parentObject);
editableObject.getCapability('status').set('editing', true);
editableObject.useCapability('mutation', function(model){
newObject.useCapability('mutation', function(model){
model.location = parentObject.getId();
});
if (countEditableViews(editableObject) > 0 && editableObject.hasCapability('composition')) {
this.navigationService.setNavigation(editableObject);
if (countEditableViews(newObject) > 0 && newObject.hasCapability('composition')) {
this.navigationService.setNavigation(newObject);
newObject.getCapability("action").perform("edit");
} else {
return editableObject.getCapability('action').perform('save');
return newObject.getCapability('action').perform('save');
}
};

View File

@ -201,7 +201,8 @@ define([
"description": "Discard changes made to these objects.",
"depends": [
"$injector",
"navigationService"
"navigationService",
"$window"
]
}
],

View File

@ -44,30 +44,16 @@ define(
* cancellation has completed
*/
CancelAction.prototype.perform = function () {
var domainObject = this.domainObject,
self = this;
var domainObject = this.domainObject;
// Look up the object's "editor.completion" capability;
// this is introduced by EditableDomainObject which is
// used to insulate underlying objects from changes made
// during editing.
function getEditorCapability() {
return domainObject.getCapability("editor");
function returnToBrowse () {
var parent;
domainObject.getCapability("location").getOriginal().then(function (original) {
parent = original.getCapability("context").getParent();
parent.getCapability("action").perform("navigate");
});
}
// Invoke any save behavior introduced by the editor.completion
// capability.
function doCancel(editor) {
return editor.cancel();
}
//Discard current 'editable' object, and retrieve original
// un-edited object.
function returnToBrowse() {
return self.navigationService.setNavigation(self.domainObject.getOriginalObject());
}
return doCancel(getEditorCapability())
return this.domainObject.getCapability("editor").cancel()
.then(returnToBrowse);
};

View File

@ -71,25 +71,12 @@ define(
*/
EditAction.prototype.perform = function () {
var self = this;
if (!this.domainObject.hasCapability("editor")) {
//TODO: This is only necessary because the drop gesture is
// wrapping the object itself, need to refactor this later.
// All responsibility for switching into edit mode should be
// in the edit action, and not duplicated in the gesture
this.domainObject = new EditableDomainObject(this.domainObject, this.$q);
}
this.navigationService.setNavigation(this.domainObject);
this.domainObject.getCapability('status').set('editing', true);
//Register a listener to automatically cancel this edit action
//if the user navigates away from this object.
function cancelEditing(navigatedTo){
if (!navigatedTo || navigatedTo.getId() !== self.domainObject.getId()) {
self.domainObject.getCapability('editor').cancel();
self.navigationService.removeListener(cancelEditing);
}
function cancelEditing(){
self.domainObject.getCapability('editor').cancel();
self.navigationService.removeListener(cancelEditing);
}
this.navigationService.addListener(cancelEditing);
this.domainObject.useCapability("editor");
};
/**

View File

@ -50,17 +50,23 @@ define(
EditorCapability.prototype.edit = function () {
this.transactionService.startTransaction();
this.getCapability('status').set('editing', true);
this.domainObject.getCapability('status').set('editing', true);
};
EditorCapability.prototype.save = function () {
return this.transactionService.commit();
var domainObject = this.domainObject;
return this.transactionService.commit().then(function() {
domainObject.getCapability('status').set('editing', false);
});
};
EditorCapability.prototype.invoke = EditorCapability.prototype.edit;
EditorCapability.prototype.cancel = function () {
var domainObject = this.domainObject;
return this.transactionService.cancel().then(function(){
domainObject.getCapability("status").set("editing", false);
return domainObject;
});
};

View File

@ -58,7 +58,8 @@ define(
* transaction is in progress.
*/
TransactionDecorator.prototype.getCapabilities = function (model) {
var capabilities = this.capabilityService.getCapabilities(model),
var self = this,
capabilities = this.capabilityService.getCapabilities(model),
persistenceCapability = capabilities.persistence;
capabilities.persistence = function (domainObject) {

View File

@ -57,7 +57,9 @@ define(
};
TransactionalPersistenceCapability.prototype.refresh = function () {
var dirtyModelCache = this.dirtyModelCache;
var domainObject = this.domainObject,
dirtyModelCache = this.dirtyModelCache;
return this.persistenceCapability.refresh().then(function (result) {
dirtyModelCache.markClean(domainObject);
return result;

View File

@ -32,7 +32,7 @@ define(
};
DirtyModelCache.prototype.isDirty = function (domainObject) {
return !!this.get(domainObject.getId());
return !!this.cache[domainObject.getId()];
};
DirtyModelCache.prototype.markDirty = function (domainObject) {

View File

@ -39,9 +39,8 @@ define(
}
TransactionService.prototype.startTransaction = function () {
if (this.transaction) {
throw "Transaction in progress";
}
if (this.transaction)
console.error("Transaction already in progress")
this.transaction = true;
};
@ -68,7 +67,7 @@ define(
}
return this.$q.all(
Object.keys(this.cache)
Object.keys(cache)
.map(keyToObject)
.map(objectToPromise))
.then(function () {
@ -93,7 +92,7 @@ define(
}
function objectToPromise(object) {
return object.getCapability('persistence').refresh();
return self.$q.when(object.getModel().persisted && object.getCapability('persistence').refresh());
}
return this.$q.all(Object.keys(cache)

View File

@ -168,13 +168,10 @@ define(
}, modified);
}
// Only update if we don't have unsaved changes
return (model.modified === model.persisted) ?
this.persistenceService.readObject(
return this.persistenceService.readObject(
this.getSpace(),
this.domainObject.getId()
).then(updateModel) :
fastPromise(false);
).then(updateModel);
};
/**

View File

@ -24,9 +24,8 @@
* Module defining DropGesture. Created by vwoeltje on 11/17/14.
*/
define(
['./GestureConstants',
'../../../commonUI/edit/src/objects/EditableDomainObject'],
function (GestureConstants, EditableDomainObject) {
['./GestureConstants'],
function (GestureConstants) {
/**
* A DropGesture adds and maintains event handlers upon an element
@ -41,7 +40,6 @@ define(
*/
function DropGesture(dndService, $q, navigationService, instantiate, typeService, element, domainObject) {
var actionCapability = domainObject.getCapability('action'),
editableDomainObject,
scope = element.scope && element.scope(),
action; // Action for the drop, when it occurs
@ -66,23 +64,13 @@ define(
x: event.pageX - rect.left,
y: event.pageY - rect.top
},
editableDomainObject
domainObject
);
}
}
function dragOver(e) {
//Refresh domain object on each dragOver to catch external
// updates to the model
//Don't use EditableDomainObject for folders, allow immediate persistence
if (domainObject.hasCapability('editor') ||
domainObject.getModel().type==='folder') {
editableDomainObject = domainObject;
} else {
editableDomainObject = new EditableDomainObject(domainObject, $q);
}
actionCapability = editableDomainObject.getCapability('action');
actionCapability = domainObject.getCapability('action');
var event = (e || {}).originalEvent || e,
selectedObject = dndService.getData(
@ -108,18 +96,19 @@ define(
function drop(e) {
var event = (e || {}).originalEvent || e,
id = event.dataTransfer.getData(GestureConstants.MCT_DRAG_TYPE),
domainObjectType = editableDomainObject.getModel().type;
domainObjectType = domainObject.getModel().type;
// Handle the drop; add the dropped identifier to the
// destination domain object's composition, and persist
// the change.
if (id) {
e.preventDefault();
$q.when(action && action.perform()).then(function (result) {
//Don't go into edit mode for folders
if (domainObjectType!=='folder') {
editableDomainObject.getCapability('action').perform('edit');
}
if (domainObjectType!=='folder') {
domainObject.getCapability('action').perform('edit');
}
$q.when(action && action.perform()).then(function () {
broadcastDrop(id, event);
});
}