[New Edit Mode] Added AddAction, modified EditableDomainObject to properly wrap inherited functions, added new EditableInstantiationCapability

This commit is contained in:
Henry
2016-01-20 18:49:39 -08:00
parent fcae3fd7a9
commit c65096f166
13 changed files with 512 additions and 71 deletions

View File

@@ -79,63 +79,18 @@ define(
function doWizardSave(parent) {
var context = domainObject.getCapability("context"),
wizard = new CreateWizard(domainObject.useCapability('type'), parent, self.policyService, domainObject.getModel());
function mergeObjects(fromObject, toObject){
Object.keys(fromObject).forEach(function(key) {
toObject[key] = fromObject[key];
});
}
// Create and persist the new object, based on user
// input.
function buildObjectFromInput(formValue) {
var parent = wizard.getLocation(formValue),
formModel = wizard.createModel(formValue);
formModel.location = parent.getId();
//Replace domain object model with model collected
// from user form.
domainObject.useCapability("mutation", function(){
//Replace object model with the model from the form
return formModel;
});
return domainObject;
}
function getAllComposees(domainObject){
return domainObject.useCapability('composition');
}
function addComposeesToObject(object){
return function(composees){
return self.$q.all(composees.map(function (composee) {
return object.getCapability('composition').add(composee);
})).then(resolveWith(object));
};
}
/**
* Add the composees of the 'virtual' object to the
* persisted object
* @param object
* @returns {*}
*/
function composeNewObject(object){
if (self.$q.when(object.hasCapability('composition') && domainObject.hasCapability('composition'))) {
return getAllComposees(domainObject)
.then(addComposeesToObject(object));
}
}
wizard = new CreateWizard(domainObject, parent, self.policyService);
return self.dialogService
.getUserInput(wizard.getFormStructure(), wizard.getInitialFormValue())
.then(buildObjectFromInput);
.then(function(formValue){
wizard.populateObjectFromInput(formValue, domainObject)
});
}
function persistObject(object){
return ((object.hasCapability('editor') && object.getCapability('editor').save(true)) ||
return ((object.hasCapability('editor') && object.getCapability('editor').save()) ||
object.getCapability('persistence').persist())
.then(resolveWith(object));
}