tidy up handling of field change and clearing org_unit field
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 15 May 2020 20:04:56 +0000 (16:04 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 15 May 2020 20:04:56 +0000 (16:04 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.html
Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.ts

index 20203f2..5c0c830 100644 (file)
@@ -27,8 +27,9 @@
   </div>
   <div class="row mb-1" *ngFor="let t of searchTerms; let idx=index" [hidden]="!showForm">
     <div class="col-lg-3">
-      <select class="form-control" id="selected-search-term" [ngModelOptions]="{standalone: true}" [(ngModel)]="t.field"
-        (change)="clearSearchTerm(t)">
+      <select class="form-control" id="selected-search-term" [ngModelOptions]="{standalone: true}" [ngModel]="t.field"
+        (ngModelChange)="old = t.field; t.field = $event"
+        (change)="clearSearchTerm(t, old)">
         <option disabled="disabled" i18n>Select Search Field</option>
         <optgroup *ngFor="let g of hints" label="{{availableSearchFields[g]['__label']}}">
           <option *ngFor="let o of availableSearchFields[g]['__fields']" value="{{g}}:{{o}}">
index afb5adf..a420101 100644 (file)
@@ -138,15 +138,34 @@ export class AcqSearchFormComponent implements OnInit, AfterViewInit, OnChanges
     delSearchTerm(index: number) {
         if (this.searchTerms.length < 2) {
             this.clearSearchTerm(this.searchTerms[0]);
+            // special case for org_unit
+            if (this.searchTerms[0].field && this.searchTermDatatypes[this.searchTerms[0].field] == 'org_unit') {
+                this.searchTerms = [{ field: this.searchTerms[0].field, op: this.searchTerms[0].op, value1: '', value2: ''}];
+            }
         } else {
             this.searchTerms.splice(index, 1);
         }
     }
-    clearSearchTerm(term: AcqSearchTerm) {
-        term.value1 = '';
-        term.value2 = '';
+    clearSearchTerm(term: AcqSearchTerm, old?) {
+        if (!old) {
+            term.value1 = '';
+            term.value2 = '';
+        }
         term.is_date = false;
 
+        // work around fact that org selector doesn't implement ngModel
+        if (old && this.searchTermDatatypes[old] == this.searchTermDatatypes[term.field] && this.searchTermDatatypes[old] == 'org_unit') {
+            // don't change values if we're moving from one
+            // org_unit field to another
+        } else {
+            term.value1 = '';
+            term.value2 = '';
+        }
+
+        // handle change of field type
+        if (old && this.searchTermDatatypes[old] != this.searchTermDatatypes[term.field]) {
+            term.op = '';
+        }
         if (term.field.startsWith('acqlia:') && term.op === '') {
             // default operator for line item attributes should be "contains"
             term.op = '__fuzzy';