[API] Support distinct region registration

This commit is contained in:
Victor Woeltjen 2016-06-17 13:10:24 -07:00
parent 1f96e84542
commit eec9b1cf4c
3 changed files with 32 additions and 20 deletions

View File

@ -31,18 +31,24 @@ define([
MCT.prototype.view = function (region, factory) {
var viewKey = region + uuid();
var adaptedViewKey = "adapted-view-" + viewKey;
var adaptedViewKey = "adapted-view-" + region;
this.legacyExtension('views', {
name: "A view",
key: adaptedViewKey,
editable: true,
template: '<mct-view key="\'' +
viewKey +
'\'" ' +
'mct-object="domainObject">' +
'</mct-view>'
});
this.legacyExtension(
region === this.regions.main ? 'views' : 'representations',
{
name: "A view",
key: adaptedViewKey,
editable: true,
template: '<mct-view region="\'' +
region +
'\'" ' +
'key="\'' +
viewKey +
'\'" ' +
'mct-object="domainObject">' +
'</mct-view>'
}
);
this.legacyExtension('policies', {
category: "view",

View File

@ -3,24 +3,21 @@ define(['angular'], function (angular) {
var factories = {};
newViews.forEach(function (newView) {
factories[newView.key] = newView.factory;
factories[newView.region] = factories[newView.region] || {};
factories[newView.region][newView.key] = newView.factory;
});
return {
restrict: 'E',
link: function (scope, element, attrs) {
var key = undefined;
var mctObject = undefined;
var key, mctObject, region;
function maybeShow() {
if (!factories[key]) {
return;
}
if (!mctObject) {
if (!factories[region] || !factories[region][key] || !mctObject) {
return;
}
var view = factories[key](mctObject);
var view = factories[region][key](mctObject);
view.show(element[0]);
}
@ -34,12 +31,19 @@ define(['angular'], function (angular) {
maybeShow();
}
function setRegion(r) {
region = r;
maybeShow();
}
scope.$watch('key', setKey);
scope.$watch('region', setRegion);
scope.$watch('mctObject', setObject);
},
scope: {
key: "=",
region: "=",
mctObject: "="
}
};

View File

@ -27,7 +27,9 @@
<div class="holder l-flex-col flex-elem grows l-object-wrapper-inner">
<!-- Toolbar and Save/Cancel buttons -->
<div class="l-edit-controls flex-elem l-flex-row flex-align-end">
<span>This is where a toolbar will go.</span>
<mct-representation key="adapted-view-TOOLBAR"
mct-object="domainObject">
</mct-representation>
<mct-representation key="'edit-action-buttons'"
mct-object="domainObject"
class='flex-elem conclude-editing'>