<div>
<ul id="dropdown-menu" class="dropdown-menu">
<li><select class="form-control filtervalg" id="ownershipSelector" (click)="setFilter()">
- <!--<option value="">-- All Facility Ownerships --</option>-->
- <option *ng-for="#owner of facilityOwnership" value={{owner}}>{{owner}}</option>
- <!--<option value="Mission">Mission</option>
- <option value="NGO">NGO</option>
- <option value="Private Clinic">Private Clinic</option>
- <option value="Public facilities">Public facilities</option>-->
+
</select></li>
<li><select class="form-control filtervalg" id="typeSelector" (click)="setFilter()">
- <option value="">-- All Facility Types --</option>
- <option value="CHC">CHC</option>
- <option value="CHP">CHP</option>
- <option value="Clinic">Clinic</option>
- <option value="Hospital">Hospital</option>
- <option value="MCHP">MCHP</option>
+
</select></li>
<li><select class="form-control filtervalg" id="locationSelector" (click)="setFilter()">
- <option value="">-- All locations --</option>
- <option value="Rural">Rural</option>
- <option value="Urban">Urban</option>
+
</select></li>
</ul>
export class Search {
orgunits: Array<any> = [];
loading: boolean = false;
- facilityType: Array<any> = [];
- facilityOwnership: Array<any> = [];
- facilityLocation: Array<any> = [];
groups: Array<any> = [];
groupSet: Array<any> = [];
counter: number = 0;
+ ownernshipSelector: any;
+ typeSelector: any;
+ locationSelector: any;
+ option: any;
+ searchBar: any;
constructor(public http:Http) {
this.newsearch = new EventEmitter();
this.visible = true;
//this.getFilterGroups();
this.getUnitGroupSets();
-
+ this.ownernshipSelector = document.getElementById("ownershipSelector");
+ this.typeSelector = document.getElementById("typeSelector");
+ this.locationSelector = document.getElementById("locationSelector");
+ this.searchBar = document.getElementById("livesearch");
+ this.ownernshipSelector.addEventListener("click", this.testFilter);
}
getMoreInfo(orgunit) {
//this.getUnitGroupSets();
}
+
getUnitGroupSets(){
this.http.get(dhisAPI + "/api/organisationUnitGroupSets")
.map(res => res.json())
.map(res => res.organisationUnitGroupSets)
.subscribe(
zone.bind( res =>{
- this.facilityOwnership .push("-- " + res[0].name + " --");
- this.facilityType.push("-- " + res[1].name + " --");
- this.facilityLocation.push("-- " + res[2].name + " --");
-
+ this.setOption("-- " + res[0].name + " --");
+ this.option.value = "";
+ this.ownernshipSelector.appendChild(this.option);
+ this.setOption("-- " + res[1].name + " --");
+ this.option.value = "";
+ this.typeSelector.appendChild(this.option);
+ this.setOption("-- " + res[2].name + " --");
+ this.option.value = "";
+ this.locationSelector.appendChild(this.option);
for(var i = 0; i < res.length; i++) {
this.http.get(res[i].href)
.map(result => result.json())
- .map(result => result.organisationUnitGroups)
.subscribe(
zone.bind(result => {
- if(this.facilityOwnership.length == 1){
- for(var j = 0; j < result.length; j++) {
- this.facilityOwnership.push(result[j].name);
+ if(result.displayName == "Facility Ownership"){
+ for(var j = 0; j < result.organisationUnitGroups.length; j++) {
+ this.setOption(result.organisationUnitGroups[j].name);
+ this.ownernshipSelector.appendChild(this.option);
}
}
- else if(this.facilityType.length == 1){
- for(var j = 0; j < result.length; j++) {
- this.facilityType.push(result[j].name);
+ else if(result.displayName == "Facility Type"){
+ for(var j = 0; j < result.organisationUnitGroups.length; j++) {
+ this.setOption(result.organisationUnitGroups[j].name);
+ this.typeSelector.appendChild(this.option);
}
}
- else if(this.facilityLocation.length == 1){
- for(var j = 0; j < result.length; j++) {
- this.facilityLocation.push(result[j].name);
+ else if(result.displayName == "Location Rural/Urban"){
+ for(var j = 0; j < result.organisationUnitGroups.length; j++) {
+ this.setOption(result.organisationUnitGroups[j].name);
+ this.locationSelector.appendChild(this.option);
}
}
}));
)
}
+ setOption(value){
+ this.option = document.createElement("option");
+ this.option.text = value;
+ this.option.value = value;
+ }
+
setFilter(){
+ console.log("Dette er setFilter");
+
var text = livesearch.value;
- livesearch.value = "";
- console.log(text);
- for(var i = 0; i < text.length; i++){
+
+ //livesearch.value = "";
+ //console.log(this.searchBar.key);
+
+ /*for(var i = 0; i < text.length; i++){
livesearch.value += text.charAt(i);
- }
+ }*/
+ //this.searchBar.createEvent('keyup');
+
+ this.searchBar.focus(true);
+ }
+
+ testFilter(test){
+ console.log("Testfilter ble aktivert!");
+ console.log(test);
}
}