[sidebar] Update existing organizational unit
[u/erikhf/frm.git] / src / components / sidebar / sidebar.ts
CommitLineData
c1cf798d 1import {Component, NgFor, NgIf, NgModel, CORE_DIRECTIVES,FORM_DIRECTIVES} from 'angular2/angular2';
9bdb78d0 2import {Http, Headers} from 'angular2/http';
ebe03648
EHF
3
4
5@Component({
6 selector: 'mou-sidebar',
9bdb78d0
EHF
7 directives: [CORE_DIRECTIVES, FORM_DIRECTIVES, NgFor, NgModel, NgIf],
8 templateUrl: './components/sidebar/sidebar.html',
9 styles: [`
10 .ng-valid[required] {
11 border-left: 5px solid #42A948; /* green */
12 }
13 .ng-invalid {
14 border-left: 5px solid #a94442; /* red */
15 }
16 `]
ebe03648
EHF
17})
18export class Sidebar {
9bdb78d0
EHF
19 http:Http;
20 activeOrgUnit:Object;
21 editmode:boolean;
22 submitted = false;
ebe03648 23
9bdb78d0 24 constructor(http:Http) {
ebe03648 25 this.http = http;
9ce2e2a9 26 this.editmode = false;
c1cf798d
EHF
27 }
28
9bdb78d0 29 update(orgunitId) {
c1cf798d
EHF
30 console.log(orgunitId);
31 this.http.get(dhisAPI + "/api/organisationUnits/" + orgunitId)
32 .map(res => res.json())
33 .subscribe(res => this.activeOrgUnit = res)
ebe03648 34 }
9ce2e2a9 35
9bdb78d0
EHF
36 onSubmit() {
37 this.editmode = false;
38
39 let headers = new Headers();
40 headers.append('Accept', 'application/json');
41 headers.append('Content-Type', 'application/json');
42
43 if (this.activeOrgUnit.id) {
44 this.http.put(dhisAPI + "/api/organisationUnits/" + this.activeOrgUnit.id, JSON.stringify(this.activeOrgUnit), {
45 headers: headers
46 })
47 .map(res => res.json())
48 .subscribe(res => console.log(res));
49 }
50
9ce2e2a9 51 }
ebe03648
EHF
52}
53