lp1751356 Typing to select with item stat cat dropdowns user/rogan/lp1751356_signoff
authorMike Risher <mrisher@catalyte.io>
Tue, 19 May 2020 16:35:49 +0000 (16:35 +0000)
committerRogan Hamby <rogan.hamby@gmail.com>
Fri, 12 Jun 2020 19:45:47 +0000 (15:45 -0400)
Stat cat dropdowns don’t show you characters as you type and doesn’t seem to work reliably. Modify them to resolve these issues.

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

Signed-off-by: Rogan Hamby <rogan.hamby@gmail.com>
Open-ILS/src/templates/staff/cat/volcopy/t_attr_edit.tt2
Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js

index 580ec61..aa2fa31 100644 (file)
     <li ng-repeat="sc in statcats | orderBy:['owner().name()','name()']" ng-if="statcat_visible(sc.owner().id())">
       <div class="bg-info"><label>{{sc.owner().name() }} : {{ sc.name()}}</label></div>
       <div ng-class="{'bg-success': working.statcats[sc.id()] !== undefined}">
-        <select class="form-control" ng-disabled="!defaults.statcats"
-          ng-change="statcatUpdate(sc.id())"
-          ng-model="working.statcats[sc.id()]"
-          ng-options="e.id() as e.value() for e in sc.entries()"
-          ng-required="sc.required() == 't' && !working.statcats_multi[sc.id()]">
-          <option value="">
-            {{ !working.statcats_multi[sc.id()] ? '[% l('&lt;NONE&gt;') %]' : '[% l('&lt;MULTIPLE&gt;') %]' }}
-          </option>
-        </select>
+        <eg-basic-combo-box list="sc.sc_entry_values" class="form-control" selected="sc.sc_selected_text" on-select="statcatUpdate(sc.id())">
+        </eg-basic-combo-box>
       </div>
       <div ng-if="hasMulti()"> </div>
     </li>
index 29bd7f0..2e0ef23 100644 (file)
@@ -1271,7 +1271,19 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
     }
 
     $scope.statcatUpdate = function (id) {
-        var newval = $scope.working.statcats[id];
+        var newval;
+
+        // use sc_selected_text to find the selected stat cat's id and update the working.statcats object with that id
+        angular.forEach($scope.statcats, function(statcat) {
+            if (statcat.id() === id) {
+                angular.forEach(statcat.entries(), function (entry) {
+                    if (entry.value() === statcat.sc_selected_text) {
+                        newval = entry.id();
+                        $scope.working.statcats[id] = entry.id();
+                    }
+                })
+            }
+        })
 
         if (typeof newval != 'undefined') {
             if (angular.isObject(newval)) { // we'll use the pkey
@@ -1814,6 +1826,12 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
 
                     if (!none && Object.keys(value_hash).length == 1) {
                         $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]];
+                        // populate stat cat combo-box with correct text
+                        angular.forEach(item.stat_cat_entries(), function (entry) {
+                            if (entry.id() === $scope.working.statcats[sc.id()]) {
+                                sc.sc_selected_text=entry.value();
+                            }
+                        });
                         $scope.working.statcats_multi[sc.id()] = false;
                     } else if (item_list.length > 1 && Object.keys(value_hash).length > 0) {
                         $scope.working.statcats[sc.id()] = undefined;
@@ -1884,6 +1902,10 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                                     if (!$scope.in_item_select) {
                                         $scope.working.statcats[s.id()] = undefined;
                                     }
+                                    s.sc_entry_values = s.entries().map(entry => {
+                                        return entry.value();
+                                    });
+                                    if (!s.sc_selected_text) s.sc_selected_text = '';
                                     createStatcatUpdateWatcher(s.id());
                                 });
                                 $scope.in_item_select = false;