[Layout] Store position/size changes

Store changes to the size and position of panels in a
layout to its configuration. The mct-representation
directive (and its constituent parts) is responsible
for detecting and persisting these changes as
appropriate. WTD-535.
This commit is contained in:
Victor Woeltjen 2014-12-05 12:49:40 -08:00
parent a6de53c118
commit 7dadc62f23

View File

@ -15,6 +15,15 @@ define(
rawPositions = {}, rawPositions = {},
positions = {}; positions = {};
function shallowCopy(obj, keys) {
var copy = {};
keys.forEach(function (k) {
copy[k] = obj[k];
});
return copy;
}
function convertPosition(raw) { function convertPosition(raw) {
return { return {
left: (width * raw.position[0]) + 'px', left: (width * raw.position[0]) + 'px',
@ -39,10 +48,11 @@ define(
} }
function lookupPanels(model) { function lookupPanels(model) {
var configuration = var configuration = $scope.configuration || {},
((model || {}).configuration || {}).layout || {}; ids = (model || {}).composition || [];
// Clear prior positions // Clear prior positions
rawPositions = shallowCopy(configuration.panels || {}, ids);
positions = {}; positions = {};
// Update width/height that we are tracking // Update width/height that we are tracking
@ -50,7 +60,7 @@ define(
// Pull values from panels field to rawPositions // Pull values from panels field to rawPositions
// Compute positions and add defaults where needed // Compute positions and add defaults where needed
((model || {}).composition || []).forEach(populatePosition); ids.forEach(populatePosition);
} }
$scope.$watch("model", lookupPanels); $scope.$watch("model", lookupPanels);
@ -76,7 +86,14 @@ define(
} }
}, },
endDrag: function () { endDrag: function () {
// TODO: Mutate, persist // Write to configuration; this is watched and
// saved by the EditRepresenter.
$scope.configuration =
$scope.configuration || {};
$scope.configuration.panels =
$scope.configuration.panels || {};
$scope.configuration.panels[activeDragId] =
rawPositions[activeDragId];
} }
}; };