/**
* UI tools and directives.
*/
-angular.module('egUiMod', ['ui.bootstrap'])
+angular.module('egUiMod', ['egCoreMod', 'ui.bootstrap'])
/**
return service;
})
+
+/**
+ * Nested org unit selector modeled as a Bootstrap dropdown button.
+ */
+.directive('egOrgSelector', function() {
+ return {
+ restrict : 'AE',
+ transclude : true,
+ scope : {
+ selected : '=', // defaults to workstation or root org
+ orgChanged : '=' // called when selected org changes
+ },
+
+ // any reason to move this into a TT2 template?
+ template :
+ '<button type="button" class="btn btn-default dropdown-toggle"'
+ + 'data-toggle="dropdown">'
+ + '<span style="padding-right: 5px;">{{getSelectedName()}}</span>'
+ + '<span class="caret"></span>'
+ + '</button>'
+ + '<ul class="dropdown-menu">'
+ + '<li ng-repeat="org in orgList">'
+ + '<a href="" ng-click="orgChanged(org)"'
+ + 'style="padding-left: {{org.depth * 10 + 5}}px">'
+ + '{{org.shortname}}'
+ + '</a>'
+ + '</li>'
+ + '</ul>',
+
+ controller : ['$scope','$timeout','egOrg','egAuth',
+ function($scope , $timeout , egOrg , egAuth) {
+
+ // avoid linking the full fleshed tree to the scope by
+ // tossing in a flattened list.
+ $scope.orgList = egOrg.list().map(function(org) {
+ return {
+ id : org.id(),
+ shortname : org.shortname(),
+ depth : org.ou_type().depth()
+ }
+ });
+
+ $scope.getSelectedName = function() {
+ if ($scope.selected)
+ return $scope.selected.shortname();
+ }
+
+ $scope.orgChanged = function(org) {
+ $scope.selected = egOrg.get(org.id);
+ }
+
+ if (!$scope.selected) {
+ // apply a default value if none provided
+ $scope.selected =
+ egAuth.workstation() ?
+ egOrg.get(egAuth.workstation().owning_lib()) :
+ egOrg.tree();
+ }
+ }]
+ }
+})
+