Project

General

Profile

1
import {Component, Input, Output, EventEmitter} from '@angular/core';
2
import {Observable}       from 'rxjs/Observable';
3
import {RouterHelper} from '../../utils/routerHelper.class';
4
import {Router} from '@angular/router';
5

    
6
@Component({
7
    selector: 'search-form',
8
    template: `
9

    
10
        <form [class]="(isDisabled)?'uk-margin uk-text-center uk-margin-top uk-disabled':'uk-margin uk-text-center uk-margin-top'">
11
                 <input type="text" class="uk-input  uk-width-1-2" [placeholder]="placeholderText" aria-describedby="sizing-addon2"  [(ngModel)]="keyword"  name="keyword" >
12
                    <button *ngIf="!link" (click)="keywordChanged()"  type="submit" class=" uk-button uk-button-default">
13
                    <span class="uk-icon">
14
                    <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>
15
                    </span>Search
16
                  </button>
17
                  <button *ngIf="link"  class=" uk-button uk-button-default" (click)="goTo()"  type="submit" >
18
                    <span class="uk-icon">
19
                    <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>
20
                    </span>Search
21
                  </button>
22
        </form>
23
    `
24
})
25

    
26
export class SearchFormComponent {
27
    @Input() isDisabled: boolean = false;
28
    @Input() keyword: string = '';
29
    @Input() generalSearch: boolean = false;
30
    @Input() placeholderText: string = "Type keywords";
31
    @Input() link: boolean = false;
32
    public routerHelper:RouterHelper = new RouterHelper();
33

    
34
    @Output() keywordChange  = new EventEmitter();
35

    
36
    constructor (private _router:Router) {
37
     }
38

    
39
    ngOnInit() {
40

    
41
    }
42

    
43
    keywordChanged() {
44
        console.info("inside form: "+this.keyword);
45
        this.keywordChange.emit({
46
            value: this.keyword
47
        });
48
    }
49
    goTo() {
50
      this._router.navigate(['/search/find'], { queryParams: this.routerHelper.createQueryParam('keyword',this.keyword) });
51
    }
52
}
(19-19/36)