Added tests, and fixed failing ones

This commit is contained in:
Henry
2016-05-24 10:23:48 -07:00
parent 96af931c0b
commit f0ab817e87
5 changed files with 103 additions and 80 deletions

View File

@@ -43,11 +43,8 @@ define(
* override this)
* @param {ActionContext} context the context in which the
* action is being performed
* @param {NavigationService} navigationService the navigation service,
* which handles changes in navigation. It allows the object
* being browsed/edited to be set.
*/
function CreateAction(type, parent, context, $q, navigationService) {
function CreateAction(type, parent, context) {
this.metadata = {
key: 'create',
glyph: type.getGlyph(),
@@ -56,24 +53,8 @@ define(
description: type.getDescription(),
context: context
};
this.type = type;
this.parent = parent;
this.navigationService = navigationService;
this.$q = $q;
}
// Get a count of views which are not flagged as non-editable.
function countEditableViews(domainObject) {
var views = domainObject && domainObject.useCapability('view'),
count = 0;
// A view is editable unless explicitly flagged as not
(views || []).forEach(function (view) {
count += (view.editable !== false) ? 1 : 0;
});
return count;
}
/**
@@ -82,7 +63,6 @@ define(
*/
CreateAction.prototype.perform = function () {
var newModel = this.type.getInitialModel(),
parentObject = this.navigationService.getNavigation(),
newObject,
editAction,
editorCapability;
@@ -96,16 +76,18 @@ define(
}
newModel.type = this.type.getKey();
newModel.location = parentObject.getId();
newObject = parentObject.useCapability('instantiation', newModel);
newModel.location = this.parent.getId();
newObject = this.parent.useCapability('instantiation', newModel);
editorCapability = newObject.hasCapability('editor') && newObject.getCapability("editor");
editAction = newObject.getCapability("action").getActions("edit")[0];
//If an edit action is available, perform it
if (editAction) {
return editAction.perform("edit");
return editAction.perform();
} else if (editorCapability) {
//otherwise, use the save action
editorCapability.edit();
return newObject.useCapability("action").perform("save").then(onSave, onCancel);
return newObject.getCapability("action").perform("save").then(onSave, onCancel);
}
};

View File

@@ -44,10 +44,8 @@ define(
* introduced in this bundle), responsible for handling actual
* object creation.
*/
function CreateActionProvider($q, typeService, navigationService, policyService) {
function CreateActionProvider(typeService, policyService) {
this.typeService = typeService;
this.navigationService = navigationService;
this.$q = $q;
this.policyService = policyService;
}
@@ -72,9 +70,7 @@ define(
return new CreateAction(
type,
destination,
context,
self.$q,
self.navigationService
context
);
});
};