lp1751356 Typing to select with item stat cat dropdowns user/mrisher/lp1751356-item-stat-cats-combobox
authorMike Risher <mrisher@catalyte.io>
Tue, 19 May 2020 16:35:49 +0000 (16:35 +0000)
committerMike Risher <mrisher@catalyte.io>
Mon, 14 Dec 2020 22:43:30 +0000 (22:43 +0000)
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

Open-ILS/src/templates/staff/cat/volcopy/t_attr_edit.tt2
Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js

index 7168f6a..80ce31e 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 501a9c1..27e05ea 100644 (file)
@@ -1286,7 +1286,21 @@ 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 (statcat.sc_selected_text === '<NONE>') {
+                        $scope.working.statcats[id] = null;
+                    } else 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
@@ -1392,8 +1406,20 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                 delete $scope.working.MultiMap[k];
             });
             egCore.hatch.setItem('cat.copy.last_template', n);
+            angular.forEach($scope.statcats, function(statcat) {
+                if ($scope.working.statcats[statcat.id()]) {
+                    angular.forEach(statcat.entries(), function (entry) {
+                        if (entry.id() === $scope.working.statcats[statcat.id()]) {
+                            $scope.working.statcats[statcat.id()] = entry.id();
+                            statcat.sc_selected_text = entry.value();
+                        }
+                    })
+                } else {
+                    statcat.sc_selected_text = undefined;
+                    $scope.working.statcats[statcat.id()] = undefined;
+                }
+            });
         }
-
         $scope.copytab = 'working';
         $scope.tab = 'edit';
         $scope.summaryRecord = null;
@@ -1829,6 +1855,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;
@@ -1899,6 +1931,11 @@ 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();
+                                    });
+                                    s.sc_entry_values.unshift('<NONE>');
+                                    if (!s.sc_selected_text) s.sc_selected_text = '';
                                     createStatcatUpdateWatcher(s.id());
                                 });
                                 $scope.in_item_select = false;
@@ -2080,6 +2117,7 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
 
         $scope.workingSaveAndExit = function () {
             $scope.workingToComplete();
+            $scope.removeNullStatCats();
             $scope.saveAndExit();
         }
 
@@ -2087,6 +2125,17 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
             $scope.saveCompletedCopies(true);
         }
 
+        $scope.removeNullStatCats = function () {
+            $scope.completed_copies.forEach(cp => {
+                var sces = cp.stat_cat_entries();
+                sces = sces.filter(entry => {
+                    var id = entry.stat_cat();
+                    return ($scope.working.statcats[id] !== null);
+                });
+                cp.stat_cat_entries(sces);
+            });
+        }
+
     }
 
     $scope.copy_notes_dialog = function(copy_list) {
@@ -2459,6 +2508,19 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                         }
                     });
                     $scope.template_name = '';
+                    angular.forEach($scope.statcats, function(statcat) {
+                        if ($scope.working.statcats[statcat.id()]) {
+                            angular.forEach(statcat.entries(), function (entry) {
+                                if (entry.id() === $scope.working.statcats[statcat.id()]) {
+                                    $scope.working.statcats[statcat.id()] = entry.id();
+                                    statcat.sc_selected_text = entry.value();
+                                }
+                            })
+                        } else {
+                            statcat.sc_selected_text = undefined;
+                            $scope.working.statcats[statcat.id()] = undefined;
+                        }
+                    })
                 }
 
                 $scope.deleteTemplate = function (n) {
@@ -2475,6 +2537,14 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                 $scope.saveTemplate = function (n) {
                     if (n) {
                         var tmpl = {};
+
+                        angular.forEach($scope.statcats, function(statcat) {
+                            angular.forEach(statcat.entries(), function (entry) {
+                                if (entry.value() === statcat.sc_selected_text) {
+                                    $scope.working.statcats[statcat.id()] = entry.id();
+                                }
+                            })
+                        })
             
                         angular.forEach($scope.working, function (v,k) {
                             if (angular.isObject(v)) { // we'll use the pkey
@@ -2632,6 +2702,9 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                             $scope.working.statcats = {};
 
                         $scope.working.statcats[s.id()] = undefined;
+                        s.sc_entry_values = s.entries().map(entry => {
+                            return entry.value();
+                        });
                         createStatcatUpdateWatcher(s.id());
                     });
                 });