Compare commits
	
		
			2 Commits
		
	
	
		
			plot-minim
			...
			nem_480
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | f5c194a854 | ||
|   | 76aecf148f | 
| @@ -99,7 +99,11 @@ define( | ||||
|                 model.location = parentObject.getId(); | ||||
|             }); | ||||
|  | ||||
|             if (countEditableViews(editableObject) > 0 && editableObject.hasCapability('composition')) { | ||||
|             /* Navigate immediately to new object if it has an editable | ||||
|              view and is not a sub-object of the currently editing object  */ | ||||
|             if (countEditableViews(editableObject) > 0 | ||||
|                 && editableObject.hasCapability('composition') | ||||
|                 && !parentObject.getCapability('status').get('editing')) { | ||||
|                 this.navigationService.setNavigation(editableObject); | ||||
|             } else { | ||||
|                 return editableObject.getCapability('action').perform('save'); | ||||
|   | ||||
| @@ -34,10 +34,11 @@ define( | ||||
|          * @memberof platform/commonUI/browse | ||||
|          * @constructor | ||||
|          */ | ||||
|         function CreateWizard(type, parent, policyService, initialModel) { | ||||
|             this.type = type; | ||||
|             this.model = initialModel || type.getInitialModel(); | ||||
|             this.properties = type.getProperties(); | ||||
|         function CreateWizard(parent, policyService, domainObject) { | ||||
|             this.type = domainObject.getCapability('type'); | ||||
|             this.model = domainObject.getModel(); | ||||
|             this.domainObject = domainObject; | ||||
|             this.properties = this.type.getProperties(); | ||||
|             this.parent = parent; | ||||
|             this.policyService = policyService; | ||||
|         } | ||||
| @@ -117,6 +118,27 @@ define( | ||||
|             return formValue; | ||||
|         }; | ||||
|  | ||||
|         /** | ||||
|          * Given a form with values to populate in a model, populate the | ||||
|          * model in wrapped domain object and return it. | ||||
|          * @param formValue the form model (returned from the | ||||
|          * {@link DialogService}) | ||||
|          * @returns {DomainObject} | ||||
|          */ | ||||
|         CreateWizard.prototype.buildObjectFromInput = function(formValue) { | ||||
|             var parent = this.getLocation(formValue), | ||||
|                 formModel = this.createModel(formValue); | ||||
|  | ||||
|             formModel.location = parent.getId(); | ||||
|             //Replace domain object model with model collected | ||||
|             // from user form. | ||||
|             this.domainObject.useCapability("mutation", function(){ | ||||
|                 //Replace object model with the model from the form | ||||
|                 return formModel; | ||||
|             }); | ||||
|             return this.domainObject; | ||||
|         } | ||||
|  | ||||
|         /** | ||||
|          * Based on a populated form, get the domain object which | ||||
|          * should be used as a parent for the newly-created object. | ||||
|   | ||||
| @@ -72,9 +72,8 @@ | ||||
|                 "implementation": "actions/SaveAction.js", | ||||
|                 "name": "Save", | ||||
|                 "description": "Save changes made to these objects.", | ||||
|                 "depends": [ "$q", "$location", "$injector",  "urlService", | ||||
|                     "navigationService", "policyService", "dialogService", | ||||
|                     "creationService" ], | ||||
|                 "depends": [ "$q", "$injector", "navigationService", | ||||
|                     "policyService", "dialogService" ], | ||||
|                 "priority": "mandatory" | ||||
|             }, | ||||
|             { | ||||
|   | ||||
| @@ -23,7 +23,9 @@ | ||||
|  | ||||
|  | ||||
| define( | ||||
|     ['../../../browse/src/creation/CreateWizard'], | ||||
|     [ | ||||
|         '../../../browse/src/creation/CreateWizard' | ||||
|     ], | ||||
|     function (CreateWizard) { | ||||
|         'use strict'; | ||||
|  | ||||
| @@ -35,17 +37,14 @@ define( | ||||
|          * @implements {Action} | ||||
|          * @memberof platform/commonUI/edit | ||||
|          */ | ||||
|         function SaveAction($q, $location, $injector, urlService, navigationService, policyService, dialogService, creationService, context) { | ||||
|         function SaveAction($q, $injector,  navigationService, policyService, dialogService, context) { | ||||
|             this.domainObject = (context || {}).domainObject; | ||||
|             this.$location = $location; | ||||
|             this.injectObjectService = function(){ | ||||
|                 this.objectService = $injector.get("objectService"); | ||||
|             }; | ||||
|             this.urlService = urlService; | ||||
|             this.navigationService = navigationService; | ||||
|             this.policyService = policyService; | ||||
|             this.dialogService = dialogService; | ||||
|             this.creationService = creationService; | ||||
|             this.$q = $q; | ||||
|         } | ||||
|  | ||||
| @@ -66,8 +65,7 @@ define( | ||||
|          */ | ||||
|         SaveAction.prototype.perform = function () { | ||||
|             var domainObject = this.domainObject, | ||||
|                 $location = this.$location, | ||||
|                 urlService = this.urlService, | ||||
|                 isNewObject = !(domainObject.getModel().persisted), | ||||
|                 self = this; | ||||
|  | ||||
|             function resolveWith(object){ | ||||
| @@ -78,65 +76,23 @@ define( | ||||
|  | ||||
|             function doWizardSave(parent) { | ||||
|                 var context = domainObject.getCapability("context"), | ||||
|                     wizard = new CreateWizard(domainObject.useCapability('type'), parent, self.policyService, domainObject.getModel()); | ||||
|                     wizard = new CreateWizard(parent, self.policyService, domainObject); | ||||
|  | ||||
|                 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)); | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 return self.dialogService | ||||
|                     .getUserInput(wizard.getFormStructure(), wizard.getInitialFormValue()) | ||||
|                     .then(buildObjectFromInput); | ||||
|                     .then(function(formValue) { | ||||
|                         return wizard.buildObjectFromInput(formValue); | ||||
|                     }); | ||||
|             } | ||||
|  | ||||
|  | ||||
|             function persistObject(object){ | ||||
|                 return  ((object.hasCapability('editor') && object.getCapability('editor').save(true)) || | ||||
|                         object.getCapability('persistence').persist()) | ||||
|                         .then(resolveWith(object)); | ||||
|                 if (object.hasCapability('editor')) { | ||||
|                     return object.getCapability('editor').save(true); | ||||
|                 } else { | ||||
|                     return object.getCapability('persistence').persist(); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             function fetchObject(objectId){ | ||||
| @@ -146,11 +102,19 @@ define( | ||||
|             } | ||||
|  | ||||
|             function getParent(object){ | ||||
|                 return fetchObject(object.getModel().location); | ||||
|                 //Skip lookup if parent is the navigated object | ||||
|                 if (object.getModel().location === self.navigationService.getNavigation().getId()){ | ||||
|                     return self.$q.when(self.navigationService.getNavigation()); | ||||
|                 } else { | ||||
|                     return fetchObject(object.getModel().location); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             function locateObjectInParent(parent){ | ||||
|                 parent.getCapability('composition').add(domainObject.getId()); | ||||
|                 if (!parent.getCapability('status').get('editing')){ | ||||
|                     persistObject(parent); | ||||
|                 } | ||||
|                 return parent; | ||||
|             } | ||||
|  | ||||
| @@ -164,21 +128,14 @@ define( | ||||
|             // used to insulate underlying objects from changes made | ||||
|             // during editing. | ||||
|             function doSave() { | ||||
|                 //WARNING: HACK | ||||
|                 //This is a new 'virtual object' that has not been persisted | ||||
|                 // yet. | ||||
|                 if (!domainObject.getModel().persisted){ | ||||
|                 if (isNewObject){ | ||||
|                     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()); | ||||
|                             }) | ||||
|                         .catch(doNothing) | ||||
|                             .catch(doNothing) | ||||
|                 } else { | ||||
|                     return domainObject.getCapability("editor").save() | ||||
|                         .then(resolveWith(domainObject.getOriginalObject())); | ||||
| @@ -188,8 +145,11 @@ define( | ||||
|             // Discard the current root view (which will be the editing | ||||
|             // UI, which will have been pushed atop the Browse UI.) | ||||
|             function returnToBrowse(object) { | ||||
|                 if (object) { | ||||
|                     self.navigationService.setNavigation(object); | ||||
|                 //Navigate to non-editable version of object. But first | ||||
|                 // check if parent is being edited (ie. this was a | ||||
|                 // sub-object creation) | ||||
|                 if (object && !object.getCapability('status').get('editing')) { | ||||
|                     self.navigationService.setNavigation(object.hasCapability('editor') ? object.getOriginalObject() : object); | ||||
|                 } | ||||
|                 return object; | ||||
|             } | ||||
|   | ||||
| @@ -98,9 +98,12 @@ define( | ||||
|  | ||||
|             editableObject.getCapability("status").set("editing", false); | ||||
|  | ||||
|             return nonrecursive ? | ||||
|             return (nonrecursive ? | ||||
|                 resolvePromise(doMutate()).then(doPersist).then(function(){self.cancel();}) : | ||||
|                 resolvePromise(cache.saveAll()); | ||||
|                 resolvePromise(cache.saveAll())) | ||||
|                 .then(function(){ | ||||
|                     return domainObject; | ||||
|                 }); | ||||
|         }; | ||||
|  | ||||
|         /** | ||||
|   | ||||
| @@ -101,6 +101,9 @@ define( | ||||
|  | ||||
|             // Recalculate swimlane state on changes | ||||
|             $scope.$watch("domainObject", swimlanePopulator.populate); | ||||
|             $scope.$watchCollection("domainObject.model.composition", function(){ | ||||
|                 swimlanePopulator.populate($scope.domainObject); | ||||
|             }); | ||||
|  | ||||
|             // Also recalculate whenever anything in view is modified | ||||
|             $scope.$watch(modificationSum, repopulateSwimlanes); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user