[New Edit Mode] #628 Removed duplicate logic from Create Action

This commit is contained in:
Henry 2016-05-23 15:03:20 -07:00
parent 5b6ea600ba
commit eff46b076c
2 changed files with 23 additions and 13 deletions

View File

@ -83,25 +83,29 @@ define(
CreateAction.prototype.perform = function () {
var newModel = this.type.getInitialModel(),
parentObject = this.navigationService.getNavigation(),
editorCapability,
newObject;
newObject,
editAction,
editorCapability;
function onSave() {
return editorCapability.save();
}
function onCancel() {
return editorCapability.cancel();
}
newModel.type = this.type.getKey();
newModel.location = parentObject.getId();
newObject = parentObject.useCapability('instantiation', newModel);
editorCapability = newObject.hasCapability('editor') && newObject.getCapability("editor");
editorCapability = newObject.getCapability("editor");
if (countEditableViews(newObject) > 0 && newObject.hasCapability('composition')) {
this.navigationService.setNavigation(newObject);
return newObject.getCapability("action").perform("edit");
} else {
editAction = newObject.getCapability("action").getActions("edit")[0];
if (editAction) {
return editAction.perform("edit");
} else if (editorCapability) {
editorCapability.edit();
return newObject.useCapability("action").perform("save").then(function () {
return editorCapability.save();
}, function () {
return editorCapability.cancel();
});
return newObject.useCapability("action").perform("save").then(onSave, onCancel);
}
};

View File

@ -74,6 +74,12 @@ define(
self.domainObject.getCapability('editor').cancel();
self.navigationService.removeListener(cancelEditing);
}
//If this is not the currently navigated object, then navigate
// to it.
if (this.navigationService.getNavigation() !== this.domainObject) {
this.navigationService.setNavigation(this.domainObject);
}
this.navigationService.addListener(cancelEditing);
this.domainObject.useCapability("editor");
};