53 lines
2.3 KiB
TypeScript
53 lines
2.3 KiB
TypeScript
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
|
import {Observable} from 'rxjs/Observable';
|
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
|
import {Router} from '@angular/router';
|
|
|
|
@Component({
|
|
selector: 'search-form',
|
|
template: `
|
|
|
|
<form [class]="(isDisabled)?'uk-margin uk-text-center uk-margin-top uk-disabled':'uk-margin uk-text-center uk-margin-top'">
|
|
<input type="text" class="uk-input uk-width-1-2" [placeholder]="placeholderText" aria-describedby="sizing-addon2" [(ngModel)]="keyword" name="keyword" >
|
|
<button *ngIf="!link" (click)="keywordChanged()" type="submit" class=" uk-button uk-button-default">
|
|
<span class="uk-icon">
|
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="search" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9" cy="9" r="7"></circle><path fill="none" stroke="#000" stroke-width="1.1" d="M14,14 L18,18 L14,14 Z"></path></svg>
|
|
</span>Search
|
|
</button>
|
|
<button *ngIf="link" class=" uk-button uk-button-primary" (click)="goTo()" type="submit" >
|
|
<span class="uk-icon">
|
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="search" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9" cy="9" r="7"></circle><path fill="none" stroke="#000" stroke-width="1.1" d="M14,14 L18,18 L14,14 Z"></path></svg>
|
|
</span>Search
|
|
</button>
|
|
</form>
|
|
`
|
|
})
|
|
|
|
export class SearchFormComponent {
|
|
@Input() isDisabled: boolean = false;
|
|
@Input() keyword: string = '';
|
|
@Input() generalSearch: boolean = false;
|
|
@Input() placeholderText: string = "Type keywords";
|
|
@Input() link: boolean = false;
|
|
public routerHelper:RouterHelper = new RouterHelper();
|
|
|
|
@Output() keywordChange = new EventEmitter();
|
|
|
|
constructor (private _router:Router) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
}
|
|
|
|
keywordChanged() {
|
|
console.info("inside form: "+this.keyword);
|
|
this.keywordChange.emit({
|
|
value: this.keyword
|
|
});
|
|
}
|
|
goTo() {
|
|
this._router.navigate(['/search/find'], { queryParams: this.routerHelper.createQueryParam('keyword',this.keyword) });
|
|
}
|
|
}
|