<div id='staffcat-search-form'>
- <div *ngIf="!showThyself" class="row pt-1 pb-1 mb-2 pr-2">
+ <div *ngIf="canBeHidden()" class="row pt-1 pr-2">
<div class="col-lg-12 d-flex">
<div class="flex-1"></div><!-- push right -->
- <a (click)="toggleFormDisplay()" class="label-with-material-icon no-href" i18n>
- Show Search Form <span class="material-icons">unfold_more</span>
+ <a (click)="toggleFormDisplay()" class="label-with-material-icon no-href">
+ <ng-container *ngIf="hideForm()" i18n>
+ Show Search Form <span class="material-icons">unfold_more</span>
+ </ng-container>
+ <ng-container *ngIf="!hideForm()" i18n>
+ Hide Search Form <span class="material-icons">unfold_less</span>
+ </ng-container>
</a>
</div>
</div>
- <div *ngIf="showThyself" class="row pt-3 pb-3 mb-3">
+ <div *ngIf="!hideForm()" class="row pt-3 pb-3 mb-3">
<div class="col-lg-8">
<ngb-tabset #searchTabs [activeId]="searchTab" (tabChange)="onTabChange($event)">
<ngb-tab title="Keyword Search" i18n-title id="term">
// Automatically collapse the search form on these pages
const COLLAPSE_ON_PAGES = [
- new RegExp(/catalog\/record\//),
- new RegExp(/catalog\/hold\//)
+ new RegExp(/staff\/catalog\/record\//),
+ new RegExp(/staff\/catalog\/hold\//)
];
@Component({
copyLocations: IdlObject[];
searchTab: string;
- // Display the full form if true, otherwise display the expandy.
- showThyself = true;
- showThyselfSetting = false;
+ // What does the user want us to do?
+ // On pages where we can be hidded, start out hidden, unless the
+ // user has opted to show us.
+ showSearchFormSetting = false;
constructor(
private renderer: Renderer2,
}
- toggleFormDisplay() {
- this.showThyself = !this.showThyself;
- this.store.setItem('eg.catalog.search.form.open', this.showThyself);
- }
-
ngOnInit() {
this.ccvmMap = this.cat.ccvmMap;
this.cmfMap = this.cat.cmfMap;
});
this.store.getItem('eg.catalog.search.form.open')
- .then(value => this.showThyselfSetting = value);
-
- this.router.events.subscribe(routeEvent => {
- if (routeEvent instanceof NavigationEnd) {
- this.showThyself = true;
- if (!this.showThyselfSetting) {
- COLLAPSE_ON_PAGES.forEach(pageRegex => {
- if (routeEvent.url.match(pageRegex)) {
- this.showThyself = false;
- }
- });
- }
+ .then(value => this.showSearchFormSetting = value);
+ }
+
+ // Are we on a page where the form is allowed to be collapsed.
+ canBeHidden(): boolean {
+ for (let idx = 0; idx < COLLAPSE_ON_PAGES.length; idx++) {
+ const pageRegex = COLLAPSE_ON_PAGES[idx];
+ if (this.router.url.match(pageRegex)) {
+ return true;
}
- });
+ }
+ return false;
+ }
+
+ hideForm(): boolean {
+ return this.canBeHidden() && !this.showSearchFormSetting;
+ }
+
+ toggleFormDisplay() {
+ this.showSearchFormSetting = !this.showSearchFormSetting;
+ this.store.setItem('eg.catalog.search.form.open', this.showSearchFormSetting);
}
ngAfterViewInit() {