merge faardih
authorRoza Moustafa <roza.92m@hotmail.com>
Sun, 6 Dec 2015 16:37:51 +0000 (17:37 +0100)
committerRoza Moustafa <roza.92m@hotmail.com>
Sun, 6 Dec 2015 16:37:51 +0000 (17:37 +0100)
1  2 
src/components/search/search.html
src/components/search/search.ts

                      value=""/>
  
  
-             <!--<button class="exitsearch" id="exitsearch" (click)="emptyByClick()">
-           &cross; </button>-->
              <button type="button" class="knapp col-md-2" (click)="toggle()"
 -                    onclick="$('#ownershipSelector, #typeSelector, #locationSelector').prop('selectedIndex',0);"
                      data-toggle="collapse" data-target="#dropdown-menu">
                  {{ visible ? '&xdtri;' : '&cross;' }}
              </button>
          </div>
      </form>
  
+     <div class="row">
  <span [hidden]="hideDiv()">
-     <div class="divresult" id="divresult" [hidden]="checkOrgunits()">
-         <ul id="d" class="dropdown-menu result">
-             <li id="c" *ng-for="#orgunit of filteredOrgunits" id="orglist" (click)="getMoreInfo(orgunit)">
-                 <a id="left-menu" href="#">{{orgunit.name}}<br/><span>{{orgunit.lastUpdated}}</span></a>
+     <div class="divresult col-md-10" id="divresult" [hidden]="checkOrgunits()">
+         <ul class="dropdown-menu result">
+             <li><button type="button" class="btn btn-default emptyresult" (click)="emptyByClick()">
+                 <span class="glyphicon glyphicon-remove"></span></button></li>
+             <li *ng-for="#orgunit of filteredOrgunits" id="orglist" (click)="getMoreInfo(orgunit)">
+                 <a id="left-menu" href="#">{{orgunit.name}}</a>
              </li>
 +            <li *ng-if="filteredOrgunits.length == 0">
 +                No matching results
 +            </li>
          </ul>
      </div>
  </span>
-     <ul id="dropdown-menu" class="dropdown-menu">
-         <li><select class="form-control filtervalg" id="ownershipSelector" (click)="setFilter()">
-         </select></li>
-         <li><select class="form-control filtervalg" id="typeSelector" (click)="setFilter()">
-         </select></li>
-         <li><select class="form-control filtervalg" id="locationSelector" (click)="setFilter()">
-         </select></li>
+         <div class="row">
+            <span [hidden]="!hideDiv()">
+                 <div class="divhelp col-md-8"></div>
+            </span>
+ <div id="dropdowndiv" class="btn-group collapse col-md-2">
+     <ul id="dropdown-menu" role="menu" class="dropdown-menu meny">
+         <li>Facility</li>
+         <li class="dropdown-header">Ownership</li>
+         <li>
+             <select class="form-control filtervalg" id="ownershipSelector" (click)="setFilter()"></select>
+         </li>
+         <li class="dropdown-header">Type</li>
+         <li>
+             <select class="form-control filtervalg" id="typeSelector" (click)="setFilter()"></select>
+         </li>
+         <li class="divider"></li>
+         <li>Location</li>
+         <li class="dropdown-header">Rural/Urban</li>
+         <li>
+             <select class="form-control filtervalg" id="locationSelector" (click)="setFilter()"></select>
+         </li>
      </ul>
  
  </div>
  
+         </div>
+ </div>
  
  
  
