// optional name of settings key for persisting
// the last selected org unit
- stickySetting : '@'
+ stickySetting : '@',
+
+ // if set to true alphabetize org list
+ alphabetizedOrgs : '@'
},
templateUrl : './share/t_org_select',
return " ".repeat(org.ou_type().depth()) + org.shortname();
}
+ // creates list of $scope.shortNames from orgArray provided
+ function createShortNames(orgArray) {
+ $scope.shortNames = orgArray
+ .filter(function(org) {
+ return !(
+ $scope.hiddenTest &&
+ $scope.hiddenTest(org.id())
+ );
+ }).map(function(org) {
+ return formatName(org);
+ });
+ }
+
// avoid linking the full fleshed tree to the scope by
// tossing in a flattened list.
// --
}
).then(
function() {
-
- $scope.selecteName = '';
-
- $scope.shortNames = egCore.org.list()
- .filter(function(org) {
- return !(
- $scope.hiddenTest &&
- $scope.hiddenTest(org.id())
- );
- }).map(function(org) {
- return formatName(org);
- });
+ $scope.selectedName = '';
+
+ if ($scope.alphabetizedOrgs === "true") {
+ if (!$scope.allOrgsSorted) {
+ $scope.allOrgsSorted = [];
+ recursiveAddAndSort(egCore.org.root());
+
+ function recursiveAddAndSort(org) {
+ $scope.allOrgsSorted.push(org);
+ currentOrgChildren = org.children().sort(function(a, b) {
+ return a.shortname() < b.shortname() ? -1 : 1
+ });
+ currentOrgChildren.forEach(function (org) {
+ recursiveAddAndSort(org);
+ });
+ }
+ }
+ if ($scope.allOrgsSorted.length) {
+ createShortNames($scope.allOrgsSorted);
+ }
+ } else {
+ createShortNames(egCore.org.list());
+ }
// Apply default values
-
if ($scope.stickySetting) {
var orgId = egCore.hatch.getLocalItem($scope.stickySetting);
if (orgId) {