mirror of
https://github.com/nasa/openmct.git
synced 2025-04-07 11:26:49 +00:00
[Layout] Add auto-save behavior
Add an EditRepresenter which detects changes to domain object model or view configuration and, when these occur, triggers mutation and persistence of the domain object. (Note that in Edit mode, 'persistence' only flags an object as dirty; actual persistence does not occur until the user chooses Save.) This supports editing of position/size in Layout mode, and the persistence of those changes. WTD-535
This commit is contained in:
parent
67b9af54b3
commit
a6de53c118
@ -89,6 +89,12 @@
|
||||
"key": "topbar-edit",
|
||||
"templateUrl": "templates/topbar-edit.html"
|
||||
}
|
||||
],
|
||||
"representers": [
|
||||
{
|
||||
"implementation": "EditRepresenter.js",
|
||||
"depends": [ "$q" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
62
platform/commonUI/edit/src/EditRepresenter.js
Normal file
62
platform/commonUI/edit/src/EditRepresenter.js
Normal file
@ -0,0 +1,62 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
function EditRepresenter($q, scope, element, attrs) {
|
||||
var watches = [],
|
||||
domainObject,
|
||||
key;
|
||||
|
||||
function doPersist(model) {
|
||||
return $q.when(function () {
|
||||
return domainObject.useCapability("mutation", function () {
|
||||
return model;
|
||||
});
|
||||
}).then(function (result) {
|
||||
return result &&
|
||||
domainObject.getCapability("persistence").persist();
|
||||
});
|
||||
}
|
||||
|
||||
function update() {
|
||||
var model = scope.model,
|
||||
configuration = scope.configuration,
|
||||
key = scope.key;
|
||||
|
||||
if (domainObject && domainObject.hasCapability("persistence")) {
|
||||
model.configuration = model.configuration || {};
|
||||
model.configuration[key] = configuration;
|
||||
doPersist(model);
|
||||
}
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
// Stop watching for changes
|
||||
watches.forEach(function (deregister) { deregister(); });
|
||||
watches = [];
|
||||
}
|
||||
|
||||
function represent(representation, representedObject) {
|
||||
key = representation.key;
|
||||
domainObject = representedObject;
|
||||
|
||||
destroy(); // Ensure existing watches are released
|
||||
|
||||
watches = representedObject.hasCapability("editor") ? [
|
||||
scope.$watch("model", update, true),
|
||||
scope.$watch("configuration", update, true)
|
||||
] : [];
|
||||
}
|
||||
|
||||
return {
|
||||
represent: represent,
|
||||
destroy: destroy
|
||||
};
|
||||
}
|
||||
|
||||
return EditRepresenter;
|
||||
}
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user