@@@ -14,18 -14,18 +14,19 @@@ declare var zone: Zone
      styleUrls: ['./components/search/search.css']
  })
  export class Search {
-     orgunits:Array<any> = [];
-     filteredOrgunits:Array<any> = [];
-     loading:boolean = false;
-     groups:Array<any> = [];
-     groupSet:Array<any> = [];
-     ownershipSelector:any;
-     typeSelector:any;
-     locationSelector:any;
-     option:any;
-     searchBar:any;
-     filterset:boolean = false;
-     emptySearch:any;
+     orgunits: Array<any> = [];
+     filteredOrgunits: Array<any> = [];
+     loading: boolean = false;
+     groups: Array<any> = [];
+     groupSet: Array<any> = [];
+     ownershipSelector: any;
+     typeSelector: any;
+     locationSelector: any;
+     option: any;
+     searchBar: any;
+     filterset: boolean = false;
++    emptySearch: any;
  
      constructor(public http:Http) {
          this.newsearch = new EventEmitter();
  
      toggle() {
          this.visible = !this.visible;
 -        //this.getUnitGroupSets();
 +        if (this.visible) {
 +            this.resetSelector();
 +        }
 +    }
 +
 +    resetSelector(){
 +        this.ownershipSelector.selectedIndex = 0;
 +        this.typeSelector.selectedIndex = 0;
 +        this.locationSelector.selectedIndex = 0;
 +        this.checkOrgunits();
      }
  
 -    hideDiv(){
 -        if(livesearch.value == "")
 +    hideDiv() {
 +        if (this.searchBar.value == "")
              return true;
++
      }
  
-     emptyByClick() {
-         return this.emptySearch = document.getElementById("divresult").style.visibility = "hidden";
+     emptyByClick(){
+         this.orgunits = [];
+         return document.getElementById("myForm").reset();
      }
  
 -    getUnitGroupSets(){
 +    getUnitGroupSets() {
          this.http.get(dhisAPI + "/api/organisationUnitGroupSets")
 -        .map(res => res.json())
 -        .map(res => res.organisationUnitGroupSets)
 -        .subscribe(
 -            zone.bind( res =>{
 -                this.setOptionHeader(this.ownershipSelector, res[0].name);
 -                this.setOptionHeader(this.typeSelector, res[1].name);
 -                this.setOptionHeader(this.locationSelector, res[2].name);
 -
 -                for(var i = 0; i < res.length; i++) {
 -                    this.http.get(res[i].href)
 -                    .map(result => result.json())
 -                    .subscribe(
 -                        zone.bind(result => {
 -                            if(result.displayName == "Facility Ownership"){
 -                                for(var j = 0; j < result.organisationUnitGroups.length; j++) {
 -                                    this.setOption(this.ownershipSelector, result.organisationUnitGroups[j].name);
 -                                }
 -                            }
 -                            else if(result.displayName == "Facility Type"){
 -                                for(var j = 0; j < result.organisationUnitGroups.length; j++) {
 -                                    this.setOption(this.typeSelector, result.organisationUnitGroups[j].name);
 -                                }
 -                            }
 -                            else if(result.displayName == "Location Rural/Urban"){
 -                                for(var j = 0; j < result.organisationUnitGroups.length; j++) {
 -                                    this.setOption(this.locationSelector, result.organisationUnitGroups[j].name);
 -                                }
 -                            }
 -                    }));
 -                }
 -            })
 -        )
 +            .map(res => res.json())
 +            .map(res => res.organisationUnitGroupSets)
 +            .subscribe(
 +                zone.bind(res => {
 +                    this.setOptionHeader(this.ownershipSelector, res[0].name);
 +                    this.setOptionHeader(this.typeSelector, res[1].name);
 +                    this.setOptionHeader(this.locationSelector, res[2].name);
 +
 +                    for (var i = 0; i < res.length; i++) {
 +                        this.http.get(res[i].href)
 +                            .map(result => result.json())
 +                            .subscribe(
 +                                zone.bind(result => {
 +                                    if (result.displayName == "Facility Ownership") {
 +                                        for (var j = 0; j < result.organisationUnitGroups.length; j++) {
 +                                            this.setOption(this.ownershipSelector, result.organisationUnitGroups[j].name);
 +                                        }
 +                                    }
 +                                    else if (result.displayName == "Facility Type") {
 +                                        for (var j = 0; j < result.organisationUnitGroups.length; j++) {
 +                                            this.setOption(this.typeSelector, result.organisationUnitGroups[j].name);
 +                                        }
 +                                    }
 +                                    else if (result.displayName == "Location Rural/Urban") {
 +                                        for (var j = 0; j < result.organisationUnitGroups.length; j++) {
 +                                            this.setOption(this.locationSelector, result.organisationUnitGroups[j].name);
 +                                        }
 +                                    }
 +                                }));
 +                    }
 +                })
 +            )
      }
  
 -    setOptionHeader(selector, value){
 +    setOptionHeader(selector, value) {
          this.option = document.createElement("option");
-         this.option.text = "-- " + value + " --";
+         this.option.text = "All";
          this.option.value = "";
          selector.appendChild(this.option);
      }