Henry
2015-11-17 15:01:13 -08:00
parent ba669f1395
commit 2251a0c1e9
5 changed files with 106 additions and 70 deletions

View File

@@ -78,7 +78,7 @@
"implementation": "actions/CancelAction.js",
"name": "Cancel",
"description": "Discard changes made to these objects.",
"depends": ["$location", "urlService"]
"depends": ["$injector", "navigationService"]
}
],
"policies": [

View File

@@ -33,10 +33,10 @@ define(
* @memberof platform/commonUI/edit
* @implements {Action}
*/
function CancelAction($location, urlService, context) {
function CancelAction($injector, navigationService, context) {
this.domainObject = context.domainObject;
this.$location = $location;
this.urlService = urlService;
this.navigationService = navigationService;
this.objectService = $injector.get('objectService');
}
/**
@@ -47,8 +47,7 @@ define(
*/
CancelAction.prototype.perform = function () {
var domainObject = this.domainObject,
$location = this.$location,
urlService = this.urlService;
self = this;
// Look up the object's "editor.completion" capability;
// this is introduced by EditableDomainObject which is
@@ -64,13 +63,10 @@ define(
return editor.cancel();
}
// Discard the current root view (which will be the editing
// UI, which will have been pushed atop the Browise UI.)
//Discard current 'editable' object, and retrieve original
// un-edited object.
function returnToBrowse() {
$location.path(urlService.urlForLocation(
"browse",
domainObject.getOriginalObject()
));
return self.navigationService.setNavigation(self.domainObject.getOriginalObject());
}
return doCancel(getEditorCapability())

View File

@@ -70,16 +70,27 @@ define(
urlService = this.urlService,
self = this;
function doWizardSave(domainObject, parent) {
function resolveWith(object){
return function() {return object};
}
function doWizardSave(parent) {
var context = domainObject.getCapability("context");
var wizard = new CreateWizard(domainObject.useCapability('type'), parent, self.policyService);
// Create and persist the new object, based on user
// input.
function persistResult(formValue) {
function buildObjectFromInput(formValue) {
var parent = wizard.getLocation(formValue),
newModel = wizard.createModel(formValue);
return self.creationService.createObject(newModel, parent);
//Replace domain object model with model collected
// from user form.
domainObject.useCapability("mutation", function(){
newModel.location = parent.getId();
newModel.composition = domainObject.getModel().composition;
return newModel;
});
return domainObject;
}
function doNothing() {
@@ -87,29 +98,65 @@ define(
return false;
}
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 composeObject(object){
return object && self.$q.when(object.hasCapability('composition') && domainObject.hasCapability('composition'))
.then(function(){
return domainObject.useCapability('composition')
.then(function(composees){
return self.$q.all(composees.map(function(composee){
object.getCapability('composition').add(composee);
return object;
})).then(function(){return object});
});
});
function composeNewObject(object){
if (self.$q.when(object.hasCapability('composition') && domainObject.hasCapability('composition'))) {
return getAllComposees(domainObject)
.then(addComposeesToObject(object))
}
}
return self.dialogService.getUserInput(
wizard.getFormStructure(),
wizard.getInitialFormValue()
).then(persistResult, doNothing).then(composeObject);
return self.dialogService
.getUserInput(wizard.getFormStructure(), wizard.getInitialFormValue())
.then(buildObjectFromInput, doNothing)
//.then(composeNewObject)
//.then(object.getCapability("persistence"));
}
function persistObject(object){
return (object.hasCapability('editor') && object.getCapability('editor').save() || object.getCapability('persistence').persist())
.then(resolveWith(object));
/*
if (object.hasCapability('editor')){
return object.getCapability('editor').save(true)
.then(resolveWith(object));
} else {
return object.useCapability(persistence);
}*/
}
function fetchObject(objectId){
return self.getObjectService().getObjects([objectId]).then(function(objects){
return objects[objectId];
})
}
function getParent(object){
return fetchObject(object.getModel().location);
}
function locateObjectInParent(parent){
parent.getCapability('composition').add(domainObject.getId());
return parent;
}
// Invoke any save behavior introduced by the editor capability;
@@ -121,20 +168,30 @@ define(
//This is a new 'virtual panel' that has not been persisted
// yet.
if (domainObject.getModel().type === 'telemetry.panel' && !domainObject.getModel().persisted){
return self.getObjectService()
.getObjects([domainObject.getModel().location])
.then(function(objs){ return doWizardSave(domainObject, objs[domainObject.getModel().location])});
return getParent(domainObject)
.then(doWizardSave)
.then(persistObject)
.then(getParent)//Parent may have changed based
// on user selection
.then(locateObjectInParent)
.then(persistObject)
.then(function(){return fetchObject(domainObject.getId());})
} else {
return domainObject.getCapability("editor").save().then(function(){return domainObject.getOriginalObject()});
return domainObject.getCapability("editor").save()
.then(resolveWith(domainObject.getOriginalObject()));
}
}
// Discard the current root view (which will be the editing
// UI, which will have been pushed atop the Browse UI.)
function returnToBrowse(object) {
self.navigationService.setNavigation(object)
if (object) {
self.navigationService.setNavigation(object);
}
return object;
}
//return doSave().then(returnToBrowse);
return doSave().then(returnToBrowse);
};