diff --git a/platform/commonUI/general/bundle.json b/platform/commonUI/general/bundle.json index 4c3bbd0a2b..2bf8f37c47 100644 --- a/platform/commonUI/general/bundle.json +++ b/platform/commonUI/general/bundle.json @@ -29,8 +29,8 @@ "depends": [ "$scope" ] }, { - "key": "AccordionController", - "implementation": "AccordionController.js" + "key": "ToggleController", + "implementation": "ToggleController.js" }, { "key": "ContextMenuController", diff --git a/platform/commonUI/general/res/templates/containers/accordion.html b/platform/commonUI/general/res/templates/containers/accordion.html index f549fa13b4..c39719f77d 100644 --- a/platform/commonUI/general/res/templates/containers/accordion.html +++ b/platform/commonUI/general/res/templates/containers/accordion.html @@ -1,9 +1,9 @@ -
-
+
+
{{container.title}}
diff --git a/platform/commonUI/general/res/templates/tree-item.html b/platform/commonUI/general/res/templates/tree-item.html index 757957e996..60c3ed276a 100644 --- a/platform/commonUI/general/res/templates/tree-item.html +++ b/platform/commonUI/general/res/templates/tree-item.html @@ -1,7 +1,9 @@ - - - - {{node.expanded ? "v" : ">"}} + + + + {{toggle.isActive() ? "v" : ">"}} - + diff --git a/platform/commonUI/general/src/AccordionController.js b/platform/commonUI/general/src/AccordionController.js deleted file mode 100644 index 56e2e74d23..0000000000 --- a/platform/commonUI/general/src/AccordionController.js +++ /dev/null @@ -1,29 +0,0 @@ -/*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; - } -); \ No newline at end of file diff --git a/platform/commonUI/general/src/ActionGroupController.js b/platform/commonUI/general/src/ActionGroupController.js index b9fb3e8d42..5f1c2d3ea1 100644 --- a/platform/commonUI/general/src/ActionGroupController.js +++ b/platform/commonUI/general/src/ActionGroupController.js @@ -38,7 +38,7 @@ define( function updateGroups() { var actionCapability = $scope.action, - params = $scope.parameters ? $scope.parameters : {}, + params = $scope.parameters || {}, category = params.category; if (actionCapability && category) { diff --git a/platform/commonUI/general/src/ToggleController.js b/platform/commonUI/general/src/ToggleController.js new file mode 100644 index 0000000000..e1268a47bb --- /dev/null +++ b/platform/commonUI/general/src/ToggleController.js @@ -0,0 +1,45 @@ +/*global define,Promise*/ + +define( + [], + function () { + "use strict"; + + /** + * A ToggleController is used to activate/deactivate things. + * A common usage is for "twistie" + * + * @constructor + */ + function ToggleController() { + var state = false; + + return { + /** + * Get the current state of the toggle. + * @return {boolean} true if active + */ + isActive: function () { + return state; + }, + /** + * Set a new state for the toggle. + * @return {boolean} true to activate + */ + setState: function (newState) { + state = newState; + }, + /** + * Toggle the current state; activate if it is inactive, + * deactivate if it is active. + */ + toggle: function () { + state = !state; + } + }; + + } + + return ToggleController; + } +); \ No newline at end of file diff --git a/platform/commonUI/general/src/TreeNodeController.js b/platform/commonUI/general/src/TreeNodeController.js index 64b9e8677b..1593393fe7 100644 --- a/platform/commonUI/general/src/TreeNodeController.js +++ b/platform/commonUI/general/src/TreeNodeController.js @@ -29,6 +29,15 @@ define( return obj.getId(); } + // Verify that id paths are equivalent, staring at + // index, ending at the end of the node path. + function checkPath(nodePath, navPath, index) { + index = index || 0; + return index > nodePath.length || + (navPath[index] === nodePath[index] && + checkPath(nodePath, navPath, index + 1)); + } + function isOnNavigationPath(nodeObject, navObject) { var nodeContext = nodeObject && nodeObject.getCapability('context'), @@ -41,12 +50,7 @@ define( 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); - + checkPath(nodePath, navPath); } return false; // No context to judge by } @@ -58,8 +62,10 @@ define( idsEqual(nodeObject, navigatedObject) && idsEqual(parentOf(nodeObject), parentOf(navigatedObject)); // Expand if necessary - if (!$scope.node.expanded && isOnNavigationPath(nodeObject, navigatedObject)) { - $scope.toggle(); + if (!$scope.node.expanded && + isOnNavigationPath(nodeObject, navigatedObject) && + $scope.toggle !== undefined) { + $scope.toggle.toggle(); } } @@ -68,21 +74,25 @@ define( checkNavigation(); } - $scope.node = { expanded: false }; + // When the node is expanded, set "node.domainObject" in + // the scope; this is used to populate the subtree, which + // should only happen when first expanded (lazy loading) + function doExpand(state) { + if (state) { + $scope.node.domainObject = $scope.domainObject; + } + } - $scope.toggle = function () { - var expanded = !$scope.node.expanded; - $scope.node.expanded = expanded; - - // Trigger load of composition, if needed - $scope.node.domainObject = $scope.domainObject; - }; + // Set up a little namespace for tree node properties + $scope.node = {}; navigationService.addListener(setNavigation); $scope.$on("$destroy", function () { navigationService.removeListener(setNavigation); }); $scope.$watch("domainObject", checkNavigation); + $scope.$watch("toggle.isActive()", doExpand); + } return TreeNodeController;