lp1724019 offline working locations unsorted user/mrisher/lp1724019-offline-location-dropdown-orgs
authorMike Risher <mrisher@catalyte.io>
Sun, 8 Mar 2020 19:31:43 +0000 (19:31 +0000)
committerMike Risher <mrisher@catalyte.io>
Tue, 10 Mar 2020 22:56:15 +0000 (22:56 +0000)
The offline working locations are not sorted alphabetically. This
fix involves putting all orgs in alphabetical order and preserving
org hierarchy. This change is only being applied to the offline
working locations dropdown of orgs.

Signed-off-by: Mike Risher <mrisher@catalyte.io>
 Changes to be committed:
modified:   Open-ILS/src/templates/staff/offline-interface.tt2
modified:   Open-ILS/web/js/ui/default/staff/services/ui.js

Open-ILS/src/templates/staff/offline-interface.tt2
Open-ILS/web/js/ui/default/staff/services/ui.js

index dc7b56b..eb8ca80 100644 (file)
@@ -18,7 +18,8 @@
       </div>
       <div class="input-group-addon"><b>[% l('Working location') %]</b></div>
       <div class="input-group-addon">
-        <eg-org-selector sticky-setting="eg.org.offline_location" selected="org"></eg-org-selector>
+        <eg-org-selector sticky-setting="eg.org.offline_location" selected="org"
+          alphabetized-orgs="true"></eg-org-selector>
       </div>
       <div class="input-group-addon">
         <button
index f8f7cd1..fb25a56 100644 (file)
@@ -1081,7 +1081,10 @@ function($uibModal , $interpolate , egCore) {
 
             // 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',
@@ -1096,6 +1099,19 @@ function($uibModal , $interpolate , egCore) {
                 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.
             // --
@@ -1112,21 +1128,31 @@ function($uibModal , $interpolate , egCore) {
                 }
             ).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) {