lp1739277 AngJS Org Select Class Callback
authorKyle Huckins <khuckins@catalyte.io>
Wed, 31 Jul 2019 16:34:05 +0000 (16:34 +0000)
committerKyle Huckins <khuckins@catalyte.io>
Tue, 13 Aug 2019 15:22:05 +0000 (15:22 +0000)
- Refactor Org Selector to contain org ID information in addition to
shortname.
- Add OrgClassCallback support to AngJS egOrgSelector, featuring an
array of ids and a function returning a CSS key/value pair.
- Implement OrgClassCallback in the AngJS Catalog Holdings View UI.

Signed-off-by: Kyle Huckins <khuckins@catalyte.io>
 Changes to be committed:
modified:   Open-ILS/src/templates/staff/cat/catalog/t_holdings.tt2
modified:   Open-ILS/src/templates/staff/share/t_org_select.tt2
modified:   Open-ILS/web/js/ui/default/staff/cat/catalog/app.js
modified:   Open-ILS/web/js/ui/default/staff/services/ui.js

Open-ILS/src/templates/staff/cat/catalog/t_holdings.tt2
Open-ILS/src/templates/staff/share/t_org_select.tt2
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js
Open-ILS/web/js/ui/default/staff/services/ui.js

index d30ad1a..060ec31 100644 (file)
@@ -4,7 +4,9 @@
     <div class="col-md-3">
       <div class="input-group">
         <span class="input-group-addon">[% l('Show holdings at or below') %]</span>
-        <eg-org-selector selected="holdings_ou" onchange="holdings_ou_changed" sticky-setting="cat.holdings_view_ou"></eg-org-selector>
+        <eg-org-selector selected="holdings_ou" onchange="holdings_ou_changed"
+            sticky-setting="cat.holdings_view_ou" org-class-callback="orgClassCallback">
+        </eg-org-selector>
       </div>
     </div>
   </div>
index 613c28d..26454ef 100644 (file)
@@ -1,7 +1,8 @@
 <span>
   <script type="text/ng-template" id="org-select-entry.html">
-    <a ng-class="{disabled : $parent.$parent.$parent.orgIsDisabled(match.label)}">
-      <span ng-bind-html="match.label | uibTypeaheadHighlight:query"></span>
+    <a ng-disabled="$parent.$parent.$parent.orgIsDisabled(match.label)">
+      <span ng-bind-html="match.label.label | uibTypeaheadHighlight:query"
+        ng-style="$parent.$parent.$parent.orgClassCallback.apply(match.label.orgId, $parent.$parent.$parent.orgClassCallback.orgs)"></span>
     </a>
   </script>
 
index c853cb8..ffeee8e 100644 (file)
@@ -1204,6 +1204,26 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         $scope.holdings_cb_changed(item.checkbox,item.checked);
     }
 
+    $scope.orgClassCallback =  {
+        apply: function(id, orgs) {
+            if (orgs.includes(id)) return {'font-weight': 'bold'};
+            return {};
+        },
+        orgs: []
+    };
+
+    egCore.net.request(
+        'open-ils.search',
+        'open-ils.search.biblio.copy_counts.retrieve.staff',
+        $scope.record_id
+    ).then(function(res) {
+        if (res) {
+            angular.forEach(res, function(copy_count) {
+                $scope.orgClassCallback.orgs.push(copy_count[0]);
+            });
+        }
+    });
+
     function gatherSelectedHoldingsIds () {
         var cp_id_list = [];
         angular.forEach(
index 0fe9918..a273913 100644 (file)
@@ -1081,7 +1081,12 @@ function($uibModal , $interpolate , egCore) {
 
             // optional name of settings key for persisting
             // the last selected org unit
-            stickySetting : '@'
+            stickySetting : '@',
+
+            // Function which should return a string value representing
+            // a CSS class name to use for styling each org unit label
+            // in the selector.
+            orgClassCallback : '='
         },
 
         templateUrl : './share/t_org_select',
@@ -1122,7 +1127,7 @@ function($uibModal , $interpolate , egCore) {
                             $scope.hiddenTest(org.id())
                         );
                     }).map(function(org) {
-                        return formatName(org);
+                        return {label: formatName(org), orgId: org.id()};
                     });
     
                     // Apply default values
@@ -1133,7 +1138,7 @@ function($uibModal , $interpolate , egCore) {
                             var org = egCore.org.get(orgId);
                             if (org) {
                                 $scope.selected = org;
-                                $scope.selectedName = org.shortname();
+                                $scope.selectedName = {label: formatName(org), orgId: org.id()};
                             }
                         }
                     }
@@ -1141,7 +1146,7 @@ function($uibModal , $interpolate , egCore) {
                     if (!$scope.selected && !$scope.nodefault && egCore.auth.user()) {
                         var org = egCore.org.get(egCore.auth.user().ws_ou());
                         $scope.selected = org;
-                        $scope.selectedName = org.shortname();
+                        $scope.selectedName = {label: formatName(org), orgId: org.id()};
                     }
     
                     fire_orgsel_onchange(); // no-op if nothing is selected
@@ -1185,20 +1190,24 @@ function($uibModal , $interpolate , egCore) {
 
             $scope.compare = function(shortName, inputValue) {
                 return inputValue === secretEmptyKey ||
-                    (shortName || '').toLowerCase().trim()
+                    (shortName.label || '').toLowerCase().trim()
                         .indexOf((inputValue || '').toLowerCase().trim()) > -1;
             }
 
             // Trim leading tree-spaces before displaying selected value
             $scope.formatDisplayName = function(shortName) {
-                return ($scope.selectedName || '').trim();
+                if ($scope.selectedName && $scope.selectedName.label) {
+                    return $scope.selectedName.label.trim();
+                } else {
+                    return '';
+                }
             }
 
             $scope.orgIsDisabled = function(shortName) {
                 if ($scope.alldisabled === 'true') return true;
                 if (shortName && $scope.disableTest) {
                     var org = egCore.org.list().filter(function(org) {
-                        return org.shortname() === shortName.trim();
+                        return org.shortname() === shortName.label.trim();
                     })[0];
 
                     return org && $scope.disableTest(org.id());
@@ -1215,7 +1224,7 @@ function($uibModal , $interpolate , egCore) {
                 if ($scope.selectedName && 
                     !$scope.orgIsDisabled($scope.selectedName)) {
                     $scope.selected = egCore.org.list().filter(function(org) {
-                        return org.shortname() === $scope.selectedName.trim()
+                        return org.shortname() === $scope.selectedName.label.trim()
                     })[0];
                 } else {
                     $scope.selected = null;
@@ -1234,9 +1243,9 @@ function($uibModal , $interpolate , egCore) {
             function watch_external_changes() {
                 dewatcher = $scope.$watch('selected', function(newVal, oldVal) {
                     if (newVal) {
-                        $scope.selectedName = newVal.shortname();
+                        $scope.selectedName = {label: formatName(newVal), orgId: newVal.id()};
                     } else {
-                        $scope.selectedName = '';
+                        $scope.selectedName = {};
                     }
                 });
             }