[Common UI] Initial commonUI bundles

Bring in work on general-purpose and over-arching
user interface bundles from the sandbox transition
branch. WTD-574.
This commit is contained in:
Victor Woeltjen
2014-11-23 15:41:20 -08:00
parent 0cd331e8a5
commit 1b0303e517
73 changed files with 6035 additions and 0 deletions

View File

@ -0,0 +1,29 @@
/*global define,Promise*/
/**
* Module defining AccordionController. Created by vwoeltje on 11/14/14.
*/
define(
[],
function () {
"use strict";
/**
*
* @constructor
*/
function AccordionController() {
var isExpanded = true;
return {
toggle: function () {
isExpanded = !isExpanded;
},
expanded: function () {
return isExpanded;
}
};
}
return AccordionController;
}
);

View File

@ -0,0 +1,59 @@
/*global define,Promise*/
/**
* Module defining ActionGroupController. Created by vwoeltje on 11/14/14.
*/
define(
[],
function () {
"use strict";
/**
*
* @constructor
*/
function ActionGroupController($scope) {
function groupActions(actions) {
var groups = {},
ungrouped = [];
function assignToGroup(action) {
var metadata = action.getMetadata(),
group = metadata.group;
if (group) {
groups[group] = groups[group] || [];
groups[group].push(action);
} else {
ungrouped.push(action);
}
}
actions.forEach(assignToGroup);
$scope.ungrouped = ungrouped;
$scope.groups = Object.keys(groups).map(function (k) {
return groups[k];
});
}
function updateGroups() {
var actionCapability = $scope.action,
params = $scope.parameters ? $scope.parameters : {},
category = params.category;
if (actionCapability && category) {
groupActions(actionCapability.getActions({ category: category }));
}
}
$scope.$watch("domainObject", updateGroups);
$scope.$watch("action", updateGroups);
$scope.$watch("parameters.category", updateGroups);
$scope.ungrouped = [];
$scope.groups = [];
}
return ActionGroupController;
}
);

View File

@ -0,0 +1,27 @@
/*global define,Promise*/
/**
* Module defining ContextMenuController. Created by vwoeltje on 11/17/14.
*/
define(
[],
function () {
"use strict";
/**
*
* @constructor
*/
function ContextMenuController($scope) {
function updateActions() {
$scope.menuActions = $scope.action ?
$scope.action.getActions({ category: 'contextual' }) :
[];
}
$scope.$watch("action", updateActions);
}
return ContextMenuController;
}
);

View File

@ -0,0 +1,57 @@
/*global define,Promise*/
/**
* Module defining MCTContainer. Created by vwoeltje on 11/17/14.
*/
define(
[],
function () {
"use strict";
/**
*
* @constructor
*/
function MCTContainer(containers) {
var containerMap = {};
// Initialize container map from extensions
containers.forEach(function (container) {
var key = container.key;
containerMap[key] = Object.create(container);
containerMap[key].templateUrl = [
container.bundle.path,
container.bundle.resources,
container.templateUrl
].join("/");
});
return {
restrict: 'E',
transclude: true,
scope: true,
link: function (scope, element, attrs) {
var key = attrs.key,
container = containerMap[key],
alias = "container",
copiedAttributes = {};
if (container) {
alias = container.alias || alias;
(container.attributes || []).forEach(function (attr) {
copiedAttributes[attr] = attrs[attr];
});
}
scope[alias] = copiedAttributes;
},
templateUrl: function (element, attrs) {
var key = attrs.key;
return containerMap[key].templateUrl;
}
};
}
return MCTContainer;
}
);

View File

@ -0,0 +1,90 @@
/*global define,Promise*/
/**
* Module defining TreeNodeController. Created by vwoeltje on 11/10/14.
*/
define(
[],
function () {
"use strict";
/**
*
* @constructor
*/
function TreeNodeController($scope, navigationService) {
var navigatedObject = navigationService.getNavigation();
function idsEqual(objA, objB) {
return objA && objB && (objA.getId() === objB.getId());
}
function parentOf(domainObject) {
var context = domainObject &&
domainObject.getCapability("context");
return context && context.getParent();
}
function getId(obj) {
return obj.getId();
}
function isOnNavigationPath(nodeObject, navObject) {
var nodeContext = nodeObject &&
nodeObject.getCapability('context'),
navContext = navObject &&
navObject.getCapability('context'),
nodePath,
navPath;
if (nodeContext && navContext) {
nodePath = nodeContext.getPath().map(getId);
navPath = navContext.getPath().map(getId);
return (navPath.length > nodePath.length) &&
nodePath.map(function (id, i) {
return id === navPath[i];
}).reduce(function (a, b) {
return a && b;
}, true);
}
return false; // No context to judge by
}
function checkNavigation() {
var nodeObject = $scope.domainObject;
$scope.node.isSelected =
idsEqual(nodeObject, navigatedObject) &&
idsEqual(parentOf(nodeObject), parentOf(navigatedObject));
// Expand if necessary
if (!$scope.node.expanded && isOnNavigationPath(nodeObject, navigatedObject)) {
$scope.toggle();
}
}
function setNavigation(object) {
navigatedObject = object;
checkNavigation();
}
$scope.node = { expanded: false };
$scope.toggle = function () {
var expanded = !$scope.node.expanded;
$scope.node.expanded = expanded;
// Trigger load of composition, if needed
$scope.node.domainObject = $scope.domainObject;
};
navigationService.addListener(setNavigation);
$scope.$on("$destroy", function () {
navigationService.removeListener(setNavigation);
});
$scope.$watch("domainObject", checkNavigation);
}
return TreeNodeController;
}
);