From 51ceeafb499e446452d456d68b7814da9c50d268 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 30 Apr 2014 12:42:32 -0400 Subject: [PATCH] new directive Signed-off-by: Bill Erickson --- Open-ILS/web/js/ui/default/staff/services/ui.js | 64 ++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/Open-ILS/web/js/ui/default/staff/services/ui.js b/Open-ILS/web/js/ui/default/staff/services/ui.js index 4eebe7d36f..44a466ea62 100644 --- a/Open-ILS/web/js/ui/default/staff/services/ui.js +++ b/Open-ILS/web/js/ui/default/staff/services/ui.js @@ -1,7 +1,7 @@ /** * UI tools and directives. */ -angular.module('egUiMod', ['ui.bootstrap']) +angular.module('egUiMod', ['egCoreMod', 'ui.bootstrap']) /** @@ -133,3 +133,65 @@ function($timeout, $parse) { 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 : + '' + + '', + + 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(); + } + }] + } +}) + -- 2.11.0